Commit 80b4125a by Nicolas Capens

Share the name space implementation between all GL versions.

Bug 18962347 Change-Id: Ifd7ca4142d90798d0bbe2defa9337bac17e20daf Reviewed-on: https://swiftshader-review.googlesource.com/1881Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent d7d9b4bd
......@@ -9,58 +9,60 @@
// or implied, including but not limited to any patent rights, are granted to you.
//
// HandleAllocator.cpp: Implements the HandleAllocator class, which is used
// to allocate GL handles.
// NameSpace.cpp: Implements the NameSpace class, which is used
// to allocate GL object names.
#include "HandleAllocator.h"
#include "common/NameSpace.hpp"
#include "main.h"
#include "debug.h"
namespace gl
{
HandleAllocator::HandleAllocator() : mBaseValue(1), mNextValue(1)
NameSpace::NameSpace() : baseValue(1), nextValue(1)
{
}
HandleAllocator::~HandleAllocator()
NameSpace::~NameSpace()
{
}
void HandleAllocator::setBaseHandle(GLuint value)
void NameSpace::setBaseHandle(GLuint value)
{
ASSERT(mBaseValue == mNextValue);
mBaseValue = value;
mNextValue = value;
ASSERT(baseValue == nextValue);
baseValue = value;
nextValue = value;
}
GLuint HandleAllocator::allocate()
GLuint NameSpace::allocate()
{
if(mFreeValues.size())
if(freeValues.size())
{
GLuint handle = mFreeValues.back();
mFreeValues.pop_back();
GLuint handle = freeValues.back();
freeValues.pop_back();
return handle;
}
return mNextValue++;
return nextValue++;
}
void HandleAllocator::release(GLuint handle)
void NameSpace::release(GLuint handle)
{
if(handle == mNextValue - 1)
if(handle == nextValue - 1)
{
// Don't drop below base value
if(mNextValue > mBaseValue)
if(nextValue > baseValue)
{
mNextValue--;
nextValue--;
}
}
else
{
// Only free handles that we own - don't drop below the base value
if(handle >= mBaseValue)
if(handle >= baseValue)
{
mFreeValues.push_back(handle);
freeValues.push_back(handle);
}
}
}
......
......@@ -9,38 +9,37 @@
// or implied, including but not limited to any patent rights, are granted to you.
//
// HandleAllocator.h: Defines the HandleAllocator class, which is used to
// allocate GL handles.
// NameSpace.h: Defines the NameSpace class, which is used to
// allocate GL object names.
#ifndef LIBGL_HANDLEALLOCATOR_H_
#define LIBGL_HANDLEALLOCATOR_H_
#define GL_APICALL
#include <GLES2/gl2.h>
#ifndef gl_NameSpace_hpp
#define gl_NameSpace_hpp
#include <vector>
typedef unsigned int GLuint;
namespace gl
{
class HandleAllocator
class NameSpace
{
public:
HandleAllocator();
virtual ~HandleAllocator();
NameSpace();
virtual ~NameSpace();
void setBaseHandle(GLuint value);
GLuint allocate();
void release(GLuint handle);
private:
GLuint mBaseValue;
GLuint mNextValue;
private:
GLuint baseValue;
GLuint nextValue;
typedef std::vector<GLuint> HandleList;
HandleList mFreeValues;
HandleList freeValues;
};
}
#endif // LIBGL_HANDLEALLOCATOR_H_
#endif // gl_NameSpace_hpp
......@@ -44,7 +44,7 @@ Context::Context(const egl::Config *config, const Context *shareContext) : mConf
sw::Context *context = new sw::Context();
device = new gl::Device(context);
mFenceHandleAllocator.setBaseHandle(0);
mFenceNameSpace.setBaseHandle(0);
setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
......@@ -773,7 +773,7 @@ GLuint Context::createRenderbuffer()
// Returns an unused framebuffer name
GLuint Context::createFramebuffer()
{
GLuint handle = mFramebufferHandleAllocator.allocate();
GLuint handle = mFramebufferNameSpace.allocate();
mFramebufferMap[handle] = NULL;
......@@ -782,7 +782,7 @@ GLuint Context::createFramebuffer()
GLuint Context::createFence()
{
GLuint handle = mFenceHandleAllocator.allocate();
GLuint handle = mFenceNameSpace.allocate();
mFenceMap[handle] = new Fence;
......@@ -792,7 +792,7 @@ GLuint Context::createFence()
// Returns an unused query name
GLuint Context::createQuery()
{
GLuint handle = mQueryHandleAllocator.allocate();
GLuint handle = mQueryNameSpace.allocate();
mQueryMap[handle] = NULL;
......@@ -847,7 +847,7 @@ void Context::deleteFramebuffer(GLuint framebuffer)
{
detachFramebuffer(framebuffer);
mFramebufferHandleAllocator.release(framebufferObject->first);
mFramebufferNameSpace.release(framebufferObject->first);
delete framebufferObject->second;
mFramebufferMap.erase(framebufferObject);
}
......@@ -859,7 +859,7 @@ void Context::deleteFence(GLuint fence)
if(fenceObject != mFenceMap.end())
{
mFenceHandleAllocator.release(fenceObject->first);
mFenceNameSpace.release(fenceObject->first);
delete fenceObject->second;
mFenceMap.erase(fenceObject);
}
......@@ -871,7 +871,7 @@ void Context::deleteQuery(GLuint query)
if(queryObject != mQueryMap.end())
{
mQueryHandleAllocator.release(queryObject->first);
mQueryNameSpace.release(queryObject->first);
if(queryObject->second)
{
......
......@@ -17,7 +17,7 @@
#include "libEGL/Context.hpp"
#include "ResourceManager.h"
#include "HandleAllocator.h"
#include "common/NameSpace.hpp"
#include "common/Object.hpp"
#include "Image.hpp"
#include "Renderer/Sampler.hpp"
......@@ -469,15 +469,15 @@ private:
typedef std::map<GLint, Framebuffer*> FramebufferMap;
FramebufferMap mFramebufferMap;
HandleAllocator mFramebufferHandleAllocator;
NameSpace mFramebufferNameSpace;
typedef std::map<GLint, Fence*> FenceMap;
FenceMap mFenceMap;
HandleAllocator mFenceHandleAllocator;
NameSpace mFenceNameSpace;
typedef std::map<GLint, Query*> QueryMap;
QueryMap mQueryMap;
HandleAllocator mQueryHandleAllocator;
NameSpace mQueryNameSpace;
VertexDataManager *mVertexDataManager;
IndexDataManager *mIndexDataManager;
......
......@@ -71,7 +71,7 @@ void ResourceManager::release()
// Returns an unused buffer name
GLuint ResourceManager::createBuffer()
{
GLuint handle = mBufferHandleAllocator.allocate();
GLuint handle = mBufferNameSpace.allocate();
mBufferMap[handle] = NULL;
......@@ -81,7 +81,7 @@ GLuint ResourceManager::createBuffer()
// Returns an unused shader/program name
GLuint ResourceManager::createShader(GLenum type)
{
GLuint handle = mProgramShaderHandleAllocator.allocate();
GLuint handle = mProgramShaderNameSpace.allocate();
if(type == GL_VERTEX_SHADER)
{
......@@ -99,7 +99,7 @@ GLuint ResourceManager::createShader(GLenum type)
// Returns an unused program/shader name
GLuint ResourceManager::createProgram()
{
GLuint handle = mProgramShaderHandleAllocator.allocate();
GLuint handle = mProgramShaderNameSpace.allocate();
mProgramMap[handle] = new Program(this, handle);
......@@ -109,7 +109,7 @@ GLuint ResourceManager::createProgram()
// Returns an unused texture name
GLuint ResourceManager::createTexture()
{
GLuint handle = mTextureHandleAllocator.allocate();
GLuint handle = mTextureNameSpace.allocate();
mTextureMap[handle] = NULL;
......@@ -119,7 +119,7 @@ GLuint ResourceManager::createTexture()
// Returns an unused renderbuffer name
GLuint ResourceManager::createRenderbuffer()
{
GLuint handle = mRenderbufferHandleAllocator.allocate();
GLuint handle = mRenderbufferNameSpace.allocate();
mRenderbufferMap[handle] = NULL;
......@@ -132,7 +132,7 @@ void ResourceManager::deleteBuffer(GLuint buffer)
if(bufferObject != mBufferMap.end())
{
mBufferHandleAllocator.release(bufferObject->first);
mBufferNameSpace.release(bufferObject->first);
if(bufferObject->second) bufferObject->second->release();
mBufferMap.erase(bufferObject);
}
......@@ -146,7 +146,7 @@ void ResourceManager::deleteShader(GLuint shader)
{
if(shaderObject->second->getRefCount() == 0)
{
mProgramShaderHandleAllocator.release(shaderObject->first);
mProgramShaderNameSpace.release(shaderObject->first);
delete shaderObject->second;
mShaderMap.erase(shaderObject);
}
......@@ -165,7 +165,7 @@ void ResourceManager::deleteProgram(GLuint program)
{
if(programObject->second->getRefCount() == 0)
{
mProgramShaderHandleAllocator.release(programObject->first);
mProgramShaderNameSpace.release(programObject->first);
delete programObject->second;
mProgramMap.erase(programObject);
}
......@@ -182,7 +182,7 @@ void ResourceManager::deleteTexture(GLuint texture)
if(textureObject != mTextureMap.end())
{
mTextureHandleAllocator.release(textureObject->first);
mTextureNameSpace.release(textureObject->first);
if(textureObject->second) textureObject->second->release();
mTextureMap.erase(textureObject);
}
......@@ -194,7 +194,7 @@ void ResourceManager::deleteRenderbuffer(GLuint renderbuffer)
if(renderbufferObject != mRenderbufferMap.end())
{
mRenderbufferHandleAllocator.release(renderbufferObject->first);
mRenderbufferNameSpace.release(renderbufferObject->first);
if(renderbufferObject->second) renderbufferObject->second->release();
mRenderbufferMap.erase(renderbufferObject);
}
......
......@@ -15,7 +15,7 @@
#ifndef LIBGL_RESOURCEMANAGER_H_
#define LIBGL_RESOURCEMANAGER_H_
#include "HandleAllocator.h"
#include "common/NameSpace.hpp"
#define GL_APICALL
#include <GLES2/gl2.h>
......@@ -77,22 +77,22 @@ class ResourceManager
typedef std::map<GLint, Buffer*> BufferMap;
BufferMap mBufferMap;
HandleAllocator mBufferHandleAllocator;
NameSpace mBufferNameSpace;
typedef std::map<GLint, Shader*> ShaderMap;
ShaderMap mShaderMap;
typedef std::map<GLint, Program*> ProgramMap;
ProgramMap mProgramMap;
HandleAllocator mProgramShaderHandleAllocator;
NameSpace mProgramShaderNameSpace;
typedef std::map<GLint, Texture*> TextureMap;
TextureMap mTextureMap;
HandleAllocator mTextureHandleAllocator;
NameSpace mTextureNameSpace;
typedef std::map<GLint, Renderbuffer*> RenderbufferMap;
RenderbufferMap mRenderbufferMap;
HandleAllocator mRenderbufferHandleAllocator;
NameSpace mRenderbufferNameSpace;
};
}
......
......@@ -318,6 +318,7 @@ copy "$(OutDir)opengl32.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Platf
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\common\NameSpace.cpp" />
<ClCompile Include="..\common\Object.cpp" />
<ClCompile Include="Buffer.cpp" />
<ClCompile Include="Context.cpp" />
......@@ -325,7 +326,6 @@ copy "$(OutDir)opengl32.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Platf
<ClCompile Include="Device.cpp" />
<ClCompile Include="Fence.cpp" />
<ClCompile Include="Framebuffer.cpp" />
<ClCompile Include="HandleAllocator.cpp" />
<ClCompile Include="Image.cpp" />
<ClCompile Include="IndexDataManager.cpp" />
<ClCompile Include="libGL.cpp" />
......@@ -341,6 +341,7 @@ copy "$(OutDir)opengl32.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Platf
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\common\debug.h" />
<ClInclude Include="..\common\NameSpace.hpp" />
<ClInclude Include="..\common\Object.hpp" />
<ClInclude Include="..\include\GLES2\gl2.h" />
<ClInclude Include="..\include\GLES2\gl2ext.h" />
......@@ -350,7 +351,6 @@ copy "$(OutDir)opengl32.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Platf
<ClInclude Include="Device.hpp" />
<ClInclude Include="Fence.h" />
<ClInclude Include="Framebuffer.h" />
<ClInclude Include="HandleAllocator.h" />
<ClInclude Include="Image.hpp" />
<ClInclude Include="IndexDataManager.h" />
<ClInclude Include="main.h" />
......
......@@ -26,9 +26,6 @@
<ClCompile Include="Framebuffer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="HandleAllocator.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="IndexDataManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
......@@ -71,6 +68,9 @@
<ClCompile Include="..\common\Object.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\common\NameSpace.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Buffer.h">
......@@ -85,9 +85,6 @@
<ClInclude Include="Framebuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HandleAllocator.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="IndexDataManager.h">
<Filter>Header Files</Filter>
</ClInclude>
......@@ -145,6 +142,9 @@
<ClInclude Include="..\common\Object.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\common\NameSpace.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="libGL.rc" />
......
......@@ -761,7 +761,7 @@ GLuint Context::createRenderbuffer()
// Returns an unused framebuffer name
GLuint Context::createFramebuffer()
{
GLuint handle = mFramebufferHandleAllocator.allocate();
GLuint handle = mFramebufferNameSpace.allocate();
mFramebufferMap[handle] = NULL;
......@@ -806,7 +806,7 @@ void Context::deleteFramebuffer(GLuint framebuffer)
{
detachFramebuffer(framebuffer);
mFramebufferHandleAllocator.release(framebufferObject->first);
mFramebufferNameSpace.release(framebufferObject->first);
delete framebufferObject->second;
mFramebufferMap.erase(framebufferObject);
}
......
......@@ -17,7 +17,7 @@
#include "libEGL/Context.hpp"
#include "ResourceManager.h"
#include "HandleAllocator.h"
#include "common/NameSpace.hpp"
#include "common/Object.hpp"
#include "Image.hpp"
#include "Renderer/Sampler.hpp"
......@@ -472,7 +472,7 @@ private:
typedef std::map<GLint, Framebuffer*> FramebufferMap;
FramebufferMap mFramebufferMap;
HandleAllocator mFramebufferHandleAllocator;
gl::NameSpace mFramebufferNameSpace;
VertexDataManager *mVertexDataManager;
IndexDataManager *mIndexDataManager;
......
// 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.
//
// HandleAllocator.cpp: Implements the HandleAllocator class, which is used
// to allocate GL handles.
#include "HandleAllocator.h"
#include "main.h"
namespace es1
{
HandleAllocator::HandleAllocator() : mBaseValue(1), mNextValue(1)
{
}
HandleAllocator::~HandleAllocator()
{
}
void HandleAllocator::setBaseHandle(GLuint value)
{
ASSERT(mBaseValue == mNextValue);
mBaseValue = value;
mNextValue = value;
}
GLuint HandleAllocator::allocate()
{
if(mFreeValues.size())
{
GLuint handle = mFreeValues.back();
mFreeValues.pop_back();
return handle;
}
return mNextValue++;
}
void HandleAllocator::release(GLuint handle)
{
if(handle == mNextValue - 1)
{
// Don't drop below base value
if(mNextValue > mBaseValue)
{
mNextValue--;
}
}
else
{
// Only free handles that we own - don't drop below the base value
if(handle >= mBaseValue)
{
mFreeValues.push_back(handle);
}
}
}
}
// 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.
//
// HandleAllocator.h: Defines the HandleAllocator class, which is used to
// allocate GL handles.
#ifndef LIBGLES_CM_HANDLEALLOCATOR_H_
#define LIBGLES_CM_HANDLEALLOCATOR_H_
#define GL_API
#include <GLES/gl.h>
#include <vector>
namespace es1
{
class HandleAllocator
{
public:
HandleAllocator();
virtual ~HandleAllocator();
void setBaseHandle(GLuint value);
GLuint allocate();
void release(GLuint handle);
private:
GLuint mBaseValue;
GLuint mNextValue;
typedef std::vector<GLuint> HandleList;
HandleList mFreeValues;
};
}
#endif // LIBGLES_CM_HANDLEALLOCATOR_H_
......@@ -59,7 +59,7 @@ void ResourceManager::release()
// Returns an unused buffer name
GLuint ResourceManager::createBuffer()
{
GLuint handle = mBufferHandleAllocator.allocate();
GLuint handle = mBufferNameSpace.allocate();
mBufferMap[handle] = NULL;
......@@ -69,7 +69,7 @@ GLuint ResourceManager::createBuffer()
// Returns an unused texture name
GLuint ResourceManager::createTexture()
{
GLuint handle = mTextureHandleAllocator.allocate();
GLuint handle = mTextureNameSpace.allocate();
mTextureMap[handle] = NULL;
......@@ -79,7 +79,7 @@ GLuint ResourceManager::createTexture()
// Returns an unused renderbuffer name
GLuint ResourceManager::createRenderbuffer()
{
GLuint handle = mRenderbufferHandleAllocator.allocate();
GLuint handle = mRenderbufferNameSpace.allocate();
mRenderbufferMap[handle] = NULL;
......@@ -92,7 +92,7 @@ void ResourceManager::deleteBuffer(GLuint buffer)
if(bufferObject != mBufferMap.end())
{
mBufferHandleAllocator.release(bufferObject->first);
mBufferNameSpace.release(bufferObject->first);
if(bufferObject->second) bufferObject->second->release();
mBufferMap.erase(bufferObject);
}
......@@ -104,7 +104,7 @@ void ResourceManager::deleteTexture(GLuint texture)
if(textureObject != mTextureMap.end())
{
mTextureHandleAllocator.release(textureObject->first);
mTextureNameSpace.release(textureObject->first);
if(textureObject->second) textureObject->second->release();
mTextureMap.erase(textureObject);
}
......@@ -116,7 +116,7 @@ void ResourceManager::deleteRenderbuffer(GLuint renderbuffer)
if(renderbufferObject != mRenderbufferMap.end())
{
mRenderbufferHandleAllocator.release(renderbufferObject->first);
mRenderbufferNameSpace.release(renderbufferObject->first);
if(renderbufferObject->second) renderbufferObject->second->release();
mRenderbufferMap.erase(renderbufferObject);
}
......
......@@ -15,7 +15,7 @@
#ifndef LIBGLES_CM_RESOURCEMANAGER_H_
#define LIBGLES_CM_RESOURCEMANAGER_H_
#include "HandleAllocator.h"
#include "common/NameSpace.hpp"
#define GL_API
#include <GLES/gl.h>
......@@ -69,15 +69,15 @@ class ResourceManager
typedef std::map<GLint, Buffer*> BufferMap;
BufferMap mBufferMap;
HandleAllocator mBufferHandleAllocator;
gl::NameSpace mBufferNameSpace;
typedef std::map<GLint, Texture*> TextureMap;
TextureMap mTextureMap;
HandleAllocator mTextureHandleAllocator;
gl::NameSpace mTextureNameSpace;
typedef std::map<GLint, Renderbuffer*> RenderbufferMap;
RenderbufferMap mRenderbufferMap;
HandleAllocator mRenderbufferHandleAllocator;
gl::NameSpace mRenderbufferNameSpace;
};
}
......
......@@ -318,13 +318,13 @@ copy "$(OutDir)libGLES_CM.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Pla
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\common\NameSpace.cpp" />
<ClCompile Include="..\common\Object.cpp" />
<ClCompile Include="Buffer.cpp" />
<ClCompile Include="Context.cpp" />
<ClCompile Include="..\common\debug.cpp" />
<ClCompile Include="Device.cpp" />
<ClCompile Include="Framebuffer.cpp" />
<ClCompile Include="HandleAllocator.cpp" />
<ClCompile Include="Image.cpp" />
<ClCompile Include="IndexDataManager.cpp" />
<ClCompile Include="libGLES_CM.cpp" />
......@@ -338,6 +338,7 @@ copy "$(OutDir)libGLES_CM.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Pla
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\common\debug.h" />
<ClInclude Include="..\common\NameSpace.hpp" />
<ClInclude Include="..\common\Object.hpp" />
<ClInclude Include="..\include\GLES\egl.h" />
<ClInclude Include="..\include\GLES\gl.h" />
......@@ -347,7 +348,6 @@ copy "$(OutDir)libGLES_CM.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Pla
<ClInclude Include="Context.h" />
<ClInclude Include="Device.hpp" />
<ClInclude Include="Framebuffer.h" />
<ClInclude Include="HandleAllocator.h" />
<ClInclude Include="Image.hpp" />
<ClInclude Include="IndexDataManager.h" />
<ClInclude Include="main.h" />
......
......@@ -23,9 +23,6 @@
<ClCompile Include="Framebuffer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="HandleAllocator.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="IndexDataManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
......@@ -62,6 +59,9 @@
<ClCompile Include="..\common\Object.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\common\NameSpace.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Buffer.h">
......@@ -73,9 +73,6 @@
<ClInclude Include="Framebuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HandleAllocator.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="IndexDataManager.h">
<Filter>Header Files</Filter>
</ClInclude>
......@@ -130,6 +127,9 @@
<ClInclude Include="..\common\Object.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\common\NameSpace.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="libGLES_CM.rc" />
......
......@@ -44,7 +44,7 @@ Context::Context(const egl::Config *config, const Context *shareContext) : mConf
sw::Context *context = new sw::Context();
device = new es2::Device(context);
mFenceHandleAllocator.setBaseHandle(0);
mFenceNameSpace.setBaseHandle(0);
setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
......@@ -775,7 +775,7 @@ GLuint Context::createRenderbuffer()
// Returns an unused framebuffer name
GLuint Context::createFramebuffer()
{
GLuint handle = mFramebufferHandleAllocator.allocate();
GLuint handle = mFramebufferNameSpace.allocate();
mFramebufferMap[handle] = NULL;
......@@ -784,7 +784,7 @@ GLuint Context::createFramebuffer()
GLuint Context::createFence()
{
GLuint handle = mFenceHandleAllocator.allocate();
GLuint handle = mFenceNameSpace.allocate();
mFenceMap[handle] = new Fence;
......@@ -794,7 +794,7 @@ GLuint Context::createFence()
// Returns an unused query name
GLuint Context::createQuery()
{
GLuint handle = mQueryHandleAllocator.allocate();
GLuint handle = mQueryNameSpace.allocate();
mQueryMap[handle] = NULL;
......@@ -849,7 +849,7 @@ void Context::deleteFramebuffer(GLuint framebuffer)
{
detachFramebuffer(framebuffer);
mFramebufferHandleAllocator.release(framebufferObject->first);
mFramebufferNameSpace.release(framebufferObject->first);
delete framebufferObject->second;
mFramebufferMap.erase(framebufferObject);
}
......@@ -861,7 +861,7 @@ void Context::deleteFence(GLuint fence)
if(fenceObject != mFenceMap.end())
{
mFenceHandleAllocator.release(fenceObject->first);
mFenceNameSpace.release(fenceObject->first);
delete fenceObject->second;
mFenceMap.erase(fenceObject);
}
......@@ -873,7 +873,7 @@ void Context::deleteQuery(GLuint query)
if(queryObject != mQueryMap.end())
{
mQueryHandleAllocator.release(queryObject->first);
mQueryNameSpace.release(queryObject->first);
if(queryObject->second)
{
......
......@@ -17,7 +17,7 @@
#include "libEGL/Context.hpp"
#include "ResourceManager.h"
#include "HandleAllocator.h"
#include "common/NameSpace.hpp"
#include "common/Object.hpp"
#include "Image.hpp"
#include "Renderer/Sampler.hpp"
......@@ -470,15 +470,15 @@ private:
typedef std::map<GLint, Framebuffer*> FramebufferMap;
FramebufferMap mFramebufferMap;
HandleAllocator mFramebufferHandleAllocator;
gl::NameSpace mFramebufferNameSpace;
typedef std::map<GLint, Fence*> FenceMap;
FenceMap mFenceMap;
HandleAllocator mFenceHandleAllocator;
gl::NameSpace mFenceNameSpace;
typedef std::map<GLint, Query*> QueryMap;
QueryMap mQueryMap;
HandleAllocator mQueryHandleAllocator;
gl::NameSpace mQueryNameSpace;
VertexDataManager *mVertexDataManager;
IndexDataManager *mIndexDataManager;
......
// 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.
//
// HandleAllocator.cpp: Implements the HandleAllocator class, which is used
// to allocate GL handles.
#include "HandleAllocator.h"
#include "main.h"
namespace es2
{
HandleAllocator::HandleAllocator() : mBaseValue(1), mNextValue(1)
{
}
HandleAllocator::~HandleAllocator()
{
}
void HandleAllocator::setBaseHandle(GLuint value)
{
ASSERT(mBaseValue == mNextValue);
mBaseValue = value;
mNextValue = value;
}
GLuint HandleAllocator::allocate()
{
if(mFreeValues.size())
{
GLuint handle = mFreeValues.back();
mFreeValues.pop_back();
return handle;
}
return mNextValue++;
}
void HandleAllocator::release(GLuint handle)
{
if(handle == mNextValue - 1)
{
// Don't drop below base value
if(mNextValue > mBaseValue)
{
mNextValue--;
}
}
else
{
// Only free handles that we own - don't drop below the base value
if(handle >= mBaseValue)
{
mFreeValues.push_back(handle);
}
}
}
}
// 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.
//
// HandleAllocator.h: Defines the HandleAllocator class, which is used to
// allocate GL handles.
#ifndef LIBGLESV2_HANDLEALLOCATOR_H_
#define LIBGLESV2_HANDLEALLOCATOR_H_
#define GL_APICALL
#include <GLES2/gl2.h>
#include <vector>
namespace es2
{
class HandleAllocator
{
public:
HandleAllocator();
virtual ~HandleAllocator();
void setBaseHandle(GLuint value);
GLuint allocate();
void release(GLuint handle);
private:
GLuint mBaseValue;
GLuint mNextValue;
typedef std::vector<GLuint> HandleList;
HandleList mFreeValues;
};
}
#endif // LIBGLESV2_HANDLEALLOCATOR_H_
......@@ -71,7 +71,7 @@ void ResourceManager::release()
// Returns an unused buffer name
GLuint ResourceManager::createBuffer()
{
GLuint handle = mBufferHandleAllocator.allocate();
GLuint handle = mBufferNameSpace.allocate();
mBufferMap[handle] = NULL;
......@@ -81,7 +81,7 @@ GLuint ResourceManager::createBuffer()
// Returns an unused shader/program name
GLuint ResourceManager::createShader(GLenum type)
{
GLuint handle = mProgramShaderHandleAllocator.allocate();
GLuint handle = mProgramShaderNameSpace.allocate();
if(type == GL_VERTEX_SHADER)
{
......@@ -99,7 +99,7 @@ GLuint ResourceManager::createShader(GLenum type)
// Returns an unused program/shader name
GLuint ResourceManager::createProgram()
{
GLuint handle = mProgramShaderHandleAllocator.allocate();
GLuint handle = mProgramShaderNameSpace.allocate();
mProgramMap[handle] = new Program(this, handle);
......@@ -109,7 +109,7 @@ GLuint ResourceManager::createProgram()
// Returns an unused texture name
GLuint ResourceManager::createTexture()
{
GLuint handle = mTextureHandleAllocator.allocate();
GLuint handle = mTextureNameSpace.allocate();
mTextureMap[handle] = NULL;
......@@ -119,7 +119,7 @@ GLuint ResourceManager::createTexture()
// Returns an unused renderbuffer name
GLuint ResourceManager::createRenderbuffer()
{
GLuint handle = mRenderbufferHandleAllocator.allocate();
GLuint handle = mRenderbufferNameSpace.allocate();
mRenderbufferMap[handle] = NULL;
......@@ -132,7 +132,7 @@ void ResourceManager::deleteBuffer(GLuint buffer)
if(bufferObject != mBufferMap.end())
{
mBufferHandleAllocator.release(bufferObject->first);
mBufferNameSpace.release(bufferObject->first);
if(bufferObject->second) bufferObject->second->release();
mBufferMap.erase(bufferObject);
}
......@@ -146,7 +146,7 @@ void ResourceManager::deleteShader(GLuint shader)
{
if(shaderObject->second->getRefCount() == 0)
{
mProgramShaderHandleAllocator.release(shaderObject->first);
mProgramShaderNameSpace.release(shaderObject->first);
delete shaderObject->second;
mShaderMap.erase(shaderObject);
}
......@@ -165,7 +165,7 @@ void ResourceManager::deleteProgram(GLuint program)
{
if(programObject->second->getRefCount() == 0)
{
mProgramShaderHandleAllocator.release(programObject->first);
mProgramShaderNameSpace.release(programObject->first);
delete programObject->second;
mProgramMap.erase(programObject);
}
......@@ -182,7 +182,7 @@ void ResourceManager::deleteTexture(GLuint texture)
if(textureObject != mTextureMap.end())
{
mTextureHandleAllocator.release(textureObject->first);
mTextureNameSpace.release(textureObject->first);
if(textureObject->second) textureObject->second->release();
mTextureMap.erase(textureObject);
}
......@@ -194,7 +194,7 @@ void ResourceManager::deleteRenderbuffer(GLuint renderbuffer)
if(renderbufferObject != mRenderbufferMap.end())
{
mRenderbufferHandleAllocator.release(renderbufferObject->first);
mRenderbufferNameSpace.release(renderbufferObject->first);
if(renderbufferObject->second) renderbufferObject->second->release();
mRenderbufferMap.erase(renderbufferObject);
}
......
......@@ -15,7 +15,7 @@
#ifndef LIBGLESV2_RESOURCEMANAGER_H_
#define LIBGLESV2_RESOURCEMANAGER_H_
#include "HandleAllocator.h"
#include "common/NameSpace.hpp"
#define GL_APICALL
#include <GLES2/gl2.h>
......@@ -78,22 +78,22 @@ class ResourceManager
typedef std::map<GLint, Buffer*> BufferMap;
BufferMap mBufferMap;
HandleAllocator mBufferHandleAllocator;
gl::NameSpace mBufferNameSpace;
typedef std::map<GLint, Shader*> ShaderMap;
ShaderMap mShaderMap;
typedef std::map<GLint, Program*> ProgramMap;
ProgramMap mProgramMap;
HandleAllocator mProgramShaderHandleAllocator;
gl::NameSpace mProgramShaderNameSpace;
typedef std::map<GLint, Texture*> TextureMap;
TextureMap mTextureMap;
HandleAllocator mTextureHandleAllocator;
gl::NameSpace mTextureNameSpace;
typedef std::map<GLint, Renderbuffer*> RenderbufferMap;
RenderbufferMap mRenderbufferMap;
HandleAllocator mRenderbufferHandleAllocator;
gl::NameSpace mRenderbufferNameSpace;
};
}
......
......@@ -318,6 +318,7 @@ copy "$(OutDir)libGLESv2.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Plat
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\common\NameSpace.cpp" />
<ClCompile Include="..\common\Object.cpp" />
<ClCompile Include="Buffer.cpp" />
<ClCompile Include="Context.cpp" />
......@@ -325,7 +326,6 @@ copy "$(OutDir)libGLESv2.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Plat
<ClCompile Include="Device.cpp" />
<ClCompile Include="Fence.cpp" />
<ClCompile Include="Framebuffer.cpp" />
<ClCompile Include="HandleAllocator.cpp" />
<ClCompile Include="Image.cpp" />
<ClCompile Include="IndexDataManager.cpp" />
<ClCompile Include="libGLESv2.cpp" />
......@@ -341,6 +341,7 @@ copy "$(OutDir)libGLESv2.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Plat
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\common\debug.h" />
<ClInclude Include="..\common\NameSpace.hpp" />
<ClInclude Include="..\common\Object.hpp" />
<ClInclude Include="..\include\GLES2\gl2.h" />
<ClInclude Include="..\include\GLES2\gl2ext.h" />
......@@ -350,7 +351,6 @@ copy "$(OutDir)libGLESv2.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Plat
<ClInclude Include="Device.hpp" />
<ClInclude Include="Fence.h" />
<ClInclude Include="Framebuffer.h" />
<ClInclude Include="HandleAllocator.h" />
<ClInclude Include="Image.hpp" />
<ClInclude Include="IndexDataManager.h" />
<ClInclude Include="main.h" />
......
......@@ -26,9 +26,6 @@
<ClCompile Include="Framebuffer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="HandleAllocator.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="IndexDataManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
......@@ -71,6 +68,9 @@
<ClCompile Include="..\common\Object.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\common\NameSpace.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Buffer.h">
......@@ -85,9 +85,6 @@
<ClInclude Include="Framebuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HandleAllocator.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="IndexDataManager.h">
<Filter>Header Files</Filter>
</ClInclude>
......@@ -145,6 +142,9 @@
<ClInclude Include="..\common\Object.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\common\NameSpace.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="libGLESv2.rc" />
......
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