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