blob: 346e51f21bad7bb984235dbab484aa91a07a796f [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;
27
28enum SamplerType
29{
30 SAMPLER_2D,
31 SAMPLER_CUBE,
32
33 SAMPLER_TYPE_COUNT
34};
35
36class ResourceManager
37{
38 public:
39 ResourceManager();
40 ~ResourceManager();
41
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000042 void addRef();
43 void release();
44
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000045 GLuint createBuffer();
46 GLuint createShader(GLenum type);
47 GLuint createProgram();
48 GLuint createTexture();
49 GLuint createRenderbuffer();
50
51 void deleteBuffer(GLuint buffer);
52 void deleteShader(GLuint shader);
53 void deleteProgram(GLuint program);
54 void deleteTexture(GLuint texture);
55 void deleteRenderbuffer(GLuint renderbuffer);
56
57 Buffer *getBuffer(GLuint handle);
58 Shader *getShader(GLuint handle);
59 Program *getProgram(GLuint handle);
60 Texture *getTexture(GLuint handle);
61 Renderbuffer *getRenderbuffer(GLuint handle);
62
63 void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
64
65 void checkBufferAllocation(unsigned int buffer);
66 void checkTextureAllocation(GLuint texture, SamplerType type);
67 void checkRenderbufferAllocation(GLuint renderbuffer);
68
69 private:
70 DISALLOW_COPY_AND_ASSIGN(ResourceManager);
71
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000072 std::size_t mRefCount;
73
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000074 typedef std::map<GLuint, Buffer*> BufferMap;
75 BufferMap mBufferMap;
76
77 typedef std::map<GLuint, Shader*> ShaderMap;
78 ShaderMap mShaderMap;
79
80 typedef std::map<GLuint, Program*> ProgramMap;
81 ProgramMap mProgramMap;
82
83 typedef std::map<GLuint, Texture*> TextureMap;
84 TextureMap mTextureMap;
85
86 typedef std::map<GLuint, Renderbuffer*> RenderbufferMap;
87 RenderbufferMap mRenderbufferMap;
88};
89
90}
91
92#endif // LIBGLESV2_RESOURCEMANAGER_H_