daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 1 | // |
| 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.com | 733ba93 | 2011-04-14 15:03:48 +0000 | [diff] [blame] | 16 | #include <hash_map> |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 17 | |
| 18 | #include "common/angleutils.h" |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 19 | #include "libGLESv2/HandleAllocator.h" |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 20 | |
| 21 | namespace gl |
| 22 | { |
| 23 | class Buffer; |
| 24 | class Shader; |
| 25 | class Program; |
| 26 | class Texture; |
| 27 | class Renderbuffer; |
| 28 | |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame^] | 29 | enum TextureType |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 30 | { |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame^] | 31 | TEXTURE_2D, |
| 32 | TEXTURE_CUBE, |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 33 | |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame^] | 34 | TEXTURE_TYPE_COUNT |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | class ResourceManager |
| 38 | { |
| 39 | public: |
| 40 | ResourceManager(); |
| 41 | ~ResourceManager(); |
| 42 | |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 43 | void addRef(); |
| 44 | void release(); |
| 45 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 46 | 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.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame^] | 67 | void checkTextureAllocation(GLuint texture, TextureType type); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 68 | void checkRenderbufferAllocation(GLuint renderbuffer); |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 69 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 70 | private: |
| 71 | DISALLOW_COPY_AND_ASSIGN(ResourceManager); |
| 72 | |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 73 | std::size_t mRefCount; |
| 74 | |
daniel@transgaming.com | 733ba93 | 2011-04-14 15:03:48 +0000 | [diff] [blame] | 75 | typedef stdext::hash_map<GLuint, Buffer*> BufferMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 76 | BufferMap mBufferMap; |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 77 | HandleAllocator mBufferHandleAllocator; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 78 | |
daniel@transgaming.com | 733ba93 | 2011-04-14 15:03:48 +0000 | [diff] [blame] | 79 | typedef stdext::hash_map<GLuint, Shader*> ShaderMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 80 | ShaderMap mShaderMap; |
| 81 | |
daniel@transgaming.com | 733ba93 | 2011-04-14 15:03:48 +0000 | [diff] [blame] | 82 | typedef stdext::hash_map<GLuint, Program*> ProgramMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 83 | ProgramMap mProgramMap; |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 84 | HandleAllocator mProgramShaderHandleAllocator; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 85 | |
daniel@transgaming.com | 733ba93 | 2011-04-14 15:03:48 +0000 | [diff] [blame] | 86 | typedef stdext::hash_map<GLuint, Texture*> TextureMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 87 | TextureMap mTextureMap; |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 88 | HandleAllocator mTextureHandleAllocator; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 89 | |
daniel@transgaming.com | 733ba93 | 2011-04-14 15:03:48 +0000 | [diff] [blame] | 90 | typedef stdext::hash_map<GLuint, Renderbuffer*> RenderbufferMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 91 | RenderbufferMap mRenderbufferMap; |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 92 | HandleAllocator mRenderbufferHandleAllocator; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } |
| 96 | |
| 97 | #endif // LIBGLESV2_RESOURCEMANAGER_H_ |