blob: e89c2b13c47c7a7895e14e83b06a47e485485a9d [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
shannon.woods%transgaming.com@gtempaccount.comf26ddae2013-04-13 03:29:13 +000014#include <GLES3/gl3.h>
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000015#include <GLES2/gl2.h>
16
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000017#ifdef _MSC_VER
daniel@transgaming.com733ba932011-04-14 15:03:48 +000018#include <hash_map>
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000019#else
20#include <unordered_map>
21#endif
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000022
23#include "common/angleutils.h"
daniel@transgaming.comef19da52012-11-28 19:35:08 +000024#include "libGLESv2/angletypes.h"
benvanik@google.com1a233342011-04-28 19:44:39 +000025#include "libGLESv2/HandleAllocator.h"
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000026
daniel@transgaming.com370482e2012-11-28 19:32:13 +000027namespace rx
28{
29class Renderer;
30}
31
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000032namespace gl
33{
34class Buffer;
35class Shader;
36class Program;
37class Texture;
38class Renderbuffer;
39
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000040class ResourceManager
41{
42 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +000043 explicit ResourceManager(rx::Renderer *renderer);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000044 ~ResourceManager();
45
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000046 void addRef();
47 void release();
48
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000049 GLuint createBuffer();
50 GLuint createShader(GLenum type);
51 GLuint createProgram();
52 GLuint createTexture();
53 GLuint createRenderbuffer();
54
55 void deleteBuffer(GLuint buffer);
56 void deleteShader(GLuint shader);
57 void deleteProgram(GLuint program);
58 void deleteTexture(GLuint texture);
59 void deleteRenderbuffer(GLuint renderbuffer);
60
61 Buffer *getBuffer(GLuint handle);
62 Shader *getShader(GLuint handle);
63 Program *getProgram(GLuint handle);
64 Texture *getTexture(GLuint handle);
65 Renderbuffer *getRenderbuffer(GLuint handle);
66
67 void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
68
69 void checkBufferAllocation(unsigned int buffer);
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +000070 void checkTextureAllocation(GLuint texture, TextureType type);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000071 void checkRenderbufferAllocation(GLuint renderbuffer);
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000072
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000073 private:
74 DISALLOW_COPY_AND_ASSIGN(ResourceManager);
75
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000076 std::size_t mRefCount;
daniel@transgaming.com370482e2012-11-28 19:32:13 +000077 rx::Renderer *mRenderer;
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000078
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000079#ifndef HASH_MAP
80# ifdef _MSC_VER
81# define HASH_MAP stdext::hash_map
82# else
83# define HASH_MAP std::unordered_map
84# endif
85#endif
86
87 typedef HASH_MAP<GLuint, Buffer*> BufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000088 BufferMap mBufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000089 HandleAllocator mBufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000090
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000091 typedef HASH_MAP<GLuint, Shader*> ShaderMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000092 ShaderMap mShaderMap;
93
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000094 typedef HASH_MAP<GLuint, Program*> ProgramMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000095 ProgramMap mProgramMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000096 HandleAllocator mProgramShaderHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000097
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000098 typedef HASH_MAP<GLuint, Texture*> TextureMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000099 TextureMap mTextureMap;
benvanik@google.com1a233342011-04-28 19:44:39 +0000100 HandleAllocator mTextureHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000101
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +0000102 typedef HASH_MAP<GLuint, Renderbuffer*> RenderbufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000103 RenderbufferMap mRenderbufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +0000104 HandleAllocator mRenderbufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000105};
106
107}
108
109#endif // LIBGLESV2_RESOURCEMANAGER_H_