Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 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 LIBGLES_CM_RESOURCEMANAGER_H_ |
| 19 | #define LIBGLES_CM_RESOURCEMANAGER_H_ |
| 20 | |
| 21 | #include "common/NameSpace.hpp" |
| 22 | |
| 23 | #include <GLES/gl.h> |
| 24 | |
| 25 | #include <map> |
| 26 | |
| 27 | namespace es1 |
| 28 | { |
| 29 | class Buffer; |
| 30 | class Texture; |
| 31 | class Renderbuffer; |
| 32 | |
| 33 | enum TextureType |
| 34 | { |
| 35 | TEXTURE_2D, |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 36 | TEXTURE_EXTERNAL, |
| 37 | |
| 38 | TEXTURE_TYPE_COUNT, |
| 39 | TEXTURE_UNKNOWN |
| 40 | }; |
| 41 | |
| 42 | class ResourceManager |
| 43 | { |
| 44 | public: |
| 45 | ResourceManager(); |
| 46 | ~ResourceManager(); |
| 47 | |
| 48 | void addRef(); |
| 49 | void release(); |
| 50 | |
| 51 | GLuint createBuffer(); |
| 52 | GLuint createTexture(); |
| 53 | GLuint createRenderbuffer(); |
| 54 | |
| 55 | void deleteBuffer(GLuint buffer); |
| 56 | void deleteTexture(GLuint texture); |
| 57 | void deleteRenderbuffer(GLuint renderbuffer); |
| 58 | |
| 59 | Buffer *getBuffer(GLuint handle); |
| 60 | Texture *getTexture(GLuint handle); |
| 61 | Renderbuffer *getRenderbuffer(GLuint handle); |
| 62 | |
| 63 | void checkBufferAllocation(unsigned int buffer); |
| 64 | void checkTextureAllocation(GLuint texture, TextureType type); |
| 65 | void checkRenderbufferAllocation(GLuint handle); |
| 66 | |
| 67 | private: |
| 68 | std::size_t mRefCount; |
| 69 | |
| 70 | gl::NameSpace<Buffer> mBufferNameSpace; |
| 71 | gl::NameSpace<Texture> mTextureNameSpace; |
| 72 | gl::NameSpace<Renderbuffer> mRenderbufferNameSpace; |
| 73 | }; |
| 74 | |
| 75 | } |
| 76 | |
| 77 | #endif // LIBGLES_CM_RESOURCEMANAGER_H_ |