• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
27 
28 enum SamplerType
29 {
30     SAMPLER_2D,
31     SAMPLER_CUBE,
32 
33     SAMPLER_TYPE_COUNT
34 };
35 
36 class ResourceManager
37 {
38   public:
39     ResourceManager();
40     ~ResourceManager();
41 
42     void addRef();
43     void release();
44 
45     GLuint createBuffer();
46     GLuint createShader(GLenum type);
47     GLuint createProgram();
48     GLuint createTexture();
49     GLuint createRenderbuffer();
50 
51     void deleteBuffer(GLuint buffer);
52     void deleteShader(GLuint shader);
53     void deleteProgram(GLuint program);
54     void deleteTexture(GLuint texture);
55     void deleteRenderbuffer(GLuint renderbuffer);
56 
57     Buffer *getBuffer(GLuint handle);
58     Shader *getShader(GLuint handle);
59     Program *getProgram(GLuint handle);
60     Texture *getTexture(GLuint handle);
61     Renderbuffer *getRenderbuffer(GLuint handle);
62 
63     void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
64 
65     void checkBufferAllocation(unsigned int buffer);
66     void checkTextureAllocation(GLuint texture, SamplerType type);
67     void checkRenderbufferAllocation(GLuint renderbuffer);
68 
69   private:
70     DISALLOW_COPY_AND_ASSIGN(ResourceManager);
71 
72     std::size_t mRefCount;
73 
74     typedef std::map<GLuint, Buffer*> BufferMap;
75     BufferMap mBufferMap;
76 
77     typedef std::map<GLuint, Shader*> ShaderMap;
78     ShaderMap mShaderMap;
79 
80     typedef std::map<GLuint, Program*> ProgramMap;
81     ProgramMap mProgramMap;
82 
83     typedef std::map<GLuint, Texture*> TextureMap;
84     TextureMap mTextureMap;
85 
86     typedef std::map<GLuint, Renderbuffer*> RenderbufferMap;
87     RenderbufferMap mRenderbufferMap;
88 };
89 
90 }
91 
92 #endif // LIBGLESV2_RESOURCEMANAGER_H_
93