blob: 3bd6cad6a5a4168333851d392760c1d1bcebc56b [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
10#ifndef LIBGLESV2_RESOURCEMANAGER_H_
11#define LIBGLESV2_RESOURCEMANAGER_H_
12
13#define GL_APICALL
shannon.woods%transgaming.com@gtempaccount.comf26ddae2013-04-13 03:29:13 +000014#include <GLES3/gl3.h>
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000015#include <GLES2/gl2.h>
16
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000017#include <unordered_map>
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000018
19#include "common/angleutils.h"
daniel@transgaming.comef19da52012-11-28 19:35:08 +000020#include "libGLESv2/angletypes.h"
benvanik@google.com1a233342011-04-28 19:44:39 +000021#include "libGLESv2/HandleAllocator.h"
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000022
daniel@transgaming.com370482e2012-11-28 19:32:13 +000023namespace rx
24{
25class Renderer;
26}
27
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000028namespace gl
29{
30class Buffer;
31class Shader;
32class Program;
33class Texture;
34class Renderbuffer;
Jamie Madilldc356042013-07-19 16:36:57 -040035class Sampler;
Jamie Madillcd055f82013-07-26 11:55:15 -040036class FenceSync;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000037
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000038class ResourceManager
39{
40 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +000041 explicit ResourceManager(rx::Renderer *renderer);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000042 ~ResourceManager();
43
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000044 void addRef();
45 void release();
46
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000047 GLuint createBuffer();
48 GLuint createShader(GLenum type);
49 GLuint createProgram();
50 GLuint createTexture();
51 GLuint createRenderbuffer();
Jamie Madilldc356042013-07-19 16:36:57 -040052 GLuint createSampler();
Jamie Madillcd055f82013-07-26 11:55:15 -040053 GLuint createFenceSync();
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000054
55 void deleteBuffer(GLuint buffer);
56 void deleteShader(GLuint shader);
57 void deleteProgram(GLuint program);
58 void deleteTexture(GLuint texture);
59 void deleteRenderbuffer(GLuint renderbuffer);
Jamie Madilldc356042013-07-19 16:36:57 -040060 void deleteSampler(GLuint sampler);
Jamie Madillcd055f82013-07-26 11:55:15 -040061 void deleteFenceSync(GLuint fenceSync);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000062
63 Buffer *getBuffer(GLuint handle);
64 Shader *getShader(GLuint handle);
65 Program *getProgram(GLuint handle);
66 Texture *getTexture(GLuint handle);
67 Renderbuffer *getRenderbuffer(GLuint handle);
Jamie Madilldc356042013-07-19 16:36:57 -040068 Sampler *getSampler(GLuint handle);
Jamie Madillcd055f82013-07-26 11:55:15 -040069 FenceSync *getFenceSync(GLuint handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000070
71 void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
72
73 void checkBufferAllocation(unsigned int buffer);
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +000074 void checkTextureAllocation(GLuint texture, TextureType type);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000075 void checkRenderbufferAllocation(GLuint renderbuffer);
Jamie Madilldc356042013-07-19 16:36:57 -040076 void checkSamplerAllocation(GLuint sampler);
77
78 bool isSampler(GLuint sampler);
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000079
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000080 private:
81 DISALLOW_COPY_AND_ASSIGN(ResourceManager);
82
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000083 std::size_t mRefCount;
daniel@transgaming.com370482e2012-11-28 19:32:13 +000084 rx::Renderer *mRenderer;
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000085
Geoff Lang9b8f92e2013-07-30 15:23:30 -040086 typedef std::unordered_map<GLuint, Buffer*> BufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000087 BufferMap mBufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000088 HandleAllocator mBufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000089
Geoff Lang9b8f92e2013-07-30 15:23:30 -040090 typedef std::unordered_map<GLuint, Shader*> ShaderMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000091 ShaderMap mShaderMap;
92
Geoff Lang9b8f92e2013-07-30 15:23:30 -040093 typedef std::unordered_map<GLuint, Program*> ProgramMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000094 ProgramMap mProgramMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000095 HandleAllocator mProgramShaderHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000096
Geoff Lang9b8f92e2013-07-30 15:23:30 -040097 typedef std::unordered_map<GLuint, Texture*> TextureMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000098 TextureMap mTextureMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000099 HandleAllocator mTextureHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000100
Geoff Lang9b8f92e2013-07-30 15:23:30 -0400101 typedef std::unordered_map<GLuint, Renderbuffer*> RenderbufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000102 RenderbufferMap mRenderbufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +0000103 HandleAllocator mRenderbufferHandleAllocator;
Jamie Madilldc356042013-07-19 16:36:57 -0400104
Geoff Lang9b8f92e2013-07-30 15:23:30 -0400105 typedef std::unordered_map<GLuint, Sampler*> SamplerMap;
106 SamplerMap mSamplerMap;
Jamie Madilldc356042013-07-19 16:36:57 -0400107 HandleAllocator mSamplerHandleAllocator;
Jamie Madillcd055f82013-07-26 11:55:15 -0400108
Geoff Lang9b8f92e2013-07-30 15:23:30 -0400109 typedef std::unordered_map<GLuint, FenceSync*> FenceMap;
110 FenceMap mFenceSyncMap;
Jamie Madillcd055f82013-07-26 11:55:15 -0400111 HandleAllocator mFenceSyncHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000112};
113
114}
115
116#endif // LIBGLESV2_RESOURCEMANAGER_H_