blob: 97f82b7583b3f4cc5d98496f5361fe6fb6713253 [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
16#include <map>
17
18#include "common/angleutils.h"
19
20namespace gl
21{
22class Buffer;
23class Shader;
24class Program;
25class Texture;
26class Renderbuffer;
apatrick@chromium.org55255022010-09-11 02:12:47 +000027class Framebuffer;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000028
29enum SamplerType
30{
31 SAMPLER_2D,
32 SAMPLER_CUBE,
33
34 SAMPLER_TYPE_COUNT
35};
36
37class ResourceManager
38{
39 public:
40 ResourceManager();
41 ~ResourceManager();
42
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000043 void addRef();
44 void release();
45
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000046 GLuint createBuffer();
47 GLuint createShader(GLenum type);
48 GLuint createProgram();
49 GLuint createTexture();
50 GLuint createRenderbuffer();
apatrick@chromium.org55255022010-09-11 02:12:47 +000051 GLuint createFramebuffer();
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000052
53 void deleteBuffer(GLuint buffer);
54 void deleteShader(GLuint shader);
55 void deleteProgram(GLuint program);
56 void deleteTexture(GLuint texture);
57 void deleteRenderbuffer(GLuint renderbuffer);
apatrick@chromium.org55255022010-09-11 02:12:47 +000058 void deleteFramebuffer(GLuint framebuffer);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000059
60 Buffer *getBuffer(GLuint handle);
61 Shader *getShader(GLuint handle);
62 Program *getProgram(GLuint handle);
63 Texture *getTexture(GLuint handle);
64 Renderbuffer *getRenderbuffer(GLuint handle);
apatrick@chromium.org55255022010-09-11 02:12:47 +000065 Framebuffer *getFramebuffer(GLuint handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000066
67 void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
68
69 void checkBufferAllocation(unsigned int buffer);
70 void checkTextureAllocation(GLuint texture, SamplerType type);
71 void checkRenderbufferAllocation(GLuint renderbuffer);
apatrick@chromium.org55255022010-09-11 02:12:47 +000072 void checkFramebufferAllocation(GLuint framebuffer);
73
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000074 private:
75 DISALLOW_COPY_AND_ASSIGN(ResourceManager);
76
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000077 std::size_t mRefCount;
78
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000079 typedef std::map<GLuint, Buffer*> BufferMap;
80 BufferMap mBufferMap;
81
82 typedef std::map<GLuint, Shader*> ShaderMap;
83 ShaderMap mShaderMap;
84
85 typedef std::map<GLuint, Program*> ProgramMap;
86 ProgramMap mProgramMap;
87
88 typedef std::map<GLuint, Texture*> TextureMap;
89 TextureMap mTextureMap;
90
91 typedef std::map<GLuint, Renderbuffer*> RenderbufferMap;
92 RenderbufferMap mRenderbufferMap;
apatrick@chromium.org55255022010-09-11 02:12:47 +000093
94 typedef std::map<GLuint, Framebuffer*> FramebufferMap;
95 FramebufferMap mFramebufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000096};
97
98}
99
100#endif // LIBGLESV2_RESOURCEMANAGER_H_