OSDN Git Service

Implemented glDrawRangeElements
authorAlexis Hetu <sugoi@google.com>
Fri, 10 Apr 2015 18:51:27 +0000 (14:51 -0400)
committerAlexis Hétu <sugoi@google.com>
Wed, 22 Apr 2015 15:39:37 +0000 (15:39 +0000)
This function is basically the same as
glDrawElements, except, in Debug, it
returns an error if the draw operation
reads outside of the expected range.

Change-Id: I2472c317eb5d8a1da89c5a76f076fe95adc6789e
Reviewed-on: https://swiftshader-review.googlesource.com/2829
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
src/OpenGL/libGLESv2/Context.cpp
src/OpenGL/libGLESv2/Context.h
src/OpenGL/libGLESv2/IndexDataManager.cpp
src/OpenGL/libGLESv2/IndexDataManager.h
src/OpenGL/libGLESv2/libGLESv2.cpp
src/OpenGL/libGLESv2/libGLESv3.cpp

index 70beb74..bc6064c 100644 (file)
@@ -2700,9 +2700,9 @@ GLenum Context::applyVertexBuffer(GLint base, GLint first, GLsizei count)
 }\r
 \r
 // Applies the indices and element array bindings\r
-GLenum Context::applyIndexBuffer(const void *indices, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo)\r
+GLenum Context::applyIndexBuffer(const void *indices, GLuint start, GLuint end, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo)\r
 {\r
-    GLenum err = mIndexDataManager->prepareIndexData(type, count, mState.elementArrayBuffer, indices, indexInfo);\r
+    GLenum err = mIndexDataManager->prepareIndexData(type, start, end, count, mState.elementArrayBuffer, indices, indexInfo);\r
 \r
     if(err == GL_NO_ERROR)\r
     {\r
@@ -3285,7 +3285,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
     }\r
 }\r
 \r
-void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)\r
+void Context::drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices)\r
 {\r
     if(!mState.currentProgram)\r
     {\r
@@ -3316,7 +3316,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *
     applyState(mode);\r
 \r
     TranslatedIndexData indexInfo;\r
-    GLenum err = applyIndexBuffer(indices, count, mode, type, &indexInfo);\r
+    GLenum err = applyIndexBuffer(indices, start, end, count, mode, type, &indexInfo);\r
     if(err != GL_NO_ERROR)\r
     {\r
         return error(err);\r
index 995015a..b2bd8ee 100644 (file)
@@ -553,7 +553,7 @@ public:
     void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels);\r
     void clear(GLbitfield mask);\r
     void drawArrays(GLenum mode, GLint first, GLsizei count);\r
-    void drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices);\r
+    void drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices);\r
     void finish();\r
     void flush();\r
 \r
@@ -585,7 +585,7 @@ private:
     bool applyRenderTarget();\r
     void applyState(GLenum drawMode);\r
     GLenum applyVertexBuffer(GLint base, GLint first, GLsizei count);\r
-    GLenum applyIndexBuffer(const void *indices, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);\r
+    GLenum applyIndexBuffer(const void *indices, GLuint start, GLuint end, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);\r
     void applyShaders();\r
     void applyTextures();\r
     void applyTextures(sw::SamplerType type);\r
index a2b468c..0bf93f0 100644 (file)
@@ -90,7 +90,7 @@ void computeRange(GLenum type, const void *indices, GLsizei count, GLuint *minIn
     else UNREACHABLE();\r
 }\r
 \r
-GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, Buffer *buffer, const void *indices, TranslatedIndexData *translated)\r
+GLenum IndexDataManager::prepareIndexData(GLenum type, GLuint start, GLuint end, GLsizei count, Buffer *buffer, const void *indices, TranslatedIndexData *translated)\r
 {\r
     if(!mStreamingBuffer)\r
     {\r
@@ -152,6 +152,11 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, Buffer *bu
                translated->indexOffset = streamOffset;\r
     }\r
 \r
+       if(translated->minIndex < start || translated->maxIndex > end)\r
+       {\r
+               ERR("glDrawRangeElements: out of range access. Range provided: [%d -> %d]. Range used: [%d -> %d].", start, end, translated->minIndex, translated->maxIndex);\r
+       }\r
+\r
     return GL_NO_ERROR;\r
 }\r
 \r
index 0bab66e..5ff6d94 100644 (file)
@@ -56,7 +56,7 @@ class IndexDataManager
     IndexDataManager();\r
     virtual ~IndexDataManager();\r
 \r
-    GLenum prepareIndexData(GLenum type, GLsizei count, Buffer *arrayElementBuffer, const void *indices, TranslatedIndexData *translated);\r
+    GLenum prepareIndexData(GLenum type, GLuint start, GLuint end, GLsizei count, Buffer *arrayElementBuffer, const void *indices, TranslatedIndexData *translated);\r
 \r
        static std::size_t typeSize(GLenum type);\r
 \r
index 3277120..e528154 100644 (file)
@@ -1819,7 +1819,7 @@ void GL_APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const G
                        return error(GL_INVALID_ENUM);\r
                }\r
 \r
-               context->drawElements(mode, count, type, indices);\r
+               context->drawElements(mode, 0, UINT_MAX, count, type, indices);\r
        }\r
 }\r
 \r
index 05f2468..4d4964a 100644 (file)
@@ -517,7 +517,12 @@ void GL_APIENTRY glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsi
                return error(GL_INVALID_VALUE);\r
        }\r
 \r
-       UNIMPLEMENTED();\r
+       es2::Context *context = es2::getContext();\r
+\r
+       if(context)\r
+       {\r
+               context->drawElements(mode, start, end, count, type, indices);\r
+       }\r
 }\r
 \r
 void GL_APIENTRY glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels)\r