Commit 4df0c65b by Nicolas Capens

Use namespaces for context owned objects.

Bug 19219444 Change-Id: I9606dfb30693a15a06896d83888022ccbaa8db2e Reviewed-on: https://swiftshader-review.googlesource.com/5010Tested-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 433ae74c
...@@ -46,7 +46,7 @@ public: ...@@ -46,7 +46,7 @@ public:
return map.begin()->first; return map.begin()->first;
} }
GLuint allocate() GLuint allocate(ObjectType *object = nullptr)
{ {
GLuint name = freeName; GLuint name = freeName;
...@@ -55,13 +55,13 @@ public: ...@@ -55,13 +55,13 @@ public:
name++; name++;
} }
map.insert({name, nullptr}); map.insert({name, object});
freeName = name + 1; freeName = name + 1;
return name; return name;
} }
bool isReserved(GLuint name) bool isReserved(GLuint name) const
{ {
return map.find(name) != map.end(); return map.find(name) != map.end();
} }
...@@ -96,13 +96,8 @@ public: ...@@ -96,13 +96,8 @@ public:
return nullptr; return nullptr;
} }
ObjectType *find(GLuint name) ObjectType *find(GLuint name) const
{ {
if(name < baseName)
{
return nullptr;
}
auto element = map.find(name); auto element = map.find(name);
if(element == map.end()) if(element == map.end())
......
...@@ -116,7 +116,7 @@ Context::Context(const Context *shareContext) ...@@ -116,7 +116,7 @@ Context::Context(const Context *shareContext)
mState.colorMaskAlpha = true; mState.colorMaskAlpha = true;
mState.depthMask = true; mState.depthMask = true;
if(shareContext != NULL) if(shareContext)
{ {
mResourceManager = shareContext->mResourceManager; mResourceManager = shareContext->mResourceManager;
mResourceManager->addRef(); mResourceManager->addRef();
...@@ -149,8 +149,8 @@ Context::Context(const Context *shareContext) ...@@ -149,8 +149,8 @@ Context::Context(const Context *shareContext)
mState.packAlignment = 4; mState.packAlignment = 4;
mState.unpackAlignment = 4; mState.unpackAlignment = 4;
mVertexDataManager = NULL; mVertexDataManager = nullptr;
mIndexDataManager = NULL; mIndexDataManager = nullptr;
mInvalidEnum = false; mInvalidEnum = false;
mInvalidValue = false; mInvalidValue = false;
...@@ -210,46 +210,46 @@ Context::~Context() ...@@ -210,46 +210,46 @@ Context::~Context()
mState.currentProgram = 0; mState.currentProgram = 0;
} }
while(!mFramebufferMap.empty()) while(!mFramebufferNameSpace.empty())
{ {
deleteFramebuffer(mFramebufferMap.begin()->first); deleteFramebuffer(mFramebufferNameSpace.firstName());
} }
while(!mFenceMap.empty()) while(!mFenceNameSpace.empty())
{ {
deleteFence(mFenceMap.begin()->first); deleteFence(mFenceNameSpace.firstName());
} }
while(!mQueryMap.empty()) while(!mQueryNameSpace.empty())
{ {
deleteQuery(mQueryMap.begin()->first); deleteQuery(mQueryNameSpace.firstName());
} }
for(int type = 0; type < TEXTURE_TYPE_COUNT; type++) for(int type = 0; type < TEXTURE_TYPE_COUNT; type++)
{ {
for(int sampler = 0; sampler < MAX_COMBINED_TEXTURE_IMAGE_UNITS; sampler++) for(int sampler = 0; sampler < MAX_COMBINED_TEXTURE_IMAGE_UNITS; sampler++)
{ {
mState.samplerTexture[type][sampler] = NULL; mState.samplerTexture[type][sampler] = nullptr;
} }
} }
for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++) for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
{ {
mState.vertexAttribute[i].mBoundBuffer = NULL; mState.vertexAttribute[i].mBoundBuffer = nullptr;
} }
for(int i = 0; i < QUERY_TYPE_COUNT; i++) for(int i = 0; i < QUERY_TYPE_COUNT; i++)
{ {
mState.activeQuery[i] = NULL; mState.activeQuery[i] = nullptr;
} }
mState.arrayBuffer = NULL; mState.arrayBuffer = nullptr;
mState.elementArrayBuffer = NULL; mState.elementArrayBuffer = nullptr;
mState.renderbuffer = NULL; mState.renderbuffer = nullptr;
mTexture2DZero = NULL; mTexture2DZero = nullptr;
mProxyTexture2DZero = NULL; mProxyTexture2DZero = nullptr;
mTextureCubeMapZero = NULL; mTextureCubeMapZero = nullptr;
delete mVertexDataManager; delete mVertexDataManager;
delete mIndexDataManager; delete mIndexDataManager;
...@@ -297,7 +297,7 @@ void Context::makeCurrent(Surface *surface) ...@@ -297,7 +297,7 @@ void Context::makeCurrent(Surface *surface)
{ {
depthStencil->release(); depthStencil->release();
} }
markAllStateDirty(); markAllStateDirty();
} }
...@@ -699,8 +699,8 @@ GLuint Context::getArrayBufferName() const ...@@ -699,8 +699,8 @@ GLuint Context::getArrayBufferName() const
GLuint Context::getActiveQuery(GLenum target) const GLuint Context::getActiveQuery(GLenum target) const
{ {
Query *queryObject = NULL; Query *queryObject = nullptr;
switch(target) switch(target)
{ {
case GL_ANY_SAMPLES_PASSED: case GL_ANY_SAMPLES_PASSED:
...@@ -717,7 +717,7 @@ GLuint Context::getActiveQuery(GLenum target) const ...@@ -717,7 +717,7 @@ GLuint Context::getActiveQuery(GLenum target) const
{ {
return queryObject->name; return queryObject->name;
} }
return 0; return 0;
} }
...@@ -800,48 +800,18 @@ GLuint Context::createRenderbuffer() ...@@ -800,48 +800,18 @@ GLuint Context::createRenderbuffer()
// Returns an unused framebuffer name // Returns an unused framebuffer name
GLuint Context::createFramebuffer() GLuint Context::createFramebuffer()
{ {
//GLuint handle = mFramebufferNameSpace.allocate(); return mFramebufferNameSpace.allocate();
unsigned int handle = 1;
while(mFramebufferMap.find(handle) != mFramebufferMap.end())
{
handle++;
}
mFramebufferMap[handle] = NULL;
return handle;
} }
GLuint Context::createFence() GLuint Context::createFence()
{ {
//GLuint handle = mFenceNameSpace.allocate(); return mFenceNameSpace.allocate(new Fence());
unsigned int handle = 1;
while (mFenceMap.find(handle) != mFenceMap.end())
{
handle++;
}
mFenceMap[handle] = new Fence;
return handle;
} }
// Returns an unused query name // Returns an unused query name
GLuint Context::createQuery() GLuint Context::createQuery()
{ {
//GLuint handle = mQueryNameSpace.allocate(); return mQueryNameSpace.allocate();
unsigned int handle = 1;
while (mQueryMap.find(handle) != mQueryMap.end())
{
handle++;
}
mQueryMap[handle] = NULL;
return handle;
} }
void Context::deleteBuffer(GLuint buffer) void Context::deleteBuffer(GLuint buffer)
...@@ -850,7 +820,7 @@ void Context::deleteBuffer(GLuint buffer) ...@@ -850,7 +820,7 @@ void Context::deleteBuffer(GLuint buffer)
{ {
detachBuffer(buffer); detachBuffer(buffer);
} }
mResourceManager->deleteBuffer(buffer); mResourceManager->deleteBuffer(buffer);
} }
...@@ -880,51 +850,40 @@ void Context::deleteRenderbuffer(GLuint renderbuffer) ...@@ -880,51 +850,40 @@ void Context::deleteRenderbuffer(GLuint renderbuffer)
{ {
detachRenderbuffer(renderbuffer); detachRenderbuffer(renderbuffer);
} }
mResourceManager->deleteRenderbuffer(renderbuffer); mResourceManager->deleteRenderbuffer(renderbuffer);
} }
void Context::deleteFramebuffer(GLuint framebuffer) void Context::deleteFramebuffer(GLuint framebuffer)
{ {
FramebufferMap::iterator framebufferObject = mFramebufferMap.find(framebuffer); Framebuffer *framebufferObject = mFramebufferNameSpace.remove(framebuffer);
if(framebufferObject != mFramebufferMap.end()) if(framebufferObject)
{ {
detachFramebuffer(framebuffer); detachFramebuffer(framebuffer);
//mFramebufferNameSpace.release(framebufferObject->first); delete framebufferObject;
delete framebufferObject->second;
mFramebufferMap.erase(framebufferObject);
} }
} }
void Context::deleteFence(GLuint fence) void Context::deleteFence(GLuint fence)
{ {
FenceMap::iterator fenceObject = mFenceMap.find(fence); Fence *fenceObject = mFenceNameSpace.remove(fence);
if(fenceObject != mFenceMap.end()) if(fenceObject)
{ {
//mFenceNameSpace.release(fenceObject->first); delete fenceObject;
delete fenceObject->second;
mFenceMap.erase(fenceObject);
} }
} }
void Context::deleteQuery(GLuint query) void Context::deleteQuery(GLuint query)
{ {
QueryMap::iterator queryObject = mQueryMap.find(query); Query *queryObject = mQueryNameSpace.remove(query);
if(queryObject != mQueryMap.end()) if(queryObject)
{ {
//mQueryNameSpace.release(queryObject->first); queryObject->release();
}
if(queryObject->second)
{
queryObject->second->release();
}
mQueryMap.erase(queryObject);
}
} }
Buffer *Context::getBuffer(GLuint handle) Buffer *Context::getBuffer(GLuint handle)
...@@ -994,7 +953,7 @@ void Context::bindReadFramebuffer(GLuint framebuffer) ...@@ -994,7 +953,7 @@ void Context::bindReadFramebuffer(GLuint framebuffer)
{ {
if(!getFramebuffer(framebuffer)) if(!getFramebuffer(framebuffer))
{ {
mFramebufferMap[framebuffer] = new Framebuffer(); mFramebufferNameSpace.insert(framebuffer, new Framebuffer());
} }
mState.readFramebuffer = framebuffer; mState.readFramebuffer = framebuffer;
...@@ -1004,7 +963,7 @@ void Context::bindDrawFramebuffer(GLuint framebuffer) ...@@ -1004,7 +963,7 @@ void Context::bindDrawFramebuffer(GLuint framebuffer)
{ {
if(!getFramebuffer(framebuffer)) if(!getFramebuffer(framebuffer))
{ {
mFramebufferMap[framebuffer] = new Framebuffer(); mFramebufferNameSpace.insert(framebuffer, new Framebuffer());
} }
mState.drawFramebuffer = framebuffer; mState.drawFramebuffer = framebuffer;
...@@ -1031,7 +990,7 @@ void Context::useProgram(GLuint program) ...@@ -1031,7 +990,7 @@ void Context::useProgram(GLuint program)
{ {
newProgram->addRef(); newProgram->addRef();
} }
if(oldProgram) if(oldProgram)
{ {
oldProgram->release(); oldProgram->release();
...@@ -1041,10 +1000,10 @@ void Context::useProgram(GLuint program) ...@@ -1041,10 +1000,10 @@ void Context::useProgram(GLuint program)
void Context::beginQuery(GLenum target, GLuint query) void Context::beginQuery(GLenum target, GLuint query)
{ {
// From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id>
// of zero, if the active query object name for <target> is non-zero (for the // of zero, if the active query object name for <target> is non-zero (for the
// targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if
// the active query for either target is non-zero), if <id> is the name of an // the active query for either target is non-zero), if <id> is the name of an
// existing query object whose type does not match <target>, or if <id> is the // existing query object whose type does not match <target>, or if <id> is the
// active query object name for any query type, the error INVALID_OPERATION is // active query object name for any query type, the error INVALID_OPERATION is
// generated. // generated.
...@@ -1058,7 +1017,7 @@ void Context::beginQuery(GLenum target, GLuint query) ...@@ -1058,7 +1017,7 @@ void Context::beginQuery(GLenum target, GLuint query)
// no query may be active for either if glBeginQuery targets either. // no query may be active for either if glBeginQuery targets either.
for(int i = 0; i < QUERY_TYPE_COUNT; i++) for(int i = 0; i < QUERY_TYPE_COUNT; i++)
{ {
if(mState.activeQuery[i] != NULL) if(mState.activeQuery[i])
{ {
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
...@@ -1067,13 +1026,13 @@ void Context::beginQuery(GLenum target, GLuint query) ...@@ -1067,13 +1026,13 @@ void Context::beginQuery(GLenum target, GLuint query)
QueryType qType; QueryType qType;
switch(target) switch(target)
{ {
case GL_ANY_SAMPLES_PASSED: case GL_ANY_SAMPLES_PASSED:
qType = QUERY_ANY_SAMPLES_PASSED; qType = QUERY_ANY_SAMPLES_PASSED;
break; break;
case GL_ANY_SAMPLES_PASSED_CONSERVATIVE: case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
qType = QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE; qType = QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE;
break; break;
default: default:
ASSERT(false); ASSERT(false);
} }
...@@ -1105,31 +1064,31 @@ void Context::endQuery(GLenum target) ...@@ -1105,31 +1064,31 @@ void Context::endQuery(GLenum target)
switch(target) switch(target)
{ {
case GL_ANY_SAMPLES_PASSED: case GL_ANY_SAMPLES_PASSED:
qType = QUERY_ANY_SAMPLES_PASSED; qType = QUERY_ANY_SAMPLES_PASSED;
break; break;
case GL_ANY_SAMPLES_PASSED_CONSERVATIVE: case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
qType = QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE; qType = QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE;
break; break;
default: default:
ASSERT(false); ASSERT(false);
} }
Query *queryObject = mState.activeQuery[qType]; Query *queryObject = mState.activeQuery[qType];
if(queryObject == NULL) if(!queryObject)
{ {
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
queryObject->end(); queryObject->end();
mState.activeQuery[qType] = NULL; mState.activeQuery[qType] = nullptr;
} }
void Context::setFramebufferZero(Framebuffer *buffer) void Context::setFramebufferZero(Framebuffer *buffer)
{ {
delete mFramebufferMap[0]; delete mFramebufferNameSpace.remove(0);
mFramebufferMap[0] = buffer; mFramebufferNameSpace.insert(0, buffer);
} }
void Context::setRenderbufferStorage(RenderbufferStorage *renderbuffer) void Context::setRenderbufferStorage(RenderbufferStorage *renderbuffer)
...@@ -1140,49 +1099,31 @@ void Context::setRenderbufferStorage(RenderbufferStorage *renderbuffer) ...@@ -1140,49 +1099,31 @@ void Context::setRenderbufferStorage(RenderbufferStorage *renderbuffer)
Framebuffer *Context::getFramebuffer(unsigned int handle) Framebuffer *Context::getFramebuffer(unsigned int handle)
{ {
FramebufferMap::iterator framebuffer = mFramebufferMap.find(handle); return mFramebufferNameSpace.find(handle);
if(framebuffer == mFramebufferMap.end())
{
return NULL;
}
else
{
return framebuffer->second;
}
} }
Fence *Context::getFence(unsigned int handle) Fence *Context::getFence(unsigned int handle)
{ {
FenceMap::iterator fence = mFenceMap.find(handle); return mFenceNameSpace.find(handle);
if(fence == mFenceMap.end())
{
return NULL;
}
else
{
return fence->second;
}
} }
Query *Context::getQuery(unsigned int handle, bool create, GLenum type) Query *Context::getQuery(unsigned int handle, bool create, GLenum type)
{ {
QueryMap::iterator query = mQueryMap.find(handle); if(!mQueryNameSpace.isReserved(handle))
if(query == mQueryMap.end())
{ {
return NULL; return nullptr;
} }
else else
{ {
if(!query->second && create) Query *query = mQueryNameSpace.find(handle);
if(!query && create)
{ {
query->second = new Query(handle, type); query = new Query(handle, type);
query->second->addRef(); query->addRef();
mQueryNameSpace.insert(handle, query);
} }
return query->second; return query;
} }
} }
...@@ -1332,7 +1273,7 @@ bool Context::getIntegerv(GLenum pname, GLint *params) ...@@ -1332,7 +1273,7 @@ bool Context::getIntegerv(GLenum pname, GLint *params)
// Please note: DEPTH_CLEAR_VALUE is not included in our internal getIntegerv implementation // Please note: DEPTH_CLEAR_VALUE is not included in our internal getIntegerv implementation
// because it is stored as a float, despite the fact that the GL ES 2.0 spec names // because it is stored as a float, despite the fact that the GL ES 2.0 spec names
// GetIntegerv as its native query function. As it would require conversion in any // GetIntegerv as its native query function. As it would require conversion in any
// case, this should make no difference to the calling application. You may find it in // case, this should make no difference to the calling application. You may find it in
// Context::getFloatv. // Context::getFloatv.
switch (pname) switch (pname)
{ {
...@@ -1388,7 +1329,7 @@ bool Context::getIntegerv(GLenum pname, GLint *params) ...@@ -1388,7 +1329,7 @@ bool Context::getIntegerv(GLenum pname, GLint *params)
case GL_MAX_ARRAY_TEXTURE_LAYERS: *params = 0; break; case GL_MAX_ARRAY_TEXTURE_LAYERS: *params = 0; break;
case GL_NUM_COMPRESSED_TEXTURE_FORMATS: *params = NUM_COMPRESSED_TEXTURE_FORMATS; break; case GL_NUM_COMPRESSED_TEXTURE_FORMATS: *params = NUM_COMPRESSED_TEXTURE_FORMATS; break;
case GL_MAX_SAMPLES: *params = IMPLEMENTATION_MAX_SAMPLES; break; case GL_MAX_SAMPLES: *params = IMPLEMENTATION_MAX_SAMPLES; break;
case GL_SAMPLE_BUFFERS: case GL_SAMPLE_BUFFERS:
case GL_SAMPLES: case GL_SAMPLES:
{ {
Framebuffer *framebuffer = getDrawFramebuffer(); Framebuffer *framebuffer = getDrawFramebuffer();
...@@ -1538,7 +1479,7 @@ bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *nu ...@@ -1538,7 +1479,7 @@ bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *nu
// Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
// is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
// to the fact that it is stored internally as a float, and so would require conversion // to the fact that it is stored internally as a float, and so would require conversion
// if returned from Context::getIntegerv. Since this conversion is already implemented // if returned from Context::getIntegerv. Since this conversion is already implemented
// in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
// place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
// application. // application.
...@@ -1737,7 +1678,7 @@ bool Context::applyRenderTarget() ...@@ -1737,7 +1678,7 @@ bool Context::applyRenderTarget()
{ {
sw::Rect scissor = {mState.scissorX, mState.scissorY, mState.scissorX + mState.scissorWidth, mState.scissorY + mState.scissorHeight}; sw::Rect scissor = {mState.scissorX, mState.scissorY, mState.scissorX + mState.scissorWidth, mState.scissorY + mState.scissorHeight};
scissor.clip(0, 0, width, height); scissor.clip(0, 0, width, height);
device->setScissorRect(scissor); device->setScissorRect(scissor);
device->setScissorEnable(true); device->setScissorEnable(true);
} }
...@@ -1835,8 +1776,8 @@ void Context::applyState(GLenum drawMode) ...@@ -1835,8 +1776,8 @@ void Context::applyState(GLenum drawMode)
device->setStencilEnable(true); device->setStencilEnable(true);
device->setTwoSidedStencil(true); device->setTwoSidedStencil(true);
if(mState.stencilWritemask != mState.stencilBackWritemask || if(mState.stencilWritemask != mState.stencilBackWritemask ||
mState.stencilRef != mState.stencilBackRef || mState.stencilRef != mState.stencilBackRef ||
mState.stencilMask != mState.stencilBackMask) mState.stencilMask != mState.stencilBackMask)
{ {
ERR("Separate front/back stencil writemasks, reference values, or stencil mask values are invalid under WebGL."); ERR("Separate front/back stencil writemasks, reference values, or stencil mask values are invalid under WebGL.");
...@@ -1962,7 +1903,7 @@ void Context::applyState(GLenum drawMode) ...@@ -1962,7 +1903,7 @@ void Context::applyState(GLenum drawMode)
} }
} }
} }
if(mState.sampleCoverageInvert) if(mState.sampleCoverageInvert)
{ {
mask = ~mask; mask = ~mask;
...@@ -2009,7 +1950,7 @@ GLenum Context::applyVertexBuffer(GLint base, GLint first, GLsizei count) ...@@ -2009,7 +1950,7 @@ GLenum Context::applyVertexBuffer(GLint base, GLint first, GLsizei count)
sw::Resource *resource = attributes[i].vertexBuffer; sw::Resource *resource = attributes[i].vertexBuffer;
const void *buffer = (char*)resource->data() + attributes[i].offset; const void *buffer = (char*)resource->data() + attributes[i].offset;
int stride = attributes[i].stride; int stride = attributes[i].stride;
buffer = (char*)buffer + stride * base; buffer = (char*)buffer + stride * base;
...@@ -2162,7 +2103,7 @@ void Context::applyTexture(sw::SamplerType type, int index, Texture *baseTexture ...@@ -2162,7 +2103,7 @@ void Context::applyTexture(sw::SamplerType type, int index, Texture *baseTexture
} }
device->setTextureResource(sampler, resource); device->setTextureResource(sampler, resource);
if(baseTexture && textureUsed) if(baseTexture && textureUsed)
{ {
int levelCount = baseTexture->getLevelCount(); int levelCount = baseTexture->getLevelCount();
...@@ -2237,7 +2178,7 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, ...@@ -2237,7 +2178,7 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
} }
GLsizei outputPitch = ComputePitch(width, format, type, mState.packAlignment); GLsizei outputPitch = ComputePitch(width, format, type, mState.packAlignment);
// Sized query sanity check // Sized query sanity check
if(bufSize) if(bufSize)
{ {
...@@ -2412,7 +2353,7 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, ...@@ -2412,7 +2353,7 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
switch(type) switch(type)
{ {
case GL_UNSIGNED_SHORT_5_6_5: // IMPLEMENTATION_COLOR_READ_TYPE case GL_UNSIGNED_SHORT_5_6_5: // IMPLEMENTATION_COLOR_READ_TYPE
dest16[i + j * outputPitch / sizeof(unsigned short)] = dest16[i + j * outputPitch / sizeof(unsigned short)] =
((unsigned short)(31 * b + 0.5f) << 0) | ((unsigned short)(31 * b + 0.5f) << 0) |
((unsigned short)(63 * g + 0.5f) << 5) | ((unsigned short)(63 * g + 0.5f) << 5) |
((unsigned short)(31 * r + 0.5f) << 11); ((unsigned short)(31 * r + 0.5f) << 11);
...@@ -2450,7 +2391,7 @@ void Context::clear(GLbitfield mask) ...@@ -2450,7 +2391,7 @@ void Context::clear(GLbitfield mask)
if(mask & GL_COLOR_BUFFER_BIT) if(mask & GL_COLOR_BUFFER_BIT)
{ {
unsigned int rgbaMask = (mState.colorMaskRed ? 0x1 : 0) | unsigned int rgbaMask = (mState.colorMaskRed ? 0x1 : 0) |
(mState.colorMaskGreen ? 0x2 : 0) | (mState.colorMaskGreen ? 0x2 : 0) |
(mState.colorMaskBlue ? 0x4 : 0) | (mState.colorMaskBlue ? 0x4 : 0) |
(mState.colorMaskAlpha ? 0x8 : 0); (mState.colorMaskAlpha ? 0x8 : 0);
...@@ -2694,19 +2635,19 @@ void Context::detachBuffer(GLuint buffer) ...@@ -2694,19 +2635,19 @@ void Context::detachBuffer(GLuint buffer)
if(mState.arrayBuffer.name() == buffer) if(mState.arrayBuffer.name() == buffer)
{ {
mState.arrayBuffer = NULL; mState.arrayBuffer = nullptr;
} }
if(mState.elementArrayBuffer.name() == buffer) if(mState.elementArrayBuffer.name() == buffer)
{ {
mState.elementArrayBuffer = NULL; mState.elementArrayBuffer = nullptr;
} }
for(int attribute = 0; attribute < MAX_VERTEX_ATTRIBS; attribute++) for(int attribute = 0; attribute < MAX_VERTEX_ATTRIBS; attribute++)
{ {
if(mState.vertexAttribute[attribute].mBoundBuffer.name() == buffer) if(mState.vertexAttribute[attribute].mBoundBuffer.name() == buffer)
{ {
mState.vertexAttribute[attribute].mBoundBuffer = NULL; mState.vertexAttribute[attribute].mBoundBuffer = nullptr;
} }
} }
} }
...@@ -2722,7 +2663,7 @@ void Context::detachTexture(GLuint texture) ...@@ -2722,7 +2663,7 @@ void Context::detachTexture(GLuint texture)
{ {
if(mState.samplerTexture[type][sampler].name() == texture) if(mState.samplerTexture[type][sampler].name() == texture)
{ {
mState.samplerTexture[type][sampler] = NULL; mState.samplerTexture[type][sampler] = nullptr;
} }
} }
} }
...@@ -2825,7 +2766,7 @@ void Context::setVertexAttrib(GLuint index, float x, float y, float z, float w) ...@@ -2825,7 +2766,7 @@ void Context::setVertexAttrib(GLuint index, float x, float y, float z, float w)
mVertexDataManager->dirtyCurrentValue(index); mVertexDataManager->dirtyCurrentValue(index);
} }
void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
GLbitfield mask) GLbitfield mask)
{ {
...@@ -2916,7 +2857,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1 ...@@ -2916,7 +2857,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1
sw::Rect sourceTrimmedRect = sourceScissoredRect; sw::Rect sourceTrimmedRect = sourceScissoredRect;
sw::Rect destTrimmedRect = destScissoredRect; sw::Rect destTrimmedRect = destScissoredRect;
// The source & destination rectangles also may need to be trimmed if they fall out of the bounds of // The source & destination rectangles also may need to be trimmed if they fall out of the bounds of
// the actual draw and read surfaces. // the actual draw and read surfaces.
if(sourceTrimmedRect.x0 < 0) if(sourceTrimmedRect.x0 < 0)
{ {
...@@ -2977,7 +2918,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1 ...@@ -2977,7 +2918,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1
bool partialBufferCopy = false; bool partialBufferCopy = false;
if(sourceTrimmedRect.y1 - sourceTrimmedRect.y0 < readBufferHeight || if(sourceTrimmedRect.y1 - sourceTrimmedRect.y0 < readBufferHeight ||
sourceTrimmedRect.x1 - sourceTrimmedRect.x0 < readBufferWidth || sourceTrimmedRect.x1 - sourceTrimmedRect.x0 < readBufferWidth ||
destTrimmedRect.y1 - destTrimmedRect.y0 < drawBufferHeight || destTrimmedRect.y1 - destTrimmedRect.y0 < drawBufferHeight ||
destTrimmedRect.x1 - destTrimmedRect.x0 < drawBufferWidth || destTrimmedRect.x1 - destTrimmedRect.x0 < drawBufferWidth ||
sourceTrimmedRect.y0 != 0 || destTrimmedRect.y0 != 0 || sourceTrimmedRect.x0 != 0 || destTrimmedRect.x0 != 0) sourceTrimmedRect.y0 != 0 || destTrimmedRect.y0 != 0 || sourceTrimmedRect.x0 != 0 || destTrimmedRect.x0 != 0)
...@@ -3000,7 +2941,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1 ...@@ -3000,7 +2941,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1
ERR("Color buffer format conversion in BlitFramebufferANGLE not supported by this implementation"); ERR("Color buffer format conversion in BlitFramebufferANGLE not supported by this implementation");
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
if(partialBufferCopy && readBufferSamples > 1) if(partialBufferCopy && readBufferSamples > 1)
{ {
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
...@@ -3011,8 +2952,8 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1 ...@@ -3011,8 +2952,8 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1
if(mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) if(mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
{ {
Renderbuffer *readDSBuffer = NULL; Renderbuffer *readDSBuffer = nullptr;
Renderbuffer *drawDSBuffer = NULL; Renderbuffer *drawDSBuffer = nullptr;
// We support OES_packed_depth_stencil, and do not support a separately attached depth and stencil buffer, so if we have // We support OES_packed_depth_stencil, and do not support a separately attached depth and stencil buffer, so if we have
// both a depth and stencil buffer, it will be the same buffer. // both a depth and stencil buffer, it will be the same buffer.
...@@ -3055,7 +2996,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1 ...@@ -3055,7 +2996,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1
return error(GL_INVALID_OPERATION); // Only whole-buffer copies are permitted return error(GL_INVALID_OPERATION); // Only whole-buffer copies are permitted
} }
if((drawDSBuffer && drawDSBuffer->getSamples() > 1) || if((drawDSBuffer && drawDSBuffer->getSamples() > 1) ||
(readDSBuffer && readDSBuffer->getSamples() > 1)) (readDSBuffer && readDSBuffer->getSamples() > 1))
{ {
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
...@@ -3068,7 +3009,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1 ...@@ -3068,7 +3009,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1
{ {
Image *readRenderTarget = readFramebuffer->getRenderTarget(); Image *readRenderTarget = readFramebuffer->getRenderTarget();
Image *drawRenderTarget = drawFramebuffer->getRenderTarget(); Image *drawRenderTarget = drawFramebuffer->getRenderTarget();
bool success = device->stretchRect(readRenderTarget, &sourceRect, drawRenderTarget, &destRect, false); bool success = device->stretchRect(readRenderTarget, &sourceRect, drawRenderTarget, &destRect, false);
readRenderTarget->release(); readRenderTarget->release();
...@@ -3083,7 +3024,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1 ...@@ -3083,7 +3024,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1
if(blitDepthStencil) if(blitDepthStencil)
{ {
bool success = device->stretchRect(readFramebuffer->getDepthStencil(), NULL, drawFramebuffer->getDepthStencil(), NULL, false); bool success = device->stretchRect(readFramebuffer->getDepthStencil(), nullptr, drawFramebuffer->getDepthStencil(), nullptr, false);
if(!success) if(!success)
{ {
...@@ -3163,7 +3104,7 @@ void Context::translate(GLfloat x, GLfloat y, GLfloat z) ...@@ -3163,7 +3104,7 @@ void Context::translate(GLfloat x, GLfloat y, GLfloat z)
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
currentMatrixStack().translate(x, y, z); currentMatrixStack().translate(x, y, z);
} }
void Context::scale(GLfloat x, GLfloat y, GLfloat z) void Context::scale(GLfloat x, GLfloat y, GLfloat z)
...@@ -3252,7 +3193,7 @@ void Context::alphaFunc(GLenum func, GLclampf ref) ...@@ -3252,7 +3193,7 @@ void Context::alphaFunc(GLenum func, GLclampf ref)
{ {
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
switch(func) switch(func)
{ {
case GL_NEVER: device->setAlphaCompare(sw::ALPHA_NEVER); break; case GL_NEVER: device->setAlphaCompare(sw::ALPHA_NEVER); break;
...@@ -3560,7 +3501,7 @@ void Context::end() ...@@ -3560,7 +3501,7 @@ void Context::end()
} }
applyTextures(); applyTextures();
switch(drawMode) switch(drawMode)
{ {
case GL_POINTS: case GL_POINTS:
......
...@@ -523,7 +523,7 @@ public: ...@@ -523,7 +523,7 @@ public:
bool isDepthTestEnabled() const; bool isDepthTestEnabled() const;
void setDepthFunc(GLenum depthFunc); void setDepthFunc(GLenum depthFunc);
void setDepthRange(float zNear, float zFar); void setDepthRange(float zNear, float zFar);
void setBlendEnabled(bool enabled); void setBlendEnabled(bool enabled);
bool isBlendEnabled() const; bool isBlendEnabled() const;
void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha); void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha);
...@@ -590,7 +590,7 @@ public: ...@@ -590,7 +590,7 @@ public:
void setPackAlignment(GLint alignment); void setPackAlignment(GLint alignment);
GLint getPackAlignment() const; GLint getPackAlignment() const;
// These create and destroy methods are merely pass-throughs to // These create and destroy methods are merely pass-throughs to
// ResourceManager, which owns these object types // ResourceManager, which owns these object types
GLuint createBuffer(); GLuint createBuffer();
GLuint createShader(GLenum type); GLuint createShader(GLenum type);
...@@ -674,8 +674,8 @@ public: ...@@ -674,8 +674,8 @@ public:
GLenum getError(); GLenum getError();
static int getSupportedMultisampleCount(int requested); static int getSupportedMultisampleCount(int requested);
void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
GLbitfield mask); GLbitfield mask);
...@@ -753,17 +753,9 @@ private: ...@@ -753,17 +753,9 @@ private:
BindingPointer<Texture2D> mProxyTexture2DZero; BindingPointer<Texture2D> mProxyTexture2DZero;
BindingPointer<TextureCubeMap> mTextureCubeMapZero; BindingPointer<TextureCubeMap> mTextureCubeMapZero;
typedef std::map<GLint, Framebuffer*> FramebufferMap; gl::NameSpace<Framebuffer> mFramebufferNameSpace;
FramebufferMap mFramebufferMap; gl::NameSpace<Fence, 0> mFenceNameSpace;
//NameSpace mFramebufferNameSpace; gl::NameSpace<Query> mQueryNameSpace;
typedef std::map<GLint, Fence*> FenceMap;
FenceMap mFenceMap;
//NameSpace mFenceNameSpace;
typedef std::map<GLint, Query*> QueryMap;
QueryMap mQueryMap;
//NameSpace mQueryNameSpace;
VertexDataManager *mVertexDataManager; VertexDataManager *mVertexDataManager;
IndexDataManager *mIndexDataManager; IndexDataManager *mIndexDataManager;
...@@ -778,7 +770,7 @@ private: ...@@ -778,7 +770,7 @@ private:
bool mHasBeenCurrent; bool mHasBeenCurrent;
unsigned int mAppliedProgramSerial; unsigned int mAppliedProgramSerial;
// state caching flags // state caching flags
bool mDepthStateDirty; bool mDepthStateDirty;
bool mMaskStateDirty; bool mMaskStateDirty;
......
...@@ -245,9 +245,9 @@ Context::Context(const egl::Config *config, const Context *shareContext) ...@@ -245,9 +245,9 @@ Context::Context(const egl::Config *config, const Context *shareContext)
Context::~Context() Context::~Context()
{ {
while(!mFramebufferMap.empty()) while(!mFramebufferNameSpace.empty())
{ {
deleteFramebuffer(mFramebufferMap.begin()->first); deleteFramebuffer(mFramebufferNameSpace.firstName());
} }
for(int type = 0; type < TEXTURE_TYPE_COUNT; type++) for(int type = 0; type < TEXTURE_TYPE_COUNT; type++)
...@@ -933,54 +933,39 @@ GLuint Context::createRenderbuffer() ...@@ -933,54 +933,39 @@ GLuint Context::createRenderbuffer()
// Returns an unused framebuffer name // Returns an unused framebuffer name
GLuint Context::createFramebuffer() GLuint Context::createFramebuffer()
{ {
GLuint handle = mFramebufferNameSpace.allocate(); return mFramebufferNameSpace.allocate();
mFramebufferMap[handle] = nullptr;
return handle;
} }
void Context::deleteBuffer(GLuint buffer) void Context::deleteBuffer(GLuint buffer)
{ {
if(mResourceManager->getBuffer(buffer)) detachBuffer(buffer);
{
detachBuffer(buffer);
}
mResourceManager->deleteBuffer(buffer); mResourceManager->deleteBuffer(buffer);
} }
void Context::deleteTexture(GLuint texture) void Context::deleteTexture(GLuint texture)
{ {
if(mResourceManager->getTexture(texture)) detachTexture(texture);
{
detachTexture(texture);
}
mResourceManager->deleteTexture(texture); mResourceManager->deleteTexture(texture);
} }
void Context::deleteRenderbuffer(GLuint renderbuffer) void Context::deleteRenderbuffer(GLuint renderbuffer)
{ {
if(mResourceManager->getRenderbuffer(renderbuffer)) detachRenderbuffer(renderbuffer);
{
detachRenderbuffer(renderbuffer);
}
mResourceManager->deleteRenderbuffer(renderbuffer); mResourceManager->deleteRenderbuffer(renderbuffer);
} }
void Context::deleteFramebuffer(GLuint framebuffer) void Context::deleteFramebuffer(GLuint framebuffer)
{ {
FramebufferMap::iterator framebufferObject = mFramebufferMap.find(framebuffer); detachFramebuffer(framebuffer);
if(framebufferObject != mFramebufferMap.end()) Framebuffer *framebufferObject = mFramebufferNameSpace.remove(framebuffer);
{
detachFramebuffer(framebuffer);
delete framebufferObject->second; if(framebufferObject)
mFramebufferNameSpace.remove(framebufferObject->first); {
mFramebufferMap.erase(framebufferObject); delete framebufferObject;
} }
} }
...@@ -1036,7 +1021,7 @@ void Context::bindFramebuffer(GLuint framebuffer) ...@@ -1036,7 +1021,7 @@ void Context::bindFramebuffer(GLuint framebuffer)
{ {
if(!getFramebuffer(framebuffer)) if(!getFramebuffer(framebuffer))
{ {
mFramebufferMap[framebuffer] = new Framebuffer(); mFramebufferNameSpace.insert(framebuffer, new Framebuffer());
} }
mState.framebuffer = framebuffer; mState.framebuffer = framebuffer;
...@@ -1051,8 +1036,8 @@ void Context::bindRenderbuffer(GLuint renderbuffer) ...@@ -1051,8 +1036,8 @@ void Context::bindRenderbuffer(GLuint renderbuffer)
void Context::setFramebufferZero(Framebuffer *buffer) void Context::setFramebufferZero(Framebuffer *buffer)
{ {
delete mFramebufferMap[0]; delete mFramebufferNameSpace.remove(0);
mFramebufferMap[0] = buffer; mFramebufferNameSpace.insert(0, buffer);
} }
void Context::setRenderbufferStorage(RenderbufferStorage *renderbuffer) void Context::setRenderbufferStorage(RenderbufferStorage *renderbuffer)
...@@ -1063,16 +1048,7 @@ void Context::setRenderbufferStorage(RenderbufferStorage *renderbuffer) ...@@ -1063,16 +1048,7 @@ void Context::setRenderbufferStorage(RenderbufferStorage *renderbuffer)
Framebuffer *Context::getFramebuffer(unsigned int handle) Framebuffer *Context::getFramebuffer(unsigned int handle)
{ {
FramebufferMap::iterator framebuffer = mFramebufferMap.find(handle); return mFramebufferNameSpace.find(handle);
if(framebuffer == mFramebufferMap.end())
{
return nullptr;
}
else
{
return framebuffer->second;
}
} }
Buffer *Context::getArrayBuffer() Buffer *Context::getArrayBuffer()
......
...@@ -594,9 +594,7 @@ private: ...@@ -594,9 +594,7 @@ private:
gl::BindingPointer<Texture2D> mTexture2DZero; gl::BindingPointer<Texture2D> mTexture2DZero;
gl::BindingPointer<TextureExternal> mTextureExternalZero; gl::BindingPointer<TextureExternal> mTextureExternalZero;
typedef std::map<GLint, Framebuffer*> FramebufferMap; gl::NameSpace<Framebuffer> mFramebufferNameSpace;
FramebufferMap mFramebufferMap;
gl::NameSpace<Framebuffer> mFramebufferNameSpace;
VertexDataManager *mVertexDataManager; VertexDataManager *mVertexDataManager;
IndexDataManager *mIndexDataManager; IndexDataManager *mIndexDataManager;
......
...@@ -86,7 +86,7 @@ void ResourceManager::deleteBuffer(GLuint buffer) ...@@ -86,7 +86,7 @@ void ResourceManager::deleteBuffer(GLuint buffer)
void ResourceManager::deleteTexture(GLuint texture) void ResourceManager::deleteTexture(GLuint texture)
{ {
Texture *textureObject = mTextureNameSpace.find(texture); Texture *textureObject = mTextureNameSpace.remove(texture);
if(textureObject) if(textureObject)
{ {
...@@ -96,7 +96,7 @@ void ResourceManager::deleteTexture(GLuint texture) ...@@ -96,7 +96,7 @@ void ResourceManager::deleteTexture(GLuint texture)
void ResourceManager::deleteRenderbuffer(GLuint renderbuffer) void ResourceManager::deleteRenderbuffer(GLuint renderbuffer)
{ {
Renderbuffer *renderbufferObject = mRenderbufferNameSpace.find(renderbuffer); Renderbuffer *renderbufferObject = mRenderbufferNameSpace.remove(renderbuffer);
if(renderbufferObject) if(renderbufferObject)
{ {
......
...@@ -115,7 +115,7 @@ Context::Context(const egl::Config *config, const Context *shareContext, EGLint ...@@ -115,7 +115,7 @@ Context::Context(const egl::Config *config, const Context *shareContext, EGLint
mState.colorMaskAlpha = true; mState.colorMaskAlpha = true;
mState.depthMask = true; mState.depthMask = true;
if(shareContext != NULL) if(shareContext)
{ {
mResourceManager = shareContext->mResourceManager; mResourceManager = shareContext->mResourceManager;
mResourceManager->addRef(); mResourceManager->addRef();
...@@ -164,8 +164,8 @@ Context::Context(const egl::Config *config, const Context *shareContext, EGLint ...@@ -164,8 +164,8 @@ Context::Context(const egl::Config *config, const Context *shareContext, EGLint
mState.unpackInfo.skipRows = 0; mState.unpackInfo.skipRows = 0;
mState.unpackInfo.skipImages = 0; mState.unpackInfo.skipImages = 0;
mVertexDataManager = NULL; mVertexDataManager = nullptr;
mIndexDataManager = NULL; mIndexDataManager = nullptr;
mInvalidEnum = false; mInvalidEnum = false;
mInvalidValue = false; mInvalidValue = false;
...@@ -190,67 +190,67 @@ Context::~Context() ...@@ -190,67 +190,67 @@ Context::~Context()
mState.currentProgram = 0; mState.currentProgram = 0;
} }
while(!mFramebufferMap.empty()) while(!mFramebufferNameSpace.empty())
{ {
deleteFramebuffer(mFramebufferMap.begin()->first); deleteFramebuffer(mFramebufferNameSpace.firstName());
} }
while(!mFenceMap.empty()) while(!mFenceNameSpace.empty())
{ {
deleteFence(mFenceMap.begin()->first); deleteFence(mFenceNameSpace.firstName());
} }
while(!mQueryMap.empty()) while(!mQueryNameSpace.empty())
{ {
deleteQuery(mQueryMap.begin()->first); deleteQuery(mQueryNameSpace.firstName());
} }
while(!mVertexArrayMap.empty()) while(!mVertexArrayNameSpace.empty())
{ {
deleteVertexArray(mVertexArrayMap.begin()->first); deleteVertexArray(mVertexArrayNameSpace.firstName());
} }
while(!mTransformFeedbackMap.empty()) while(!mTransformFeedbackNameSpace.empty())
{ {
deleteTransformFeedback(mTransformFeedbackMap.begin()->first); deleteTransformFeedback(mTransformFeedbackNameSpace.firstName());
} }
for(int type = 0; type < TEXTURE_TYPE_COUNT; type++) for(int type = 0; type < TEXTURE_TYPE_COUNT; type++)
{ {
for(int sampler = 0; sampler < MAX_COMBINED_TEXTURE_IMAGE_UNITS; sampler++) for(int sampler = 0; sampler < MAX_COMBINED_TEXTURE_IMAGE_UNITS; sampler++)
{ {
mState.samplerTexture[type][sampler] = NULL; mState.samplerTexture[type][sampler] = nullptr;
} }
} }
for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++) for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
{ {
mState.vertexAttribute[i].mBoundBuffer = NULL; mState.vertexAttribute[i].mBoundBuffer = nullptr;
} }
for(int i = 0; i < QUERY_TYPE_COUNT; i++) for(int i = 0; i < QUERY_TYPE_COUNT; i++)
{ {
mState.activeQuery[i] = NULL; mState.activeQuery[i] = nullptr;
} }
mState.arrayBuffer = NULL; mState.arrayBuffer = nullptr;
mState.copyReadBuffer = NULL; mState.copyReadBuffer = nullptr;
mState.copyWriteBuffer = NULL; mState.copyWriteBuffer = nullptr;
mState.pixelPackBuffer = NULL; mState.pixelPackBuffer = nullptr;
mState.pixelUnpackBuffer = NULL; mState.pixelUnpackBuffer = nullptr;
mState.genericUniformBuffer = NULL; mState.genericUniformBuffer = nullptr;
mState.renderbuffer = NULL; mState.renderbuffer = nullptr;
for(int i = 0; i < MAX_COMBINED_TEXTURE_IMAGE_UNITS; ++i) for(int i = 0; i < MAX_COMBINED_TEXTURE_IMAGE_UNITS; ++i)
{ {
mState.sampler[i] = NULL; mState.sampler[i] = nullptr;
} }
mTexture2DZero = NULL; mTexture2DZero = nullptr;
mTexture3DZero = NULL; mTexture3DZero = nullptr;
mTexture2DArrayZero = NULL; mTexture2DArrayZero = nullptr;
mTextureCubeMapZero = NULL; mTextureCubeMapZero = nullptr;
mTextureExternalZero = NULL; mTextureExternalZero = nullptr;
delete mVertexDataManager; delete mVertexDataManager;
delete mIndexDataManager; delete mIndexDataManager;
...@@ -767,7 +767,7 @@ GLuint Context::getElementArrayBufferName() const ...@@ -767,7 +767,7 @@ GLuint Context::getElementArrayBufferName() const
GLuint Context::getActiveQuery(GLenum target) const GLuint Context::getActiveQuery(GLenum target) const
{ {
Query *queryObject = NULL; Query *queryObject = nullptr;
switch(target) switch(target)
{ {
...@@ -921,40 +921,24 @@ GLuint Context::createRenderbuffer() ...@@ -921,40 +921,24 @@ GLuint Context::createRenderbuffer()
// Returns an unused framebuffer name // Returns an unused framebuffer name
GLuint Context::createFramebuffer() GLuint Context::createFramebuffer()
{ {
GLuint handle = mFramebufferNameSpace.allocate(); return mFramebufferNameSpace.allocate();
mFramebufferMap[handle] = NULL;
return handle;
} }
GLuint Context::createFence() GLuint Context::createFence()
{ {
GLuint handle = mFenceNameSpace.allocate(); return mFenceNameSpace.allocate(new Fence());
mFenceMap[handle] = new Fence;
return handle;
} }
// Returns an unused query name // Returns an unused query name
GLuint Context::createQuery() GLuint Context::createQuery()
{ {
GLuint handle = mQueryNameSpace.allocate(); return mQueryNameSpace.allocate();
mQueryMap[handle] = NULL;
return handle;
} }
// Returns an unused vertex array name // Returns an unused vertex array name
GLuint Context::createVertexArray() GLuint Context::createVertexArray()
{ {
GLuint handle = mVertexArrayNameSpace.allocate(); return mVertexArrayNameSpace.allocate();
mVertexArrayMap[handle] = nullptr;
return handle;
} }
GLsync Context::createFenceSync(GLenum condition, GLbitfield flags) GLsync Context::createFenceSync(GLenum condition, GLbitfield flags)
...@@ -967,11 +951,7 @@ GLsync Context::createFenceSync(GLenum condition, GLbitfield flags) ...@@ -967,11 +951,7 @@ GLsync Context::createFenceSync(GLenum condition, GLbitfield flags)
// Returns an unused transform feedback name // Returns an unused transform feedback name
GLuint Context::createTransformFeedback() GLuint Context::createTransformFeedback()
{ {
GLuint handle = mTransformFeedbackNameSpace.allocate(); return mTransformFeedbackNameSpace.allocate();
mTransformFeedbackMap[handle] = NULL;
return handle;
} }
// Returns an unused sampler name // Returns an unused sampler name
...@@ -982,10 +962,7 @@ GLuint Context::createSampler() ...@@ -982,10 +962,7 @@ GLuint Context::createSampler()
void Context::deleteBuffer(GLuint buffer) void Context::deleteBuffer(GLuint buffer)
{ {
if(mResourceManager->getBuffer(buffer)) detachBuffer(buffer);
{
detachBuffer(buffer);
}
mResourceManager->deleteBuffer(buffer); mResourceManager->deleteBuffer(buffer);
} }
...@@ -1002,87 +979,65 @@ void Context::deleteProgram(GLuint program) ...@@ -1002,87 +979,65 @@ void Context::deleteProgram(GLuint program)
void Context::deleteTexture(GLuint texture) void Context::deleteTexture(GLuint texture)
{ {
if(mResourceManager->getTexture(texture)) detachTexture(texture);
{
detachTexture(texture);
}
mResourceManager->deleteTexture(texture); mResourceManager->deleteTexture(texture);
} }
void Context::deleteRenderbuffer(GLuint renderbuffer) void Context::deleteRenderbuffer(GLuint renderbuffer)
{ {
if(mResourceManager->getRenderbuffer(renderbuffer)) detachRenderbuffer(renderbuffer);
{
detachRenderbuffer(renderbuffer);
}
mResourceManager->deleteRenderbuffer(renderbuffer); mResourceManager->deleteRenderbuffer(renderbuffer);
} }
void Context::deleteFramebuffer(GLuint framebuffer) void Context::deleteFramebuffer(GLuint framebuffer)
{ {
FramebufferMap::iterator framebufferObject = mFramebufferMap.find(framebuffer); detachFramebuffer(framebuffer);
if(framebufferObject != mFramebufferMap.end()) Framebuffer *framebufferObject = mFramebufferNameSpace.remove(framebuffer);
{
detachFramebuffer(framebuffer);
delete framebufferObject->second; if(framebufferObject)
mFramebufferNameSpace.remove(framebufferObject->first); {
mFramebufferMap.erase(framebufferObject); delete framebufferObject;
} }
} }
void Context::deleteFence(GLuint fence) void Context::deleteFence(GLuint fence)
{ {
FenceMap::iterator fenceObject = mFenceMap.find(fence); Fence *fenceObject = mFenceNameSpace.remove(fence);
if(fenceObject != mFenceMap.end()) if(fenceObject)
{ {
delete fenceObject->second; delete fenceObject;
mFenceNameSpace.remove(fenceObject->first);
mFenceMap.erase(fenceObject);
} }
} }
void Context::deleteQuery(GLuint query) void Context::deleteQuery(GLuint query)
{ {
QueryMap::iterator queryObject = mQueryMap.find(query); Query *queryObject = mQueryNameSpace.remove(query);
if(queryObject != mQueryMap.end()) if(queryObject)
{ {
if(queryObject->second) queryObject->release();
{
queryObject->second->release();
}
mQueryNameSpace.remove(queryObject->first);
mQueryMap.erase(queryObject);
} }
} }
void Context::deleteVertexArray(GLuint vertexArray) void Context::deleteVertexArray(GLuint vertexArray)
{ {
VertexArrayMap::iterator vertexArrayObject = mVertexArrayMap.find(vertexArray); // [OpenGL ES 3.0.2] section 2.10 page 43:
// If a vertex array object that is currently bound is deleted, the binding
if(vertexArrayObject != mVertexArrayMap.end()) // for that object reverts to zero and the default vertex array becomes current.
if(getCurrentVertexArray()->name == vertexArray)
{ {
// Vertex array detachment is handled by Context, because 0 is a valid bindVertexArray(0);
// VAO, and a pointer to it must be passed from Context to State at }
// binding time.
// [OpenGL ES 3.0.2] section 2.10 page 43:
// If a vertex array object that is currently bound is deleted, the binding
// for that object reverts to zero and the default vertex array becomes current.
if(getCurrentVertexArray()->name == vertexArray)
{
bindVertexArray(0);
}
delete vertexArrayObject->second; VertexArray *vertexArrayObject = mVertexArrayNameSpace.remove(vertexArray);
mVertexArrayNameSpace.remove(vertexArrayObject->first);
mVertexArrayMap.erase(vertexArrayObject); if(vertexArrayObject)
{
delete vertexArrayObject;
} }
} }
...@@ -1097,22 +1052,17 @@ void Context::deleteFenceSync(GLsync fenceSync) ...@@ -1097,22 +1052,17 @@ void Context::deleteFenceSync(GLsync fenceSync)
void Context::deleteTransformFeedback(GLuint transformFeedback) void Context::deleteTransformFeedback(GLuint transformFeedback)
{ {
TransformFeedbackMap::iterator transformFeedbackObject = mTransformFeedbackMap.find(transformFeedback); TransformFeedback *transformFeedbackObject = mTransformFeedbackNameSpace.remove(transformFeedback);
if(transformFeedbackObject != mTransformFeedbackMap.end()) if(transformFeedbackObject)
{ {
delete transformFeedbackObject->second; delete transformFeedbackObject;
mTransformFeedbackNameSpace.remove(transformFeedbackObject->first);
mTransformFeedbackMap.erase(transformFeedbackObject);
} }
} }
void Context::deleteSampler(GLuint sampler) void Context::deleteSampler(GLuint sampler)
{ {
if(mResourceManager->getSampler(sampler)) detachSampler(sampler);
{
detachSampler(sampler);
}
mResourceManager->deleteSampler(sampler); mResourceManager->deleteSampler(sampler);
} }
...@@ -1245,7 +1195,7 @@ void Context::bindReadFramebuffer(GLuint framebuffer) ...@@ -1245,7 +1195,7 @@ void Context::bindReadFramebuffer(GLuint framebuffer)
{ {
if(!getFramebuffer(framebuffer)) if(!getFramebuffer(framebuffer))
{ {
mFramebufferMap[framebuffer] = new Framebuffer(); mFramebufferNameSpace.insert(framebuffer, new Framebuffer());
} }
mState.readFramebuffer = framebuffer; mState.readFramebuffer = framebuffer;
...@@ -1255,7 +1205,7 @@ void Context::bindDrawFramebuffer(GLuint framebuffer) ...@@ -1255,7 +1205,7 @@ void Context::bindDrawFramebuffer(GLuint framebuffer)
{ {
if(!getFramebuffer(framebuffer)) if(!getFramebuffer(framebuffer))
{ {
mFramebufferMap[framebuffer] = new Framebuffer(); mFramebufferNameSpace.insert(framebuffer, new Framebuffer());
} }
mState.drawFramebuffer = framebuffer; mState.drawFramebuffer = framebuffer;
...@@ -1275,7 +1225,7 @@ void Context::bindVertexArray(GLuint array) ...@@ -1275,7 +1225,7 @@ void Context::bindVertexArray(GLuint array)
if(!vertexArray) if(!vertexArray)
{ {
vertexArray = new VertexArray(array); vertexArray = new VertexArray(array);
mVertexArrayMap[array] = vertexArray; mVertexArrayNameSpace.insert(array, vertexArray);
} }
mState.vertexArray = array; mState.vertexArray = array;
...@@ -1311,16 +1261,14 @@ void Context::bindIndexedTransformFeedbackBuffer(GLuint buffer, GLuint index, GL ...@@ -1311,16 +1261,14 @@ void Context::bindIndexedTransformFeedbackBuffer(GLuint buffer, GLuint index, GL
getTransformFeedback()->setBuffer(index, bufferObject, offset, size); getTransformFeedback()->setBuffer(index, bufferObject, offset, size);
} }
bool Context::bindTransformFeedback(GLuint id) void Context::bindTransformFeedback(GLuint id)
{ {
if(!getTransformFeedback(id)) if(!getTransformFeedback(id))
{ {
mTransformFeedbackMap[id] = new TransformFeedback(id); mTransformFeedbackNameSpace.insert(id, new TransformFeedback(id));
} }
mState.transformFeedback = id; mState.transformFeedback = id;
return true;
} }
bool Context::bindSampler(GLuint unit, GLuint sampler) bool Context::bindSampler(GLuint unit, GLuint sampler)
...@@ -1378,7 +1326,7 @@ void Context::beginQuery(GLenum target, GLuint query) ...@@ -1378,7 +1326,7 @@ void Context::beginQuery(GLenum target, GLuint query)
// no query may be active for either if glBeginQuery targets either. // no query may be active for either if glBeginQuery targets either.
for(int i = 0; i < QUERY_TYPE_COUNT; i++) for(int i = 0; i < QUERY_TYPE_COUNT; i++)
{ {
if(mState.activeQuery[i] != NULL) if(mState.activeQuery[i])
{ {
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
...@@ -1435,20 +1383,20 @@ void Context::endQuery(GLenum target) ...@@ -1435,20 +1383,20 @@ void Context::endQuery(GLenum target)
Query *queryObject = mState.activeQuery[qType]; Query *queryObject = mState.activeQuery[qType];
if(queryObject == NULL) if(!queryObject)
{ {
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
queryObject->end(); queryObject->end();
mState.activeQuery[qType] = NULL; mState.activeQuery[qType] = nullptr;
} }
void Context::setFramebufferZero(Framebuffer *buffer) void Context::setFramebufferZero(Framebuffer *buffer)
{ {
delete mFramebufferMap[0]; delete mFramebufferNameSpace.remove(0);
mFramebufferMap[0] = buffer; mFramebufferNameSpace.insert(0, buffer);
} }
void Context::setRenderbufferStorage(RenderbufferStorage *renderbuffer) void Context::setRenderbufferStorage(RenderbufferStorage *renderbuffer)
...@@ -1459,30 +1407,12 @@ void Context::setRenderbufferStorage(RenderbufferStorage *renderbuffer) ...@@ -1459,30 +1407,12 @@ void Context::setRenderbufferStorage(RenderbufferStorage *renderbuffer)
Framebuffer *Context::getFramebuffer(unsigned int handle) const Framebuffer *Context::getFramebuffer(unsigned int handle) const
{ {
FramebufferMap::const_iterator framebuffer = mFramebufferMap.find(handle); return mFramebufferNameSpace.find(handle);
if(framebuffer == mFramebufferMap.end())
{
return NULL;
}
else
{
return framebuffer->second;
}
} }
Fence *Context::getFence(unsigned int handle) const Fence *Context::getFence(unsigned int handle) const
{ {
FenceMap::const_iterator fence = mFenceMap.find(handle); return mFenceNameSpace.find(handle);
if(fence == mFenceMap.end())
{
return NULL;
}
else
{
return fence->second;
}
} }
FenceSync *Context::getFenceSync(GLsync handle) const FenceSync *Context::getFenceSync(GLsync handle) const
...@@ -1492,43 +1422,32 @@ FenceSync *Context::getFenceSync(GLsync handle) const ...@@ -1492,43 +1422,32 @@ FenceSync *Context::getFenceSync(GLsync handle) const
Query *Context::getQuery(unsigned int handle) const Query *Context::getQuery(unsigned int handle) const
{ {
QueryMap::const_iterator query = mQueryMap.find(handle); return mQueryNameSpace.find(handle);
if(query == mQueryMap.end())
{
return NULL;
}
else
{
return query->second;
}
} }
Query *Context::createQuery(unsigned int handle, GLenum type) Query *Context::createQuery(unsigned int handle, GLenum type)
{ {
QueryMap::iterator query = mQueryMap.find(handle); if(!mQueryNameSpace.isReserved(handle))
if(query == mQueryMap.end())
{ {
return NULL; return nullptr;
} }
else else
{ {
if(!query->second) Query *query = mQueryNameSpace.find(handle);
if(!query)
{ {
query->second = new Query(handle, type); query = new Query(handle, type);
query->second->addRef(); query->addRef();
mQueryNameSpace.insert(handle, query);
} }
return query->second; return query;
} }
} }
VertexArray *Context::getVertexArray(GLuint array) const VertexArray *Context::getVertexArray(GLuint array) const
{ {
VertexArrayMap::const_iterator vertexArray = mVertexArrayMap.find(array); return mVertexArrayNameSpace.find(array);
return (vertexArray == mVertexArrayMap.end()) ? nullptr : vertexArray->second;
} }
VertexArray *Context::getCurrentVertexArray() const VertexArray *Context::getCurrentVertexArray() const
...@@ -1538,9 +1457,7 @@ VertexArray *Context::getCurrentVertexArray() const ...@@ -1538,9 +1457,7 @@ VertexArray *Context::getCurrentVertexArray() const
bool Context::isVertexArray(GLuint array) const bool Context::isVertexArray(GLuint array) const
{ {
VertexArrayMap::const_iterator vertexArray = mVertexArrayMap.find(array); return mVertexArrayNameSpace.isReserved(array);
return vertexArray != mVertexArrayMap.end();
} }
bool Context::hasZeroDivisor() const bool Context::hasZeroDivisor() const
...@@ -1561,9 +1478,7 @@ bool Context::hasZeroDivisor() const ...@@ -1561,9 +1478,7 @@ bool Context::hasZeroDivisor() const
TransformFeedback *Context::getTransformFeedback(GLuint transformFeedback) const TransformFeedback *Context::getTransformFeedback(GLuint transformFeedback) const
{ {
TransformFeedbackMap::const_iterator transformFeedbackObject = mTransformFeedbackMap.find(transformFeedback); return mTransformFeedbackNameSpace.find(transformFeedback);
return (transformFeedbackObject == mTransformFeedbackMap.end()) ? NULL : transformFeedbackObject->second;
} }
Sampler *Context::getSampler(GLuint sampler) const Sampler *Context::getSampler(GLuint sampler) const
...@@ -3740,7 +3655,7 @@ void Context::detachBuffer(GLuint buffer) ...@@ -3740,7 +3655,7 @@ void Context::detachBuffer(GLuint buffer)
{ {
if(mState.vertexAttribute[attribute].mBoundBuffer.name() == buffer) if(mState.vertexAttribute[attribute].mBoundBuffer.name() == buffer)
{ {
mState.vertexAttribute[attribute].mBoundBuffer = NULL; mState.vertexAttribute[attribute].mBoundBuffer = nullptr;
} }
} }
} }
...@@ -3757,7 +3672,7 @@ void Context::detachTexture(GLuint texture) ...@@ -3757,7 +3672,7 @@ void Context::detachTexture(GLuint texture)
{ {
if(mState.samplerTexture[type][sampler].name() == texture) if(mState.samplerTexture[type][sampler].name() == texture)
{ {
mState.samplerTexture[type][sampler] = NULL; mState.samplerTexture[type][sampler] = nullptr;
} }
} }
} }
...@@ -3839,7 +3754,7 @@ void Context::detachSampler(GLuint sampler) ...@@ -3839,7 +3754,7 @@ void Context::detachSampler(GLuint sampler)
gl::BindingPointer<Sampler> &samplerBinding = mState.sampler[textureUnit]; gl::BindingPointer<Sampler> &samplerBinding = mState.sampler[textureUnit];
if(samplerBinding.name() == sampler) if(samplerBinding.name() == sampler)
{ {
samplerBinding = NULL; samplerBinding = nullptr;
} }
} }
} }
...@@ -4095,8 +4010,8 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1 ...@@ -4095,8 +4010,8 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1
if(mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) if(mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
{ {
Renderbuffer *readDSBuffer = NULL; Renderbuffer *readDSBuffer = nullptr;
Renderbuffer *drawDSBuffer = NULL; Renderbuffer *drawDSBuffer = nullptr;
if(mask & GL_DEPTH_BUFFER_BIT) if(mask & GL_DEPTH_BUFFER_BIT)
{ {
...@@ -4357,7 +4272,7 @@ const GLubyte* Context::getExtensions(GLuint index, GLuint* numExt) const ...@@ -4357,7 +4272,7 @@ const GLubyte* Context::getExtensions(GLuint index, GLuint* numExt) const
if(index == GL_INVALID_INDEX) if(index == GL_INVALID_INDEX)
{ {
static GLubyte* extensionsCat = nullptr; static GLubyte* extensionsCat = nullptr;
if((extensionsCat == nullptr) && (numExtensions > 0)) if(!extensionsCat && (numExtensions > 0))
{ {
int totalLength = numExtensions; // 1 space between each extension name + terminating null int totalLength = numExtensions; // 1 space between each extension name + terminating null
for(unsigned int i = 0; i < numExtensions; i++) for(unsigned int i = 0; i < numExtensions; i++)
......
...@@ -575,7 +575,7 @@ public: ...@@ -575,7 +575,7 @@ public:
void bindIndexedUniformBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size); void bindIndexedUniformBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);
void bindGenericTransformFeedbackBuffer(GLuint buffer); void bindGenericTransformFeedbackBuffer(GLuint buffer);
void bindIndexedTransformFeedbackBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size); void bindIndexedTransformFeedbackBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);
bool bindTransformFeedback(GLuint transformFeedback); void bindTransformFeedback(GLuint transformFeedback);
bool bindSampler(GLuint unit, GLuint sampler); bool bindSampler(GLuint unit, GLuint sampler);
void useProgram(GLuint program); void useProgram(GLuint program);
...@@ -709,24 +709,10 @@ private: ...@@ -709,24 +709,10 @@ private:
gl::BindingPointer<TextureCubeMap> mTextureCubeMapZero; gl::BindingPointer<TextureCubeMap> mTextureCubeMapZero;
gl::BindingPointer<TextureExternal> mTextureExternalZero; gl::BindingPointer<TextureExternal> mTextureExternalZero;
typedef std::map<GLint, Framebuffer*> FramebufferMap; gl::NameSpace<Framebuffer> mFramebufferNameSpace;
FramebufferMap mFramebufferMap; gl::NameSpace<Fence, 0> mFenceNameSpace;
gl::NameSpace<Framebuffer> mFramebufferNameSpace; gl::NameSpace<Query> mQueryNameSpace;
typedef std::map<GLint, Fence*> FenceMap;
FenceMap mFenceMap;
gl::NameSpace<Fence, 0> mFenceNameSpace;
typedef std::map<GLint, Query*> QueryMap;
QueryMap mQueryMap;
gl::NameSpace<Query> mQueryNameSpace;
typedef std::map<GLint, VertexArray*> VertexArrayMap;
VertexArrayMap mVertexArrayMap;
gl::NameSpace<VertexArray> mVertexArrayNameSpace; gl::NameSpace<VertexArray> mVertexArrayNameSpace;
typedef std::map<GLint, TransformFeedback*> TransformFeedbackMap;
TransformFeedbackMap mTransformFeedbackMap;
gl::NameSpace<TransformFeedback> mTransformFeedbackNameSpace; gl::NameSpace<TransformFeedback> mTransformFeedbackNameSpace;
VertexDataManager *mVertexDataManager; VertexDataManager *mVertexDataManager;
......
...@@ -3576,10 +3576,7 @@ GL_APICALL void GL_APIENTRY glBindTransformFeedback(GLenum target, GLuint id) ...@@ -3576,10 +3576,7 @@ GL_APICALL void GL_APIENTRY glBindTransformFeedback(GLenum target, GLuint id)
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
if(!context->bindTransformFeedback(id)) context->bindTransformFeedback(id);
{
return error(GL_INVALID_OPERATION);
}
} }
} }
......
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