blob: f04a34c7c38861dc31ef267f35eca2cf1c4ebdd0 [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
Geoff Lang0a73dd82014-11-19 16:18:08 -050010#ifndef LIBANGLE_RESOURCEMANAGER_H_
11#define LIBANGLE_RESOURCEMANAGER_H_
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000012
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000013#include "common/angleutils.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050014#include "libANGLE/angletypes.h"
15#include "libANGLE/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;
Jamie Madill245d3602014-11-13 10:03:30 -050035struct Data;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000036
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000037class ResourceManager
38{
39 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +000040 explicit ResourceManager(rx::Renderer *renderer);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000041 ~ResourceManager();
42
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000043 void addRef();
44 void release();
45
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000046 GLuint createBuffer();
Jamie Madill245d3602014-11-13 10:03:30 -050047 GLuint createShader(const gl::Data &data, GLenum type);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000048 GLuint createProgram();
49 GLuint createTexture();
50 GLuint createRenderbuffer();
Jamie Madilldc356042013-07-19 16:36:57 -040051 GLuint createSampler();
Jamie Madillcd055f82013-07-26 11:55:15 -040052 GLuint createFenceSync();
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000053
54 void deleteBuffer(GLuint buffer);
55 void deleteShader(GLuint shader);
56 void deleteProgram(GLuint program);
57 void deleteTexture(GLuint texture);
58 void deleteRenderbuffer(GLuint renderbuffer);
Jamie Madilldc356042013-07-19 16:36:57 -040059 void deleteSampler(GLuint sampler);
Jamie Madillcd055f82013-07-26 11:55:15 -040060 void deleteFenceSync(GLuint fenceSync);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000061
62 Buffer *getBuffer(GLuint handle);
63 Shader *getShader(GLuint handle);
Jamie Madilld9e58302014-11-06 15:27:26 -050064 Program *getProgram(GLuint handle) const;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000065 Texture *getTexture(GLuint handle);
Jamie Madill6c7b4ad2014-06-16 10:33:59 -040066 Renderbuffer *getRenderbuffer(GLuint handle);
Jamie Madilldc356042013-07-19 16:36:57 -040067 Sampler *getSampler(GLuint handle);
Jamie Madillcd055f82013-07-26 11:55:15 -040068 FenceSync *getFenceSync(GLuint handle);
Geoff Lang76b10c92014-09-05 16:28:14 -040069
Jamie Madill6c7b4ad2014-06-16 10:33:59 -040070 void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000071
72 void checkBufferAllocation(unsigned int buffer);
Geoff Lang76b10c92014-09-05 16:28:14 -040073 void checkTextureAllocation(GLuint texture, GLenum type);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000074 void checkRenderbufferAllocation(GLuint renderbuffer);
Jamie Madilldc356042013-07-19 16:36:57 -040075 void checkSamplerAllocation(GLuint sampler);
76
77 bool isSampler(GLuint sampler);
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000078
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000079 private:
80 DISALLOW_COPY_AND_ASSIGN(ResourceManager);
81
daniel@transgaming.com370482e2012-11-28 19:32:13 +000082 rx::Renderer *mRenderer;
Jamie Madill93e13fb2014-11-06 15:27:25 -050083 std::size_t mRefCount;
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000084
Geoff Lang9b8f92e2013-07-30 15:23:30 -040085 typedef std::unordered_map<GLuint, Buffer*> BufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000086 BufferMap mBufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000087 HandleAllocator mBufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000088
Geoff Lang9b8f92e2013-07-30 15:23:30 -040089 typedef std::unordered_map<GLuint, Shader*> ShaderMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000090 ShaderMap mShaderMap;
91
Geoff Lang9b8f92e2013-07-30 15:23:30 -040092 typedef std::unordered_map<GLuint, Program*> ProgramMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000093 ProgramMap mProgramMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000094 HandleAllocator mProgramShaderHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000095
Geoff Lang9b8f92e2013-07-30 15:23:30 -040096 typedef std::unordered_map<GLuint, Texture*> TextureMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000097 TextureMap mTextureMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000098 HandleAllocator mTextureHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000099
Jamie Madill6c7b4ad2014-06-16 10:33:59 -0400100 typedef std::unordered_map<GLuint, Renderbuffer*> RenderbufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000101 RenderbufferMap mRenderbufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +0000102 HandleAllocator mRenderbufferHandleAllocator;
Jamie Madilldc356042013-07-19 16:36:57 -0400103
Geoff Lang9b8f92e2013-07-30 15:23:30 -0400104 typedef std::unordered_map<GLuint, Sampler*> SamplerMap;
105 SamplerMap mSamplerMap;
Jamie Madilldc356042013-07-19 16:36:57 -0400106 HandleAllocator mSamplerHandleAllocator;
Jamie Madillcd055f82013-07-26 11:55:15 -0400107
Geoff Lang9b8f92e2013-07-30 15:23:30 -0400108 typedef std::unordered_map<GLuint, FenceSync*> FenceMap;
109 FenceMap mFenceSyncMap;
Jamie Madillcd055f82013-07-26 11:55:15 -0400110 HandleAllocator mFenceSyncHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000111};
112
113}
114
Geoff Lang0a73dd82014-11-19 16:18:08 -0500115#endif // LIBANGLE_RESOURCEMANAGER_H_