blob: e16a7a48b2393834a4189483107bf31841f890d4 [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;
Jamie Madillcd055f82013-07-26 11:55:15 -040040class FenceSync;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000041
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000042class ResourceManager
43{
44 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +000045 explicit ResourceManager(rx::Renderer *renderer);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000046 ~ResourceManager();
47
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000048 void addRef();
49 void release();
50
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000051 GLuint createBuffer();
52 GLuint createShader(GLenum type);
53 GLuint createProgram();
54 GLuint createTexture();
55 GLuint createRenderbuffer();
Jamie Madilldc356042013-07-19 16:36:57 -040056 GLuint createSampler();
Jamie Madillcd055f82013-07-26 11:55:15 -040057 GLuint createFenceSync();
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000058
59 void deleteBuffer(GLuint buffer);
60 void deleteShader(GLuint shader);
61 void deleteProgram(GLuint program);
62 void deleteTexture(GLuint texture);
63 void deleteRenderbuffer(GLuint renderbuffer);
Jamie Madilldc356042013-07-19 16:36:57 -040064 void deleteSampler(GLuint sampler);
Jamie Madillcd055f82013-07-26 11:55:15 -040065 void deleteFenceSync(GLuint fenceSync);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000066
67 Buffer *getBuffer(GLuint handle);
68 Shader *getShader(GLuint handle);
69 Program *getProgram(GLuint handle);
70 Texture *getTexture(GLuint handle);
71 Renderbuffer *getRenderbuffer(GLuint handle);
Jamie Madilldc356042013-07-19 16:36:57 -040072 Sampler *getSampler(GLuint handle);
Jamie Madillcd055f82013-07-26 11:55:15 -040073 FenceSync *getFenceSync(GLuint handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000074
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);
Jamie Madilldc356042013-07-19 16:36:57 -040080 void checkSamplerAllocation(GLuint sampler);
81
82 bool isSampler(GLuint sampler);
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000083
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000084 private:
85 DISALLOW_COPY_AND_ASSIGN(ResourceManager);
86
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000087 std::size_t mRefCount;
daniel@transgaming.com370482e2012-11-28 19:32:13 +000088 rx::Renderer *mRenderer;
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000089
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000090#ifndef HASH_MAP
91# ifdef _MSC_VER
92# define HASH_MAP stdext::hash_map
93# else
94# define HASH_MAP std::unordered_map
95# endif
96#endif
97
98 typedef HASH_MAP<GLuint, Buffer*> BufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000099 BufferMap mBufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +0000100 HandleAllocator mBufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000101
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +0000102 typedef HASH_MAP<GLuint, Shader*> ShaderMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000103 ShaderMap mShaderMap;
104
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +0000105 typedef HASH_MAP<GLuint, Program*> ProgramMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000106 ProgramMap mProgramMap;
benvanik@google.com1a233342011-04-28 19:44:39 +0000107 HandleAllocator mProgramShaderHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000108
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +0000109 typedef HASH_MAP<GLuint, Texture*> TextureMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000110 TextureMap mTextureMap;
benvanik@google.com1a233342011-04-28 19:44:39 +0000111 HandleAllocator mTextureHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000112
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +0000113 typedef HASH_MAP<GLuint, Renderbuffer*> RenderbufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000114 RenderbufferMap mRenderbufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +0000115 HandleAllocator mRenderbufferHandleAllocator;
Jamie Madilldc356042013-07-19 16:36:57 -0400116
117 HASH_MAP<GLuint, Sampler*> mSamplerMap;
118 HandleAllocator mSamplerHandleAllocator;
Jamie Madillcd055f82013-07-26 11:55:15 -0400119
120 HASH_MAP<GLuint, FenceSync*> mFenceSyncMap;
121 HandleAllocator mFenceSyncHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000122};
123
124}
125
126#endif // LIBGLESV2_RESOURCEMANAGER_H_