blob: 5185fc9dbe9397643d668f8672be4d4781b07196 [file] [log] [blame]
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +00001//
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
daniel@transgaming.com733ba932011-04-14 15:03:48 +000016#include <hash_map>
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000017
18#include "common/angleutils.h"
benvanik@google.com1a233342011-04-28 19:44:39 +000019#include "libGLESv2/HandleAllocator.h"
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000020
21namespace gl
22{
23class Buffer;
24class Shader;
25class Program;
26class Texture;
27class Renderbuffer;
28
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +000029enum TextureType
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000030{
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +000031 TEXTURE_2D,
32 TEXTURE_CUBE,
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000033
daniel@transgaming.comd4a35172011-05-11 15:36:45 +000034 TEXTURE_TYPE_COUNT,
35 TEXTURE_UNKNOWN
36};
37
38enum SamplerType
39{
40 SAMPLER_PIXEL,
41 SAMPLER_VERTEX
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000042};
43
44class ResourceManager
45{
46 public:
47 ResourceManager();
48 ~ResourceManager();
49
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000050 void addRef();
51 void release();
52
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000053 GLuint createBuffer();
54 GLuint createShader(GLenum type);
55 GLuint createProgram();
56 GLuint createTexture();
57 GLuint createRenderbuffer();
58
59 void deleteBuffer(GLuint buffer);
60 void deleteShader(GLuint shader);
61 void deleteProgram(GLuint program);
62 void deleteTexture(GLuint texture);
63 void deleteRenderbuffer(GLuint renderbuffer);
64
65 Buffer *getBuffer(GLuint handle);
66 Shader *getShader(GLuint handle);
67 Program *getProgram(GLuint handle);
68 Texture *getTexture(GLuint handle);
69 Renderbuffer *getRenderbuffer(GLuint handle);
70
71 void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
72
73 void checkBufferAllocation(unsigned int buffer);
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +000074 void checkTextureAllocation(GLuint texture, TextureType type);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000075 void checkRenderbufferAllocation(GLuint renderbuffer);
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000076
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000077 private:
78 DISALLOW_COPY_AND_ASSIGN(ResourceManager);
79
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000080 std::size_t mRefCount;
81
daniel@transgaming.com733ba932011-04-14 15:03:48 +000082 typedef stdext::hash_map<GLuint, Buffer*> BufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000083 BufferMap mBufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000084 HandleAllocator mBufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000085
daniel@transgaming.com733ba932011-04-14 15:03:48 +000086 typedef stdext::hash_map<GLuint, Shader*> ShaderMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000087 ShaderMap mShaderMap;
88
daniel@transgaming.com733ba932011-04-14 15:03:48 +000089 typedef stdext::hash_map<GLuint, Program*> ProgramMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000090 ProgramMap mProgramMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000091 HandleAllocator mProgramShaderHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000092
daniel@transgaming.com733ba932011-04-14 15:03:48 +000093 typedef stdext::hash_map<GLuint, Texture*> TextureMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000094 TextureMap mTextureMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000095 HandleAllocator mTextureHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000096
daniel@transgaming.com733ba932011-04-14 15:03:48 +000097 typedef stdext::hash_map<GLuint, Renderbuffer*> RenderbufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000098 RenderbufferMap mRenderbufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000099 HandleAllocator mRenderbufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000100};
101
102}
103
104#endif // LIBGLESV2_RESOURCEMANAGER_H_