summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-07 23:04:31 +0000
committergman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-07 23:04:31 +0000
commitff81c190a987065d3d3f394af4c1a591417cb5ab (patch)
treef1f7a5c50223b432402ff30208bedcc11d79a13e
parent4b3c95dd199586b4c540800be8cd223e948e5e3f (diff)
downloadchromium_src-ff81c190a987065d3d3f394af4c1a591417cb5ab.zip
chromium_src-ff81c190a987065d3d3f394af4c1a591417cb5ab.tar.gz
chromium_src-ff81c190a987065d3d3f394af4c1a591417cb5ab.tar.bz2
Make glVertexAttribPointer return INVALID_OPERATION for offsets
and strides that do not match type. TEST=unit tests BUG=none Review URL: http://codereview.chromium.org/5991012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70800 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder.cc11
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc142
2 files changed, 147 insertions, 6 deletions
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index 51d4e9f1..4537212 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -4684,7 +4684,7 @@ error::Error GLES2DecoderImpl::HandleVertexAttribPointer(
return error::kNoError;
}
if (!validators_->vertex_attrib_size.IsValid(size)) {
- SetGLError(GL_INVALID_ENUM,
+ SetGLError(GL_INVALID_VALUE,
"glVertexAttribPointer: size GL_INVALID_VALUE");
return error::kNoError;
}
@@ -4708,9 +4708,14 @@ error::Error GLES2DecoderImpl::HandleVertexAttribPointer(
return error::kNoError;
}
GLsizei component_size =
- GLES2Util::GetGLTypeSizeForTexturesAndBuffers(type);
+ GLES2Util::GetGLTypeSizeForTexturesAndBuffers(type);
if (offset % component_size > 0) {
- SetGLError(GL_INVALID_VALUE,
+ SetGLError(GL_INVALID_OPERATION,
+ "glVertexAttribPointer: offset not valid for type");
+ return error::kNoError;
+ }
+ if (stride % component_size > 0) {
+ SetGLError(GL_INVALID_OPERATION,
"glVertexAttribPointer: stride not valid for type");
return error::kNoError;
}
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc
index e0fa9fb..4099e33 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc
@@ -234,7 +234,7 @@ TEST_F(GLES2DecoderWithShaderTest, DrawArraysInvalidCountFails) {
// Try with stride > 8 (vec2 + vec2 byte)
GLfloat f;
- DoVertexAttribPointer(1, 2, GL_FLOAT, sizeof(f) * 2 + 1, 0);
+ DoVertexAttribPointer(1, 2, GL_FLOAT, sizeof(f) * 2 + sizeof(f), 0);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
EXPECT_EQ(GL_NO_ERROR, GetGLError());
@@ -2658,6 +2658,144 @@ TEST_F(GLES2DecoderTest, FramebufferRenderbufferClearDepthStencil) {
}
#endif
+TEST_F(GLES2DecoderWithShaderTest, VertexAttribPointer) {
+ SetupVertexBuffer();
+ static const GLenum types[] = {
+ GL_BYTE,
+ GL_UNSIGNED_BYTE,
+ GL_SHORT,
+ GL_UNSIGNED_SHORT,
+ GL_FLOAT,
+ GL_FIXED,
+ GL_INT,
+ GL_UNSIGNED_INT,
+ };
+ static const GLsizei sizes[] = {
+ 1,
+ 1,
+ 2,
+ 2,
+ 4,
+ 4,
+ 4,
+ 4,
+ };
+ static const GLuint indices[] = {
+ 0,
+ 1,
+ kNumVertexAttribs - 1,
+ kNumVertexAttribs,
+ };
+ static const GLsizei offset_mult[] = {
+ 0,
+ 0,
+ 1,
+ 1,
+ 2,
+ 1000,
+ };
+ static const GLsizei offset_offset[] = {
+ 0,
+ 1,
+ 0,
+ 1,
+ 0,
+ 0,
+ };
+ static const GLsizei stride_mult[] = {
+ -1,
+ 0,
+ 0,
+ 1,
+ 1,
+ 2,
+ 1000,
+ };
+ static const GLsizei stride_offset[] = {
+ 0,
+ 0,
+ 1,
+ 0,
+ 1,
+ 0,
+ 0,
+ };
+ for (size_t tt = 0; tt < arraysize(types); ++tt) {
+ GLenum type = types[tt];
+ GLsizei num_bytes = sizes[tt];
+ for (size_t ii = 0; ii < arraysize(indices); ++ii) {
+ GLuint index = indices[ii];
+ for (GLint size = 0; size < 5; ++size) {
+ for (size_t oo = 0; oo < arraysize(offset_mult); ++oo) {
+ GLuint offset = num_bytes * offset_mult[oo] + offset_offset[oo];
+ for (size_t ss = 0; ss <= arraysize(stride_mult); ++ss) {
+ GLsizei stride = num_bytes * stride_mult[ss] + stride_offset[ss];
+ for (int normalize = 0; normalize < 2; ++normalize) {
+ bool index_good = index < static_cast<GLuint>(kNumVertexAttribs);
+ bool size_good = (size > 0 && size < 5);
+ bool offset_good = (offset % num_bytes == 0);
+ bool stride_good = (stride % num_bytes == 0) && stride >= 0 &&
+ stride <= 255;
+ bool type_good = (type != GL_INT && type != GL_UNSIGNED_INT &&
+ type != GL_FIXED);
+ bool good = size_good && offset_good && stride_good &&
+ type_good && index_good;
+ bool call = good && (type != GL_FIXED);
+ if (call) {
+ EXPECT_CALL(*gl_, VertexAttribPointer(
+ index, size, type, normalize, stride,
+ BufferOffset(offset)));
+ }
+ VertexAttribPointer cmd;
+ cmd.Init(index, size, type, normalize, stride, offset);
+ EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
+ if (good) {
+ EXPECT_EQ(GL_NO_ERROR, GetGLError());
+ } else if (size_good &&
+ offset_good &&
+ stride_good &&
+ type_good &&
+ !index_good) {
+ EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
+ } else if (size_good &&
+ offset_good &&
+ stride_good &&
+ !type_good &&
+ index_good) {
+ EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
+ } else if (size_good &&
+ offset_good &&
+ !stride_good &&
+ type_good &&
+ index_good) {
+ if (stride < 0 || stride > 255) {
+ EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
+ } else {
+ EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
+ }
+ } else if (size_good &&
+ !offset_good &&
+ stride_good &&
+ type_good &&
+ index_good) {
+ EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
+ } else if (!size_good &&
+ offset_good &&
+ stride_good &&
+ type_good &&
+ index_good) {
+ EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
+ } else {
+ EXPECT_NE(GL_NO_ERROR, GetGLError());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
// TODO(gman): BufferData
// TODO(gman): BufferDataImmediate
@@ -2688,7 +2826,5 @@ TEST_F(GLES2DecoderTest, FramebufferRenderbufferClearDepthStencil) {
// TODO(gman): SwapBuffers
-// TODO(gman): VertexAttribPointer
-
} // namespace gles2
} // namespace gpu