blob: ae4f1b04a52b8c3b48d929bc715f15c061887c53 [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.comdb2115d2012-08-27 16:25:33 +000016#ifdef _MSC_VER
daniel@transgaming.com733ba932011-04-14 15:03:48 +000017#include <hash_map>
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000018#else
19#include <unordered_map>
20#endif
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000021
22#include "common/angleutils.h"
benvanik@google.com1a233342011-04-28 19:44:39 +000023#include "libGLESv2/HandleAllocator.h"
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000024
25namespace gl
26{
27class Buffer;
28class Shader;
29class Program;
30class Texture;
31class Renderbuffer;
32
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +000033enum TextureType
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000034{
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +000035 TEXTURE_2D,
36 TEXTURE_CUBE,
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000037
daniel@transgaming.comd4a35172011-05-11 15:36:45 +000038 TEXTURE_TYPE_COUNT,
39 TEXTURE_UNKNOWN
40};
41
42enum SamplerType
43{
44 SAMPLER_PIXEL,
45 SAMPLER_VERTEX
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000046};
47
48class ResourceManager
49{
50 public:
51 ResourceManager();
52 ~ResourceManager();
53
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000054 void addRef();
55 void release();
56
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000057 GLuint createBuffer();
58 GLuint createShader(GLenum type);
59 GLuint createProgram();
60 GLuint createTexture();
61 GLuint createRenderbuffer();
62
63 void deleteBuffer(GLuint buffer);
64 void deleteShader(GLuint shader);
65 void deleteProgram(GLuint program);
66 void deleteTexture(GLuint texture);
67 void deleteRenderbuffer(GLuint renderbuffer);
68
69 Buffer *getBuffer(GLuint handle);
70 Shader *getShader(GLuint handle);
71 Program *getProgram(GLuint handle);
72 Texture *getTexture(GLuint handle);
73 Renderbuffer *getRenderbuffer(GLuint handle);
74
75 void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
76
77 void checkBufferAllocation(unsigned int buffer);
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +000078 void checkTextureAllocation(GLuint texture, TextureType type);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000079 void checkRenderbufferAllocation(GLuint renderbuffer);
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000080
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000081 private:
82 DISALLOW_COPY_AND_ASSIGN(ResourceManager);
83
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000084 std::size_t mRefCount;
85
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000086#ifndef HASH_MAP
87# ifdef _MSC_VER
88# define HASH_MAP stdext::hash_map
89# else
90# define HASH_MAP std::unordered_map
91# endif
92#endif
93
94 typedef HASH_MAP<GLuint, Buffer*> BufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000095 BufferMap mBufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000096 HandleAllocator mBufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000097
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000098 typedef HASH_MAP<GLuint, Shader*> ShaderMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000099 ShaderMap mShaderMap;
100
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +0000101 typedef HASH_MAP<GLuint, Program*> ProgramMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000102 ProgramMap mProgramMap;
benvanik@google.com1a233342011-04-28 19:44:39 +0000103 HandleAllocator mProgramShaderHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000104
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +0000105 typedef HASH_MAP<GLuint, Texture*> TextureMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000106 TextureMap mTextureMap;
benvanik@google.com1a233342011-04-28 19:44:39 +0000107 HandleAllocator mTextureHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000108
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +0000109 typedef HASH_MAP<GLuint, Renderbuffer*> RenderbufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000110 RenderbufferMap mRenderbufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +0000111 HandleAllocator mRenderbufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000112};
113
114}
115
116#endif // LIBGLESV2_RESOURCEMANAGER_H_