Commit 0733469e by Alexis Hetu Committed by Alexis Hétu

Implemented glDrawRangeElements

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/2829Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 82196a20
......@@ -2700,9 +2700,9 @@ GLenum Context::applyVertexBuffer(GLint base, GLint first, GLsizei count)
}
// Applies the indices and element array bindings
GLenum Context::applyIndexBuffer(const void *indices, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo)
GLenum Context::applyIndexBuffer(const void *indices, GLuint start, GLuint end, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo)
{
GLenum err = mIndexDataManager->prepareIndexData(type, count, mState.elementArrayBuffer, indices, indexInfo);
GLenum err = mIndexDataManager->prepareIndexData(type, start, end, count, mState.elementArrayBuffer, indices, indexInfo);
if(err == GL_NO_ERROR)
{
......@@ -3285,7 +3285,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
}
}
void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
void Context::drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices)
{
if(!mState.currentProgram)
{
......@@ -3316,7 +3316,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *
applyState(mode);
TranslatedIndexData indexInfo;
GLenum err = applyIndexBuffer(indices, count, mode, type, &indexInfo);
GLenum err = applyIndexBuffer(indices, start, end, count, mode, type, &indexInfo);
if(err != GL_NO_ERROR)
{
return error(err);
......
......@@ -553,7 +553,7 @@ public:
void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels);
void clear(GLbitfield mask);
void drawArrays(GLenum mode, GLint first, GLsizei count);
void drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices);
void drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices);
void finish();
void flush();
......@@ -585,7 +585,7 @@ private:
bool applyRenderTarget();
void applyState(GLenum drawMode);
GLenum applyVertexBuffer(GLint base, GLint first, GLsizei count);
GLenum applyIndexBuffer(const void *indices, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
GLenum applyIndexBuffer(const void *indices, GLuint start, GLuint end, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
void applyShaders();
void applyTextures();
void applyTextures(sw::SamplerType type);
......
......@@ -90,7 +90,7 @@ void computeRange(GLenum type, const void *indices, GLsizei count, GLuint *minIn
else UNREACHABLE();
}
GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, Buffer *buffer, const void *indices, TranslatedIndexData *translated)
GLenum IndexDataManager::prepareIndexData(GLenum type, GLuint start, GLuint end, GLsizei count, Buffer *buffer, const void *indices, TranslatedIndexData *translated)
{
if(!mStreamingBuffer)
{
......@@ -152,6 +152,11 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, Buffer *bu
translated->indexOffset = streamOffset;
}
if(translated->minIndex < start || translated->maxIndex > end)
{
ERR("glDrawRangeElements: out of range access. Range provided: [%d -> %d]. Range used: [%d -> %d].", start, end, translated->minIndex, translated->maxIndex);
}
return GL_NO_ERROR;
}
......
......@@ -56,7 +56,7 @@ class IndexDataManager
IndexDataManager();
virtual ~IndexDataManager();
GLenum prepareIndexData(GLenum type, GLsizei count, Buffer *arrayElementBuffer, const void *indices, TranslatedIndexData *translated);
GLenum prepareIndexData(GLenum type, GLuint start, GLuint end, GLsizei count, Buffer *arrayElementBuffer, const void *indices, TranslatedIndexData *translated);
static std::size_t typeSize(GLenum type);
......
......@@ -1819,7 +1819,7 @@ void GL_APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const G
return error(GL_INVALID_ENUM);
}
context->drawElements(mode, count, type, indices);
context->drawElements(mode, 0, UINT_MAX, count, type, indices);
}
}
......
......@@ -517,7 +517,12 @@ void GL_APIENTRY glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsi
return error(GL_INVALID_VALUE);
}
UNIMPLEMENTED();
es2::Context *context = es2::getContext();
if(context)
{
context->drawElements(mode, start, end, count, type, indices);
}
}
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)
......
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