diff options
author | 2014-05-05 12:32:37 +0000 | |
---|---|---|
committer | 2014-05-05 12:32:37 +0000 | |
commit | 160b478eed1dd4924a86a87fd60c91139e08ff71 (patch) | |
tree | e33d47f4047f613a97d93314a73351952a996b56 /src/gpu/gl/debug | |
parent | 889112012449b35132a9dc196b025c5f4145904a (diff) |
Add support for glMapBufferRange. Use glMapBufferRange and glMapBufferSubData.
BUG=skia:2402
Committed: http://code.google.com/p/skia/source/detail?r=14533
R=robertphillips@google.com, djsollen@google.com
Author: bsalomon@google.com
Review URL: https://codereview.chromium.org/243413002
git-svn-id: http://skia.googlecode.com/svn/trunk@14564 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/gl/debug')
-rw-r--r-- | src/gpu/gl/debug/GrBufferObj.h | 12 | ||||
-rw-r--r-- | src/gpu/gl/debug/GrGLCreateDebugInterface.cpp | 82 |
2 files changed, 78 insertions, 16 deletions
diff --git a/src/gpu/gl/debug/GrBufferObj.h b/src/gpu/gl/debug/GrBufferObj.h index fecfeb5e3c..05d3cfddde 100644 --- a/src/gpu/gl/debug/GrBufferObj.h +++ b/src/gpu/gl/debug/GrBufferObj.h @@ -34,9 +34,15 @@ public: GrAlwaysAssert(!fMapped); } - void setMapped() { fMapped = true; } + void setMapped(GrGLintptr offset, GrGLsizeiptr length) { + fMapped = true; + fMappedOffset = offset; + fMappedLength = length; + } void resetMapped() { fMapped = false; } bool getMapped() const { return fMapped; } + GrGLsizei getMappedOffset() const { return fMappedOffset; } + GrGLsizei getMappedLength() const { return fMappedLength; } void setBound() { fBound = true; } void resetBound() { fBound = false; } @@ -55,7 +61,9 @@ protected: private: GrGLchar* fDataPtr; - bool fMapped; // is the buffer object mapped via "glMapBuffer"? + bool fMapped; // is the buffer object mapped via "glMapBuffer[Range]"? + GrGLintptr fMappedOffset; // the offset of the buffer range that is mapped + GrGLsizeiptr fMappedLength; // the size of the buffer range that is mapped bool fBound; // is the buffer object bound via "glBindBuffer"? GrGLsizeiptr fSize; // size in bytes GrGLint fUsage; // one of: GL_STREAM_DRAW, diff --git a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp b/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp index 087bd4723e..7c430b4b73 100644 --- a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp +++ b/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp @@ -622,12 +622,14 @@ GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteBuffers(GrGLsizei n, const GrGLuint* i } // map a buffer to the caller's address space -GrGLvoid* GR_GL_FUNCTION_TYPE debugGLMapBuffer(GrGLenum target, GrGLenum access) { - +GrGLvoid* GR_GL_FUNCTION_TYPE debugGLMapBufferRange(GrGLenum target, GrGLintptr offset, + GrGLsizeiptr length, GrGLbitfield access) { GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target || GR_GL_ELEMENT_ARRAY_BUFFER == target); - // GR_GL_READ_ONLY == access || || GR_GL_READ_WRIT == access); - GrAlwaysAssert(GR_GL_WRITE_ONLY == access); + + // We only expect read access and we expect that the buffer or range is always invalidated. + GrAlwaysAssert(!SkToBool(GR_GL_MAP_READ_BIT & access)); + GrAlwaysAssert((GR_GL_MAP_INVALIDATE_BUFFER_BIT | GR_GL_MAP_INVALIDATE_RANGE_BIT) & access); GrBufferObj *buffer = NULL; switch (target) { @@ -638,20 +640,41 @@ GrGLvoid* GR_GL_FUNCTION_TYPE debugGLMapBuffer(GrGLenum target, GrGLenum access) buffer = GrDebugGL::getInstance()->getElementArrayBuffer(); break; default: - SkFAIL("Unexpected target to glMapBuffer"); + SkFAIL("Unexpected target to glMapBufferRange"); break; } - if (buffer) { + if (NULL != buffer) { + GrAlwaysAssert(offset >= 0 && offset + length <= buffer->getSize()); GrAlwaysAssert(!buffer->getMapped()); - buffer->setMapped(); - return buffer->getDataPtr(); + buffer->setMapped(offset, length); + return buffer->getDataPtr() + offset; } GrAlwaysAssert(false); return NULL; // no buffer bound to the target } +GrGLvoid* GR_GL_FUNCTION_TYPE debugGLMapBuffer(GrGLenum target, GrGLenum access) { + GrAlwaysAssert(GR_GL_WRITE_ONLY == access); + + GrBufferObj *buffer = NULL; + switch (target) { + case GR_GL_ARRAY_BUFFER: + buffer = GrDebugGL::getInstance()->getArrayBuffer(); + break; + case GR_GL_ELEMENT_ARRAY_BUFFER: + buffer = GrDebugGL::getInstance()->getElementArrayBuffer(); + break; + default: + SkFAIL("Unexpected target to glMapBuffer"); + break; + } + + return debugGLMapBufferRange(target, 0, buffer->getSize(), + GR_GL_MAP_WRITE_BIT | GR_GL_MAP_INVALIDATE_BUFFER_BIT); +} + // remove a buffer from the caller's address space // TODO: check if the "access" method from "glMapBuffer" was honored GrGLboolean GR_GL_FUNCTION_TYPE debugGLUnmapBuffer(GrGLenum target) { @@ -672,7 +695,7 @@ GrGLboolean GR_GL_FUNCTION_TYPE debugGLUnmapBuffer(GrGLenum target) { break; } - if (buffer) { + if (NULL != buffer) { GrAlwaysAssert(buffer->getMapped()); buffer->resetMapped(); return GR_GL_TRUE; @@ -682,6 +705,34 @@ GrGLboolean GR_GL_FUNCTION_TYPE debugGLUnmapBuffer(GrGLenum target) { return GR_GL_FALSE; // GR_GL_INVALID_OPERATION; } +GrGLvoid GR_GL_FUNCTION_TYPE debugGLFlushMappedBufferRange(GrGLenum target, + GrGLintptr offset, + GrGLsizeiptr length) { + GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target || + GR_GL_ELEMENT_ARRAY_BUFFER == target); + + GrBufferObj *buffer = NULL; + switch (target) { + case GR_GL_ARRAY_BUFFER: + buffer = GrDebugGL::getInstance()->getArrayBuffer(); + break; + case GR_GL_ELEMENT_ARRAY_BUFFER: + buffer = GrDebugGL::getInstance()->getElementArrayBuffer(); + break; + default: + SkFAIL("Unexpected target to glUnmapBuffer"); + break; + } + + if (NULL != buffer) { + GrAlwaysAssert(buffer->getMapped()); + GrAlwaysAssert(offset >= 0 && (offset + length) <= buffer->getMappedLength()); + } else { + GrAlwaysAssert(false); + } +} + + GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetBufferParameteriv(GrGLenum target, GrGLenum value, GrGLint* params) { @@ -706,17 +757,17 @@ GrGLvoid GR_GL_FUNCTION_TYPE debugGLGetBufferParameteriv(GrGLenum target, switch (value) { case GR_GL_BUFFER_MAPPED: *params = GR_GL_FALSE; - if (buffer) + if (NULL != buffer) *params = buffer->getMapped() ? GR_GL_TRUE : GR_GL_FALSE; break; case GR_GL_BUFFER_SIZE: *params = 0; - if (buffer) + if (NULL != buffer) *params = SkToInt(buffer->getSize()); break; case GR_GL_BUFFER_USAGE: *params = GR_GL_STATIC_DRAW; - if (buffer) + if (NULL != buffer) *params = buffer->getUsage(); break; default: @@ -826,6 +877,7 @@ const GrGLInterface* GrGLCreateDebugInterface() { functions->fEndQuery = noOpGLEndQuery; functions->fFinish = noOpGLFinish; functions->fFlush = noOpGLFlush; + functions->fFlushMappedBufferRange = debugGLFlushMappedBufferRange; functions->fFrontFace = noOpGLFrontFace; functions->fGenerateMipmap = debugGLGenerateMipmap; functions->fGenBuffers = debugGLGenBuffers; @@ -850,6 +902,8 @@ const GrGLInterface* GrGLCreateDebugInterface() { functions->fGenVertexArrays = debugGLGenVertexArrays; functions->fLineWidth = noOpGLLineWidth; functions->fLinkProgram = noOpGLLinkProgram; + functions->fMapBuffer = debugGLMapBuffer; + functions->fMapBufferRange = debugGLMapBufferRange; functions->fPixelStorei = debugGLPixelStorei; functions->fQueryCounter = noOpGLQueryCounter; functions->fReadBuffer = noOpGLReadBuffer; @@ -887,6 +941,7 @@ const GrGLInterface* GrGLCreateDebugInterface() { functions->fUniformMatrix2fv = noOpGLUniformMatrix2fv; functions->fUniformMatrix3fv = noOpGLUniformMatrix3fv; functions->fUniformMatrix4fv = noOpGLUniformMatrix4fv; + functions->fUnmapBuffer = debugGLUnmapBuffer; functions->fUseProgram = debugGLUseProgram; functions->fVertexAttrib4fv = noOpGLVertexAttrib4fv; functions->fVertexAttribPointer = noOpGLVertexAttribPointer; @@ -909,10 +964,9 @@ const GrGLInterface* GrGLCreateDebugInterface() { functions->fBlitFramebuffer = noOpGLBlitFramebuffer; functions->fResolveMultisampleFramebuffer = noOpGLResolveMultisampleFramebuffer; - functions->fMapBuffer = debugGLMapBuffer; functions->fMatrixLoadf = noOpGLMatrixLoadf; functions->fMatrixLoadIdentity = noOpGLMatrixLoadIdentity; - functions->fUnmapBuffer = debugGLUnmapBuffer; + functions->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationIndexed; |