Changeset 8569 in orxonox.OLD for branches/terrain/src/lib/graphics
- Timestamp:
- Jun 18, 2006, 8:26:57 PM (18 years ago)
- Location:
- branches/terrain/src/lib/graphics/importer
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/terrain/src/lib/graphics/importer/Makefile.am
r8319 r8569 25 25 terrain/terrain_quad.cc \ 26 26 terrain/terrain_page.cc \ 27 terrain/frustum.cc 27 terrain/frustum.cc \ 28 terrain/buffer_broker.cc 28 29 29 30 libtc_a_SOURCES = tc.cc … … 56 57 terrain/terrain_quad.h \ 57 58 terrain/frustum.h \ 58 terrain/types.h 59 terrain/types.h \ 60 terrain/buffer_broker.h -
branches/terrain/src/lib/graphics/importer/terrain/frustum.h
r8328 r8569 28 28 29 29 /** 30 * Code borrowed from Lighthouse 3D 30 * Code borrowed from Lighthouse 3D. Its a very good tutorial on culling. 31 31 */ 32 32 class Frustum; … … 64 64 { 65 65 int result = INSIDE; 66 for(int i=0; i < 6; i++) { 66 //for each plane do ... 67 for( int i = 0; i < 6; ++i ) { 67 68 69 // is the positive vertex outside? 68 70 if ( planes[i].distance( _box.vertexP( planes[i].n ) ) < 0 ) 69 71 return OUTSIDE; 70 if ( planes[i].distance( _box.vertexN( planes[i].n) ) < 0 ) 71 result = INTERSECT; 72 // is the negative vertex outside? 73 else if ( planes[i].distance( _box.vertexN( planes[i].n ) ) < 0 ) 74 result = INTERSECT; 72 75 } 73 return result; 76 return result; 74 77 } 75 78 … … 78 81 int result = INSIDE; 79 82 for(int i=0; i < 6; i++) { 80 81 83 if (planes[i].distance( _point ) < 0) 82 84 return OUTSIDE; -
branches/terrain/src/lib/graphics/importer/terrain/terrain.cc
r8548 r8569 129 129 void Terrain::draw( ) 130 130 { 131 static float s = 0.0f , x = 0.0f;131 static float s = 0.0f; 132 132 glGetError(); 133 133 pTerrainPage page = NULL; … … 158 158 pTerrainPage neighbor = NULL; 159 159 page = activePages; 160 bool dirty; 161 do { 162 dirty = false; 163 page = activePages; 164 while ( page ) { 165 if ( !page->isActive() ) { 166 pTerrainPage tmp = page; 167 page = tmp->getNext(); 168 tmp->setVisibility( false ); 169 continue; 170 } 171 wantedLeft = wantedRight = wantedBottom = wantedTop = page->getWantedLOD(); 172 if ( ( neighbor = page->getLeft() ) ) 173 wantedLeft = neighbor->getWantedLOD(); 174 if ( ( neighbor = page->getRight() ) ) 175 wantedRight = neighbor->getWantedLOD(); 176 if ( ( neighbor = page->getTop() ) ) 177 wantedTop = neighbor->getWantedLOD(); 178 if ( ( neighbor = page->getBottom() ) ) 179 wantedBottom = neighbor->getWantedLOD(); 180 181 minLOD = std::min( std::min( wantedBottom, wantedTop ), std::min( wantedLeft, wantedRight ) ); 182 if ( minLOD < page->getWantedLOD()-1 ) { 183 page->setWantedLOD( minLOD+1 ); 184 dirty = true; 185 } 186 page = page->getNext(); 187 } 188 } while ( dirty ); 189 page = activePages; 160 190 161 191 while ( page ) { 162 if ( !page->isActive() ) { 163 pTerrainPage tmp = page; 164 page = tmp->getNext(); 165 tmp->setVisibility( false ); 166 continue; 167 } 168 wantedLeft = wantedRight = wantedBottom = wantedTop = page->getWantedLOD(); 169 if ( ( neighbor = page->getLeft() ) ) 170 wantedLeft = neighbor->getWantedLOD(); 171 if ( ( neighbor = page->getRight() ) ) 172 wantedRight = neighbor->getWantedLOD(); 173 if ( ( neighbor = page->getTop() ) ) 174 wantedTop = neighbor->getWantedLOD(); 175 if ( ( neighbor = page->getBottom() ) ) 176 wantedBottom = neighbor->getWantedLOD(); 177 178 minLOD = std::min( std::min( wantedBottom, wantedTop ), std::min( wantedLeft, wantedRight ) ); 179 /*if ( minLOD < page->getWantedLOD()-1 ) 180 page->setWantedLOD( minLOD+1 );*/ 181 182 page->updateTesselation(); 192 page->updateTesselation(); 183 193 page = page->getNext(); 184 194 } 185 s = 50.0f; 195 196 s = 500.0f; 186 197 for ( int i = 0; i < materials.size(); ++i ) { 187 198 page = activePages; … … 189 200 //This is a hack! Remove this as soon as possible 190 201 materials[i]->unselect(); 191 192 202 materials[i]->select(); 193 203 … … 214 224 //printf( "culled %f%% terrain pages away\n", percentage ); 215 225 } 226 glClientActiveTextureARB( GL_TEXTURE1_ARB ); 227 glDisableClientState( GL_VERTEX_ARRAY ); 228 glDisableClientState( GL_TEXTURE_COORD_ARRAY ); 229 glDisableClientState( GL_VERTEX_ARRAY ); 230 glDisableClientState( GL_TEXTURE_COORD_ARRAY ); 231 materials[0]->unselect(); 232 glActiveTextureARB( GL_TEXTURE0_ARB ); 233 glClientActiveTextureARB( GL_TEXTURE0_ARB ); 234 glDisableClientState( GL_VERTEX_ARRAY ); 235 glDisableClientState( GL_TEXTURE_COORD_ARRAY ); 236 glEnable( GL_LIGHTING ); 216 237 } 217 238 -
branches/terrain/src/lib/graphics/importer/terrain/terrain.h
r8548 r8569 17 17 #define _TERRAIN_H 18 18 19 #define USE_VBO 20 #ifdef USE_VBO 21 #include "buffer_broker.h" 22 #endif 19 23 #include "types.h" 20 24 #include "terrain_page.h" … … 82 86 frustum = new Frustum(); 83 87 activatedCount = deactivatedCount = 0; 88 #ifdef USE_VBO 89 broker = new BufferBroker( 200, pageSize*pageSize*sizeof( Vertex ), 90 pageSize*pageSize*sizeof( short )*3 ); 91 #endif 84 92 } 85 93 … … 146 154 scale = _scale; 147 155 } 148 156 #ifdef USE_VBO 157 inline pBufferBroker getBufferBroker() { return broker; } 158 #endif 149 159 inline TerrainPage *getPage( int _x, int _z ) 150 160 { … … 170 180 void determineVisiblePages( pTerrainQuad _node ); 171 181 182 #ifdef USE_VBO 183 pBufferBroker broker; 184 #endif 172 185 pTerrainQuad root; // The quad-tree root node. 173 186 pTerrainPage *pages; // the references to all pages -
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 } -
branches/terrain/src/lib/graphics/importer/terrain/terrain_page.h
r8548 r8569 17 17 #ifndef TERRAIN_PAGE_H 18 18 #define TERRAIN_PAGE_H 19 19 #define USE_VBO 20 20 #include "terrain_quad.h" 21 21 #include <stdio.h> … … 26 26 27 27 typedef TerrainPage *pTerrainPage; 28 29 struct Vertex { 30 TexCoord t; 31 Triple p; 32 }; 33 34 typedef Vertex *pVertex; 28 35 29 36 typedef struct { … … 208 215 if ( wantedLOD >= TerrainPage::MAX_LODS ) 209 216 wantedLOD = 4; 217 else if ( wantedLOD < 0 ) 218 wantedLOD = 0; 210 219 else 211 220 wantedLOD = _lod; … … 271 280 bool forceTesselation; 272 281 bool active; 273 Triple *vertices;282 pVertex vertices; 274 283 unsigned short *indices; 275 284 unsigned short *indexHash; 276 TexCoord *coords;277 285 int numIndices; 278 286 int numVertices; 287 288 #ifdef USE_VBO 289 GLuint ibIdentifier, 290 vbIdentifier; 291 #endif 279 292 bool isVisible; 280 293 pTerrainPage next;
Note: See TracChangeset
for help on using the changeset viewer.