blob: 7d53bd485495f3b96431b1233fc76e035f271037 [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
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000013#include "common/angleutils.h"
daniel@transgaming.comef19da52012-11-28 19:35:08 +000014#include "libGLESv2/angletypes.h"
benvanik@google.com1a233342011-04-28 19:44:39 +000015#include "libGLESv2/HandleAllocator.h"
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000016
Geoff Lang0b7eef72014-06-12 14:10:47 -040017#include "angle_gl.h"
18
19#include <unordered_map>
20
daniel@transgaming.com370482e2012-11-28 19:32:13 +000021namespace rx
22{
23class Renderer;
24}
25
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000026namespace gl
27{
28class Buffer;
29class Shader;
30class Program;
31class Texture;
Jamie Madill6c7b4ad2014-06-16 10:33:59 -040032class Renderbuffer;
Jamie Madilldc356042013-07-19 16:36:57 -040033class Sampler;
Jamie Madillcd055f82013-07-26 11:55:15 -040034class FenceSync;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000035
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000036class ResourceManager
37{
38 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +000039 explicit ResourceManager(rx::Renderer *renderer);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000040 ~ResourceManager();
41
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000042 void addRef();
43 void release();
44
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000045 GLuint createBuffer();
46 GLuint createShader(GLenum type);
47 GLuint createProgram();
48 GLuint createTexture();
49 GLuint createRenderbuffer();
Jamie Madilldc356042013-07-19 16:36:57 -040050 GLuint createSampler();
Jamie Madillcd055f82013-07-26 11:55:15 -040051 GLuint createFenceSync();
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000052
53 void deleteBuffer(GLuint buffer);
54 void deleteShader(GLuint shader);
55 void deleteProgram(GLuint program);
56 void deleteTexture(GLuint texture);
57 void deleteRenderbuffer(GLuint renderbuffer);
Jamie Madilldc356042013-07-19 16:36:57 -040058 void deleteSampler(GLuint sampler);
Jamie Madillcd055f82013-07-26 11:55:15 -040059 void deleteFenceSync(GLuint fenceSync);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000060
61 Buffer *getBuffer(GLuint handle);
62 Shader *getShader(GLuint handle);
63 Program *getProgram(GLuint handle);
64 Texture *getTexture(GLuint handle);
Jamie Madill6c7b4ad2014-06-16 10:33:59 -040065 Renderbuffer *getRenderbuffer(GLuint handle);
Jamie Madilldc356042013-07-19 16:36:57 -040066 Sampler *getSampler(GLuint handle);
Jamie Madillcd055f82013-07-26 11:55:15 -040067 FenceSync *getFenceSync(GLuint handle);
Geoff Lang76b10c92014-09-05 16:28:14 -040068
Jamie Madill6c7b4ad2014-06-16 10:33:59 -040069 void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000070
71 void checkBufferAllocation(unsigned int buffer);
Geoff Lang76b10c92014-09-05 16:28:14 -040072 void checkTextureAllocation(GLuint texture, GLenum type);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000073 void checkRenderbufferAllocation(GLuint renderbuffer);
Jamie Madilldc356042013-07-19 16:36:57 -040074 void checkSamplerAllocation(GLuint sampler);
75
76 bool isSampler(GLuint sampler);
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000077
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000078 private:
79 DISALLOW_COPY_AND_ASSIGN(ResourceManager);
80
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000081 std::size_t mRefCount;
daniel@transgaming.com370482e2012-11-28 19:32:13 +000082 rx::Renderer *mRenderer;
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000083
Geoff Lang9b8f92e2013-07-30 15:23:30 -040084 typedef std::unordered_map<GLuint, Buffer*> BufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000085 BufferMap mBufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000086 HandleAllocator mBufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000087
Geoff Lang9b8f92e2013-07-30 15:23:30 -040088 typedef std::unordered_map<GLuint, Shader*> ShaderMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000089 ShaderMap mShaderMap;
90
Geoff Lang9b8f92e2013-07-30 15:23:30 -040091 typedef std::unordered_map<GLuint, Program*> ProgramMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000092 ProgramMap mProgramMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000093 HandleAllocator mProgramShaderHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000094
Geoff Lang9b8f92e2013-07-30 15:23:30 -040095 typedef std::unordered_map<GLuint, Texture*> TextureMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000096 TextureMap mTextureMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000097 HandleAllocator mTextureHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000098
Jamie Madill6c7b4ad2014-06-16 10:33:59 -040099 typedef std::unordered_map<GLuint, Renderbuffer*> RenderbufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000100 RenderbufferMap mRenderbufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +0000101 HandleAllocator mRenderbufferHandleAllocator;
Jamie Madilldc356042013-07-19 16:36:57 -0400102
Geoff Lang9b8f92e2013-07-30 15:23:30 -0400103 typedef std::unordered_map<GLuint, Sampler*> SamplerMap;
104 SamplerMap mSamplerMap;
Jamie Madilldc356042013-07-19 16:36:57 -0400105 HandleAllocator mSamplerHandleAllocator;
Jamie Madillcd055f82013-07-26 11:55:15 -0400106
Geoff Lang9b8f92e2013-07-30 15:23:30 -0400107 typedef std::unordered_map<GLuint, FenceSync*> FenceMap;
108 FenceMap mFenceSyncMap;
Jamie Madillcd055f82013-07-26 11:55:15 -0400109 HandleAllocator mFenceSyncHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000110};
111
112}
113
114#endif // LIBGLESV2_RESOURCEMANAGER_H_