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 += \ ...@@ -80,7 +80,6 @@ COMMON_SRC_FILES += \
COMMON_SRC_FILES += \ COMMON_SRC_FILES += \
OpenGL/common/Image.cpp \ OpenGL/common/Image.cpp \
OpenGL/common/NameSpace.cpp \
OpenGL/common/Object.cpp \ OpenGL/common/Object.cpp \
OpenGL/common/MatrixStack.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; ...@@ -22,16 +22,46 @@ typedef unsigned int GLuint;
namespace gl namespace gl
{ {
template<class ObjectType, GLuint baseName = 1>
class NameSpace class NameSpace
{ {
public: public:
NameSpace(); NameSpace() : baseValue(baseName), nextValue(baseName)
virtual ~NameSpace(); {
}
void setBaseHandle(GLuint value); GLuint allocate()
{
if(freeValues.size())
{
GLuint handle = freeValues.back();
freeValues.pop_back();
GLuint allocate(); return handle;
void release(GLuint 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: private:
GLuint baseValue; GLuint baseValue;
......
...@@ -46,8 +46,6 @@ Context::Context(const Context *shareContext) ...@@ -46,8 +46,6 @@ Context::Context(const Context *shareContext)
sw::Context *context = new sw::Context(); sw::Context *context = new sw::Context();
device = new gl::Device(context); device = new gl::Device(context);
//mFenceNameSpace.setBaseHandle(0);
setClearColor(0.0f, 0.0f, 0.0f, 0.0f); setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
mState.depthClearValue = 1.0f; mState.depthClearValue = 1.0f;
......
...@@ -328,7 +328,6 @@ copy "$(OutDir)opengl32.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Platf ...@@ -328,7 +328,6 @@ copy "$(OutDir)opengl32.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Platf
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\common\MatrixStack.cpp" /> <ClCompile Include="..\common\MatrixStack.cpp" />
<ClCompile Include="..\common\NameSpace.cpp" />
<ClCompile Include="..\common\Object.cpp" /> <ClCompile Include="..\common\Object.cpp" />
<ClCompile Include="Buffer.cpp" /> <ClCompile Include="Buffer.cpp" />
<ClCompile Include="Context.cpp" /> <ClCompile Include="Context.cpp" />
......
...@@ -65,9 +65,6 @@ ...@@ -65,9 +65,6 @@
<ClCompile Include="Query.cpp"> <ClCompile Include="Query.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\common\NameSpace.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Display.cpp"> <ClCompile Include="Display.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
......
...@@ -596,7 +596,7 @@ private: ...@@ -596,7 +596,7 @@ private:
typedef std::map<GLint, Framebuffer*> FramebufferMap; typedef std::map<GLint, Framebuffer*> FramebufferMap;
FramebufferMap mFramebufferMap; FramebufferMap mFramebufferMap;
gl::NameSpace mFramebufferNameSpace; gl::NameSpace<Framebuffer> mFramebufferNameSpace;
VertexDataManager *mVertexDataManager; VertexDataManager *mVertexDataManager;
IndexDataManager *mIndexDataManager; IndexDataManager *mIndexDataManager;
......
...@@ -39,7 +39,7 @@ enum TextureType ...@@ -39,7 +39,7 @@ enum TextureType
class ResourceManager class ResourceManager
{ {
public: public:
ResourceManager(); ResourceManager();
~ResourceManager(); ~ResourceManager();
...@@ -57,26 +57,26 @@ class ResourceManager ...@@ -57,26 +57,26 @@ class ResourceManager
Buffer *getBuffer(GLuint handle); Buffer *getBuffer(GLuint handle);
Texture *getTexture(GLuint handle); Texture *getTexture(GLuint handle);
Renderbuffer *getRenderbuffer(GLuint handle); Renderbuffer *getRenderbuffer(GLuint handle);
void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer); void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
void checkBufferAllocation(unsigned int buffer); void checkBufferAllocation(unsigned int buffer);
void checkTextureAllocation(GLuint texture, TextureType type); void checkTextureAllocation(GLuint texture, TextureType type);
private: private:
std::size_t mRefCount; std::size_t mRefCount;
typedef std::map<GLint, Buffer*> BufferMap; typedef std::map<GLint, Buffer*> BufferMap;
BufferMap mBufferMap; BufferMap mBufferMap;
gl::NameSpace mBufferNameSpace; gl::NameSpace<Buffer> mBufferNameSpace;
typedef std::map<GLint, Texture*> TextureMap; typedef std::map<GLint, Texture*> TextureMap;
TextureMap mTextureMap; TextureMap mTextureMap;
gl::NameSpace mTextureNameSpace; gl::NameSpace<Texture> mTextureNameSpace;
typedef std::map<GLint, Renderbuffer*> RenderbufferMap; typedef std::map<GLint, Renderbuffer*> RenderbufferMap;
RenderbufferMap mRenderbufferMap; RenderbufferMap mRenderbufferMap;
gl::NameSpace mRenderbufferNameSpace; gl::NameSpace<Renderbuffer> mRenderbufferNameSpace;
}; };
} }
......
...@@ -262,7 +262,6 @@ ...@@ -262,7 +262,6 @@
<Unit filename="../common/Image.hpp" /> <Unit filename="../common/Image.hpp" />
<Unit filename="../common/MatrixStack.cpp" /> <Unit filename="../common/MatrixStack.cpp" />
<Unit filename="../common/MatrixStack.hpp" /> <Unit filename="../common/MatrixStack.hpp" />
<Unit filename="../common/NameSpace.cpp" />
<Unit filename="../common/NameSpace.hpp" /> <Unit filename="../common/NameSpace.hpp" />
<Unit filename="../common/Object.cpp" /> <Unit filename="../common/Object.cpp" />
<Unit filename="../common/Object.hpp" /> <Unit filename="../common/Object.hpp" />
......
...@@ -323,7 +323,6 @@ copy "$(OutDir)libGLES_CM.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Pla ...@@ -323,7 +323,6 @@ copy "$(OutDir)libGLES_CM.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Pla
<ItemGroup> <ItemGroup>
<ClCompile Include="..\common\Image.cpp" /> <ClCompile Include="..\common\Image.cpp" />
<ClCompile Include="..\common\MatrixStack.cpp" /> <ClCompile Include="..\common\MatrixStack.cpp" />
<ClCompile Include="..\common\NameSpace.cpp" />
<ClCompile Include="..\common\Object.cpp" /> <ClCompile Include="..\common\Object.cpp" />
<ClCompile Include="Buffer.cpp" /> <ClCompile Include="Buffer.cpp" />
<ClCompile Include="Context.cpp" /> <ClCompile Include="Context.cpp" />
......
...@@ -53,9 +53,6 @@ ...@@ -53,9 +53,6 @@
<ClCompile Include="..\common\Object.cpp"> <ClCompile Include="..\common\Object.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\common\NameSpace.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\common\MatrixStack.cpp"> <ClCompile Include="..\common\MatrixStack.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
......
...@@ -45,8 +45,6 @@ Context::Context(const egl::Config *config, const Context *shareContext, EGLint ...@@ -45,8 +45,6 @@ Context::Context(const egl::Config *config, const Context *shareContext, EGLint
sw::Context *context = new sw::Context(); sw::Context *context = new sw::Context();
device = new es2::Device(context); device = new es2::Device(context);
mFenceNameSpace.setBaseHandle(0);
setClearColor(0.0f, 0.0f, 0.0f, 0.0f); setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
mState.depthClearValue = 1.0f; mState.depthClearValue = 1.0f;
......
...@@ -711,23 +711,23 @@ private: ...@@ -711,23 +711,23 @@ private:
typedef std::map<GLint, Framebuffer*> FramebufferMap; typedef std::map<GLint, Framebuffer*> FramebufferMap;
FramebufferMap mFramebufferMap; FramebufferMap mFramebufferMap;
gl::NameSpace mFramebufferNameSpace; gl::NameSpace<Framebuffer> mFramebufferNameSpace;
typedef std::map<GLint, Fence*> FenceMap; typedef std::map<GLint, Fence*> FenceMap;
FenceMap mFenceMap; FenceMap mFenceMap;
gl::NameSpace mFenceNameSpace; gl::NameSpace<Fence, 0> mFenceNameSpace;
typedef std::map<GLint, Query*> QueryMap; typedef std::map<GLint, Query*> QueryMap;
QueryMap mQueryMap; QueryMap mQueryMap;
gl::NameSpace mQueryNameSpace; gl::NameSpace<Query> mQueryNameSpace;
typedef std::map<GLint, VertexArray*> VertexArrayMap; typedef std::map<GLint, VertexArray*> VertexArrayMap;
VertexArrayMap mVertexArrayMap; VertexArrayMap mVertexArrayMap;
gl::NameSpace mVertexArrayNameSpace; gl::NameSpace<VertexArray> mVertexArrayNameSpace;
typedef std::map<GLint, TransformFeedback*> TransformFeedbackMap; typedef std::map<GLint, TransformFeedback*> TransformFeedbackMap;
TransformFeedbackMap mTransformFeedbackMap; TransformFeedbackMap mTransformFeedbackMap;
gl::NameSpace mTransformFeedbackNameSpace; gl::NameSpace<TransformFeedback> mTransformFeedbackNameSpace;
VertexDataManager *mVertexDataManager; VertexDataManager *mVertexDataManager;
IndexDataManager *mIndexDataManager; IndexDataManager *mIndexDataManager;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
// or implied, including but not limited to any patent rights, are granted to you. // 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. // retrieves objects which may be shared by multiple Contexts.
#include "ResourceManager.h" #include "ResourceManager.h"
...@@ -85,7 +85,7 @@ GLuint ResourceManager::createBuffer() ...@@ -85,7 +85,7 @@ GLuint ResourceManager::createBuffer()
{ {
GLuint handle = mBufferNameSpace.allocate(); GLuint handle = mBufferNameSpace.allocate();
mBufferMap[handle] = NULL; mBufferMap[handle] = nullptr;
return handle; return handle;
} }
...@@ -123,7 +123,7 @@ GLuint ResourceManager::createTexture() ...@@ -123,7 +123,7 @@ GLuint ResourceManager::createTexture()
{ {
GLuint handle = mTextureNameSpace.allocate(); GLuint handle = mTextureNameSpace.allocate();
mTextureMap[handle] = NULL; mTextureMap[handle] = nullptr;
return handle; return handle;
} }
...@@ -133,7 +133,7 @@ GLuint ResourceManager::createRenderbuffer() ...@@ -133,7 +133,7 @@ GLuint ResourceManager::createRenderbuffer()
{ {
GLuint handle = mRenderbufferNameSpace.allocate(); GLuint handle = mRenderbufferNameSpace.allocate();
mRenderbufferMap[handle] = NULL; mRenderbufferMap[handle] = nullptr;
return handle; return handle;
} }
...@@ -143,7 +143,7 @@ GLuint ResourceManager::createSampler() ...@@ -143,7 +143,7 @@ GLuint ResourceManager::createSampler()
{ {
GLuint handle = mSamplerHandleAllocator.allocate(); GLuint handle = mSamplerHandleAllocator.allocate();
mSamplerMap[handle] = NULL; mSamplerMap[handle] = nullptr;
return handle; return handle;
} }
...@@ -204,7 +204,7 @@ void ResourceManager::deleteProgram(GLuint program) ...@@ -204,7 +204,7 @@ void ResourceManager::deleteProgram(GLuint program)
mProgramMap.erase(programObject); mProgramMap.erase(programObject);
} }
else else
{ {
programObject->second->flagForDeletion(); programObject->second->flagForDeletion();
} }
} }
...@@ -264,7 +264,7 @@ Buffer *ResourceManager::getBuffer(unsigned int handle) ...@@ -264,7 +264,7 @@ Buffer *ResourceManager::getBuffer(unsigned int handle)
if(buffer == mBufferMap.end()) if(buffer == mBufferMap.end())
{ {
return NULL; return nullptr;
} }
else else
{ {
...@@ -278,7 +278,7 @@ Shader *ResourceManager::getShader(unsigned int handle) ...@@ -278,7 +278,7 @@ Shader *ResourceManager::getShader(unsigned int handle)
if(shader == mShaderMap.end()) if(shader == mShaderMap.end())
{ {
return NULL; return nullptr;
} }
else else
{ {
...@@ -288,13 +288,13 @@ Shader *ResourceManager::getShader(unsigned int handle) ...@@ -288,13 +288,13 @@ Shader *ResourceManager::getShader(unsigned int handle)
Texture *ResourceManager::getTexture(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); TextureMap::iterator texture = mTextureMap.find(handle);
if(texture == mTextureMap.end()) if(texture == mTextureMap.end())
{ {
return NULL; return nullptr;
} }
else else
{ {
...@@ -308,7 +308,7 @@ Program *ResourceManager::getProgram(unsigned int handle) ...@@ -308,7 +308,7 @@ Program *ResourceManager::getProgram(unsigned int handle)
if(program == mProgramMap.end()) if(program == mProgramMap.end())
{ {
return NULL; return nullptr;
} }
else else
{ {
...@@ -322,7 +322,7 @@ Renderbuffer *ResourceManager::getRenderbuffer(unsigned int handle) ...@@ -322,7 +322,7 @@ Renderbuffer *ResourceManager::getRenderbuffer(unsigned int handle)
if(renderbuffer == mRenderbufferMap.end()) if(renderbuffer == mRenderbufferMap.end())
{ {
return NULL; return nullptr;
} }
else else
{ {
...@@ -336,7 +336,7 @@ Sampler *ResourceManager::getSampler(unsigned int handle) ...@@ -336,7 +336,7 @@ Sampler *ResourceManager::getSampler(unsigned int handle)
if(sampler == mSamplerMap.end()) if(sampler == mSamplerMap.end())
{ {
return NULL; return nullptr;
} }
else else
{ {
...@@ -350,7 +350,7 @@ FenceSync *ResourceManager::getFenceSync(unsigned int handle) ...@@ -350,7 +350,7 @@ FenceSync *ResourceManager::getFenceSync(unsigned int handle)
if(fenceObjectIt == mFenceSyncMap.end()) if(fenceObjectIt == mFenceSyncMap.end())
{ {
return NULL; return nullptr;
} }
else else
{ {
......
...@@ -75,7 +75,7 @@ class ResourceManager ...@@ -75,7 +75,7 @@ class ResourceManager
Renderbuffer *getRenderbuffer(GLuint handle); Renderbuffer *getRenderbuffer(GLuint handle);
Sampler *getSampler(GLuint handle); Sampler *getSampler(GLuint handle);
FenceSync *getFenceSync(GLuint handle); FenceSync *getFenceSync(GLuint handle);
void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer); void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
void checkBufferAllocation(unsigned int buffer); void checkBufferAllocation(unsigned int buffer);
...@@ -90,30 +90,30 @@ class ResourceManager ...@@ -90,30 +90,30 @@ class ResourceManager
typedef std::map<GLint, Buffer*> BufferMap; typedef std::map<GLint, Buffer*> BufferMap;
BufferMap mBufferMap; BufferMap mBufferMap;
gl::NameSpace mBufferNameSpace; gl::NameSpace<Buffer> mBufferNameSpace;
typedef std::map<GLint, Shader*> ShaderMap; typedef std::map<GLint, Shader*> ShaderMap;
ShaderMap mShaderMap; ShaderMap mShaderMap;
typedef std::map<GLint, Program*> ProgramMap; typedef std::map<GLint, Program*> ProgramMap;
ProgramMap mProgramMap; ProgramMap mProgramMap;
gl::NameSpace mProgramShaderNameSpace; gl::NameSpace<Program> mProgramShaderNameSpace;
typedef std::map<GLint, Texture*> TextureMap; typedef std::map<GLint, Texture*> TextureMap;
TextureMap mTextureMap; TextureMap mTextureMap;
gl::NameSpace mTextureNameSpace; gl::NameSpace<Texture> mTextureNameSpace;
typedef std::map<GLint, Renderbuffer*> RenderbufferMap; typedef std::map<GLint, Renderbuffer*> RenderbufferMap;
RenderbufferMap mRenderbufferMap; RenderbufferMap mRenderbufferMap;
gl::NameSpace mRenderbufferNameSpace; gl::NameSpace<Renderbuffer> mRenderbufferNameSpace;
typedef std::map<GLint, Sampler*> SamplerMap; typedef std::map<GLint, Sampler*> SamplerMap;
SamplerMap mSamplerMap; SamplerMap mSamplerMap;
gl::NameSpace mSamplerHandleAllocator; gl::NameSpace<Sampler> mSamplerHandleAllocator;
typedef std::map<GLint, FenceSync*> FenceMap; typedef std::map<GLint, FenceSync*> FenceMap;
FenceMap mFenceSyncMap; FenceMap mFenceSyncMap;
gl::NameSpace mFenceSyncHandleAllocator; gl::NameSpace<FenceSync> mFenceSyncHandleAllocator;
}; };
} }
......
...@@ -259,7 +259,6 @@ ...@@ -259,7 +259,6 @@
<Unit filename="../../Shader/VertexShader.hpp" /> <Unit filename="../../Shader/VertexShader.hpp" />
<Unit filename="../common/Image.cpp" /> <Unit filename="../common/Image.cpp" />
<Unit filename="../common/Image.hpp" /> <Unit filename="../common/Image.hpp" />
<Unit filename="../common/NameSpace.cpp" />
<Unit filename="../common/NameSpace.hpp" /> <Unit filename="../common/NameSpace.hpp" />
<Unit filename="../common/Object.cpp" /> <Unit filename="../common/Object.cpp" />
<Unit filename="../common/Object.hpp" /> <Unit filename="../common/Object.hpp" />
......
...@@ -322,7 +322,6 @@ copy "$(OutDir)libGLESv2.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Plat ...@@ -322,7 +322,6 @@ copy "$(OutDir)libGLESv2.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Plat
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\common\Image.cpp" /> <ClCompile Include="..\common\Image.cpp" />
<ClCompile Include="..\common\NameSpace.cpp" />
<ClCompile Include="..\common\Object.cpp" /> <ClCompile Include="..\common\Object.cpp" />
<ClCompile Include="Buffer.cpp" /> <ClCompile Include="Buffer.cpp" />
<ClCompile Include="Context.cpp" /> <ClCompile Include="Context.cpp" />
......
...@@ -65,9 +65,6 @@ ...@@ -65,9 +65,6 @@
<ClCompile Include="..\common\Object.cpp"> <ClCompile Include="..\common\Object.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\common\NameSpace.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="libGLESv3.cpp"> <ClCompile Include="libGLESv3.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </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