blob: 3c9c5680e8e7e2f3ec720be200e7dc6969f761cc [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.comba0570e2012-10-31 18:07:39 +000023#include "libGLESv2/EnumTypes.h"
benvanik@google.com1a233342011-04-28 19:44:39 +000024#include "libGLESv2/HandleAllocator.h"
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000025
26namespace gl
27{
28class Buffer;
29class Shader;
30class Program;
31class Texture;
32class Renderbuffer;
33
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000034class ResourceManager
35{
36 public:
37 ResourceManager();
38 ~ResourceManager();
39
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000040 void addRef();
41 void release();
42
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000043 GLuint createBuffer();
44 GLuint createShader(GLenum type);
45 GLuint createProgram();
46 GLuint createTexture();
47 GLuint createRenderbuffer();
48
49 void deleteBuffer(GLuint buffer);
50 void deleteShader(GLuint shader);
51 void deleteProgram(GLuint program);
52 void deleteTexture(GLuint texture);
53 void deleteRenderbuffer(GLuint renderbuffer);
54
55 Buffer *getBuffer(GLuint handle);
56 Shader *getShader(GLuint handle);
57 Program *getProgram(GLuint handle);
58 Texture *getTexture(GLuint handle);
59 Renderbuffer *getRenderbuffer(GLuint handle);
60
61 void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
62
63 void checkBufferAllocation(unsigned int buffer);
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +000064 void checkTextureAllocation(GLuint texture, TextureType type);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000065 void checkRenderbufferAllocation(GLuint renderbuffer);
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000066
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000067 private:
68 DISALLOW_COPY_AND_ASSIGN(ResourceManager);
69
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000070 std::size_t mRefCount;
71
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000072#ifndef HASH_MAP
73# ifdef _MSC_VER
74# define HASH_MAP stdext::hash_map
75# else
76# define HASH_MAP std::unordered_map
77# endif
78#endif
79
80 typedef HASH_MAP<GLuint, Buffer*> BufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000081 BufferMap mBufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000082 HandleAllocator mBufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000083
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000084 typedef HASH_MAP<GLuint, Shader*> ShaderMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000085 ShaderMap mShaderMap;
86
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000087 typedef HASH_MAP<GLuint, Program*> ProgramMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000088 ProgramMap mProgramMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000089 HandleAllocator mProgramShaderHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000090
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000091 typedef HASH_MAP<GLuint, Texture*> TextureMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000092 TextureMap mTextureMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000093 HandleAllocator mTextureHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000094
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000095 typedef HASH_MAP<GLuint, Renderbuffer*> RenderbufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000096 RenderbufferMap mRenderbufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000097 HandleAllocator mRenderbufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000098};
99
100}
101
102#endif // LIBGLESV2_RESOURCEMANAGER_H_