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 | |
| 16 | #include <map> |
| 17 | |
| 18 | #include "common/angleutils.h" |
| 19 | |
| 20 | namespace gl |
| 21 | { |
| 22 | class Buffer; |
| 23 | class Shader; |
| 24 | class Program; |
| 25 | class Texture; |
| 26 | class Renderbuffer; |
apatrick@chromium.org | 5525502 | 2010-09-11 02:12:47 +0000 | [diff] [blame] | 27 | class Framebuffer; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 28 | |
| 29 | enum SamplerType |
| 30 | { |
| 31 | SAMPLER_2D, |
| 32 | SAMPLER_CUBE, |
| 33 | |
| 34 | SAMPLER_TYPE_COUNT |
| 35 | }; |
| 36 | |
| 37 | class ResourceManager |
| 38 | { |
| 39 | public: |
| 40 | ResourceManager(); |
| 41 | ~ResourceManager(); |
| 42 | |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 43 | void addRef(); |
| 44 | void release(); |
| 45 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 46 | GLuint createBuffer(); |
| 47 | GLuint createShader(GLenum type); |
| 48 | GLuint createProgram(); |
| 49 | GLuint createTexture(); |
| 50 | GLuint createRenderbuffer(); |
apatrick@chromium.org | 5525502 | 2010-09-11 02:12:47 +0000 | [diff] [blame] | 51 | GLuint createFramebuffer(); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 52 | |
| 53 | void deleteBuffer(GLuint buffer); |
| 54 | void deleteShader(GLuint shader); |
| 55 | void deleteProgram(GLuint program); |
| 56 | void deleteTexture(GLuint texture); |
| 57 | void deleteRenderbuffer(GLuint renderbuffer); |
apatrick@chromium.org | 5525502 | 2010-09-11 02:12:47 +0000 | [diff] [blame] | 58 | void deleteFramebuffer(GLuint framebuffer); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 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); |
apatrick@chromium.org | 5525502 | 2010-09-11 02:12:47 +0000 | [diff] [blame] | 65 | Framebuffer *getFramebuffer(GLuint handle); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 66 | |
| 67 | void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer); |
| 68 | |
| 69 | void checkBufferAllocation(unsigned int buffer); |
| 70 | void checkTextureAllocation(GLuint texture, SamplerType type); |
| 71 | void checkRenderbufferAllocation(GLuint renderbuffer); |
apatrick@chromium.org | 5525502 | 2010-09-11 02:12:47 +0000 | [diff] [blame] | 72 | void checkFramebufferAllocation(GLuint framebuffer); |
| 73 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 74 | private: |
| 75 | DISALLOW_COPY_AND_ASSIGN(ResourceManager); |
| 76 | |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 77 | std::size_t mRefCount; |
| 78 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 79 | typedef std::map<GLuint, Buffer*> BufferMap; |
| 80 | BufferMap mBufferMap; |
| 81 | |
| 82 | typedef std::map<GLuint, Shader*> ShaderMap; |
| 83 | ShaderMap mShaderMap; |
| 84 | |
| 85 | typedef std::map<GLuint, Program*> ProgramMap; |
| 86 | ProgramMap mProgramMap; |
| 87 | |
| 88 | typedef std::map<GLuint, Texture*> TextureMap; |
| 89 | TextureMap mTextureMap; |
| 90 | |
| 91 | typedef std::map<GLuint, Renderbuffer*> RenderbufferMap; |
| 92 | RenderbufferMap mRenderbufferMap; |
apatrick@chromium.org | 5525502 | 2010-09-11 02:12:47 +0000 | [diff] [blame] | 93 | |
| 94 | typedef std::map<GLuint, Framebuffer*> FramebufferMap; |
| 95 | FramebufferMap mFramebufferMap; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | } |
| 99 | |
| 100 | #endif // LIBGLESV2_RESOURCEMANAGER_H_ |