Refactor ResourceManager into separate managers per resource type.
BUG=angleproject:1639
Change-Id: I943f553cfb0e0feb57953770784b48e22fccc875
Reviewed-on: https://chromium-review.googlesource.com/423172
Commit-Queue: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/ResourceManager.cpp b/src/libANGLE/ResourceManager.cpp
index cfb965d..2e7f2a8 100644
--- a/src/libANGLE/ResourceManager.cpp
+++ b/src/libANGLE/ResourceManager.cpp
@@ -1,11 +1,11 @@
//
-// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2002-2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
-// ResourceManager.cpp: Implements the gl::ResourceManager class, which tracks and
-// retrieves objects which may be shared by multiple Contexts.
+// ResourceManager.cpp: Implements the the ResourceManager classes, which handle allocation and
+// lifetime of GL objects.
#include "libANGLE/ResourceManager.h"
@@ -21,60 +21,71 @@
namespace gl
{
-ResourceManager::ResourceManager() : mRefCount(1)
+
+namespace
+{
+
+template <typename ResourceType>
+GLuint AllocateEmptyObject(HandleAllocator *handleAllocator, ResourceMap<ResourceType> *objectMap)
+{
+ GLuint handle = handleAllocator->allocate();
+ (*objectMap)[handle] = nullptr;
+ return handle;
+}
+
+template <typename ResourceType, typename CreationFunction>
+GLuint InsertObject(HandleAllocator *handleAllocator,
+ ResourceMap<ResourceType> *objectMap,
+ const CreationFunction &func)
+{
+ GLuint handle = handleAllocator->allocate();
+ (*objectMap)[handle] = func(handle);
+ return handle;
+}
+
+template <typename ResourceType, typename DeletionFunction>
+void DeleteObject(HandleAllocator *handleAllocator,
+ ResourceMap<ResourceType> *objectMap,
+ GLuint handle,
+ const DeletionFunction &deletionFunc)
+{
+ auto objectIter = objectMap->find(handle);
+ if (objectIter == objectMap->end())
+ {
+ return;
+ }
+
+ if (objectIter->second != nullptr)
+ {
+ deletionFunc(objectIter->second);
+ }
+
+ handleAllocator->release(objectIter->first);
+ objectMap->erase(objectIter);
+}
+
+template <typename ResourceType>
+ResourceType *GetObject(const ResourceMap<ResourceType> &objectMap, GLuint handle)
+{
+ auto iter = objectMap.find(handle);
+ return iter != objectMap.end() ? iter->second : nullptr;
+}
+
+} // anonymous namespace
+
+template <typename HandleAllocatorType>
+ResourceManagerBase<HandleAllocatorType>::ResourceManagerBase() : mRefCount(1)
{
}
-ResourceManager::~ResourceManager()
-{
- while (!mBufferMap.empty())
- {
- deleteBuffer(mBufferMap.begin()->first);
- }
-
- while (!mProgramMap.empty())
- {
- deleteProgram(mProgramMap.begin()->first);
- }
-
- while (!mShaderMap.empty())
- {
- deleteShader(mShaderMap.begin()->first);
- }
-
- while (!mRenderbufferMap.empty())
- {
- deleteRenderbuffer(mRenderbufferMap.begin()->first);
- }
-
- while (!mTextureMap.empty())
- {
- deleteTexture(mTextureMap.begin()->first);
- }
-
- while (!mSamplerMap.empty())
- {
- deleteSampler(mSamplerMap.begin()->first);
- }
-
- while (!mFenceSyncMap.empty())
- {
- deleteFenceSync(mFenceSyncMap.begin()->first);
- }
-
- for (auto it = mPathMap.begin(); it != mPathMap.end(); ++it)
- {
- const auto *p = it->second;
- delete p;
- }
-}
-
-void ResourceManager::addRef()
+template <typename HandleAllocatorType>
+void ResourceManagerBase<HandleAllocatorType>::addRef()
{
mRefCount++;
}
-void ResourceManager::release()
+template <typename HandleAllocatorType>
+void ResourceManagerBase<HandleAllocatorType>::release()
{
if (--mRefCount == 0)
{
@@ -82,481 +93,396 @@
}
}
-// Returns an unused buffer name
-GLuint ResourceManager::createBuffer()
+template <typename ResourceType, typename HandleAllocatorType>
+TypedResourceManager<ResourceType, HandleAllocatorType>::~TypedResourceManager()
{
- GLuint handle = mBufferHandleAllocator.allocate();
-
- mBufferMap[handle] = nullptr;
-
- return handle;
+ while (!mObjectMap.empty())
+ {
+ deleteObject(mObjectMap.begin()->first);
+ }
}
-// Returns an unused shader/program name
-GLuint ResourceManager::createShader(rx::GLImplFactory *factory,
- const gl::Limitations &rendererLimitations,
- GLenum type)
+template <typename ResourceType, typename HandleAllocatorType>
+void TypedResourceManager<ResourceType, HandleAllocatorType>::deleteObject(GLuint handle)
+{
+ DeleteObject(&this->mHandleAllocator, &mObjectMap, handle,
+ [](ResourceType *object) { object->release(); });
+}
+
+// Instantiations of ResourceManager
+template class ResourceManagerBase<HandleAllocator>;
+template class ResourceManagerBase<HandleRangeAllocator>;
+template class TypedResourceManager<Buffer, HandleAllocator>;
+template class TypedResourceManager<Texture, HandleAllocator>;
+template class TypedResourceManager<Renderbuffer, HandleAllocator>;
+template class TypedResourceManager<Sampler, HandleAllocator>;
+template class TypedResourceManager<FenceSync, HandleAllocator>;
+
+GLuint BufferManager::createBuffer()
+{
+ return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
+}
+
+void BufferManager::deleteBuffer(GLuint buffer)
+{
+ deleteObject(buffer);
+}
+
+Buffer *BufferManager::getBuffer(GLuint handle) const
+{
+ return GetObject(mObjectMap, handle);
+}
+
+Buffer *BufferManager::checkBufferAllocation(rx::GLImplFactory *factory, GLuint handle)
+{
+ if (handle == 0)
+ {
+ return nullptr;
+ }
+
+ auto objectMapIter = mObjectMap.find(handle);
+ bool handleAllocated = (objectMapIter != mObjectMap.end());
+
+ if (handleAllocated && objectMapIter->second != nullptr)
+ {
+ return objectMapIter->second;
+ }
+
+ Buffer *object = new Buffer(factory, handle);
+ object->addRef();
+
+ if (handleAllocated)
+ {
+ objectMapIter->second = object;
+ }
+ else
+ {
+ mHandleAllocator.reserve(handle);
+ mObjectMap[handle] = object;
+ }
+
+ return object;
+}
+
+bool BufferManager::isBufferGenerated(GLuint buffer) const
+{
+ return buffer == 0 || mObjectMap.find(buffer) != mObjectMap.end();
+}
+
+ShaderProgramManager::~ShaderProgramManager()
+{
+ while (!mPrograms.empty())
+ {
+ deleteProgram(mPrograms.begin()->first);
+ }
+ while (!mShaders.empty())
+ {
+ deleteShader(mShaders.begin()->first);
+ }
+}
+
+GLuint ShaderProgramManager::createShader(rx::GLImplFactory *factory,
+ const gl::Limitations &rendererLimitations,
+ GLenum type)
{
ASSERT(type == GL_VERTEX_SHADER || type == GL_FRAGMENT_SHADER || type == GL_COMPUTE_SHADER);
- GLuint handle = mProgramShaderHandleAllocator.allocate();
-
- mShaderMap[handle] = new Shader(this, factory, rendererLimitations, type, handle);
-
+ GLuint handle = mHandleAllocator.allocate();
+ mShaders[handle] = new Shader(this, factory, rendererLimitations, type, handle);
return handle;
}
-// Returns an unused program/shader name
-GLuint ResourceManager::createProgram(rx::GLImplFactory *factory)
+void ShaderProgramManager::deleteShader(GLuint shader)
{
- GLuint handle = mProgramShaderHandleAllocator.allocate();
-
- mProgramMap[handle] = new Program(factory, this, handle);
-
- return handle;
+ deleteObject(&mShaders, shader);
}
-// Returns an unused texture name
-GLuint ResourceManager::createTexture()
+Shader *ShaderProgramManager::getShader(GLuint handle) const
{
- GLuint handle = mTextureHandleAllocator.allocate();
-
- mTextureMap[handle] = nullptr;
-
- return handle;
+ return GetObject(mShaders, handle);
}
-// Returns an unused renderbuffer name
-GLuint ResourceManager::createRenderbuffer()
+GLuint ShaderProgramManager::createProgram(rx::GLImplFactory *factory)
{
- GLuint handle = mRenderbufferHandleAllocator.allocate();
-
- mRenderbufferMap[handle] = nullptr;
-
+ GLuint handle = mHandleAllocator.allocate();
+ mPrograms[handle] = new Program(factory, this, handle);
return handle;
}
-// Returns an unused sampler name
-GLuint ResourceManager::createSampler()
+void ShaderProgramManager::deleteProgram(GLuint program)
{
- GLuint handle = mSamplerHandleAllocator.allocate();
-
- mSamplerMap[handle] = nullptr;
-
- return handle;
+ deleteObject(&mPrograms, program);
}
-// Returns the next unused fence name, and allocates the fence
-GLuint ResourceManager::createFenceSync(rx::GLImplFactory *factory)
+Program *ShaderProgramManager::getProgram(GLuint handle) const
{
- GLuint handle = mFenceSyncHandleAllocator.allocate();
-
- FenceSync *fenceSync = new FenceSync(factory->createFenceSync(), handle);
- fenceSync->addRef();
- mFenceSyncMap[handle] = fenceSync;
-
- return handle;
+ return GetObject(mPrograms, handle);
}
-ErrorOrResult<GLuint> ResourceManager::createPaths(rx::GLImplFactory *factory, GLsizei range)
+template <typename ObjectType>
+void ShaderProgramManager::deleteObject(ResourceMap<ObjectType> *objectMap, GLuint id)
+{
+ auto iter = objectMap->find(id);
+ if (iter == objectMap->end())
+ {
+ return;
+ }
+
+ auto object = iter->second;
+ if (object->getRefCount() == 0)
+ {
+ mHandleAllocator.release(id);
+ SafeDelete(object);
+ objectMap->erase(iter);
+ }
+ else
+ {
+ object->flagForDeletion();
+ }
+}
+
+GLuint TextureManager::createTexture()
+{
+ return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
+}
+
+void TextureManager::deleteTexture(GLuint texture)
+{
+ deleteObject(texture);
+}
+
+Texture *TextureManager::getTexture(GLuint handle) const
+{
+ ASSERT(GetObject(mObjectMap, 0) == nullptr);
+ return GetObject(mObjectMap, handle);
+}
+
+Texture *TextureManager::checkTextureAllocation(rx::GLImplFactory *factory,
+ GLuint handle,
+ GLenum type)
+{
+ if (handle == 0)
+ {
+ return nullptr;
+ }
+
+ auto objectMapIter = mObjectMap.find(handle);
+ bool handleAllocated = (objectMapIter != mObjectMap.end());
+
+ if (handleAllocated && objectMapIter->second != nullptr)
+ {
+ return objectMapIter->second;
+ }
+
+ Texture *object = new Texture(factory, handle, type);
+ object->addRef();
+
+ if (handleAllocated)
+ {
+ objectMapIter->second = object;
+ }
+ else
+ {
+ mHandleAllocator.reserve(handle);
+ mObjectMap[handle] = object;
+ }
+
+ return object;
+}
+
+bool TextureManager::isTextureGenerated(GLuint texture) const
+{
+ return texture == 0 || mObjectMap.find(texture) != mObjectMap.end();
+}
+
+GLuint RenderbufferManager::createRenderbuffer()
+{
+ return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
+}
+
+void RenderbufferManager::deleteRenderbuffer(GLuint renderbuffer)
+{
+ deleteObject(renderbuffer);
+}
+
+Renderbuffer *RenderbufferManager::getRenderbuffer(GLuint handle)
+{
+ return GetObject(mObjectMap, handle);
+}
+
+Renderbuffer *RenderbufferManager::checkRenderbufferAllocation(rx::GLImplFactory *factory,
+ GLuint handle)
+{
+ if (handle == 0)
+ {
+ return nullptr;
+ }
+
+ auto objectMapIter = mObjectMap.find(handle);
+ bool handleAllocated = (objectMapIter != mObjectMap.end());
+
+ if (handleAllocated && objectMapIter->second != nullptr)
+ {
+ return objectMapIter->second;
+ }
+
+ Renderbuffer *object = new Renderbuffer(factory->createRenderbuffer(), handle);
+ object->addRef();
+
+ if (handleAllocated)
+ {
+ objectMapIter->second = object;
+ }
+ else
+ {
+ mHandleAllocator.reserve(handle);
+ mObjectMap[handle] = object;
+ }
+
+ return object;
+}
+
+bool RenderbufferManager::isRenderbufferGenerated(GLuint renderbuffer) const
+{
+ return renderbuffer == 0 || mObjectMap.find(renderbuffer) != mObjectMap.end();
+}
+
+GLuint SamplerManager::createSampler()
+{
+ return AllocateEmptyObject(&mHandleAllocator, &mObjectMap);
+}
+
+void SamplerManager::deleteSampler(GLuint sampler)
+{
+ deleteObject(sampler);
+}
+
+Sampler *SamplerManager::getSampler(GLuint handle)
+{
+ return GetObject(mObjectMap, handle);
+}
+
+Sampler *SamplerManager::checkSamplerAllocation(rx::GLImplFactory *factory, GLuint handle)
+{
+ if (handle == 0)
+ {
+ return nullptr;
+ }
+
+ auto objectMapIter = mObjectMap.find(handle);
+ bool handleAllocated = (objectMapIter != mObjectMap.end());
+
+ if (handleAllocated && objectMapIter->second != nullptr)
+ {
+ return objectMapIter->second;
+ }
+
+ Sampler *object = new Sampler(factory, handle);
+ object->addRef();
+
+ if (handleAllocated)
+ {
+ objectMapIter->second = object;
+ }
+ else
+ {
+ mHandleAllocator.reserve(handle);
+ mObjectMap[handle] = object;
+ }
+
+ return object;
+}
+
+bool SamplerManager::isSampler(GLuint sampler)
+{
+ return mObjectMap.find(sampler) != mObjectMap.end();
+}
+
+GLuint FenceSyncManager::createFenceSync(rx::GLImplFactory *factory)
+{
+ struct fenceSyncAllocator
+ {
+ fenceSyncAllocator(rx::GLImplFactory *factory) : factory(factory) {}
+
+ rx::GLImplFactory *factory;
+
+ FenceSync *operator()(GLuint handle) const
+ {
+ FenceSync *fenceSync = new FenceSync(factory->createFenceSync(), handle);
+ fenceSync->addRef();
+ return fenceSync;
+ }
+ };
+
+ return InsertObject(&mHandleAllocator, &mObjectMap, fenceSyncAllocator(factory));
+}
+
+void FenceSyncManager::deleteFenceSync(GLuint fenceSync)
+{
+ deleteObject(fenceSync);
+}
+
+FenceSync *FenceSyncManager::getFenceSync(GLuint handle)
+{
+ return GetObject(mObjectMap, handle);
+}
+
+ErrorOrResult<GLuint> PathManager::createPaths(rx::GLImplFactory *factory, GLsizei range)
{
// Allocate client side handles.
- const GLuint client = mPathHandleAllocator.allocateRange(static_cast<GLuint>(range));
+ const GLuint client = mHandleAllocator.allocateRange(static_cast<GLuint>(range));
if (client == HandleRangeAllocator::kInvalidHandle)
- return gl::Error(GL_OUT_OF_MEMORY, "Failed to allocate path handle range.");
+ return Error(GL_OUT_OF_MEMORY, "Failed to allocate path handle range.");
const auto &paths = factory->createPaths(range);
if (paths.empty())
{
- mPathHandleAllocator.releaseRange(client, range);
- return gl::Error(GL_OUT_OF_MEMORY, "Failed to allocate path objects.");
+ mHandleAllocator.releaseRange(client, range);
+ return Error(GL_OUT_OF_MEMORY, "Failed to allocate path objects.");
}
- auto hint = mPathMap.begin();
+ auto hint = mPaths.begin();
for (GLsizei i = 0; i < range; ++i)
{
const auto impl = paths[static_cast<unsigned>(i)];
const auto id = client + i;
- hint = mPathMap.insert(hint, std::make_pair(id, new Path(impl)));
+ hint = mPaths.insert(hint, std::make_pair(id, new Path(impl)));
}
return client;
}
-void ResourceManager::deleteBuffer(GLuint buffer)
-{
- auto bufferObject = mBufferMap.find(buffer);
-
- if (bufferObject != mBufferMap.end())
- {
- mBufferHandleAllocator.release(bufferObject->first);
- if (bufferObject->second) bufferObject->second->release();
- mBufferMap.erase(bufferObject);
- }
-}
-
-void ResourceManager::deleteShader(GLuint shader)
-{
- auto shaderObject = mShaderMap.find(shader);
-
- if (shaderObject != mShaderMap.end())
- {
- if (shaderObject->second->getRefCount() == 0)
- {
- mProgramShaderHandleAllocator.release(shaderObject->first);
- delete shaderObject->second;
- mShaderMap.erase(shaderObject);
- }
- else
- {
- shaderObject->second->flagForDeletion();
- }
- }
-}
-
-void ResourceManager::deleteProgram(GLuint program)
-{
- auto programObject = mProgramMap.find(program);
-
- if (programObject != mProgramMap.end())
- {
- if (programObject->second->getRefCount() == 0)
- {
- mProgramShaderHandleAllocator.release(programObject->first);
- delete programObject->second;
- mProgramMap.erase(programObject);
- }
- else
- {
- programObject->second->flagForDeletion();
- }
- }
-}
-
-void ResourceManager::deleteTexture(GLuint texture)
-{
- auto textureObject = mTextureMap.find(texture);
-
- if (textureObject != mTextureMap.end())
- {
- mTextureHandleAllocator.release(textureObject->first);
- if (textureObject->second) textureObject->second->release();
- mTextureMap.erase(textureObject);
- }
-}
-
-void ResourceManager::deleteRenderbuffer(GLuint renderbuffer)
-{
- auto renderbufferObject = mRenderbufferMap.find(renderbuffer);
-
- if (renderbufferObject != mRenderbufferMap.end())
- {
- mRenderbufferHandleAllocator.release(renderbufferObject->first);
- if (renderbufferObject->second) renderbufferObject->second->release();
- mRenderbufferMap.erase(renderbufferObject);
- }
-}
-
-void ResourceManager::deleteSampler(GLuint sampler)
-{
- auto samplerObject = mSamplerMap.find(sampler);
-
- if (samplerObject != mSamplerMap.end())
- {
- mSamplerHandleAllocator.release(samplerObject->first);
- if (samplerObject->second) samplerObject->second->release();
- mSamplerMap.erase(samplerObject);
- }
-}
-
-void ResourceManager::deleteFenceSync(GLuint fenceSync)
-{
- auto fenceObjectIt = mFenceSyncMap.find(fenceSync);
-
- if (fenceObjectIt != mFenceSyncMap.end())
- {
- mFenceSyncHandleAllocator.release(fenceObjectIt->first);
- if (fenceObjectIt->second) fenceObjectIt->second->release();
- mFenceSyncMap.erase(fenceObjectIt);
- }
-}
-
-void ResourceManager::deletePaths(GLuint first, GLsizei range)
+void PathManager::deletePaths(GLuint first, GLsizei range)
{
for (GLsizei i = 0; i < range; ++i)
{
const auto id = first + i;
- const auto it = mPathMap.find(id);
- if (it == mPathMap.end())
+ const auto it = mPaths.find(id);
+ if (it == mPaths.end())
continue;
Path *p = it->second;
delete p;
- mPathMap.erase(it);
+ mPaths.erase(it);
}
- mPathHandleAllocator.releaseRange(first, static_cast<GLuint>(range));
+ mHandleAllocator.releaseRange(first, static_cast<GLuint>(range));
}
-Buffer *ResourceManager::getBuffer(unsigned int handle)
+Path *PathManager::getPath(GLuint handle) const
{
- auto buffer = mBufferMap.find(handle);
-
- if (buffer == mBufferMap.end())
- {
- return nullptr;
- }
- else
- {
- return buffer->second;
- }
+ auto iter = mPaths.find(handle);
+ return iter != mPaths.end() ? iter->second : nullptr;
}
-Shader *ResourceManager::getShader(unsigned int handle) const
+bool PathManager::hasPath(GLuint handle) const
{
- auto shader = mShaderMap.find(handle);
-
- if (shader == mShaderMap.end())
- {
- return nullptr;
- }
- else
- {
- return shader->second;
- }
+ return mHandleAllocator.isUsed(handle);
}
-Texture *ResourceManager::getTexture(unsigned int handle)
+PathManager::~PathManager()
{
- if (handle == 0)
- return nullptr;
-
- auto texture = mTextureMap.find(handle);
-
- if (texture == mTextureMap.end())
+ for (auto path : mPaths)
{
- return nullptr;
+ SafeDelete(path.second);
}
- else
- {
- return texture->second;
- }
-}
-
-Program *ResourceManager::getProgram(unsigned int handle) const
-{
- auto program = mProgramMap.find(handle);
-
- if (program == mProgramMap.end())
- {
- return nullptr;
- }
- else
- {
- return program->second;
- }
-}
-
-Renderbuffer *ResourceManager::getRenderbuffer(unsigned int handle)
-{
- auto renderbuffer = mRenderbufferMap.find(handle);
-
- if (renderbuffer == mRenderbufferMap.end())
- {
- return nullptr;
- }
- else
- {
- return renderbuffer->second;
- }
-}
-
-Sampler *ResourceManager::getSampler(unsigned int handle)
-{
- auto sampler = mSamplerMap.find(handle);
-
- if (sampler == mSamplerMap.end())
- {
- return nullptr;
- }
- else
- {
- return sampler->second;
- }
-}
-
-FenceSync *ResourceManager::getFenceSync(unsigned int handle)
-{
- auto fenceObjectIt = mFenceSyncMap.find(handle);
-
- if (fenceObjectIt == mFenceSyncMap.end())
- {
- return nullptr;
- }
- else
- {
- return fenceObjectIt->second;
- }
-}
-
-const Path *ResourceManager::getPath(GLuint handle) const
-{
- auto it = mPathMap.find(handle);
- if (it == std::end(mPathMap))
- return nullptr;
- return it->second;
-}
-
-Path *ResourceManager::getPath(GLuint handle)
-{
- auto it = mPathMap.find(handle);
- if (it == std::end(mPathMap))
- return nullptr;
-
- return it->second;
-}
-
-bool ResourceManager::hasPath(GLuint handle) const
-{
- return mPathHandleAllocator.isUsed(handle);
-}
-
-void ResourceManager::setRenderbuffer(GLuint handle, Renderbuffer *buffer)
-{
- mRenderbufferMap[handle] = buffer;
-}
-
-Buffer *ResourceManager::checkBufferAllocation(rx::GLImplFactory *factory, GLuint handle)
-{
- if (handle == 0)
- {
- return nullptr;
- }
-
- auto bufferMapIt = mBufferMap.find(handle);
- bool handleAllocated = (bufferMapIt != mBufferMap.end());
-
- if (handleAllocated && bufferMapIt->second != nullptr)
- {
- return bufferMapIt->second;
- }
-
- Buffer *buffer = new Buffer(factory, handle);
- buffer->addRef();
-
- if (handleAllocated)
- {
- bufferMapIt->second = buffer;
- }
- else
- {
- mBufferHandleAllocator.reserve(handle);
- mBufferMap[handle] = buffer;
- }
-
- return buffer;
-}
-
-Texture *ResourceManager::checkTextureAllocation(rx::GLImplFactory *factory,
- GLuint handle,
- GLenum type)
-{
- if (handle == 0)
- {
- return nullptr;
- }
-
- auto textureMapIt = mTextureMap.find(handle);
- bool handleAllocated = (textureMapIt != mTextureMap.end());
-
- if (handleAllocated && textureMapIt->second != nullptr)
- {
- return textureMapIt->second;
- }
-
- Texture *texture = new Texture(factory, handle, type);
- texture->addRef();
-
- if (handleAllocated)
- {
- textureMapIt->second = texture;
- }
- else
- {
- mTextureHandleAllocator.reserve(handle);
- mTextureMap[handle] = texture;
- }
-
- return texture;
-}
-
-Renderbuffer *ResourceManager::checkRenderbufferAllocation(rx::GLImplFactory *factory,
- GLuint handle)
-{
- if (handle == 0)
- {
- return nullptr;
- }
-
- auto renderbufferMapIt = mRenderbufferMap.find(handle);
- bool handleAllocated = (renderbufferMapIt != mRenderbufferMap.end());
-
- if (handleAllocated && renderbufferMapIt->second != nullptr)
- {
- return renderbufferMapIt->second;
- }
-
- Renderbuffer *renderbuffer = new Renderbuffer(factory->createRenderbuffer(), handle);
- renderbuffer->addRef();
-
- if (handleAllocated)
- {
- renderbufferMapIt->second = renderbuffer;
- }
- else
- {
- mRenderbufferHandleAllocator.reserve(handle);
- mRenderbufferMap[handle] = renderbuffer;
- }
-
- return renderbuffer;
-}
-
-Sampler *ResourceManager::checkSamplerAllocation(rx::GLImplFactory *factory, GLuint samplerHandle)
-{
- // Samplers cannot be created via Bind
- if (samplerHandle == 0)
- {
- return nullptr;
- }
-
- Sampler *sampler = getSampler(samplerHandle);
-
- if (!sampler)
- {
- sampler = new Sampler(factory, samplerHandle);
- mSamplerMap[samplerHandle] = sampler;
- sampler->addRef();
- }
-
- return sampler;
-}
-
-bool ResourceManager::isSampler(GLuint sampler)
-{
- return mSamplerMap.find(sampler) != mSamplerMap.end();
-}
-
-bool ResourceManager::isTextureGenerated(GLuint texture) const
-{
- return texture == 0 || mTextureMap.find(texture) != mTextureMap.end();
-}
-
-bool ResourceManager::isBufferGenerated(GLuint buffer) const
-{
- return buffer == 0 || mBufferMap.find(buffer) != mBufferMap.end();
-}
-
-bool ResourceManager::isRenderbufferGenerated(GLuint renderbuffer) const
-{
- return renderbuffer == 0 || mRenderbufferMap.find(renderbuffer) != mRenderbufferMap.end();
}
} // namespace gl