blob: 7baab150d5e7f8ba741db66f9ec964a74573117a [file] [log] [blame]
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +00001//
2// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// ResourceManager.h : Defines the ResourceManager class, which tracks objects
8// shared by multiple GL contexts.
9
10#ifndef LIBGLESV2_RESOURCEMANAGER_H_
11#define LIBGLESV2_RESOURCEMANAGER_H_
12
13#define GL_APICALL
14#include <GLES2/gl2.h>
15
daniel@transgaming.com733ba932011-04-14 15:03:48 +000016#include <hash_map>
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000017
18#include "common/angleutils.h"
benvanik@google.com1a233342011-04-28 19:44:39 +000019#include "libGLESv2/HandleAllocator.h"
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000020
21namespace gl
22{
23class Buffer;
24class Shader;
25class Program;
26class Texture;
27class Renderbuffer;
28
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +000029enum TextureType
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000030{
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +000031 TEXTURE_2D,
32 TEXTURE_CUBE,
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000033
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +000034 TEXTURE_TYPE_COUNT
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000035};
36
37class ResourceManager
38{
39 public:
40 ResourceManager();
41 ~ResourceManager();
42
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000043 void addRef();
44 void release();
45
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000046 GLuint createBuffer();
47 GLuint createShader(GLenum type);
48 GLuint createProgram();
49 GLuint createTexture();
50 GLuint createRenderbuffer();
51
52 void deleteBuffer(GLuint buffer);
53 void deleteShader(GLuint shader);
54 void deleteProgram(GLuint program);
55 void deleteTexture(GLuint texture);
56 void deleteRenderbuffer(GLuint renderbuffer);
57
58 Buffer *getBuffer(GLuint handle);
59 Shader *getShader(GLuint handle);
60 Program *getProgram(GLuint handle);
61 Texture *getTexture(GLuint handle);
62 Renderbuffer *getRenderbuffer(GLuint handle);
63
64 void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
65
66 void checkBufferAllocation(unsigned int buffer);
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +000067 void checkTextureAllocation(GLuint texture, TextureType type);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000068 void checkRenderbufferAllocation(GLuint renderbuffer);
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000069
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000070 private:
71 DISALLOW_COPY_AND_ASSIGN(ResourceManager);
72
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000073 std::size_t mRefCount;
74
daniel@transgaming.com733ba932011-04-14 15:03:48 +000075 typedef stdext::hash_map<GLuint, Buffer*> BufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000076 BufferMap mBufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000077 HandleAllocator mBufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000078
daniel@transgaming.com733ba932011-04-14 15:03:48 +000079 typedef stdext::hash_map<GLuint, Shader*> ShaderMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000080 ShaderMap mShaderMap;
81
daniel@transgaming.com733ba932011-04-14 15:03:48 +000082 typedef stdext::hash_map<GLuint, Program*> ProgramMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000083 ProgramMap mProgramMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000084 HandleAllocator mProgramShaderHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000085
daniel@transgaming.com733ba932011-04-14 15:03:48 +000086 typedef stdext::hash_map<GLuint, Texture*> TextureMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000087 TextureMap mTextureMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000088 HandleAllocator mTextureHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000089
daniel@transgaming.com733ba932011-04-14 15:03:48 +000090 typedef stdext::hash_map<GLuint, Renderbuffer*> RenderbufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000091 RenderbufferMap mRenderbufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000092 HandleAllocator mRenderbufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000093};
94
95}
96
97#endif // LIBGLESV2_RESOURCEMANAGER_H_