blob: 4845e3980489eb3a8df75a92c4fa33bfa5ce037f [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 Madillae6495e2015-03-16 10:46:56 -040020class ImplFactory;
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 -040026struct Data;
27class FenceSync;
28struct Limitations;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000029class Program;
Jamie Madill6c7b4ad2014-06-16 10:33:59 -040030class Renderbuffer;
Jamie Madilldc356042013-07-19 16:36:57 -040031class Sampler;
Jamie Madill006cbc52015-09-23 16:47:54 -040032class Shader;
33class Texture;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000034
Jamie Madillf0d10f82015-03-31 12:56:52 -040035class ResourceManager : angle::NonCopyable
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000036{
37 public:
Jamie Madillae6495e2015-03-16 10:46:56 -040038 explicit ResourceManager(rx::ImplFactory *factory);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000039 ~ResourceManager();
40
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000041 void addRef();
42 void release();
43
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000044 GLuint createBuffer();
Jamie Madill006cbc52015-09-23 16:47:54 -040045 GLuint createShader(const gl::Limitations &rendererLimitations, GLenum type);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000046 GLuint createProgram();
47 GLuint createTexture();
48 GLuint createRenderbuffer();
Jamie Madilldc356042013-07-19 16:36:57 -040049 GLuint createSampler();
Jamie Madillcd055f82013-07-26 11:55:15 -040050 GLuint createFenceSync();
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000051
52 void deleteBuffer(GLuint buffer);
53 void deleteShader(GLuint shader);
54 void deleteProgram(GLuint program);
55 void deleteTexture(GLuint texture);
56 void deleteRenderbuffer(GLuint renderbuffer);
Jamie Madilldc356042013-07-19 16:36:57 -040057 void deleteSampler(GLuint sampler);
Jamie Madillcd055f82013-07-26 11:55:15 -040058 void deleteFenceSync(GLuint fenceSync);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000059
60 Buffer *getBuffer(GLuint handle);
61 Shader *getShader(GLuint handle);
Jamie Madilld9e58302014-11-06 15:27:26 -050062 Program *getProgram(GLuint handle) const;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000063 Texture *getTexture(GLuint handle);
Jamie Madill6c7b4ad2014-06-16 10:33:59 -040064 Renderbuffer *getRenderbuffer(GLuint handle);
Jamie Madilldc356042013-07-19 16:36:57 -040065 Sampler *getSampler(GLuint handle);
Jamie Madillcd055f82013-07-26 11:55:15 -040066 FenceSync *getFenceSync(GLuint handle);
Geoff Lang76b10c92014-09-05 16:28:14 -040067
Jamie Madill6c7b4ad2014-06-16 10:33:59 -040068 void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000069
Jamie Madill3f01e6c2016-03-08 13:53:02 -050070 Buffer *checkBufferAllocation(GLuint handle);
71 Texture *checkTextureAllocation(GLuint handle, GLenum type);
72 Renderbuffer *checkRenderbufferAllocation(GLuint handle);
73 Sampler *checkSamplerAllocation(GLuint samplerHandle);
Jamie Madilldc356042013-07-19 16:36:57 -040074
75 bool isSampler(GLuint sampler);
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000076
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000077 private:
Jamie Madillbdd419f2015-03-20 15:29:42 -040078 void createTextureInternal(GLuint handle);
79
Jamie Madillae6495e2015-03-16 10:46:56 -040080 rx::ImplFactory *mFactory;
Jamie Madill93e13fb2014-11-06 15:27:25 -050081 std::size_t mRefCount;
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000082
Jamie Madill4e25a0d2016-03-08 13:53:03 -050083 ResourceMap<Buffer> mBufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000084 HandleAllocator mBufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000085
Jamie Madill4e25a0d2016-03-08 13:53:03 -050086 ResourceMap<Shader> mShaderMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000087
Jamie Madill4e25a0d2016-03-08 13:53:03 -050088 ResourceMap<Program> mProgramMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000089 HandleAllocator mProgramShaderHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000090
Jamie Madill4e25a0d2016-03-08 13:53:03 -050091 ResourceMap<Texture> mTextureMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000092 HandleAllocator mTextureHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000093
Jamie Madill4e25a0d2016-03-08 13:53:03 -050094 ResourceMap<Renderbuffer> mRenderbufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000095 HandleAllocator mRenderbufferHandleAllocator;
Jamie Madilldc356042013-07-19 16:36:57 -040096
Jamie Madill4e25a0d2016-03-08 13:53:03 -050097 ResourceMap<Sampler> mSamplerMap;
Jamie Madilldc356042013-07-19 16:36:57 -040098 HandleAllocator mSamplerHandleAllocator;
Jamie Madillcd055f82013-07-26 11:55:15 -040099
Jamie Madill4e25a0d2016-03-08 13:53:03 -0500100 ResourceMap<FenceSync> mFenceSyncMap;
Jamie Madillcd055f82013-07-26 11:55:15 -0400101 HandleAllocator mFenceSyncHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000102};
103
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500104} // namespace gl
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000105
Geoff Lang0a73dd82014-11-19 16:18:08 -0500106#endif // LIBANGLE_RESOURCEMANAGER_H_