Changeset 8569 in orxonox.OLD for branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc
- Timestamp:
- Jun 18, 2006, 8:26:57 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc
r8548 r8569 18 18 #include <stdio.h> 19 19 #include <math.h> 20 20 #define USE_VBO 21 21 22 22 #define CHECK_GL_ERROR( _d ) do { \ … … 33 33 numVertices = numIndices = 0; 34 34 errors = new LODError[TerrainPage::MAX_LODS]; 35 vertices = NULL; indices = NULL; coords = NULL;35 vertices = NULL; indices = NULL; 36 36 position = Triple( scale.x*_xOffset, 0.0f, scale.z*_zOffset ); 37 37 isVisible = false; … … 45 45 void TerrainPage::tesselateRow( int _z, int _xStride, int _zStride, bool _adaptLeft, bool _adaptRight ) 46 46 { 47 int xStart = 0, xEnd = owner->getPageSize();48 47 48 int xStart = 0, xEnd = owner->getPageSize(); 49 49 int halfStride = _zStride >> 1; 50 51 52 50 if ( _z ) { 53 51 addAgain( ); … … 454 452 determineBorderAdaption( adapt ); 455 453 assert( isVisible ); 454 #ifdef USE_VBO 455 456 glBindBufferARB( GL_ARRAY_BUFFER_ARB, vbIdentifier ); 457 458 // The call to glBufferDataARB with a null argument for data is to tell the GPU, that the 459 // old data is invalid. Then calling call glMapBuffer() tells the driver that the previous 460 // data aren’t valid. As a consequence, if the GPU is still working on them, there won’t 461 // be a conflict because we invalidated these data. The function glMapBuffer() returns a 462 // new pointer that we can use while the GPU is working on the previous set of data.. 463 464 glBufferDataARB( GL_ARRAY_BUFFER_ARB, count*sizeof( Vertex ), NULL, GL_DYNAMIC_DRAW_ARB ); 465 466 vertices = (Vertex*)glMapBufferARB( GL_ARRAY_BUFFER_ARB, 467 GL_WRITE_ONLY_ARB ); 468 469 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, ibIdentifier ); 470 471 glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 472 count*3*sizeof( short ), NULL, GL_DYNAMIC_DRAW_ARB ); 473 474 indices = (unsigned short*)glMapBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 475 GL_WRITE_ONLY_ARB ); 476 477 assert( indices ); 478 assert( vertices ); 479 480 #endif 456 481 if ( _lod == TerrainPage::MAX_LODS-1 ) { 457 482 tesselateLevelFourPatch( adapt ); … … 473 498 474 499 475 if ( !adapt[TP_BOTTOM] ) 476 return; 500 if ( adapt[TP_BOTTOM] ) { 477 501 478 502 addAgain( ); … … 480 504 481 505 tesselateRow( owner->getPageSize()-1-stride, stride / 2, stride, adapt[TP_LEFT], adapt[TP_RIGHT] ); 506 } 507 508 #ifdef USE_VBO 509 glUnmapBufferARB( GL_ARRAY_BUFFER_ARB ); 510 glUnmapBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB ); 511 #endif 482 512 483 513 } … … 488 518 int count = owner->getPageSize()*owner->getPageSize(); 489 519 490 vertices = new Triple[count]; 520 #ifdef USE_VBO 521 owner->getBufferBroker()->acquire( vbIdentifier, ibIdentifier ); 522 vertices = NULL; 523 indices = NULL; 524 #else 525 vertices = new Vertex[count]; 491 526 // Not the economical way, but we just want to have space for all indices. 492 527 indices = new unsigned short[count*3]; 528 #endif 529 493 530 indexHash = new unsigned short[count]; 494 coords = new TexCoord[count];495 531 forceTesselation = true; 496 532 activate(); 497 533 active = true; 534 498 535 } 499 536 500 537 void TerrainPage::hide( ) 501 538 { 539 #ifdef USE_VBO 540 owner->getBufferBroker()->release( vbIdentifier, ibIdentifier ); 541 #else 502 542 if ( vertices ) { 503 543 delete[] vertices; 504 544 vertices = NULL; 505 545 } 506 delete[] coords;507 546 if ( indices ) { 508 547 delete[] indices; … … 510 549 numIndices = 0; 511 550 } 551 #endif 512 552 deactivate(); 513 553 } … … 552 592 CHECK_GL_ERROR( "1" ); 553 593 554 glVertexPointer( 3, GL_FLOAT, 0, vertices ); 555 glTexCoordPointer( 2, GL_FLOAT, 0, coords ); 594 #ifdef USE_VBO 595 596 glBindBufferARB( GL_ARRAY_BUFFER_ARB, vbIdentifier ); 597 glClientActiveTextureARB( GL_TEXTURE0_ARB ); 598 glInterleavedArrays( GL_T2F_V3F, 0, NULL ); 556 599 557 600 glClientActiveTextureARB( GL_TEXTURE1_ARB ); 558 glVertexPointer( 3, GL_FLOAT, 0, vertices ); 559 glTexCoordPointer( 2, GL_FLOAT, 0, coords ); 601 glInterleavedArrays( GL_T2F_V3F, 0, NULL ); 602 603 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, ibIdentifier ); 560 604 561 605 glDrawElements( GL_TRIANGLE_STRIP, numIndices, 562 GL_UNSIGNED_SHORT, indices ); 606 GL_UNSIGNED_SHORT, NULL ); 607 #else 608 glClientActiveTextureARB( GL_TEXTURE0_ARB ); 609 glInterleavedArrays( GL_T2F_V3F, 0, vertices ); 610 611 glClientActiveTextureARB( GL_TEXTURE1_ARB ); 612 glInterleavedArrays( GL_T2F_V3F, 0, vertices ); 613 614 glDrawElements( GL_TRIANGLE_STRIP, numIndices, 615 GL_UNSIGNED_SHORT, indices ); 616 #endif 617 618 563 619 564 620 if ( owner->debug() ) … … 574 630 //The vertex didn't exists before, lets create it. 575 631 indexHash[index] = numVertices; 576 getVertex( _x, _z, vertices[numVertices] );577 getCoord( _x, _z, coords[numVertices]);632 getVertex( _x, _z, vertices[numVertices].p ); 633 getCoord( _x, _z, vertices[numVertices].t ); 578 634 numVertices++; 579 635 }
Note: See TracChangeset
for help on using the changeset viewer.