blob: 1d898d88f05f552f16254a542a4bbd25db5484de [file] [log] [blame]
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +00001//
Jamie Madilldc356042013-07-19 16:36:57 -04002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +00003// 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;
Jamie Madilldc356042013-07-19 16:36:57 -040039class Sampler;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000040
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000041class ResourceManager
42{
43 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +000044 explicit ResourceManager(rx::Renderer *renderer);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000045 ~ResourceManager();
46
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000047 void addRef();
48 void release();
49
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000050 GLuint createBuffer();
51 GLuint createShader(GLenum type);
52 GLuint createProgram();
53 GLuint createTexture();
54 GLuint createRenderbuffer();
Jamie Madilldc356042013-07-19 16:36:57 -040055 GLuint createSampler();
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000056
57 void deleteBuffer(GLuint buffer);
58 void deleteShader(GLuint shader);
59 void deleteProgram(GLuint program);
60 void deleteTexture(GLuint texture);
61 void deleteRenderbuffer(GLuint renderbuffer);
Jamie Madilldc356042013-07-19 16:36:57 -040062 void deleteSampler(GLuint sampler);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000063
64 Buffer *getBuffer(GLuint handle);
65 Shader *getShader(GLuint handle);
66 Program *getProgram(GLuint handle);
67 Texture *getTexture(GLuint handle);
68 Renderbuffer *getRenderbuffer(GLuint handle);
Jamie Madilldc356042013-07-19 16:36:57 -040069 Sampler *getSampler(GLuint handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000070
71 void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
72
73 void checkBufferAllocation(unsigned int buffer);
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +000074 void checkTextureAllocation(GLuint texture, TextureType type);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000075 void checkRenderbufferAllocation(GLuint renderbuffer);
Jamie Madilldc356042013-07-19 16:36:57 -040076 void checkSamplerAllocation(GLuint sampler);
77
78 bool isSampler(GLuint sampler);
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000079
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000080 private:
81 DISALLOW_COPY_AND_ASSIGN(ResourceManager);
82
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000083 std::size_t mRefCount;
daniel@transgaming.com370482e2012-11-28 19:32:13 +000084 rx::Renderer *mRenderer;
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000085
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;
Jamie Madilldc356042013-07-19 16:36:57 -0400112
113 HASH_MAP<GLuint, Sampler*> mSamplerMap;
114 HandleAllocator mSamplerHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000115};
116
117}
118
119#endif // LIBGLESV2_RESOURCEMANAGER_H_