blob: a08a6aae1edfbcc0f54d43c97dce7e8013e86fd6 [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
shannon.woods%transgaming.com@gtempaccount.comf26ddae2013-04-13 03:29:13 +000013#include <GLES3/gl3.h>
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000014#include <GLES2/gl2.h>
15
daniel@transgaming.comdb2115d2012-08-27 16:25:33 +000016#include <unordered_map>
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000017
18#include "common/angleutils.h"
daniel@transgaming.comef19da52012-11-28 19:35:08 +000019#include "libGLESv2/angletypes.h"
benvanik@google.com1a233342011-04-28 19:44:39 +000020#include "libGLESv2/HandleAllocator.h"
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000021
daniel@transgaming.com370482e2012-11-28 19:32:13 +000022namespace rx
23{
24class Renderer;
25}
26
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000027namespace gl
28{
29class Buffer;
30class Shader;
31class Program;
32class Texture;
Jamie Madill3c7fa222014-06-05 13:08:51 -040033class FramebufferAttachment;
Jamie Madilldc356042013-07-19 16:36:57 -040034class Sampler;
Jamie Madillcd055f82013-07-26 11:55:15 -040035class FenceSync;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000036
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000037class ResourceManager
38{
39 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +000040 explicit ResourceManager(rx::Renderer *renderer);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000041 ~ResourceManager();
42
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000043 void addRef();
44 void release();
45
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000046 GLuint createBuffer();
47 GLuint createShader(GLenum type);
48 GLuint createProgram();
49 GLuint createTexture();
50 GLuint createRenderbuffer();
Jamie Madilldc356042013-07-19 16:36:57 -040051 GLuint createSampler();
Jamie Madillcd055f82013-07-26 11:55:15 -040052 GLuint createFenceSync();
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000053
54 void deleteBuffer(GLuint buffer);
55 void deleteShader(GLuint shader);
56 void deleteProgram(GLuint program);
57 void deleteTexture(GLuint texture);
58 void deleteRenderbuffer(GLuint renderbuffer);
Jamie Madilldc356042013-07-19 16:36:57 -040059 void deleteSampler(GLuint sampler);
Jamie Madillcd055f82013-07-26 11:55:15 -040060 void deleteFenceSync(GLuint fenceSync);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000061
62 Buffer *getBuffer(GLuint handle);
63 Shader *getShader(GLuint handle);
64 Program *getProgram(GLuint handle);
65 Texture *getTexture(GLuint handle);
Jamie Madill3c7fa222014-06-05 13:08:51 -040066 FramebufferAttachment *getRenderbuffer(GLuint handle);
Jamie Madilldc356042013-07-19 16:36:57 -040067 Sampler *getSampler(GLuint handle);
Jamie Madillcd055f82013-07-26 11:55:15 -040068 FenceSync *getFenceSync(GLuint handle);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000069
Jamie Madill3c7fa222014-06-05 13:08:51 -040070 void setRenderbuffer(GLuint handle, FramebufferAttachment *renderbuffer);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000071
72 void checkBufferAllocation(unsigned int buffer);
daniel@transgaming.com0e64dd62011-05-11 15:36:37 +000073 void checkTextureAllocation(GLuint texture, TextureType type);
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000074 void checkRenderbufferAllocation(GLuint renderbuffer);
Jamie Madilldc356042013-07-19 16:36:57 -040075 void checkSamplerAllocation(GLuint sampler);
76
77 bool isSampler(GLuint sampler);
apatrick@chromium.orgff8bdfb2010-09-15 17:27:49 +000078
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000079 private:
80 DISALLOW_COPY_AND_ASSIGN(ResourceManager);
81
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000082 std::size_t mRefCount;
daniel@transgaming.com370482e2012-11-28 19:32:13 +000083 rx::Renderer *mRenderer;
daniel@transgaming.com0d25b002010-07-28 19:21:07 +000084
Geoff Lang9b8f92e2013-07-30 15:23:30 -040085 typedef std::unordered_map<GLuint, Buffer*> BufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000086 BufferMap mBufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000087 HandleAllocator mBufferHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000088
Geoff Lang9b8f92e2013-07-30 15:23:30 -040089 typedef std::unordered_map<GLuint, Shader*> ShaderMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000090 ShaderMap mShaderMap;
91
Geoff Lang9b8f92e2013-07-30 15:23:30 -040092 typedef std::unordered_map<GLuint, Program*> ProgramMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000093 ProgramMap mProgramMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000094 HandleAllocator mProgramShaderHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000095
Geoff Lang9b8f92e2013-07-30 15:23:30 -040096 typedef std::unordered_map<GLuint, Texture*> TextureMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000097 TextureMap mTextureMap;
benvanik@google.com1a233342011-04-28 19:44:39 +000098 HandleAllocator mTextureHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000099
Jamie Madill3c7fa222014-06-05 13:08:51 -0400100 typedef std::unordered_map<GLuint, FramebufferAttachment*> RenderbufferMap;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000101 RenderbufferMap mRenderbufferMap;
benvanik@google.com1a233342011-04-28 19:44:39 +0000102 HandleAllocator mRenderbufferHandleAllocator;
Jamie Madilldc356042013-07-19 16:36:57 -0400103
Geoff Lang9b8f92e2013-07-30 15:23:30 -0400104 typedef std::unordered_map<GLuint, Sampler*> SamplerMap;
105 SamplerMap mSamplerMap;
Jamie Madilldc356042013-07-19 16:36:57 -0400106 HandleAllocator mSamplerHandleAllocator;
Jamie Madillcd055f82013-07-26 11:55:15 -0400107
Geoff Lang9b8f92e2013-07-30 15:23:30 -0400108 typedef std::unordered_map<GLuint, FenceSync*> FenceMap;
109 FenceMap mFenceSyncMap;
Jamie Madillcd055f82013-07-26 11:55:15 -0400110 HandleAllocator mFenceSyncHandleAllocator;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000111};
112
113}
114
115#endif // LIBGLESV2_RESOURCEMANAGER_H_