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