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

Side by Side Diff: command_buffer/service/cross/gl/geometry_gl.cc

Issue 212018: Change command buffer client code to use structures.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 11 years, 3 months 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2009, Google Inc. 2 * Copyright 2009, Google Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 304 }
305 dirty_ = false; 305 dirty_ = false;
306 } 306 }
307 307
308 BufferSyncInterface::ParseError GAPIGL::CreateVertexBuffer(ResourceID id, 308 BufferSyncInterface::ParseError GAPIGL::CreateVertexBuffer(ResourceID id,
309 unsigned int size, 309 unsigned int size,
310 unsigned int flags) { 310 unsigned int flags) {
311 VertexBufferGL *vertex_buffer = new VertexBufferGL(size, flags); 311 VertexBufferGL *vertex_buffer = new VertexBufferGL(size, flags);
312 vertex_buffer->Create(); 312 vertex_buffer->Create();
313 vertex_buffers_.Assign(id, vertex_buffer); 313 vertex_buffers_.Assign(id, vertex_buffer);
314 return BufferSyncInterface::PARSE_NO_ERROR; 314 return BufferSyncInterface::kParseNoError;
315 } 315 }
316 316
317 BufferSyncInterface::ParseError GAPIGL::DestroyVertexBuffer(ResourceID id) { 317 BufferSyncInterface::ParseError GAPIGL::DestroyVertexBuffer(ResourceID id) {
318 return vertex_buffers_.Destroy(id) ? 318 return vertex_buffers_.Destroy(id) ?
319 BufferSyncInterface::PARSE_NO_ERROR : 319 BufferSyncInterface::kParseNoError :
320 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 320 BufferSyncInterface::kParseInvalidArguments;
321 } 321 }
322 322
323 BufferSyncInterface::ParseError GAPIGL::SetVertexBufferData(ResourceID id, 323 BufferSyncInterface::ParseError GAPIGL::SetVertexBufferData(ResourceID id,
324 unsigned int offset, 324 unsigned int offset,
325 unsigned int size, 325 unsigned int size,
326 const void *data) { 326 const void *data) {
327 VertexBufferGL *vertex_buffer = vertex_buffers_.Get(id); 327 VertexBufferGL *vertex_buffer = vertex_buffers_.Get(id);
328 if (!vertex_buffer) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 328 if (!vertex_buffer) return BufferSyncInterface::kParseInvalidArguments;
329 return vertex_buffer->SetData(offset, size, data) ? 329 return vertex_buffer->SetData(offset, size, data) ?
330 BufferSyncInterface::PARSE_NO_ERROR : 330 BufferSyncInterface::kParseNoError :
331 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 331 BufferSyncInterface::kParseInvalidArguments;
332 } 332 }
333 333
334 BufferSyncInterface::ParseError GAPIGL::GetVertexBufferData(ResourceID id, 334 BufferSyncInterface::ParseError GAPIGL::GetVertexBufferData(ResourceID id,
335 unsigned int offset, 335 unsigned int offset,
336 unsigned int size, 336 unsigned int size,
337 void *data) { 337 void *data) {
338 VertexBufferGL *vertex_buffer = vertex_buffers_.Get(id); 338 VertexBufferGL *vertex_buffer = vertex_buffers_.Get(id);
339 if (!vertex_buffer) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 339 if (!vertex_buffer) return BufferSyncInterface::kParseInvalidArguments;
340 return vertex_buffer->GetData(offset, size, data) ? 340 return vertex_buffer->GetData(offset, size, data) ?
341 BufferSyncInterface::PARSE_NO_ERROR : 341 BufferSyncInterface::kParseNoError :
342 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 342 BufferSyncInterface::kParseInvalidArguments;
343 } 343 }
344 344
345 BufferSyncInterface::ParseError GAPIGL::CreateIndexBuffer(ResourceID id, 345 BufferSyncInterface::ParseError GAPIGL::CreateIndexBuffer(ResourceID id,
346 unsigned int size, 346 unsigned int size,
347 unsigned int flags) { 347 unsigned int flags) {
348 IndexBufferGL *index_buffer = new IndexBufferGL(size, flags); 348 IndexBufferGL *index_buffer = new IndexBufferGL(size, flags);
349 index_buffer->Create(); 349 index_buffer->Create();
350 index_buffers_.Assign(id, index_buffer); 350 index_buffers_.Assign(id, index_buffer);
351 return BufferSyncInterface::PARSE_NO_ERROR; 351 return BufferSyncInterface::kParseNoError;
352 } 352 }
353 353
354 BufferSyncInterface::ParseError GAPIGL::DestroyIndexBuffer(ResourceID id) { 354 BufferSyncInterface::ParseError GAPIGL::DestroyIndexBuffer(ResourceID id) {
355 return index_buffers_.Destroy(id) ? 355 return index_buffers_.Destroy(id) ?
356 BufferSyncInterface::PARSE_NO_ERROR : 356 BufferSyncInterface::kParseNoError :
357 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 357 BufferSyncInterface::kParseInvalidArguments;
358 } 358 }
359 359
360 BufferSyncInterface::ParseError GAPIGL::SetIndexBufferData(ResourceID id, 360 BufferSyncInterface::ParseError GAPIGL::SetIndexBufferData(ResourceID id,
361 unsigned int offset, 361 unsigned int offset,
362 unsigned int size, 362 unsigned int size,
363 const void *data) { 363 const void *data) {
364 IndexBufferGL *index_buffer = index_buffers_.Get(id); 364 IndexBufferGL *index_buffer = index_buffers_.Get(id);
365 if (!index_buffer) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 365 if (!index_buffer) return BufferSyncInterface::kParseInvalidArguments;
366 return index_buffer->SetData(offset, size, data) ? 366 return index_buffer->SetData(offset, size, data) ?
367 BufferSyncInterface::PARSE_NO_ERROR : 367 BufferSyncInterface::kParseNoError :
368 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 368 BufferSyncInterface::kParseInvalidArguments;
369 } 369 }
370 370
371 BufferSyncInterface::ParseError GAPIGL::GetIndexBufferData(ResourceID id, 371 BufferSyncInterface::ParseError GAPIGL::GetIndexBufferData(ResourceID id,
372 unsigned int offset, 372 unsigned int offset,
373 unsigned int size, 373 unsigned int size,
374 void *data) { 374 void *data) {
375 IndexBufferGL *index_buffer = index_buffers_.Get(id); 375 IndexBufferGL *index_buffer = index_buffers_.Get(id);
376 if (!index_buffer) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 376 if (!index_buffer) return BufferSyncInterface::kParseInvalidArguments;
377 return index_buffer->GetData(offset, size, data) ? 377 return index_buffer->GetData(offset, size, data) ?
378 BufferSyncInterface::PARSE_NO_ERROR : 378 BufferSyncInterface::kParseNoError :
379 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 379 BufferSyncInterface::kParseInvalidArguments;
380 } 380 }
381 381
382 BufferSyncInterface::ParseError GAPIGL::CreateVertexStruct( 382 BufferSyncInterface::ParseError GAPIGL::CreateVertexStruct(
383 ResourceID id, 383 ResourceID id,
384 unsigned int input_count) { 384 unsigned int input_count) {
385 if (id == current_vertex_struct_) validate_streams_ = true; 385 if (id == current_vertex_struct_) validate_streams_ = true;
386 VertexStructGL *vertex_struct = new VertexStructGL(input_count); 386 VertexStructGL *vertex_struct = new VertexStructGL(input_count);
387 vertex_structs_.Assign(id, vertex_struct); 387 vertex_structs_.Assign(id, vertex_struct);
388 return BufferSyncInterface::PARSE_NO_ERROR; 388 return BufferSyncInterface::kParseNoError;
389 } 389 }
390 390
391 BufferSyncInterface::ParseError GAPIGL::DestroyVertexStruct(ResourceID id) { 391 BufferSyncInterface::ParseError GAPIGL::DestroyVertexStruct(ResourceID id) {
392 if (id == current_vertex_struct_) validate_streams_ = true; 392 if (id == current_vertex_struct_) validate_streams_ = true;
393 return vertex_structs_.Destroy(id) ? 393 return vertex_structs_.Destroy(id) ?
394 BufferSyncInterface::PARSE_NO_ERROR : 394 BufferSyncInterface::kParseNoError :
395 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 395 BufferSyncInterface::kParseInvalidArguments;
396 } 396 }
397 397
398 BufferSyncInterface::ParseError GAPIGL::SetVertexInput( 398 BufferSyncInterface::ParseError GAPIGL::SetVertexInput(
399 ResourceID vertex_struct_id, 399 ResourceID vertex_struct_id,
400 unsigned int input_index, 400 unsigned int input_index,
401 ResourceID vertex_buffer_id, 401 ResourceID vertex_buffer_id,
402 unsigned int offset, 402 unsigned int offset,
403 unsigned int stride, 403 unsigned int stride,
404 vertex_struct::Type type, 404 vertex_struct::Type type,
405 vertex_struct::Semantic semantic, 405 vertex_struct::Semantic semantic,
406 unsigned int semantic_index) { 406 unsigned int semantic_index) {
407 switch (semantic) { 407 switch (semantic) {
408 case vertex_struct::POSITION: 408 case vertex_struct::POSITION:
409 if (semantic_index != 0) { 409 if (semantic_index != 0) {
410 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 410 return BufferSyncInterface::kParseInvalidArguments;
411 } 411 }
412 break; 412 break;
413 case vertex_struct::NORMAL: 413 case vertex_struct::NORMAL:
414 if (semantic_index != 0) { 414 if (semantic_index != 0) {
415 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 415 return BufferSyncInterface::kParseInvalidArguments;
416 } 416 }
417 break; 417 break;
418 case vertex_struct::COLOR: 418 case vertex_struct::COLOR:
419 if (semantic_index >= 2) { 419 if (semantic_index >= 2) {
420 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 420 return BufferSyncInterface::kParseInvalidArguments;
421 } 421 }
422 break; 422 break;
423 case vertex_struct::TEX_COORD: 423 case vertex_struct::TEX_COORD:
424 if (semantic_index >= 8) { 424 if (semantic_index >= 8) {
425 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 425 return BufferSyncInterface::kParseInvalidArguments;
426 } 426 }
427 break; 427 break;
428 default: 428 default:
429 DLOG(FATAL) << "Not reached."; 429 DLOG(FATAL) << "Not reached.";
430 break; 430 break;
431 } 431 }
432 if (vertex_buffer_id == current_vertex_struct_) validate_streams_ = true; 432 if (vertex_buffer_id == current_vertex_struct_) validate_streams_ = true;
433 VertexStructGL *vertex_struct = vertex_structs_.Get(vertex_struct_id); 433 VertexStructGL *vertex_struct = vertex_structs_.Get(vertex_struct_id);
434 if (!vertex_struct || input_index >= vertex_struct->count()) 434 if (!vertex_struct || input_index >= vertex_struct->count())
435 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 435 return BufferSyncInterface::kParseInvalidArguments;
436 vertex_struct->SetInput(input_index, vertex_buffer_id, offset, stride, type, 436 vertex_struct->SetInput(input_index, vertex_buffer_id, offset, stride, type,
437 semantic, semantic_index); 437 semantic, semantic_index);
438 return BufferSyncInterface::PARSE_NO_ERROR; 438 return BufferSyncInterface::kParseNoError;
439 } 439 }
440 440
441 BufferSyncInterface::ParseError GAPIGL::SetVertexStruct(ResourceID id) { 441 BufferSyncInterface::ParseError GAPIGL::SetVertexStruct(ResourceID id) {
442 current_vertex_struct_ = id; 442 current_vertex_struct_ = id;
443 validate_streams_ = true; 443 validate_streams_ = true;
444 return BufferSyncInterface::PARSE_NO_ERROR; 444 return BufferSyncInterface::kParseNoError;
445 } 445 }
446 446
447 bool GAPIGL::ValidateStreams() { 447 bool GAPIGL::ValidateStreams() {
448 DCHECK(validate_streams_); 448 DCHECK(validate_streams_);
449 VertexStructGL *vertex_struct = vertex_structs_.Get(current_vertex_struct_); 449 VertexStructGL *vertex_struct = vertex_structs_.Get(current_vertex_struct_);
450 if (!vertex_struct) { 450 if (!vertex_struct) {
451 LOG(ERROR) << "Drawing with invalid streams."; 451 LOG(ERROR) << "Drawing with invalid streams.";
452 return false; 452 return false;
453 } 453 }
454 max_vertices_ = vertex_struct->SetStreams(this); 454 max_vertices_ = vertex_struct->SetStreams(this);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 break; 490 break;
491 } 491 }
492 } 492 }
493 493
494 } // anonymous namespace 494 } // anonymous namespace
495 495
496 BufferSyncInterface::ParseError GAPIGL::Draw(PrimitiveType primitive_type, 496 BufferSyncInterface::ParseError GAPIGL::Draw(PrimitiveType primitive_type,
497 unsigned int first, 497 unsigned int first,
498 unsigned int count) { 498 unsigned int count) {
499 if (validate_effect_ && !ValidateEffect()) { 499 if (validate_effect_ && !ValidateEffect()) {
500 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 500 return BufferSyncInterface::kParseInvalidArguments;
501 } 501 }
502 DCHECK(current_effect_); 502 DCHECK(current_effect_);
503 if (validate_streams_ && !ValidateStreams()) { 503 if (validate_streams_ && !ValidateStreams()) {
504 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 504 return BufferSyncInterface::kParseInvalidArguments;
505 } 505 }
506 GLenum gl_mode = GL_POINTS; 506 GLenum gl_mode = GL_POINTS;
507 PrimitiveTypeToGL(primitive_type, &gl_mode, &count); 507 PrimitiveTypeToGL(primitive_type, &gl_mode, &count);
508 if (first + count > max_vertices_) { 508 if (first + count > max_vertices_) {
509 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 509 return BufferSyncInterface::kParseInvalidArguments;
510 } 510 }
511 glDrawArrays(gl_mode, first, count); 511 glDrawArrays(gl_mode, first, count);
512 CHECK_GL_ERROR(); 512 CHECK_GL_ERROR();
513 return BufferSyncInterface::PARSE_NO_ERROR; 513 return BufferSyncInterface::kParseNoError;
514 } 514 }
515 515
516 BufferSyncInterface::ParseError GAPIGL::DrawIndexed( 516 BufferSyncInterface::ParseError GAPIGL::DrawIndexed(
517 PrimitiveType primitive_type, 517 PrimitiveType primitive_type,
518 ResourceID index_buffer_id, 518 ResourceID index_buffer_id,
519 unsigned int first, 519 unsigned int first,
520 unsigned int count, 520 unsigned int count,
521 unsigned int min_index, 521 unsigned int min_index,
522 unsigned int max_index) { 522 unsigned int max_index) {
523 IndexBufferGL *index_buffer = index_buffers_.Get(index_buffer_id); 523 IndexBufferGL *index_buffer = index_buffers_.Get(index_buffer_id);
524 if (!index_buffer) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 524 if (!index_buffer) return BufferSyncInterface::kParseInvalidArguments;
525 if (validate_effect_ && !ValidateEffect()) { 525 if (validate_effect_ && !ValidateEffect()) {
526 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 526 return BufferSyncInterface::kParseInvalidArguments;
527 } 527 }
528 DCHECK(current_effect_); 528 DCHECK(current_effect_);
529 if (validate_streams_ && !ValidateStreams()) { 529 if (validate_streams_ && !ValidateStreams()) {
530 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 530 return BufferSyncInterface::kParseInvalidArguments;
531 } 531 }
532 if ((min_index >= max_vertices_) || (max_index > max_vertices_)) { 532 if ((min_index >= max_vertices_) || (max_index > max_vertices_)) {
533 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 533 return BufferSyncInterface::kParseInvalidArguments;
534 } 534 }
535 GLenum gl_mode = GL_POINTS; 535 GLenum gl_mode = GL_POINTS;
536 PrimitiveTypeToGL(primitive_type, &gl_mode, &count); 536 PrimitiveTypeToGL(primitive_type, &gl_mode, &count);
537 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer->gl_buffer()); 537 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer->gl_buffer());
538 GLenum index_type = (index_buffer->flags() & index_buffer::INDEX_32BIT) ? 538 GLenum index_type = (index_buffer->flags() & index_buffer::INDEX_32BIT) ?
539 GL_UNSIGNED_INT : GL_UNSIGNED_SHORT; 539 GL_UNSIGNED_INT : GL_UNSIGNED_SHORT;
540 GLuint index_size = (index_buffer->flags() & index_buffer::INDEX_32BIT) ? 540 GLuint index_size = (index_buffer->flags() & index_buffer::INDEX_32BIT) ?
541 sizeof(GLuint) : sizeof(GLushort); // NOLINT 541 sizeof(GLuint) : sizeof(GLushort); // NOLINT
542 GLuint offset = first * index_size; 542 GLuint offset = first * index_size;
543 if (offset + count * index_size > index_buffer->size()) { 543 if (offset + count * index_size > index_buffer->size()) {
544 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 544 return BufferSyncInterface::kParseInvalidArguments;
545 } 545 }
546 glDrawRangeElements(gl_mode, min_index, max_index, count, index_type, 546 glDrawRangeElements(gl_mode, min_index, max_index, count, index_type,
547 OffsetToPtr(offset)); 547 OffsetToPtr(offset));
548 CHECK_GL_ERROR(); 548 CHECK_GL_ERROR();
549 return BufferSyncInterface::PARSE_NO_ERROR; 549 return BufferSyncInterface::kParseNoError;
550 } 550 }
551 551
552 } // namespace command_buffer 552 } // namespace command_buffer
553 } // namespace o3d 553 } // namespace o3d
OLDNEW
« no previous file with comments | « command_buffer/service/cross/gl/effect_gl.cc ('k') | command_buffer/service/cross/gl/sampler_gl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698