blob: fad47f656d4218c44ddba9c78f57f3370b1d3c55 [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
Jamie Madillcd1db9e2015-01-05 16:09:05 -050013#include "angle_gl.h"
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000014#include "common/angleutils.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050015#include "libANGLE/angletypes.h"
16#include "libANGLE/HandleAllocator.h"
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000017
Jamie Madillcd1db9e2015-01-05 16:09:05 -050018#include <map>
Geoff Lang0b7eef72014-06-12 14:10:47 -040019
daniel@transgaming.com370482e2012-11-28 19:32:13 +000020namespace rx
21{
Jamie Madillae6495e2015-03-16 10:46:56 -040022class ImplFactory;
daniel@transgaming.com370482e2012-11-28 19:32:13 +000023}
24
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000025namespace gl
26{
27class Buffer;
Jamie Madill006cbc52015-09-23 16:47:54 -040028struct Data;
29class FenceSync;
30struct Limitations;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000031class Program;
Jamie Madill6c7b4ad2014-06-16 10:33:59 -040032class Renderbuffer;
Jamie Madilldc356042013-07-19 16:36:57 -040033class Sampler;
Jamie Madill006cbc52015-09-23 16:47:54 -040034class Shader;
35class Texture;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000036
Jamie Madillf0d10f82015-03-31 12:56:52 -040037class ResourceManager : angle::NonCopyable
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000038{
39 public:
Jamie Madillae6495e2015-03-16 10:46:56 -040040 explicit ResourceManager(rx::ImplFactory *factory);
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 Madill006cbc52015-09-23 16:47:54 -040047 GLuint createShader(const gl::Limitations &rendererLimitations, 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
Jamie Madill3f01e6c2016-03-08 13:53:02 -050072 Buffer *checkBufferAllocation(GLuint handle);
73 Texture *checkTextureAllocation(GLuint handle, GLenum type);
74 Renderbuffer *checkRenderbufferAllocation(GLuint handle);
75 Sampler *checkSamplerAllocation(GLuint samplerHandle);
Jamie Madilldc356042013-07-19 16:36:57 -040076
77 bool isSampler(GLuint sampler);
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000078
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000079 private:
Jamie Madillbdd419f2015-03-20 15:29:42 -040080 void createTextureInternal(GLuint handle);
81
Jamie Madillae6495e2015-03-16 10:46:56 -040082 rx::ImplFactory *mFactory;
Jamie Madill93e13fb2014-11-06 15:27:25 -050083 std::size_t mRefCount;
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000084
Jamie Madillcd1db9e2015-01-05 16:09:05 -050085 typedef std::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
Jamie Madillcd1db9e2015-01-05 16:09:05 -050089 typedef std::map<GLuint, Shader*> ShaderMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000090 ShaderMap mShaderMap;
91
Jamie Madillcd1db9e2015-01-05 16:09:05 -050092 typedef std::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
Jamie Madillcd1db9e2015-01-05 16:09:05 -050096 typedef std::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 Madillcd1db9e2015-01-05 16:09:05 -0500100 typedef std::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
Jamie Madillcd1db9e2015-01-05 16:09:05 -0500104 typedef std::map<GLuint, Sampler*> SamplerMap;
Geoff Lang9b8f92e2013-07-30 15:23:30 -0400105 SamplerMap mSamplerMap;
Jamie Madilldc356042013-07-19 16:36:57 -0400106 HandleAllocator mSamplerHandleAllocator;
Jamie Madillcd055f82013-07-26 11:55:15 -0400107
Jamie Madillcd1db9e2015-01-05 16:09:05 -0500108 typedef std::map<GLuint, FenceSync*> FenceMap;
Geoff Lang9b8f92e2013-07-30 15:23:30 -0400109 FenceMap mFenceSyncMap;
Jamie Madillcd055f82013-07-26 11:55:15 -0400110 HandleAllocator mFenceSyncHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000111};
112
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500113} // namespace gl
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000114
Geoff Lang0a73dd82014-11-19 16:18:08 -0500115#endif // LIBANGLE_RESOURCEMANAGER_H_