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 | #include <unordered_map> |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 18 | |
| 19 | #include "common/angleutils.h" |
daniel@transgaming.com | ef19da5 | 2012-11-28 19:35:08 +0000 | [diff] [blame] | 20 | #include "libGLESv2/angletypes.h" |
benvanik@google.com | 1a23334 | 2011-04-28 19:44:39 +0000 | [diff] [blame] | 21 | #include "libGLESv2/HandleAllocator.h" |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 22 | |
daniel@transgaming.com | 370482e | 2012-11-28 19:32:13 +0000 | [diff] [blame] | 23 | namespace rx |
| 24 | { |
| 25 | class Renderer; |
| 26 | } |
| 27 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 28 | namespace gl |
| 29 | { |
| 30 | class Buffer; |
| 31 | class Shader; |
| 32 | class Program; |
| 33 | class Texture; |
| 34 | class Renderbuffer; |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 35 | class Sampler; |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 36 | class FenceSync; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 37 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 38 | class ResourceManager |
| 39 | { |
| 40 | public: |
daniel@transgaming.com | 370482e | 2012-11-28 19:32:13 +0000 | [diff] [blame] | 41 | explicit ResourceManager(rx::Renderer *renderer); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 42 | ~ResourceManager(); |
| 43 | |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 44 | void addRef(); |
| 45 | void release(); |
| 46 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 47 | GLuint createBuffer(); |
| 48 | GLuint createShader(GLenum type); |
| 49 | GLuint createProgram(); |
| 50 | GLuint createTexture(); |
| 51 | GLuint createRenderbuffer(); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 52 | GLuint createSampler(); |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 53 | GLuint createFenceSync(); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 54 | |
| 55 | void deleteBuffer(GLuint buffer); |
| 56 | void deleteShader(GLuint shader); |
| 57 | void deleteProgram(GLuint program); |
| 58 | void deleteTexture(GLuint texture); |
| 59 | void deleteRenderbuffer(GLuint renderbuffer); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 60 | void deleteSampler(GLuint sampler); |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 61 | void deleteFenceSync(GLuint fenceSync); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 62 | |
| 63 | Buffer *getBuffer(GLuint handle); |
| 64 | Shader *getShader(GLuint handle); |
| 65 | Program *getProgram(GLuint handle); |
| 66 | Texture *getTexture(GLuint handle); |
| 67 | Renderbuffer *getRenderbuffer(GLuint handle); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 68 | Sampler *getSampler(GLuint handle); |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 69 | FenceSync *getFenceSync(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 | |
Geoff Lang | 9b8f92e | 2013-07-30 15:23:30 -0400 | [diff] [blame^] | 86 | typedef std::unordered_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 | |
Geoff Lang | 9b8f92e | 2013-07-30 15:23:30 -0400 | [diff] [blame^] | 90 | typedef std::unordered_map<GLuint, Shader*> ShaderMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 91 | ShaderMap mShaderMap; |
| 92 | |
Geoff Lang | 9b8f92e | 2013-07-30 15:23:30 -0400 | [diff] [blame^] | 93 | typedef std::unordered_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 | |
Geoff Lang | 9b8f92e | 2013-07-30 15:23:30 -0400 | [diff] [blame^] | 97 | typedef std::unordered_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 | |
Geoff Lang | 9b8f92e | 2013-07-30 15:23:30 -0400 | [diff] [blame^] | 101 | typedef std::unordered_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; |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 104 | |
Geoff Lang | 9b8f92e | 2013-07-30 15:23:30 -0400 | [diff] [blame^] | 105 | typedef std::unordered_map<GLuint, Sampler*> SamplerMap; |
| 106 | SamplerMap mSamplerMap; |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 107 | HandleAllocator mSamplerHandleAllocator; |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 108 | |
Geoff Lang | 9b8f92e | 2013-07-30 15:23:30 -0400 | [diff] [blame^] | 109 | typedef std::unordered_map<GLuint, FenceSync*> FenceMap; |
| 110 | FenceMap mFenceSyncMap; |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 111 | HandleAllocator mFenceSyncHandleAllocator; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | } |
| 115 | |
| 116 | #endif // LIBGLESV2_RESOURCEMANAGER_H_ |