OLD | NEW |
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 20 matching lines...) Expand all Loading... |
31 | 31 |
32 | 32 |
33 // This file contains the implementation of the VertexBufferGL, IndexBufferGL | 33 // This file contains the implementation of the VertexBufferGL, IndexBufferGL |
34 // and VertexStructGL classes, as well as the geometry-related GAPI functions. | 34 // and VertexStructGL classes, as well as the geometry-related GAPI functions. |
35 | 35 |
36 #include "command_buffer/service/cross/gl/gapi_gl.h" | 36 #include "command_buffer/service/cross/gl/gapi_gl.h" |
37 #include "command_buffer/service/cross/gl/geometry_gl.h" | 37 #include "command_buffer/service/cross/gl/geometry_gl.h" |
38 | 38 |
39 namespace o3d { | 39 namespace o3d { |
40 namespace command_buffer { | 40 namespace command_buffer { |
| 41 namespace o3d { |
41 | 42 |
42 VertexBufferGL::~VertexBufferGL() { | 43 VertexBufferGL::~VertexBufferGL() { |
43 glDeleteBuffers(1, &gl_buffer_); | 44 glDeleteBuffers(1, &gl_buffer_); |
44 CHECK_GL_ERROR(); | 45 CHECK_GL_ERROR(); |
45 } | 46 } |
46 | 47 |
47 // Creates the GL buffer object. | 48 // Creates the GL buffer object. |
48 void VertexBufferGL::Create() { | 49 void VertexBufferGL::Create() { |
49 glGenBuffers(1, &gl_buffer_); | 50 glGenBuffers(1, &gl_buffer_); |
50 glBindBuffer(GL_ARRAY_BUFFER, gl_buffer_); | 51 glBindBuffer(GL_ARRAY_BUFFER, gl_buffer_); |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 LOG(ERROR) << "Drawing with invalid streams."; | 452 LOG(ERROR) << "Drawing with invalid streams."; |
452 return false; | 453 return false; |
453 } | 454 } |
454 max_vertices_ = vertex_struct->SetStreams(this); | 455 max_vertices_ = vertex_struct->SetStreams(this); |
455 validate_streams_ = false; | 456 validate_streams_ = false; |
456 return max_vertices_ > 0; | 457 return max_vertices_ > 0; |
457 } | 458 } |
458 | 459 |
459 namespace { | 460 namespace { |
460 | 461 |
461 void PrimitiveTypeToGL(command_buffer::PrimitiveType primitive_type, | 462 void PrimitiveTypeToGL(o3d::PrimitiveType primitive_type, |
462 GLenum *gl_mode, | 463 GLenum *gl_mode, |
463 unsigned int *count) { | 464 unsigned int *count) { |
464 switch (primitive_type) { | 465 switch (primitive_type) { |
465 case command_buffer::kPoints: | 466 case o3d::kPoints: |
466 *gl_mode = GL_POINTS; | 467 *gl_mode = GL_POINTS; |
467 break; | 468 break; |
468 case command_buffer::kLines: | 469 case o3d::kLines: |
469 *gl_mode = GL_LINES; | 470 *gl_mode = GL_LINES; |
470 *count *= 2; | 471 *count *= 2; |
471 break; | 472 break; |
472 case command_buffer::kLineStrips: | 473 case o3d::kLineStrips: |
473 *gl_mode = GL_LINE_STRIP; | 474 *gl_mode = GL_LINE_STRIP; |
474 ++*count; | 475 ++*count; |
475 break; | 476 break; |
476 case command_buffer::kTriangles: | 477 case o3d::kTriangles: |
477 *gl_mode = GL_TRIANGLES; | 478 *gl_mode = GL_TRIANGLES; |
478 *count *= 3; | 479 *count *= 3; |
479 break; | 480 break; |
480 case command_buffer::kTriangleStrips: | 481 case o3d::kTriangleStrips: |
481 *gl_mode = GL_TRIANGLE_STRIP; | 482 *gl_mode = GL_TRIANGLE_STRIP; |
482 *count += 2; | 483 *count += 2; |
483 break; | 484 break; |
484 case command_buffer::kTriangleFans: | 485 case o3d::kTriangleFans: |
485 *gl_mode = GL_TRIANGLE_FAN; | 486 *gl_mode = GL_TRIANGLE_FAN; |
486 *count += 2; | 487 *count += 2; |
487 break; | 488 break; |
488 default: | 489 default: |
489 LOG(FATAL) << "Invalid primitive type"; | 490 LOG(FATAL) << "Invalid primitive type"; |
490 break; | 491 break; |
491 } | 492 } |
492 } | 493 } |
493 | 494 |
494 } // anonymous namespace | 495 } // anonymous namespace |
495 | 496 |
496 parse_error::ParseError GAPIGL::Draw(PrimitiveType primitive_type, | 497 parse_error::ParseError GAPIGL::Draw(o3d::PrimitiveType primitive_type, |
497 unsigned int first, | 498 unsigned int first, |
498 unsigned int count) { | 499 unsigned int count) { |
499 if (validate_effect_ && !ValidateEffect()) { | 500 if (validate_effect_ && !ValidateEffect()) { |
500 return parse_error::kParseInvalidArguments; | 501 return parse_error::kParseInvalidArguments; |
501 } | 502 } |
502 DCHECK(current_effect_); | 503 DCHECK(current_effect_); |
503 if (validate_streams_ && !ValidateStreams()) { | 504 if (validate_streams_ && !ValidateStreams()) { |
504 return parse_error::kParseInvalidArguments; | 505 return parse_error::kParseInvalidArguments; |
505 } | 506 } |
506 GLenum gl_mode = GL_POINTS; | 507 GLenum gl_mode = GL_POINTS; |
507 PrimitiveTypeToGL(primitive_type, &gl_mode, &count); | 508 PrimitiveTypeToGL(primitive_type, &gl_mode, &count); |
508 if (first + count > max_vertices_) { | 509 if (first + count > max_vertices_) { |
509 return parse_error::kParseInvalidArguments; | 510 return parse_error::kParseInvalidArguments; |
510 } | 511 } |
511 glDrawArrays(gl_mode, first, count); | 512 glDrawArrays(gl_mode, first, count); |
512 CHECK_GL_ERROR(); | 513 CHECK_GL_ERROR(); |
513 return parse_error::kParseNoError; | 514 return parse_error::kParseNoError; |
514 } | 515 } |
515 | 516 |
516 parse_error::ParseError GAPIGL::DrawIndexed( | 517 parse_error::ParseError GAPIGL::DrawIndexed( |
517 PrimitiveType primitive_type, | 518 o3d::PrimitiveType primitive_type, |
518 ResourceId index_buffer_id, | 519 ResourceId index_buffer_id, |
519 unsigned int first, | 520 unsigned int first, |
520 unsigned int count, | 521 unsigned int count, |
521 unsigned int min_index, | 522 unsigned int min_index, |
522 unsigned int max_index) { | 523 unsigned int max_index) { |
523 IndexBufferGL *index_buffer = index_buffers_.Get(index_buffer_id); | 524 IndexBufferGL *index_buffer = index_buffers_.Get(index_buffer_id); |
524 if (!index_buffer) return parse_error::kParseInvalidArguments; | 525 if (!index_buffer) return parse_error::kParseInvalidArguments; |
525 if (validate_effect_ && !ValidateEffect()) { | 526 if (validate_effect_ && !ValidateEffect()) { |
526 return parse_error::kParseInvalidArguments; | 527 return parse_error::kParseInvalidArguments; |
527 } | 528 } |
(...skipping 14 matching lines...) Expand all Loading... |
542 GLuint offset = first * index_size; | 543 GLuint offset = first * index_size; |
543 if (offset + count * index_size > index_buffer->size()) { | 544 if (offset + count * index_size > index_buffer->size()) { |
544 return parse_error::kParseInvalidArguments; | 545 return parse_error::kParseInvalidArguments; |
545 } | 546 } |
546 glDrawRangeElements(gl_mode, min_index, max_index, count, index_type, | 547 glDrawRangeElements(gl_mode, min_index, max_index, count, index_type, |
547 OffsetToPtr(offset)); | 548 OffsetToPtr(offset)); |
548 CHECK_GL_ERROR(); | 549 CHECK_GL_ERROR(); |
549 return parse_error::kParseNoError; | 550 return parse_error::kParseNoError; |
550 } | 551 } |
551 | 552 |
| 553 } // namespace o3d |
552 } // namespace command_buffer | 554 } // namespace command_buffer |
553 } // namespace o3d | 555 } // namespace o3d |
OLD | NEW |