blob: baac331e28611091d533df49abc739e0d7cb7d5f [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 Madill7aea7e02016-05-10 10:39:45 -040037 explicit ResourceManager(rx::GLImplFactory *factory);
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 Madill006cbc52015-09-23 16:47:54 -040044 GLuint createShader(const gl::Limitations &rendererLimitations, GLenum type);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000045 GLuint createProgram();
46 GLuint createTexture();
47 GLuint createRenderbuffer();
Jamie Madilldc356042013-07-19 16:36:57 -040048 GLuint createSampler();
Jamie Madillcd055f82013-07-26 11:55:15 -040049 GLuint createFenceSync();
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000050
51 void deleteBuffer(GLuint buffer);
52 void deleteShader(GLuint shader);
53 void deleteProgram(GLuint program);
54 void deleteTexture(GLuint texture);
55 void deleteRenderbuffer(GLuint renderbuffer);
Jamie Madilldc356042013-07-19 16:36:57 -040056 void deleteSampler(GLuint sampler);
Jamie Madillcd055f82013-07-26 11:55:15 -040057 void deleteFenceSync(GLuint fenceSync);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000058
59 Buffer *getBuffer(GLuint handle);
60 Shader *getShader(GLuint handle);
Jamie Madilld9e58302014-11-06 15:27:26 -050061 Program *getProgram(GLuint handle) const;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000062 Texture *getTexture(GLuint handle);
Jamie Madill6c7b4ad2014-06-16 10:33:59 -040063 Renderbuffer *getRenderbuffer(GLuint handle);
Jamie Madilldc356042013-07-19 16:36:57 -040064 Sampler *getSampler(GLuint handle);
Jamie Madillcd055f82013-07-26 11:55:15 -040065 FenceSync *getFenceSync(GLuint handle);
Geoff Lang76b10c92014-09-05 16:28:14 -040066
Jamie Madill6c7b4ad2014-06-16 10:33:59 -040067 void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000068
Jamie Madill3f01e6c2016-03-08 13:53:02 -050069 Buffer *checkBufferAllocation(GLuint handle);
70 Texture *checkTextureAllocation(GLuint handle, GLenum type);
71 Renderbuffer *checkRenderbufferAllocation(GLuint handle);
72 Sampler *checkSamplerAllocation(GLuint samplerHandle);
Jamie Madilldc356042013-07-19 16:36:57 -040073
74 bool isSampler(GLuint sampler);
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000075
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000076 private:
Jamie Madillbdd419f2015-03-20 15:29:42 -040077 void createTextureInternal(GLuint handle);
78
Jamie Madill7aea7e02016-05-10 10:39:45 -040079 rx::GLImplFactory *mFactory;
Jamie Madill93e13fb2014-11-06 15:27:25 -050080 std::size_t mRefCount;
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000081
Jamie Madill4e25a0d2016-03-08 13:53:03 -050082 ResourceMap<Buffer> mBufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000083 HandleAllocator mBufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000084
Jamie Madill4e25a0d2016-03-08 13:53:03 -050085 ResourceMap<Shader> mShaderMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000086
Jamie Madill4e25a0d2016-03-08 13:53:03 -050087 ResourceMap<Program> mProgramMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000088 HandleAllocator mProgramShaderHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000089
Jamie Madill4e25a0d2016-03-08 13:53:03 -050090 ResourceMap<Texture> mTextureMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000091 HandleAllocator mTextureHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000092
Jamie Madill4e25a0d2016-03-08 13:53:03 -050093 ResourceMap<Renderbuffer> mRenderbufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000094 HandleAllocator mRenderbufferHandleAllocator;
Jamie Madilldc356042013-07-19 16:36:57 -040095
Jamie Madill4e25a0d2016-03-08 13:53:03 -050096 ResourceMap<Sampler> mSamplerMap;
Jamie Madilldc356042013-07-19 16:36:57 -040097 HandleAllocator mSamplerHandleAllocator;
Jamie Madillcd055f82013-07-26 11:55:15 -040098
Jamie Madill4e25a0d2016-03-08 13:53:03 -050099 ResourceMap<FenceSync> mFenceSyncMap;
Jamie Madillcd055f82013-07-26 11:55:15 -0400100 HandleAllocator mFenceSyncHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000101};
102
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500103} // namespace gl
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000104
Geoff Lang0a73dd82014-11-19 16:18:08 -0500105#endif // LIBANGLE_RESOURCEMANAGER_H_