blob: 900131563530b1254620217ef8e824870a957dbf [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
daniel@transgaming.com370482e2012-11-28 19:32:13 +000018namespace rx
19{
Jamie Madill7aea7e02016-05-10 10:39:45 -040020class GLImplFactory;
daniel@transgaming.com370482e2012-11-28 19:32:13 +000021}
22
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000023namespace gl
24{
25class Buffer;
Jamie Madill006cbc52015-09-23 16:47:54 -040026class FenceSync;
27struct Limitations;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000028class Program;
Jamie Madill6c7b4ad2014-06-16 10:33:59 -040029class Renderbuffer;
Jamie Madilldc356042013-07-19 16:36:57 -040030class Sampler;
Jamie Madill006cbc52015-09-23 16:47:54 -040031class Shader;
32class Texture;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000033
Jamie Madillf0d10f82015-03-31 12:56:52 -040034class ResourceManager : angle::NonCopyable
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000035{
36 public:
Jamie Madill901b3792016-05-26 09:20:40 -040037 ResourceManager();
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000038 ~ResourceManager();
39
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000040 void addRef();
41 void release();
42
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000043 GLuint createBuffer();
Jamie Madill901b3792016-05-26 09:20:40 -040044 GLuint createShader(rx::GLImplFactory *factory,
45 const gl::Limitations &rendererLimitations,
46 GLenum type);
47 GLuint createProgram(rx::GLImplFactory *factory);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000048 GLuint createTexture();
49 GLuint createRenderbuffer();
Jamie Madilldc356042013-07-19 16:36:57 -040050 GLuint createSampler();
Jamie Madill901b3792016-05-26 09:20:40 -040051 GLuint createFenceSync(rx::GLImplFactory *factory);
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 Madill901b3792016-05-26 09:20:40 -040071 Buffer *checkBufferAllocation(rx::GLImplFactory *factory, GLuint handle);
72 Texture *checkTextureAllocation(rx::GLImplFactory *factory, GLuint handle, GLenum type);
73 Renderbuffer *checkRenderbufferAllocation(rx::GLImplFactory *factory, GLuint handle);
74 Sampler *checkSamplerAllocation(rx::GLImplFactory *factory, GLuint samplerHandle);
Jamie Madilldc356042013-07-19 16:36:57 -040075
76 bool isSampler(GLuint sampler);
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000077
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000078 private:
Jamie Madillbdd419f2015-03-20 15:29:42 -040079 void createTextureInternal(GLuint handle);
80
Jamie Madill901b3792016-05-26 09:20:40 -040081 ;
Jamie Madill93e13fb2014-11-06 15:27:25 -050082 std::size_t mRefCount;
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000083
Jamie Madill4e25a0d2016-03-08 13:53:03 -050084 ResourceMap<Buffer> mBufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000085 HandleAllocator mBufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000086
Jamie Madill4e25a0d2016-03-08 13:53:03 -050087 ResourceMap<Shader> mShaderMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000088
Jamie Madill4e25a0d2016-03-08 13:53:03 -050089 ResourceMap<Program> mProgramMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000090 HandleAllocator mProgramShaderHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000091
Jamie Madill4e25a0d2016-03-08 13:53:03 -050092 ResourceMap<Texture> mTextureMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000093 HandleAllocator mTextureHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000094
Jamie Madill4e25a0d2016-03-08 13:53:03 -050095 ResourceMap<Renderbuffer> mRenderbufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000096 HandleAllocator mRenderbufferHandleAllocator;
Jamie Madilldc356042013-07-19 16:36:57 -040097
Jamie Madill4e25a0d2016-03-08 13:53:03 -050098 ResourceMap<Sampler> mSamplerMap;
Jamie Madilldc356042013-07-19 16:36:57 -040099 HandleAllocator mSamplerHandleAllocator;
Jamie Madillcd055f82013-07-26 11:55:15 -0400100
Jamie Madill4e25a0d2016-03-08 13:53:03 -0500101 ResourceMap<FenceSync> mFenceSyncMap;
Jamie Madillcd055f82013-07-26 11:55:15 -0400102 HandleAllocator mFenceSyncHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000103};
104
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500105} // namespace gl
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000106
Geoff Lang0a73dd82014-11-19 16:18:08 -0500107#endif // LIBANGLE_RESOURCEMANAGER_H_