daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 1 | // |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame^] | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 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 |
shannon.woods%transgaming.com@gtempaccount.com | f26ddae | 2013-04-13 03:29:13 +0000 | [diff] [blame] | 14 | #include <GLES3/gl3.h> |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 15 | #include <GLES2/gl2.h> |
| 16 | |
daniel@transgaming.com | db2115d | 2012-08-27 16:25:33 +0000 | [diff] [blame] | 17 | #ifdef _MSC_VER |
daniel@transgaming.com | 733ba93 | 2011-04-14 15:03:48 +0000 | [diff] [blame] | 18 | #include <hash_map> |
daniel@transgaming.com | db2115d | 2012-08-27 16:25:33 +0000 | [diff] [blame] | 19 | #else |
| 20 | #include <unordered_map> |
| 21 | #endif |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 22 | |
| 23 | #include "common/angleutils.h" |
daniel@transgaming.com | ef19da5 | 2012-11-28 19:35:08 +0000 | [diff] [blame] | 24 | #include "libGLESv2/angletypes.h" |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 25 | #include "libGLESv2/HandleAllocator.h" |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 26 | |
daniel@transgaming.com | 370482e | 2012-11-28 19:32:13 +0000 | [diff] [blame] | 27 | namespace rx |
| 28 | { |
| 29 | class Renderer; |
| 30 | } |
| 31 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 32 | namespace gl |
| 33 | { |
| 34 | class Buffer; |
| 35 | class Shader; |
| 36 | class Program; |
| 37 | class Texture; |
| 38 | class Renderbuffer; |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame^] | 39 | class Sampler; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 40 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 41 | class ResourceManager |
| 42 | { |
| 43 | public: |
daniel@transgaming.com | 370482e | 2012-11-28 19:32:13 +0000 | [diff] [blame] | 44 | explicit ResourceManager(rx::Renderer *renderer); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 45 | ~ResourceManager(); |
| 46 | |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 47 | void addRef(); |
| 48 | void release(); |
| 49 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 50 | GLuint createBuffer(); |
| 51 | GLuint createShader(GLenum type); |
| 52 | GLuint createProgram(); |
| 53 | GLuint createTexture(); |
| 54 | GLuint createRenderbuffer(); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame^] | 55 | GLuint createSampler(); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 56 | |
| 57 | void deleteBuffer(GLuint buffer); |
| 58 | void deleteShader(GLuint shader); |
| 59 | void deleteProgram(GLuint program); |
| 60 | void deleteTexture(GLuint texture); |
| 61 | void deleteRenderbuffer(GLuint renderbuffer); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame^] | 62 | void deleteSampler(GLuint sampler); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 63 | |
| 64 | Buffer *getBuffer(GLuint handle); |
| 65 | Shader *getShader(GLuint handle); |
| 66 | Program *getProgram(GLuint handle); |
| 67 | Texture *getTexture(GLuint handle); |
| 68 | Renderbuffer *getRenderbuffer(GLuint handle); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame^] | 69 | Sampler *getSampler(GLuint handle); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 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); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame^] | 76 | void checkSamplerAllocation(GLuint sampler); |
| 77 | |
| 78 | bool isSampler(GLuint sampler); |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 79 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 80 | private: |
| 81 | DISALLOW_COPY_AND_ASSIGN(ResourceManager); |
| 82 | |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 83 | std::size_t mRefCount; |
daniel@transgaming.com | 370482e | 2012-11-28 19:32:13 +0000 | [diff] [blame] | 84 | rx::Renderer *mRenderer; |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 85 | |
daniel@transgaming.com | db2115d | 2012-08-27 16:25:33 +0000 | [diff] [blame] | 86 | #ifndef HASH_MAP |
| 87 | # ifdef _MSC_VER |
| 88 | # define HASH_MAP stdext::hash_map |
| 89 | # else |
| 90 | # define HASH_MAP std::unordered_map |
| 91 | # endif |
| 92 | #endif |
| 93 | |
| 94 | typedef HASH_MAP<GLuint, Buffer*> BufferMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 95 | BufferMap mBufferMap; |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 96 | HandleAllocator mBufferHandleAllocator; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 97 | |
daniel@transgaming.com | db2115d | 2012-08-27 16:25:33 +0000 | [diff] [blame] | 98 | typedef HASH_MAP<GLuint, Shader*> ShaderMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 99 | ShaderMap mShaderMap; |
| 100 | |
daniel@transgaming.com | db2115d | 2012-08-27 16:25:33 +0000 | [diff] [blame] | 101 | typedef HASH_MAP<GLuint, Program*> ProgramMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 102 | ProgramMap mProgramMap; |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 103 | HandleAllocator mProgramShaderHandleAllocator; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 104 | |
daniel@transgaming.com | db2115d | 2012-08-27 16:25:33 +0000 | [diff] [blame] | 105 | typedef HASH_MAP<GLuint, Texture*> TextureMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 106 | TextureMap mTextureMap; |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 107 | HandleAllocator mTextureHandleAllocator; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 108 | |
daniel@transgaming.com | db2115d | 2012-08-27 16:25:33 +0000 | [diff] [blame] | 109 | typedef HASH_MAP<GLuint, Renderbuffer*> RenderbufferMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 110 | RenderbufferMap mRenderbufferMap; |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 111 | HandleAllocator mRenderbufferHandleAllocator; |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame^] | 112 | |
| 113 | HASH_MAP<GLuint, Sampler*> mSamplerMap; |
| 114 | HandleAllocator mSamplerHandleAllocator; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | } |
| 118 | |
| 119 | #endif // LIBGLESV2_RESOURCEMANAGER_H_ |