• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // ResourceManager.h : Defines the ResourceManager class, which tracks objects
16 // shared by multiple GL contexts.
17 
18 #ifndef LIBGLESV2_RESOURCEMANAGER_H_
19 #define LIBGLESV2_RESOURCEMANAGER_H_
20 
21 #include "common/NameSpace.hpp"
22 
23 #include <GLES2/gl2.h>
24 
25 #include <map>
26 
27 namespace es2
28 {
29 class Buffer;
30 class Shader;
31 class Program;
32 class Texture;
33 class Renderbuffer;
34 class Sampler;
35 class FenceSync;
36 
37 enum TextureType
38 {
39 	TEXTURE_2D,
40 	TEXTURE_3D,
41 	TEXTURE_2D_ARRAY,
42 	TEXTURE_CUBE,
43 	TEXTURE_EXTERNAL,
44 
45 	TEXTURE_TYPE_COUNT,
46 	TEXTURE_UNKNOWN
47 };
48 
49 class ResourceManager
50 {
51 public:
52 	ResourceManager();
53 	~ResourceManager();
54 
55 	void addRef();
56 	void release();
57 
58 	GLuint createBuffer();
59 	GLuint createShader(GLenum type);
60 	GLuint createProgram();
61 	GLuint createTexture();
62 	GLuint createRenderbuffer();
63 	GLuint createSampler();
64 	GLuint createFenceSync(GLenum condition, GLbitfield flags);
65 
66 	void deleteBuffer(GLuint buffer);
67 	void deleteShader(GLuint shader);
68 	void deleteProgram(GLuint program);
69 	void deleteTexture(GLuint texture);
70 	void deleteRenderbuffer(GLuint renderbuffer);
71 	void deleteSampler(GLuint sampler);
72 	void deleteFenceSync(GLuint fenceSync);
73 
74 	Buffer *getBuffer(GLuint handle);
75 	Shader *getShader(GLuint handle);
76 	Program *getProgram(GLuint handle);
77 	Texture *getTexture(GLuint handle);
78 	Renderbuffer *getRenderbuffer(GLuint handle);
79 	Sampler *getSampler(GLuint handle);
80 	FenceSync *getFenceSync(GLuint handle);
81 
82 	void checkBufferAllocation(unsigned int buffer);
83 	void checkTextureAllocation(GLuint texture, TextureType type);
84 	void checkRenderbufferAllocation(GLuint handle);
85 	void checkSamplerAllocation(GLuint sampler);
86 
87 	bool isSampler(GLuint sampler);
88 
89 private:
90 	std::size_t mRefCount;
91 
92 	gl::NameSpace<Buffer> mBufferNameSpace;
93 	gl::NameSpace<Program> mProgramNameSpace;
94 	gl::NameSpace<Shader> mShaderNameSpace;
95 	gl::NameSpace<void> mProgramShaderNameSpace;   // Shaders and programs share a namespace
96 	gl::NameSpace<Texture> mTextureNameSpace;
97 	gl::NameSpace<Renderbuffer> mRenderbufferNameSpace;
98 	gl::NameSpace<Sampler> mSamplerNameSpace;
99 	gl::NameSpace<FenceSync> mFenceSyncNameSpace;
100 };
101 
102 }
103 
104 #endif // LIBGLESV2_RESOURCEMANAGER_H_
105