Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: gpu/command_buffer/client/gles2_implementation_unittest.cc

Issue 11413094: Fix VAOs and client side arrays (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Tests for GLES2Implementation. 5 // Tests for GLES2Implementation.
6 6
7 #include "gpu/command_buffer/client/gles2_implementation.h" 7 #include "gpu/command_buffer/client/gles2_implementation.h"
8 8
9 #include <GLES2/gl2ext.h> 9 #include <GLES2/gl2ext.h>
10 #include "gpu/command_buffer/client/client_test_helper.h" 10 #include "gpu/command_buffer/client/client_test_helper.h"
(...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 static const float verts[1] = { 0.0f, }; 1188 static const float verts[1] = { 0.0f, };
1189 const GLuint kAttribIndex1 = 1; 1189 const GLuint kAttribIndex1 = 1;
1190 const GLuint kAttribIndex2 = 3; 1190 const GLuint kAttribIndex2 = 3;
1191 const GLint kNumComponents1 = 3; 1191 const GLint kNumComponents1 = 3;
1192 const GLint kNumComponents2 = 2; 1192 const GLint kNumComponents2 = 2;
1193 const GLsizei kStride1 = 12; 1193 const GLsizei kStride1 = 12;
1194 const GLsizei kStride2 = 0; 1194 const GLsizei kStride2 = 0;
1195 const GLuint kBufferId = 0x123; 1195 const GLuint kBufferId = 0x123;
1196 const GLint kOffset2 = 0x456; 1196 const GLint kOffset2 = 0x456;
1197 1197
1198 // Only one set and one get because the client side buffer's info is stored 1198 // It's all cached on the client side so no get commands are issued.
1199 // on the client side.
1200 struct Cmds { 1199 struct Cmds {
1201 BindBuffer bind; 1200 BindBuffer bind;
1202 VertexAttribPointer set_pointer; 1201 VertexAttribPointer set_pointer;
1203 GetVertexAttribPointerv get_pointer;
1204 }; 1202 };
1205 1203
1206 ExpectedMemoryInfo mem1 = GetExpectedResultMemory(16);
1207
1208 Cmds expected; 1204 Cmds expected;
1209 expected.bind.Init(GL_ARRAY_BUFFER, kBufferId); 1205 expected.bind.Init(GL_ARRAY_BUFFER, kBufferId);
1210 expected.set_pointer.Init(kAttribIndex2, kNumComponents2, GL_FLOAT, GL_FALSE, 1206 expected.set_pointer.Init(kAttribIndex2, kNumComponents2, GL_FLOAT, GL_FALSE,
1211 kStride2, kOffset2); 1207 kStride2, kOffset2);
1212 expected.get_pointer.Init(kAttribIndex2, GL_VERTEX_ATTRIB_ARRAY_POINTER,
1213 mem1.id, mem1.offset);
1214
1215 // One call to flush to way for GetVertexAttribPointerv
1216 EXPECT_CALL(*command_buffer(), OnFlush())
1217 .WillOnce(SetMemory(mem1.ptr, SizedResultHelper<uint32>(kOffset2)))
1218 .RetiresOnSaturation();
1219 1208
1220 // Set one client side buffer. 1209 // Set one client side buffer.
1221 gl_->VertexAttribPointer(kAttribIndex1, kNumComponents1, 1210 gl_->VertexAttribPointer(kAttribIndex1, kNumComponents1,
1222 GL_FLOAT, GL_FALSE, kStride1, verts); 1211 GL_FLOAT, GL_FALSE, kStride1, verts);
1223 // Set one VBO 1212 // Set one VBO
1224 gl_->BindBuffer(GL_ARRAY_BUFFER, kBufferId); 1213 gl_->BindBuffer(GL_ARRAY_BUFFER, kBufferId);
1225 gl_->VertexAttribPointer(kAttribIndex2, kNumComponents2, 1214 gl_->VertexAttribPointer(kAttribIndex2, kNumComponents2,
1226 GL_FLOAT, GL_FALSE, kStride2, 1215 GL_FLOAT, GL_FALSE, kStride2,
1227 reinterpret_cast<const void*>(kOffset2)); 1216 reinterpret_cast<const void*>(kOffset2));
1228 // now get them both. 1217 // now get them both.
1229 void* ptr1 = NULL; 1218 void* ptr1 = NULL;
1230 void* ptr2 = NULL; 1219 void* ptr2 = NULL;
1231 1220
1232 gl_->GetVertexAttribPointerv( 1221 gl_->GetVertexAttribPointerv(
1233 kAttribIndex1, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr1); 1222 kAttribIndex1, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr1);
1234 gl_->GetVertexAttribPointerv( 1223 gl_->GetVertexAttribPointerv(
1235 kAttribIndex2, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr2); 1224 kAttribIndex2, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr2);
1236 1225
1237 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); 1226 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
1238 EXPECT_TRUE(static_cast<const void*>(&verts) == ptr1); 1227 EXPECT_TRUE(static_cast<const void*>(&verts) == ptr1);
1239 // because the service is not running ptr2 is not read.
1240 EXPECT_TRUE(ptr2 == reinterpret_cast<void*>(kOffset2)); 1228 EXPECT_TRUE(ptr2 == reinterpret_cast<void*>(kOffset2));
1241 } 1229 }
1242 1230
1243 TEST_F(GLES2ImplementationTest, GetVertexAttrib) { 1231 TEST_F(GLES2ImplementationTest, GetVertexAttrib) {
1244 static const float verts[1] = { 0.0f, }; 1232 static const float verts[1] = { 0.0f, };
1245 const GLuint kAttribIndex1 = 1; 1233 const GLuint kAttribIndex1 = 1;
1246 const GLuint kAttribIndex2 = 3; 1234 const GLuint kAttribIndex2 = 3;
1247 const GLint kNumComponents1 = 3; 1235 const GLint kNumComponents1 = 3;
1248 const GLint kNumComponents2 = 2; 1236 const GLint kNumComponents2 = 2;
1249 const GLsizei kStride1 = 12; 1237 const GLsizei kStride1 = 12;
1250 const GLsizei kStride2 = 0; 1238 const GLsizei kStride2 = 0;
1251 const GLuint kBufferId = 0x123; 1239 const GLuint kBufferId = 0x123;
1252 const GLint kOffset2 = 0x456; 1240 const GLint kOffset2 = 0x456;
1253 1241
1254 // Only one set and one get because the client side buffer's info is stored 1242 // Only one set and one get because the client side buffer's info is stored
1255 // on the client side. 1243 // on the client side.
1256 struct Cmds { 1244 struct Cmds {
1257 EnableVertexAttribArray enable; 1245 EnableVertexAttribArray enable;
1258 BindBuffer bind; 1246 BindBuffer bind;
1259 VertexAttribPointer set_pointer; 1247 VertexAttribPointer set_pointer;
1260 GetVertexAttribiv get1; // for getting the buffer from attrib2
1261 GetVertexAttribfv get2; // for getting the value from attrib1 1248 GetVertexAttribfv get2; // for getting the value from attrib1
1262 }; 1249 };
1263 1250
1264 ExpectedMemoryInfo mem1 = GetExpectedResultMemory(16);
1265 ExpectedMemoryInfo mem2 = GetExpectedResultMemory(16); 1251 ExpectedMemoryInfo mem2 = GetExpectedResultMemory(16);
1266 1252
1267 Cmds expected; 1253 Cmds expected;
1268 expected.enable.Init(kAttribIndex1); 1254 expected.enable.Init(kAttribIndex1);
1269 expected.bind.Init(GL_ARRAY_BUFFER, kBufferId); 1255 expected.bind.Init(GL_ARRAY_BUFFER, kBufferId);
1270 expected.set_pointer.Init(kAttribIndex2, kNumComponents2, GL_FLOAT, GL_FALSE, 1256 expected.set_pointer.Init(kAttribIndex2, kNumComponents2, GL_FLOAT, GL_FALSE,
1271 kStride2, kOffset2); 1257 kStride2, kOffset2);
1272 expected.get1.Init(kAttribIndex2,
1273 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING,
1274 mem1.id, mem1.offset);
1275 expected.get2.Init(kAttribIndex1, 1258 expected.get2.Init(kAttribIndex1,
1276 GL_CURRENT_VERTEX_ATTRIB, 1259 GL_CURRENT_VERTEX_ATTRIB,
1277 mem2.id, mem2.offset); 1260 mem2.id, mem2.offset);
1278 1261
1279 FourFloats current_attrib(1.2f, 3.4f, 5.6f, 7.8f); 1262 FourFloats current_attrib(1.2f, 3.4f, 5.6f, 7.8f);
1280 1263
1281 // One call to flush to way for GetVertexAttribiv 1264 // One call to flush to wait for last call to GetVertexAttribiv
1265 // as others are all cached.
1282 EXPECT_CALL(*command_buffer(), OnFlush()) 1266 EXPECT_CALL(*command_buffer(), OnFlush())
1283 .WillOnce(SetMemory( 1267 .WillOnce(SetMemory(
1284 mem1.ptr, SizedResultHelper<GLuint>(kBufferId)))
1285 .WillOnce(SetMemory(
1286 mem2.ptr, SizedResultHelper<FourFloats>(current_attrib))) 1268 mem2.ptr, SizedResultHelper<FourFloats>(current_attrib)))
1287 .RetiresOnSaturation(); 1269 .RetiresOnSaturation();
1288 1270
1289 gl_->EnableVertexAttribArray(kAttribIndex1); 1271 gl_->EnableVertexAttribArray(kAttribIndex1);
1290 // Set one client side buffer. 1272 // Set one client side buffer.
1291 gl_->VertexAttribPointer(kAttribIndex1, kNumComponents1, 1273 gl_->VertexAttribPointer(kAttribIndex1, kNumComponents1,
1292 GL_FLOAT, GL_FALSE, kStride1, verts); 1274 GL_FLOAT, GL_FALSE, kStride1, verts);
1293 // Set one VBO 1275 // Set one VBO
1294 gl_->BindBuffer(GL_ARRAY_BUFFER, kBufferId); 1276 gl_->BindBuffer(GL_ARRAY_BUFFER, kBufferId);
1295 gl_->VertexAttribPointer(kAttribIndex2, kNumComponents2, 1277 gl_->VertexAttribPointer(kAttribIndex2, kNumComponents2,
(...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after
2562 gl_->Enable(state); 2544 gl_->Enable(state);
2563 EXPECT_EQ(0, memcmp(&expected, commands, sizeof(expected))); 2545 EXPECT_EQ(0, memcmp(&expected, commands, sizeof(expected)));
2564 } 2546 }
2565 ClearCommands(); 2547 ClearCommands();
2566 result = gl_->IsEnabled(state); 2548 result = gl_->IsEnabled(state);
2567 EXPECT_TRUE(result); 2549 EXPECT_TRUE(result);
2568 EXPECT_TRUE(NoCommandsWritten()); 2550 EXPECT_TRUE(NoCommandsWritten());
2569 } 2551 }
2570 } 2552 }
2571 2553
2554 TEST_F(GLES2ImplementationTest, BindVertexArrayOES) {
2555 GLuint id = 0;
2556 gl_->GenVertexArraysOES(1, &id);
2557 ClearCommands();
2558
2559 struct Cmds {
2560 BindVertexArrayOES cmd;
2561 };
2562 Cmds expected;
2563 expected.cmd.Init(id);
2564
2565 const void* commands = GetPut();
2566 gl_->BindVertexArrayOES(id);
2567 EXPECT_EQ(0, memcmp(&expected, commands, sizeof(expected)));
2568 ClearCommands();
2569 gl_->BindVertexArrayOES(id);
2570 EXPECT_TRUE(NoCommandsWritten());
2571 }
2572
2572 TEST_F(GLES2ImplementationTest, BeginEndQueryEXT) { 2573 TEST_F(GLES2ImplementationTest, BeginEndQueryEXT) {
2573 // Test GetQueryivEXT returns 0 if no current query. 2574 // Test GetQueryivEXT returns 0 if no current query.
2574 GLint param = -1; 2575 GLint param = -1;
2575 gl_->GetQueryivEXT(GL_ANY_SAMPLES_PASSED_EXT, GL_CURRENT_QUERY_EXT, &param); 2576 gl_->GetQueryivEXT(GL_ANY_SAMPLES_PASSED_EXT, GL_CURRENT_QUERY_EXT, &param);
2576 EXPECT_EQ(0, param); 2577 EXPECT_EQ(0, param);
2577 2578
2578 GLuint expected_ids[2] = { 1, 2 }; // These must match what's actually genned. 2579 GLuint expected_ids[2] = { 1, 2 }; // These must match what's actually genned.
2579 struct GenCmds { 2580 struct GenCmds {
2580 GenQueriesEXTImmediate gen; 2581 GenQueriesEXTImmediate gen;
2581 GLuint data[2]; 2582 GLuint data[2];
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
2799 gl_->Enable(GL_BLEND); 2800 gl_->Enable(GL_BLEND);
2800 EXPECT_TRUE(NoCommandsWritten()); 2801 EXPECT_TRUE(NoCommandsWritten());
2801 } 2802 }
2802 2803
2803 2804
2804 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" 2805 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h"
2805 2806
2806 } // namespace gles2 2807 } // namespace gles2
2807 } // namespace gpu 2808 } // namespace gpu
2808 2809
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698