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; |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame^] | 40 | class FenceSync; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 41 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 42 | class ResourceManager |
| 43 | { |
| 44 | public: |
daniel@transgaming.com | 370482e | 2012-11-28 19:32:13 +0000 | [diff] [blame] | 45 | explicit ResourceManager(rx::Renderer *renderer); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 46 | ~ResourceManager(); |
| 47 | |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 48 | void addRef(); |
| 49 | void release(); |
| 50 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 51 | GLuint createBuffer(); |
| 52 | GLuint createShader(GLenum type); |
| 53 | GLuint createProgram(); |
| 54 | GLuint createTexture(); |
| 55 | GLuint createRenderbuffer(); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 56 | GLuint createSampler(); |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame^] | 57 | GLuint createFenceSync(); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 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); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 64 | void deleteSampler(GLuint sampler); |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame^] | 65 | void deleteFenceSync(GLuint fenceSync); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 66 | |
| 67 | Buffer *getBuffer(GLuint handle); |
| 68 | Shader *getShader(GLuint handle); |
| 69 | Program *getProgram(GLuint handle); |
| 70 | Texture *getTexture(GLuint handle); |
| 71 | Renderbuffer *getRenderbuffer(GLuint handle); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 72 | Sampler *getSampler(GLuint handle); |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame^] | 73 | FenceSync *getFenceSync(GLuint handle); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 74 | |
| 75 | void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer); |
| 76 | |
| 77 | void checkBufferAllocation(unsigned int buffer); |
daniel@transgaming.com | 0e64dd6 | 2011-05-11 15:36:37 +0000 | [diff] [blame] | 78 | void checkTextureAllocation(GLuint texture, TextureType type); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 79 | void checkRenderbufferAllocation(GLuint renderbuffer); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 80 | void checkSamplerAllocation(GLuint sampler); |
| 81 | |
| 82 | bool isSampler(GLuint sampler); |
apatrick@chromium.org | ff8bdfb | 2010-09-15 17:27:49 +0000 | [diff] [blame] | 83 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 84 | private: |
| 85 | DISALLOW_COPY_AND_ASSIGN(ResourceManager); |
| 86 | |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 87 | std::size_t mRefCount; |
daniel@transgaming.com | 370482e | 2012-11-28 19:32:13 +0000 | [diff] [blame] | 88 | rx::Renderer *mRenderer; |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 89 | |
daniel@transgaming.com | db2115d | 2012-08-27 16:25:33 +0000 | [diff] [blame] | 90 | #ifndef HASH_MAP |
| 91 | # ifdef _MSC_VER |
| 92 | # define HASH_MAP stdext::hash_map |
| 93 | # else |
| 94 | # define HASH_MAP std::unordered_map |
| 95 | # endif |
| 96 | #endif |
| 97 | |
| 98 | typedef HASH_MAP<GLuint, Buffer*> BufferMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 99 | BufferMap mBufferMap; |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 100 | HandleAllocator mBufferHandleAllocator; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 101 | |
daniel@transgaming.com | db2115d | 2012-08-27 16:25:33 +0000 | [diff] [blame] | 102 | typedef HASH_MAP<GLuint, Shader*> ShaderMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 103 | ShaderMap mShaderMap; |
| 104 | |
daniel@transgaming.com | db2115d | 2012-08-27 16:25:33 +0000 | [diff] [blame] | 105 | typedef HASH_MAP<GLuint, Program*> ProgramMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 106 | ProgramMap mProgramMap; |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 107 | HandleAllocator mProgramShaderHandleAllocator; |
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, Texture*> TextureMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 110 | TextureMap mTextureMap; |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 111 | HandleAllocator mTextureHandleAllocator; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 112 | |
daniel@transgaming.com | db2115d | 2012-08-27 16:25:33 +0000 | [diff] [blame] | 113 | typedef HASH_MAP<GLuint, Renderbuffer*> RenderbufferMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 114 | RenderbufferMap mRenderbufferMap; |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 115 | HandleAllocator mRenderbufferHandleAllocator; |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 116 | |
| 117 | HASH_MAP<GLuint, Sampler*> mSamplerMap; |
| 118 | HandleAllocator mSamplerHandleAllocator; |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame^] | 119 | |
| 120 | HASH_MAP<GLuint, FenceSync*> mFenceSyncMap; |
| 121 | HandleAllocator mFenceSyncHandleAllocator; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | } |
| 125 | |
| 126 | #endif // LIBGLESV2_RESOURCEMANAGER_H_ |