blob: e99c77c35d254e2e1709f79e7593643a118c89d6 [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"
daniel@transgaming.comef19da52012-11-28 19:35:08 +000023#include "libGLESv2/angletypes.h"
benvanik@google.com1a233342011-04-28 19:44:39 +000024#include "libGLESv2/HandleAllocator.h"
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000025
daniel@transgaming.com370482e2012-11-28 19:32:13 +000026namespace rx
27{
28class Renderer;
29}
30
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000031namespace gl
32{
33class Buffer;
34class Shader;
35class Program;
36class Texture;
37class Renderbuffer;
38
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000039class ResourceManager
40{
41 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +000042 explicit ResourceManager(rx::Renderer *renderer);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000043 ~ResourceManager();
44
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000045 void addRef();
46 void release();
47
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000048 GLuint createBuffer();
49 GLuint createShader(GLenum type);
50 GLuint createProgram();
51 GLuint createTexture();
52 GLuint createRenderbuffer();
53
54 void deleteBuffer(GLuint buffer);
55 void deleteShader(GLuint shader);
56 void deleteProgram(GLuint program);
57 void deleteTexture(GLuint texture);
58 void deleteRenderbuffer(GLuint renderbuffer);
59
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);
65
66 void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
67
68 void checkBufferAllocation(unsigned int buffer);
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +000069 void checkTextureAllocation(GLuint texture, TextureType type);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000070 void checkRenderbufferAllocation(GLuint renderbuffer);
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000071
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000072 private:
73 DISALLOW_COPY_AND_ASSIGN(ResourceManager);
74
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000075 std::size_t mRefCount;
daniel@transgaming.com370482e2012-11-28 19:32:13 +000076 rx::Renderer *mRenderer;
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000077
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000078#ifndef HASH_MAP
79# ifdef _MSC_VER
80# define HASH_MAP stdext::hash_map
81# else
82# define HASH_MAP std::unordered_map
83# endif
84#endif
85
86 typedef HASH_MAP<GLuint, Buffer*> BufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000087 BufferMap mBufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000088 HandleAllocator mBufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000089
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000090 typedef HASH_MAP<GLuint, Shader*> ShaderMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000091 ShaderMap mShaderMap;
92
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000093 typedef HASH_MAP<GLuint, Program*> ProgramMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000094 ProgramMap mProgramMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000095 HandleAllocator mProgramShaderHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000096
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000097 typedef HASH_MAP<GLuint, Texture*> TextureMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000098 TextureMap mTextureMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000099 HandleAllocator mTextureHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000100
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +0000101 typedef HASH_MAP<GLuint, Renderbuffer*> RenderbufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000102 RenderbufferMap mRenderbufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +0000103 HandleAllocator mRenderbufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000104};
105
106}
107
108#endif // LIBGLESV2_RESOURCEMANAGER_H_