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_2D_RECT, 44 TEXTURE_EXTERNAL, 45 46 TEXTURE_TYPE_COUNT, 47 TEXTURE_UNKNOWN 48 }; 49 50 class ResourceManager 51 { 52 public: 53 ResourceManager(); 54 ~ResourceManager(); 55 56 void addRef(); 57 void release(); 58 59 GLuint createBuffer(); 60 GLuint createShader(GLenum type); 61 GLuint createProgram(); 62 GLuint createTexture(); 63 GLuint createRenderbuffer(); 64 GLuint createSampler(); 65 GLuint createFenceSync(GLenum condition, GLbitfield flags); 66 67 void deleteBuffer(GLuint buffer); 68 void deleteShader(GLuint shader); 69 void deleteProgram(GLuint program); 70 void deleteTexture(GLuint texture); 71 void deleteRenderbuffer(GLuint renderbuffer); 72 void deleteSampler(GLuint sampler); 73 void deleteFenceSync(GLuint fenceSync); 74 75 Buffer *getBuffer(GLuint handle); 76 Shader *getShader(GLuint handle); 77 Program *getProgram(GLuint handle); 78 Texture *getTexture(GLuint handle); 79 Renderbuffer *getRenderbuffer(GLuint handle); 80 Sampler *getSampler(GLuint handle); 81 FenceSync *getFenceSync(GLuint handle); 82 83 void checkBufferAllocation(unsigned int buffer); 84 void checkTextureAllocation(GLuint texture, TextureType type); 85 void checkRenderbufferAllocation(GLuint handle); 86 void checkSamplerAllocation(GLuint sampler); 87 88 bool isSampler(GLuint sampler); 89 90 private: 91 std::size_t mRefCount; 92 93 gl::NameSpace<Buffer> mBufferNameSpace; 94 gl::NameSpace<Program> mProgramNameSpace; 95 gl::NameSpace<Shader> mShaderNameSpace; 96 gl::NameSpace<void> mProgramShaderNameSpace; // Shaders and programs share a namespace 97 gl::NameSpace<Texture> mTextureNameSpace; 98 gl::NameSpace<Renderbuffer> mRenderbufferNameSpace; 99 gl::NameSpace<Sampler> mSamplerNameSpace; 100 gl::NameSpace<FenceSync> mFenceSyncNameSpace; 101 }; 102 103 } 104 105 #endif // LIBGLESV2_RESOURCEMANAGER_H_ 106