• 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 LIBGL_RESOURCEMANAGER_H_
19 #define LIBGL_RESOURCEMANAGER_H_
20 
21 #include "common/NameSpace.hpp"
22 
23 #define _GDI32_
24 #include <windows.h>
25 #include <GL/GL.h>
26 #include <GL/glext.h>
27 
28 #include <map>
29 
30 namespace gl
31 {
32 class Buffer;
33 class Shader;
34 class Program;
35 class Texture;
36 class Renderbuffer;
37 
38 enum TextureType
39 {
40 	TEXTURE_2D,
41 	PROXY_TEXTURE_2D,
42 	TEXTURE_CUBE,
43 
44 	TEXTURE_TYPE_COUNT,
45 	TEXTURE_UNKNOWN
46 };
47 
48 class ResourceManager
49 {
50 public:
51 	ResourceManager();
52 	~ResourceManager();
53 
54 	void addRef();
55 	void release();
56 
57 	GLuint createBuffer();
58 	GLuint createShader(GLenum type);
59 	GLuint createProgram();
60 	GLuint createTexture();
61 	GLuint createRenderbuffer();
62 
63 	void deleteBuffer(GLuint buffer);
64 	void deleteShader(GLuint shader);
65 	void deleteProgram(GLuint program);
66 	void deleteTexture(GLuint texture);
67 	void deleteRenderbuffer(GLuint renderbuffer);
68 
69 	Buffer *getBuffer(GLuint handle);
70 	Shader *getShader(GLuint handle);
71 	Program *getProgram(GLuint handle);
72 	Texture *getTexture(GLuint handle);
73 	Renderbuffer *getRenderbuffer(GLuint handle);
74 
75 	void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
76 
77 	void checkBufferAllocation(unsigned int buffer);
78 	void checkTextureAllocation(GLuint texture, TextureType type);
79 	void checkRenderbufferAllocation(GLuint renderbuffer);
80 
81 private:
82 	std::size_t mRefCount;
83 
84 	typedef std::map<GLint, Buffer*> BufferMap;
85 	BufferMap mBufferMap;
86 	//NameSpace mBufferNameSpace;
87 
88 	typedef std::map<GLint, Shader*> ShaderMap;
89 	ShaderMap mShaderMap;
90 
91 	typedef std::map<GLint, Program*> ProgramMap;
92 	ProgramMap mProgramMap;
93 	//NameSpace mProgramShaderNameSpace;
94 
95 	typedef std::map<GLint, Texture*> TextureMap;
96 	TextureMap mTextureMap;
97 	//NameSpace mTextureNameSpace;
98 
99 	typedef std::map<GLint, Renderbuffer*> RenderbufferMap;
100 	RenderbufferMap mRenderbufferMap;
101 	//NameSpace mRenderbufferNameSpace;
102 };
103 
104 }
105 
106 #endif // LIBGL_RESOURCEMANAGER_H_
107