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 | d4a3517 | 2011-05-11 15:36:45 +0000 | [diff] [blame] | 34 | TEXTURE_TYPE_COUNT, |
| 35 | TEXTURE_UNKNOWN |
| 36 | }; |
| 37 | |
| 38 | enum SamplerType |
| 39 | { |
| 40 | SAMPLER_PIXEL, |
| 41 | SAMPLER_VERTEX |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | class ResourceManager |
| 45 | { |
| 46 | public: |
| 47 | ResourceManager(); |
| 48 | ~ResourceManager(); |
| 49 | |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 50 | void addRef(); |
| 51 | void release(); |
| 52 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 53 | GLuint createBuffer(); |
| 54 | GLuint createShader(GLenum type); |
| 55 | GLuint createProgram(); |
| 56 | GLuint createTexture(); |
| 57 | GLuint createRenderbuffer(); |
| 58 | |
| 59 | void deleteBuffer(GLuint buffer); |
| 60 | void deleteShader(GLuint shader); |
| 61 | void deleteProgram(GLuint program); |
| 62 | void deleteTexture(GLuint texture); |
| 63 | void deleteRenderbuffer(GLuint renderbuffer); |
| 64 | |
| 65 | Buffer *getBuffer(GLuint handle); |
| 66 | Shader *getShader(GLuint handle); |
| 67 | Program *getProgram(GLuint handle); |
| 68 | Texture *getTexture(GLuint handle); |
| 69 | Renderbuffer *getRenderbuffer(GLuint handle); |
| 70 | |
| 71 | void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer); |
| 72 | |
| 73 | void checkBufferAllocation(unsigned int buffer); |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 74 | void checkTextureAllocation(GLuint texture, TextureType type); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 75 | void checkRenderbufferAllocation(GLuint renderbuffer); |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 76 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 77 | private: |
| 78 | DISALLOW_COPY_AND_ASSIGN(ResourceManager); |
| 79 | |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 80 | std::size_t mRefCount; |
| 81 | |
daniel@transgaming.com | 733ba93 | 2011-04-14 15:03:48 +0000 | [diff] [blame] | 82 | typedef stdext::hash_map<GLuint, Buffer*> BufferMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 83 | BufferMap mBufferMap; |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 84 | HandleAllocator mBufferHandleAllocator; |
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, Shader*> ShaderMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 87 | ShaderMap mShaderMap; |
| 88 | |
daniel@transgaming.com | 733ba93 | 2011-04-14 15:03:48 +0000 | [diff] [blame] | 89 | typedef stdext::hash_map<GLuint, Program*> ProgramMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 90 | ProgramMap mProgramMap; |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 91 | HandleAllocator mProgramShaderHandleAllocator; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 92 | |
daniel@transgaming.com | 733ba93 | 2011-04-14 15:03:48 +0000 | [diff] [blame] | 93 | typedef stdext::hash_map<GLuint, Texture*> TextureMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 94 | TextureMap mTextureMap; |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 95 | HandleAllocator mTextureHandleAllocator; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 96 | |
daniel@transgaming.com | 733ba93 | 2011-04-14 15:03:48 +0000 | [diff] [blame] | 97 | typedef stdext::hash_map<GLuint, Renderbuffer*> RenderbufferMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 98 | RenderbufferMap mRenderbufferMap; |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 99 | HandleAllocator mRenderbufferHandleAllocator; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | } |
| 103 | |
| 104 | #endif // LIBGLESV2_RESOURCEMANAGER_H_ |