Commit 5834c680 by Nicolas Capens

Refactor NameSpace into a template class.

Bug 19219444 Change-Id: Id4b209f491b3a3dde716118309cbc8122feb25d0 Reviewed-on: https://swiftshader-review.googlesource.com/4984Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 808074ce
......@@ -80,7 +80,6 @@ COMMON_SRC_FILES += \
COMMON_SRC_FILES += \
OpenGL/common/Image.cpp \
OpenGL/common/NameSpace.cpp \
OpenGL/common/Object.cpp \
OpenGL/common/MatrixStack.cpp \
......
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2012 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
// NameSpace.cpp: Implements the NameSpace class, which is used
// to allocate GL object names.
#include "common/NameSpace.hpp"
#include "debug.h"
namespace gl
{
NameSpace::NameSpace() : baseValue(1), nextValue(1)
{
}
NameSpace::~NameSpace()
{
}
void NameSpace::setBaseHandle(GLuint value)
{
ASSERT(baseValue == nextValue);
baseValue = value;
nextValue = value;
}
GLuint NameSpace::allocate()
{
if(freeValues.size())
{
GLuint handle = freeValues.back();
freeValues.pop_back();
return handle;
}
return nextValue++;
}
void NameSpace::release(GLuint handle)
{
if(handle == nextValue - 1)
{
// Don't drop below base value
if(nextValue > baseValue)
{
nextValue--;
}
}
else
{
// Only free handles that we own - don't drop below the base value
if(handle >= baseValue)
{
freeValues.push_back(handle);
}
}
}
}
......@@ -22,16 +22,46 @@ typedef unsigned int GLuint;
namespace gl
{
template<class ObjectType, GLuint baseName = 1>
class NameSpace
{
public:
NameSpace();
virtual ~NameSpace();
public:
NameSpace() : baseValue(baseName), nextValue(baseName)
{
}
void setBaseHandle(GLuint value);
GLuint allocate()
{
if(freeValues.size())
{
GLuint handle = freeValues.back();
freeValues.pop_back();
GLuint allocate();
void release(GLuint handle);
return handle;
}
return nextValue++;
}
void release(GLuint handle)
{
if(handle == nextValue - 1)
{
// Don't drop below base value
if(nextValue > baseValue)
{
nextValue--;
}
}
else
{
// Only free handles that we own - don't drop below the base value
if(handle >= baseValue)
{
freeValues.push_back(handle);
}
}
}
private:
GLuint baseValue;
......
......@@ -46,8 +46,6 @@ Context::Context(const Context *shareContext)
sw::Context *context = new sw::Context();
device = new gl::Device(context);
//mFenceNameSpace.setBaseHandle(0);
setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
mState.depthClearValue = 1.0f;
......
......@@ -328,7 +328,6 @@ copy "$(OutDir)opengl32.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Platf
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\common\MatrixStack.cpp" />
<ClCompile Include="..\common\NameSpace.cpp" />
<ClCompile Include="..\common\Object.cpp" />
<ClCompile Include="Buffer.cpp" />
<ClCompile Include="Context.cpp" />
......
......@@ -65,9 +65,6 @@
<ClCompile Include="Query.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\common\NameSpace.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Display.cpp">
<Filter>Source Files</Filter>
</ClCompile>
......
......@@ -596,7 +596,7 @@ private:
typedef std::map<GLint, Framebuffer*> FramebufferMap;
FramebufferMap mFramebufferMap;
gl::NameSpace mFramebufferNameSpace;
gl::NameSpace<Framebuffer> mFramebufferNameSpace;
VertexDataManager *mVertexDataManager;
IndexDataManager *mIndexDataManager;
......
......@@ -39,7 +39,7 @@ enum TextureType
class ResourceManager
{
public:
public:
ResourceManager();
~ResourceManager();
......@@ -57,26 +57,26 @@ class ResourceManager
Buffer *getBuffer(GLuint handle);
Texture *getTexture(GLuint handle);
Renderbuffer *getRenderbuffer(GLuint handle);
void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
void checkBufferAllocation(unsigned int buffer);
void checkTextureAllocation(GLuint texture, TextureType type);
private:
private:
std::size_t mRefCount;
typedef std::map<GLint, Buffer*> BufferMap;
BufferMap mBufferMap;
gl::NameSpace mBufferNameSpace;
gl::NameSpace<Buffer> mBufferNameSpace;
typedef std::map<GLint, Texture*> TextureMap;
TextureMap mTextureMap;
gl::NameSpace mTextureNameSpace;
gl::NameSpace<Texture> mTextureNameSpace;
typedef std::map<GLint, Renderbuffer*> RenderbufferMap;
RenderbufferMap mRenderbufferMap;
gl::NameSpace mRenderbufferNameSpace;
gl::NameSpace<Renderbuffer> mRenderbufferNameSpace;
};
}
......
......@@ -262,7 +262,6 @@
<Unit filename="../common/Image.hpp" />
<Unit filename="../common/MatrixStack.cpp" />
<Unit filename="../common/MatrixStack.hpp" />
<Unit filename="../common/NameSpace.cpp" />
<Unit filename="../common/NameSpace.hpp" />
<Unit filename="../common/Object.cpp" />
<Unit filename="../common/Object.hpp" />
......
......@@ -323,7 +323,6 @@ copy "$(OutDir)libGLES_CM.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Pla
<ItemGroup>
<ClCompile Include="..\common\Image.cpp" />
<ClCompile Include="..\common\MatrixStack.cpp" />
<ClCompile Include="..\common\NameSpace.cpp" />
<ClCompile Include="..\common\Object.cpp" />
<ClCompile Include="Buffer.cpp" />
<ClCompile Include="Context.cpp" />
......
......@@ -53,9 +53,6 @@
<ClCompile Include="..\common\Object.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\common\NameSpace.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\common\MatrixStack.cpp">
<Filter>Source Files</Filter>
</ClCompile>
......
......@@ -45,8 +45,6 @@ Context::Context(const egl::Config *config, const Context *shareContext, EGLint
sw::Context *context = new sw::Context();
device = new es2::Device(context);
mFenceNameSpace.setBaseHandle(0);
setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
mState.depthClearValue = 1.0f;
......
......@@ -711,23 +711,23 @@ private:
typedef std::map<GLint, Framebuffer*> FramebufferMap;
FramebufferMap mFramebufferMap;
gl::NameSpace mFramebufferNameSpace;
gl::NameSpace<Framebuffer> mFramebufferNameSpace;
typedef std::map<GLint, Fence*> FenceMap;
FenceMap mFenceMap;
gl::NameSpace mFenceNameSpace;
gl::NameSpace<Fence, 0> mFenceNameSpace;
typedef std::map<GLint, Query*> QueryMap;
QueryMap mQueryMap;
gl::NameSpace mQueryNameSpace;
gl::NameSpace<Query> mQueryNameSpace;
typedef std::map<GLint, VertexArray*> VertexArrayMap;
VertexArrayMap mVertexArrayMap;
gl::NameSpace mVertexArrayNameSpace;
gl::NameSpace<VertexArray> mVertexArrayNameSpace;
typedef std::map<GLint, TransformFeedback*> TransformFeedbackMap;
TransformFeedbackMap mTransformFeedbackMap;
gl::NameSpace mTransformFeedbackNameSpace;
gl::NameSpace<TransformFeedback> mTransformFeedbackNameSpace;
VertexDataManager *mVertexDataManager;
IndexDataManager *mIndexDataManager;
......
......@@ -9,7 +9,7 @@
// or implied, including but not limited to any patent rights, are granted to you.
//
// ResourceManager.cpp: Implements the ResourceManager class, which tracks and
// ResourceManager.cpp: Implements the ResourceManager class, which tracks and
// retrieves objects which may be shared by multiple Contexts.
#include "ResourceManager.h"
......@@ -85,7 +85,7 @@ GLuint ResourceManager::createBuffer()
{
GLuint handle = mBufferNameSpace.allocate();
mBufferMap[handle] = NULL;
mBufferMap[handle] = nullptr;
return handle;
}
......@@ -123,7 +123,7 @@ GLuint ResourceManager::createTexture()
{
GLuint handle = mTextureNameSpace.allocate();
mTextureMap[handle] = NULL;
mTextureMap[handle] = nullptr;
return handle;
}
......@@ -133,7 +133,7 @@ GLuint ResourceManager::createRenderbuffer()
{
GLuint handle = mRenderbufferNameSpace.allocate();
mRenderbufferMap[handle] = NULL;
mRenderbufferMap[handle] = nullptr;
return handle;
}
......@@ -143,7 +143,7 @@ GLuint ResourceManager::createSampler()
{
GLuint handle = mSamplerHandleAllocator.allocate();
mSamplerMap[handle] = NULL;
mSamplerMap[handle] = nullptr;
return handle;
}
......@@ -204,7 +204,7 @@ void ResourceManager::deleteProgram(GLuint program)
mProgramMap.erase(programObject);
}
else
{
{
programObject->second->flagForDeletion();
}
}
......@@ -264,7 +264,7 @@ Buffer *ResourceManager::getBuffer(unsigned int handle)
if(buffer == mBufferMap.end())
{
return NULL;
return nullptr;
}
else
{
......@@ -278,7 +278,7 @@ Shader *ResourceManager::getShader(unsigned int handle)
if(shader == mShaderMap.end())
{
return NULL;
return nullptr;
}
else
{
......@@ -288,13 +288,13 @@ Shader *ResourceManager::getShader(unsigned int handle)
Texture *ResourceManager::getTexture(unsigned int handle)
{
if(handle == 0) return NULL;
if(handle == 0) return nullptr;
TextureMap::iterator texture = mTextureMap.find(handle);
if(texture == mTextureMap.end())
{
return NULL;
return nullptr;
}
else
{
......@@ -308,7 +308,7 @@ Program *ResourceManager::getProgram(unsigned int handle)
if(program == mProgramMap.end())
{
return NULL;
return nullptr;
}
else
{
......@@ -322,7 +322,7 @@ Renderbuffer *ResourceManager::getRenderbuffer(unsigned int handle)
if(renderbuffer == mRenderbufferMap.end())
{
return NULL;
return nullptr;
}
else
{
......@@ -336,7 +336,7 @@ Sampler *ResourceManager::getSampler(unsigned int handle)
if(sampler == mSamplerMap.end())
{
return NULL;
return nullptr;
}
else
{
......@@ -350,7 +350,7 @@ FenceSync *ResourceManager::getFenceSync(unsigned int handle)
if(fenceObjectIt == mFenceSyncMap.end())
{
return NULL;
return nullptr;
}
else
{
......
......@@ -75,7 +75,7 @@ class ResourceManager
Renderbuffer *getRenderbuffer(GLuint handle);
Sampler *getSampler(GLuint handle);
FenceSync *getFenceSync(GLuint handle);
void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
void checkBufferAllocation(unsigned int buffer);
......@@ -90,30 +90,30 @@ class ResourceManager
typedef std::map<GLint, Buffer*> BufferMap;
BufferMap mBufferMap;
gl::NameSpace mBufferNameSpace;
gl::NameSpace<Buffer> mBufferNameSpace;
typedef std::map<GLint, Shader*> ShaderMap;
ShaderMap mShaderMap;
typedef std::map<GLint, Program*> ProgramMap;
ProgramMap mProgramMap;
gl::NameSpace mProgramShaderNameSpace;
gl::NameSpace<Program> mProgramShaderNameSpace;
typedef std::map<GLint, Texture*> TextureMap;
TextureMap mTextureMap;
gl::NameSpace mTextureNameSpace;
gl::NameSpace<Texture> mTextureNameSpace;
typedef std::map<GLint, Renderbuffer*> RenderbufferMap;
RenderbufferMap mRenderbufferMap;
gl::NameSpace mRenderbufferNameSpace;
gl::NameSpace<Renderbuffer> mRenderbufferNameSpace;
typedef std::map<GLint, Sampler*> SamplerMap;
SamplerMap mSamplerMap;
gl::NameSpace mSamplerHandleAllocator;
gl::NameSpace<Sampler> mSamplerHandleAllocator;
typedef std::map<GLint, FenceSync*> FenceMap;
FenceMap mFenceSyncMap;
gl::NameSpace mFenceSyncHandleAllocator;
gl::NameSpace<FenceSync> mFenceSyncHandleAllocator;
};
}
......
......@@ -259,7 +259,6 @@
<Unit filename="../../Shader/VertexShader.hpp" />
<Unit filename="../common/Image.cpp" />
<Unit filename="../common/Image.hpp" />
<Unit filename="../common/NameSpace.cpp" />
<Unit filename="../common/NameSpace.hpp" />
<Unit filename="../common/Object.cpp" />
<Unit filename="../common/Object.hpp" />
......
......@@ -322,7 +322,6 @@ copy "$(OutDir)libGLESv2.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Plat
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\common\Image.cpp" />
<ClCompile Include="..\common\NameSpace.cpp" />
<ClCompile Include="..\common\Object.cpp" />
<ClCompile Include="Buffer.cpp" />
<ClCompile Include="Context.cpp" />
......
......@@ -65,9 +65,6 @@
<ClCompile Include="..\common\Object.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\common\NameSpace.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="libGLESv3.cpp">
<Filter>Source Files</Filter>
</ClCompile>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment