blob: 14858ad8ccde7b863cbf986f0e14fa2c1808aab2 [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;
28class Shader;
29class Program;
30class Texture;
Jamie Madill6c7b4ad2014-06-16 10:33:59 -040031class Renderbuffer;
Jamie Madilldc356042013-07-19 16:36:57 -040032class Sampler;
Jamie Madillcd055f82013-07-26 11:55:15 -040033class FenceSync;
Jamie Madill245d3602014-11-13 10:03:30 -050034struct Data;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000035
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000036class ResourceManager
37{
38 public:
Jamie Madillae6495e2015-03-16 10:46:56 -040039 explicit ResourceManager(rx::ImplFactory *factory);
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();
Jamie Madill245d3602014-11-13 10:03:30 -050046 GLuint createShader(const gl::Data &data, GLenum type);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000047 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);
Jamie Madilld9e58302014-11-06 15:27:26 -050063 Program *getProgram(GLuint handle) const;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000064 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
Jamie Madill21045f52015-03-20 19:28:45 +000071 void checkBufferAllocation(unsigned int buffer);
72 void checkTextureAllocation(GLuint texture, GLenum type);
73 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
Jamie Madillae6495e2015-03-16 10:46:56 -040081 rx::ImplFactory *mFactory;
Jamie Madill93e13fb2014-11-06 15:27:25 -050082 std::size_t mRefCount;
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000083
Jamie Madillcd1db9e2015-01-05 16:09:05 -050084 typedef std::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
Jamie Madillcd1db9e2015-01-05 16:09:05 -050088 typedef std::map<GLuint, Shader*> ShaderMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000089 ShaderMap mShaderMap;
90
Jamie Madillcd1db9e2015-01-05 16:09:05 -050091 typedef std::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
Jamie Madillcd1db9e2015-01-05 16:09:05 -050095 typedef std::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 Madillcd1db9e2015-01-05 16:09:05 -050099 typedef std::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
Jamie Madillcd1db9e2015-01-05 16:09:05 -0500103 typedef std::map<GLuint, Sampler*> SamplerMap;
Geoff Lang9b8f92e2013-07-30 15:23:30 -0400104 SamplerMap mSamplerMap;
Jamie Madilldc356042013-07-19 16:36:57 -0400105 HandleAllocator mSamplerHandleAllocator;
Jamie Madillcd055f82013-07-26 11:55:15 -0400106
Jamie Madillcd1db9e2015-01-05 16:09:05 -0500107 typedef std::map<GLuint, FenceSync*> FenceMap;
Geoff Lang9b8f92e2013-07-30 15:23:30 -0400108 FenceMap mFenceSyncMap;
Jamie Madillcd055f82013-07-26 11:55:15 -0400109 HandleAllocator mFenceSyncHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000110};
111
112}
113
Geoff Lang0a73dd82014-11-19 16:18:08 -0500114#endif // LIBANGLE_RESOURCEMANAGER_H_