• 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 #ifdef _MSC_VER
17 #include <hash_map>
18 #else
19 #include <unordered_map>
20 #endif
21 
22 #include "common/angleutils.h"
23 #include "libGLESv2/angletypes.h"
24 #include "libGLESv2/HandleAllocator.h"
25 
26 namespace rx
27 {
28 class Renderer;
29 }
30 
31 namespace gl
32 {
33 class Buffer;
34 class Shader;
35 class Program;
36 class Texture;
37 class Renderbuffer;
38 
39 class ResourceManager
40 {
41   public:
42     explicit ResourceManager(rx::Renderer *renderer);
43     ~ResourceManager();
44 
45     void addRef();
46     void release();
47 
48     GLuint createBuffer();
49     GLuint createShader(GLenum type);
50     GLuint createProgram();
51     GLuint createTexture();
52     GLuint createRenderbuffer();
53 
54     void deleteBuffer(GLuint buffer);
55     void deleteShader(GLuint shader);
56     void deleteProgram(GLuint program);
57     void deleteTexture(GLuint texture);
58     void deleteRenderbuffer(GLuint renderbuffer);
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);
65 
66     void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
67 
68     void checkBufferAllocation(unsigned int buffer);
69     void checkTextureAllocation(GLuint texture, TextureType type);
70     void checkRenderbufferAllocation(GLuint renderbuffer);
71 
72   private:
73     DISALLOW_COPY_AND_ASSIGN(ResourceManager);
74 
75     std::size_t mRefCount;
76     rx::Renderer *mRenderer;
77 
78 #ifndef HASH_MAP
79 # ifdef _MSC_VER
80 #  define HASH_MAP stdext::hash_map
81 # else
82 #  define HASH_MAP std::unordered_map
83 # endif
84 #endif
85 
86     typedef HASH_MAP<GLuint, Buffer*> BufferMap;
87     BufferMap mBufferMap;
88     HandleAllocator mBufferHandleAllocator;
89 
90     typedef HASH_MAP<GLuint, Shader*> ShaderMap;
91     ShaderMap mShaderMap;
92 
93     typedef HASH_MAP<GLuint, Program*> ProgramMap;
94     ProgramMap mProgramMap;
95     HandleAllocator mProgramShaderHandleAllocator;
96 
97     typedef HASH_MAP<GLuint, Texture*> TextureMap;
98     TextureMap mTextureMap;
99     HandleAllocator mTextureHandleAllocator;
100 
101     typedef HASH_MAP<GLuint, Renderbuffer*> RenderbufferMap;
102     RenderbufferMap mRenderbufferMap;
103     HandleAllocator mRenderbufferHandleAllocator;
104 };
105 
106 }
107 
108 #endif // LIBGLESV2_RESOURCEMANAGER_H_
109