Changeset 9140 in orxonox.OLD for branches/terrain/src/lib/graphics
- Timestamp:
- Jul 4, 2006, 3:06:00 PM (18 years ago)
- Location:
- branches/terrain/src/lib/graphics
- Files:
-
- 7 edited
- 12 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/terrain/src/lib/graphics/effects/volfog_effect.cc
r9006 r9140 30 30 //#include <GL/glext.h> //OpenGL Extensions 31 31 //#include <GL/glxext.h> // GLX Extensions 32 32 #ifndef __APPLE__ 33 33 #ifndef GL_EXT_fog_coord 34 34 #define GL_EXT_fog_coord 1 … … 45 45 PFNGLFOGCOORDDVEXTPROC glFogCoorddvEXT = 0; 46 46 PFNGLFOGCOORDPOINTEREXTPROC glFogCoordPointerEXT = 0; 47 47 #endif 48 48 49 49 using namespace std; -
branches/terrain/src/lib/graphics/graphics_engine.cc
r8740 r9140 236 236 // Enable default GL stuff 237 237 glEnable(GL_DEPTH_TEST); 238 238 glEnable(GL_CULL_FACE); 239 glCullFace(GL_FRONT); 239 240 Render2D::getInstance(); 240 241 … … 297 298 } 298 299 299 glEnable(GL_CULL_FACE); 300 glCullFace(GL_FRONT); 300 301 301 } 302 302 -
branches/terrain/src/lib/graphics/importer/Makefile.am
r8724 r9140 38 38 md3/md3_mesh.cc \ 39 39 md3/md3_data.cc \ 40 md3/md3_tag.cc 41 42 40 md3/md3_tag.cc \ 41 \ 42 terrain/terrain.cc \ 43 terrain/terrain_quad.cc \ 44 terrain/terrain_page.cc \ 45 terrain/frustum.cc \ 46 terrain/buffer_broker.cc 43 47 44 48 … … 81 85 md3/md3_mesh.h \ 82 86 md3/md3_data.h \ 83 md3/md3_tag.h 87 md3/md3_tag.h \ 88 \ 89 terrain/terrain.h \ 90 terrain/terrain_page.h \ 91 terrain/terrain_quad.h \ 92 terrain/frustum.h \ 93 terrain/types.h \ 94 terrain/buffer_broker.h 84 95 -
branches/terrain/src/lib/graphics/importer/material.h
r8761 r9140 61 61 void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D); 62 62 void setBump(const std::string& bump); 63 64 63 GLuint diffuseTextureID(unsigned int i = 0) const { return (this->textures.size() > i)? this->textures[i].getTexture() : 0; }; 65 64 -
branches/terrain/src/lib/graphics/importer/md2/md2Model.cc
r9003 r9140 17 17 #include "md2Model.h" 18 18 #include "material.h" 19 19 #include "config.h" 20 #ifdef HAVE_SDL_SDL_H 21 #include <SDL/SDL.h> 22 #include <SDL/SDL_endian.h> 23 #else 24 #include <SDL.h> 25 #include <SDL_endian.h> 26 #endif 20 27 #include "debug.h" 21 28 #include "util/loading/resource_manager.h" … … 66 73 }; 67 74 68 75 #ifdef SDL_LIL_ENDIAN 76 #define BULK_CONV( _ptr, _num ) do { \ 77 int _cnt = _num;\ 78 int* _iptr = (int*)_ptr;\ 79 for( int _l = 0; _l<_cnt; ++_l )\ 80 _iptr[_l] = SDL_SwapLE32( _iptr[_l] );\ 81 } while( 0 ) 82 #define BULK_CONV16( _ptr, _num ) do { \ 83 short _cnt = _num;\ 84 short* _iptr = (short*)_ptr;\ 85 for( int _l = 0; _l<_cnt; ++_l )\ 86 _iptr[_l] = SDL_SwapLE16( _iptr[_l] );\ 87 } while( 0 ) 88 #else 89 #define BULK_CONV( _ptr, _num ) 90 #define BULK_CONV16( _ptr, _num ) 91 #endif 69 92 70 93 /******************************************************************************** … … 467 490 this->header = new MD2Header; 468 491 fread(this->header, 1, sizeof(MD2Header), pFile); 492 BULK_CONV( this->header, sizeof(MD2Header)/4 ); 469 493 /* check for the header version: make sure its a md2 file :) */ 470 if( unlikely( this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT))494 if( unlikely( this->header->version != MD2_VERSION) && unlikely( this->header->ident != MD2_IDENT)) 471 495 { 472 496 PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str()); … … 474 498 } 475 499 476 this->fileName = fileName;500 this->fileName = fileName; 477 501 /* got the data: map it to locals */ 478 502 this->numFrames = this->header->numFrames; … … 493 517 fseek(pFile, this->header->offsetFrames, SEEK_SET); 494 518 fread(buffer, this->header->frameSize, this->numFrames, pFile); 519 //BULK_CONV( buffer, this->header->frameSize*this->numFrames*sizeof(char)/4 ); 495 520 /* read opengl commands */ 496 521 fseek(pFile, this->header->offsetGlCommands, SEEK_SET); 522 497 523 fread(this->pGLCommands, sizeof(int), this->numGLCommands, pFile); 524 BULK_CONV( this->pGLCommands, this->numGLCommands ); 498 525 /* triangle list */ 499 526 fseek(pFile, this->header->offsetTriangles, SEEK_SET); 500 fread(this->pTriangles, sizeof(sTriangle), this->numTriangles, pFile); 527 fread(this->pTriangles, sizeof(sTriangle), this->numTriangles, pFile); 528 BULK_CONV16( this->pTriangles, this->numTriangles*sizeof(sTriangle)/2 ); 529 501 530 /* read in texture coordinates */ 502 531 fseek(pFile, this->header->offsetTexCoords, SEEK_SET); 503 532 fread(this->pTexCoor, sizeof(sTexCoor), this->numTexCoor, pFile); 504 533 BULK_CONV16( this->pTexCoor, this->numTexCoor*sizeof(sTexCoor)/2 ); 505 534 506 535 for(int i = 0; i < this->numFrames; ++i) 507 536 { 508 537 frame = (sFrame*)(buffer + this->header->frameSize * i); 538 //Convert the translate and scale Vec3D if needed. 539 BULK_CONV( frame, 6 ); 540 BULK_CONV( frame->pVertices, 3 ); 509 541 pVertex = this->pVertices + this->numVertices * i; 510 542 pNormals = this->pLightNormals + this->numVertices * i; -
branches/terrain/src/lib/graphics/importer/md3/md3_data.h
r8724 r9140 70 70 }; 71 71 72 73 72 //! class to store the md2 data in 74 73 class MD3Data : public BaseObject -
branches/terrain/src/lib/graphics/importer/terrain/buffer_broker.h
r9135 r9140 1 1 /* 2 3 4 5 6 7 8 9 10 11 12 2 orxonox - the future of 3D-vertical-scrollers 3 4 Copyright (C) 2006 orx 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 ### File Specific: 12 main programmer: Marco Biasini 13 13 14 14 */ … … 21 21 #include "types.h" 22 22 /** 23 * @brief 23 * @brief Manages the streaming of the vertex buffer objects for the terrain page. 24 24 */ 25 25 26 26 struct BufferPair { 27 28 29 GLuint indexName; 30 GLuintvertexName;31 BufferPair*next;27 BufferPair( int _i, int _v ) { indexName = _i; vertexName = _v; next = NULL; } 28 BufferPair() { indexName = vertexName = 0; next = NULL; } 29 GLuint indexName; 30 GLuint vertexName; 31 BufferPair *next; 32 32 }; 33 33 … … 35 35 36 36 class BufferBroker { 37 public: 38 39 BufferBroker( int _num, int _vbSize, int _ibSize ) 40 { 41 capacity = _num; 42 freeIndexBuffers = new GLuint[capacity]; 43 freeVertexBuffers = new GLuint[capacity]; 44 lastAcquired = 0; 45 vbSize = _vbSize; ibSize = _ibSize; 46 glGenBuffersARB( capacity, freeIndexBuffers ); 47 glGenBuffersARB( capacity, freeVertexBuffers ); 48 for ( int i = 0; i < capacity; ++i ) { 49 glBindBufferARB( GL_ARRAY_BUFFER_ARB, freeVertexBuffers[i] ); 50 glBufferDataARB( GL_ARRAY_BUFFER_ARB, vbSize, 51 NULL, GL_DYNAMIC_DRAW_ARB ); 52 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, freeIndexBuffers[i] ); 53 glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, ibSize, 54 NULL, GL_DYNAMIC_DRAW_ARB ); 55 } 56 head = tail = NULL; 57 } 58 ~BufferBroker() 59 { 60 pBufferPair bp = head; 61 while ( bp ) { 62 pBufferPair tmp = bp->next; 63 release( bp->vertexName, bp->indexName ); 64 bp = tmp; 65 } 66 glDeleteBuffersARB( capacity, freeVertexBuffers ); 67 glDeleteBuffersARB( capacity, freeIndexBuffers ); 68 SAVE_DELETE_ARRAY( freeIndexBuffers ); 69 SAVE_DELETE_ARRAY( freeVertexBuffers ); 70 } 71 inline int getIBSize() { return ibSize; } 72 inline int getVBSize() { return vbSize; } 73 inline void acquire( GLuint &_vbName, GLuint &_ibName ); 74 75 inline void release( const GLuint &_vbName, const GLuint &_ibName ); 76 protected: 37 public: 77 38 78 int capacity; 79 80 int vbSize, 81 ibSize; 82 int lastAcquired; 83 84 GLuint *freeIndexBuffers, 85 *freeVertexBuffers; 86 87 BufferPair *head, *tail; 39 BufferBroker( int _num, int _vbSize, int _ibSize ) 40 { 41 capacity = _num; 42 freeIndexBuffers = new GLuint[capacity]; 43 freeVertexBuffers = new GLuint[capacity]; 44 lastAcquired = 0; 45 vbSize = _vbSize; ibSize = _ibSize; 46 glGenBuffersARB( capacity, freeIndexBuffers ); 47 glGenBuffersARB( capacity, freeVertexBuffers ); 48 for ( int i = 0; i < capacity; ++i ) { 49 glBindBufferARB( GL_ARRAY_BUFFER_ARB, freeVertexBuffers[i] ); 50 glBufferDataARB( GL_ARRAY_BUFFER_ARB, vbSize, 51 NULL, GL_DYNAMIC_DRAW_ARB ); 52 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, freeIndexBuffers[i] ); 53 glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, ibSize, 54 NULL, GL_DYNAMIC_DRAW_ARB ); 55 } 56 head = tail = NULL; 57 } 58 ~BufferBroker() 59 { 60 pBufferPair bp = head; 61 while ( bp ) { 62 pBufferPair tmp = bp->next; 63 release( bp->vertexName, bp->indexName ); 64 bp = tmp; 65 } 66 glDeleteBuffersARB( capacity, freeVertexBuffers ); 67 glDeleteBuffersARB( capacity, freeIndexBuffers ); 68 SAVE_DELETE_ARRAY( freeIndexBuffers ); 69 SAVE_DELETE_ARRAY( freeVertexBuffers ); 70 } 71 inline int getIBSize() { return ibSize; } 72 inline int getVBSize() { return vbSize; } 73 inline void acquire( GLuint &_vbName, GLuint &_ibName ); 74 75 inline void release( const GLuint &_vbName, const GLuint &_ibName ); 76 protected: 77 78 int capacity; 79 80 int vbSize, 81 ibSize; 82 int lastAcquired; 83 84 GLuint *freeIndexBuffers, 85 *freeVertexBuffers; 86 87 BufferPair *head, *tail; 88 88 }; 89 89 90 90 inline void BufferBroker::release( const GLuint &_vbName, const GLuint &_ibName ) 91 91 { 92 93 94 92 pBufferPair bp = head, prev = NULL; 93 bool removed = false; 94 while ( bp ) { 95 95 96 97 98 prev->next = bp->next; 99 100 101 102 103 104 105 106 107 108 109 110 111 break; 112 113 114 115 116 96 if ( bp->indexName == _ibName && bp->vertexName == _vbName ) { 97 if ( prev ) { 98 prev->next = bp->next; 99 } 100 else { 101 head = bp->next; 102 } 103 if ( bp->next == NULL ) 104 tail = prev; 105 int index = capacity-lastAcquired; 106 lastAcquired--; 107 freeIndexBuffers[index] = bp->indexName; 108 freeVertexBuffers[index] = bp->vertexName; 109 delete bp; 110 removed = true; 111 break; 112 } 113 prev = bp; 114 bp = bp->next; 115 } 116 assert( removed ); 117 117 } 118 118 119 119 inline void BufferBroker::acquire( GLuint &_vbName, GLuint &_ibName ) 120 120 { 121 122 123 124 125 126 127 128 129 130 tail = head = new BufferPair( _ibName, _vbName ); 131 121 assert( capacity > lastAcquired ); 122 int index = capacity-lastAcquired-1; 123 _vbName = freeVertexBuffers[index]; _ibName = freeIndexBuffers[index]; 124 lastAcquired++; 125 if ( tail ) { 126 tail->next = new BufferPair( _ibName, _vbName ); 127 tail = tail->next; 128 } 129 else { 130 tail = head = new BufferPair( _ibName, _vbName ); 131 } 132 132 } 133 133 -
branches/terrain/src/lib/graphics/importer/terrain/types.h
r9135 r9140 1 1 /* 2 3 4 5 6 7 8 9 10 11 12 13 2 orxonox - the future of 3D-vertical-scrollers 3 4 Copyright (C) 2006 orx 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 ### File Specific: 12 main programmer: Marco Biasini 13 This files needs to be removed after code-revision... 14 14 */ 15 #ifndef TYPES_H16 #define TYPES_H15 #ifndef _TYPES_H 16 #define _TYPES_H 17 17 18 18 #ifndef NULL … … 21 21 #include <math.h> 22 22 #include "texture.h" 23 #include "plane.h" 23 24 24 25 #define SAVE_DELETE_ARRAY( _a ) if ( _a ) { delete[] _a; _a = NULL; } 25 26 #define SAVE_DELETE( _a ) if ( _a ) { delete _a; _a = NULL; } 26 27 27 struct Triple { 28 Triple( float _x, float _y, float _z ) 29 { 30 x = _x; y = _y; z = _z; 31 } 32 Triple() { x = y = z = 0.0f; } 33 inline float length() const 34 { return sqrt( x*x+y*y+z*z ); } 35 float x, y, z; 28 struct Triple 29 { 30 Triple( float _x, float _y, float _z ) 31 { 32 x = _x; y = _y; z = _z; 33 } 34 Triple() { x = y = z = 0.0f; } 35 inline float length() const 36 { return sqrt( x*x+y*y+z*z ); } 37 float x, y, z; 36 38 }; 37 39 38 struct TexCoord { 39 TexCoord( float _u, float _v ) 40 { 41 u = _u; v = _v; 42 } 43 TexCoord() { u = v = 0.0f; } 44 float u, v; 40 struct TexCoord 41 { 42 TexCoord( float _u, float _v ) 43 { 44 u = _u; v = _v; 45 } 46 TexCoord() { u = v = 0.0f; } 47 float u, v; 45 48 }; 46 49 … … 48 51 * Defines an axis aligned box. 49 52 */ 50 struct ABox { 51 52 ABox( Triple _min, Triple _max) 53 { 54 corner = _min; 55 x = _max.x-_min.x; 56 y = _max.y-_min.y; 57 z = _max.z-_min.z; 58 } 59 60 ABox() 61 { 62 corner = Triple( 0.0f, 0.0f, 0.0f ); 63 x = y = z = 0.0f; 64 } 65 inline void set( const Triple& _min, const Triple& _max ) 66 { 67 setMin( _min ); setMax( _max ); 68 } 69 inline void setMax( const Triple& _max ) 70 { 71 x = _max.x-corner.x; 72 y = _max.y-corner.y; 73 z = _max.z-corner.z; 74 } 75 inline void setMin( const Triple& _min ) 76 { 77 corner = _min; 78 } 79 inline Triple vertexP( const Triple& _normal ) const 80 { 81 Triple res = corner; 82 if ( _normal.x > 0 ) 83 res.x+= x; 84 if ( _normal.y > 0 ) 85 res.y+= y; 86 if ( _normal.z > 0 ) 87 res.z+= z; 88 89 return res; 90 } 91 inline Triple vertexN( const Triple& _normal ) const 92 { 93 Triple res = corner; 94 if ( _normal.x < 0 ) 95 res.x+= x; 96 if ( _normal.y < 0 ) 97 res.y+= y; 98 if ( _normal.z < 0 ) 99 res.z+= z; 100 101 return res; 102 103 } 104 inline Triple min() const { return Triple(corner); } 105 inline Triple max() const { return Triple( corner.x+x, corner.y+y, corner.z+z ); } 106 Triple corner; 107 float x, y, z; 108 53 struct ABox 54 { 55 56 ABox( Triple _min, Triple _max) 57 { 58 corner = _min; 59 x = _max.x-_min.x; 60 y = _max.y-_min.y; 61 z = _max.z-_min.z; 62 } 63 64 ABox() 65 { 66 corner = Triple( 0.0f, 0.0f, 0.0f ); 67 x = y = z = 0.0f; 68 } 69 inline void set( const Triple& _min, const Triple& _max ) 70 { 71 setMin( _min ); setMax( _max ); 72 } 73 inline void setMax( const Triple& _max ) 74 { 75 x = _max.x-corner.x; 76 y = _max.y-corner.y; 77 z = _max.z-corner.z; 78 } 79 inline void setMin( const Triple& _min ) 80 { 81 corner = _min; 82 } 83 inline Triple vertexP( const Triple& _normal ) const 84 { 85 Triple res = corner; 86 if ( _normal.x > 0 ) 87 res.x+= x; 88 if ( _normal.y > 0 ) 89 res.y+= y; 90 if ( _normal.z > 0 ) 91 res.z+= z; 92 93 return res; 94 } 95 inline Triple vertexN( const Triple& _normal ) const 96 { 97 Triple res = corner; 98 if ( _normal.x < 0 ) 99 res.x+= x; 100 if ( _normal.y < 0 ) 101 res.y+= y; 102 if ( _normal.z < 0 ) 103 res.z+= z; 104 105 return res; 106 107 } 108 inline Triple min() const { return Triple(corner); } 109 inline Triple max() const { return Triple( corner.x+x, corner.y+y, corner.z+z ); } 110 Triple corner; 111 float x, y, z; 112 109 113 }; 110 114 111 struct Plane { 112 Plane() { n = Triple( 0.0f, 1.0f, 0.0f ); d = 0.0f; } 113 inline void setCoefficients( float _nx, float _ny, float _nz, float _d ) 114 { 115 n = Triple( _nx, _ny, _nz ); 116 float l = n.length(); 117 n.x /= l; n.y/=l; n.z/=l; 118 d = _d/l; 119 } 120 inline float distance( const Triple& _point ) const 121 { 122 return _point.x*n.x+_point.y*n.y+_point.z*n.z+d; 123 } 124 Triple n; 125 float d; 126 }; 115 // struct Plane 116 // { 117 // Plane() { n = Triple( 0.0f, 1.0f, 0.0f ); d = 0.0f; } 118 // inline void setCoefficients( float _nx, float _ny, float _nz, float _d ) 119 // { 120 // n = Triple( _nx, _ny, _nz ); 121 // float l = n.length(); 122 // n.x /= l; n.y/=l; n.z/=l; 123 // d = _d/l; 124 // } 125 // inline float distance( const Triple& _point ) const 126 // { 127 // return _point.x*n.x+_point.y*n.y+_point.z*n.z+d; 128 // } 129 // Triple n; 130 // float d; 131 // }; 127 132 128 133 /** 129 134 * TODO: Replace this method with the actual matrix multiplication code! 130 135 */ 131 inline void multMat(float *res,float *a, float *b) { 136 inline void multMat(float *res,float *a, float *b) 137 { 132 138 133 139 134 for (int i=0;i<4;i++) { 135 for (int j = 0;j < 4;j++) { 136 res[i*4+j] = 0.0; 137 for (int k = 0; k < 4; k++) { 138 res[i*4+j] += a[i*4+k] * b[k*4+j]; 139 } 140 } 141 } 140 for (int i=0;i<4;i++) 141 { 142 for (int j = 0;j < 4;j++) 143 { 144 res[i*4+j] = 0.0; 145 for (int k = 0; k < 4; k++) 146 { 147 res[i*4+j] += a[i*4+k] * b[k*4+j]; 148 } 149 } 150 } 142 151 } 143 152 typedef unsigned char UByte; 144 struct Heightfield { 145 int width; 146 int height; 147 int pitch; 148 UByte *data; 149 Heightfield() { data = NULL; width=0;height=0;pitch=0;} 153 struct Heightfield 154 { 155 int width; 156 int height; 157 int pitch; 158 UByte *data; 159 Heightfield() { data = NULL; width=0;height=0;pitch=0;} 150 160 }; 151 161 152 struct LayerInfo { 162 struct LayerInfo 163 { 153 164 154 intenvmode;155 floatrepeatX,156 157 Texture*alpha;158 Texture*detail;159 165 int envmode; 166 float repeatX, 167 repeatZ; 168 Texture *alpha; 169 Texture *detail; 170 160 171 }; 161 172 typedef enum { LV_FULL, LV_PARTIAL, LV_NO } LayerVisibility; 162 173 163 struct BufferInfo { 164 165 BufferInfo( unsigned int _vb, unsigned int _ib, 166 unsigned int _numV, unsigned int _numI ) 167 { 168 vbIdentifier = _vb; ibIdentifier = _ib; 169 numIndices = _numI; numVertices =_numV; 170 171 } 172 173 BufferInfo() 174 { 175 vbIdentifier = ibIdentifier = numIndices = numVertices = 0; 176 } 177 unsigned int vbIdentifier, 178 ibIdentifier, 179 numIndices, 180 numVertices; 174 struct BufferInfo 175 { 176 177 BufferInfo( unsigned int _vb, unsigned int _ib, 178 unsigned int _numV, unsigned int _numI ) 179 { 180 vbIdentifier = _vb; ibIdentifier = _ib; 181 numIndices = _numI; numVertices =_numV; 182 183 } 184 185 BufferInfo() 186 { 187 vbIdentifier = ibIdentifier = numIndices = numVertices = 0; 188 } 189 unsigned int vbIdentifier, 190 ibIdentifier, 191 numIndices, 192 numVertices; 181 193 }; 182 194 #endif -
branches/terrain/src/lib/graphics/importer/texture.cc
r8761 r9140 332 332 else 333 333 { 334 assert(surface->format->BitsPerPixel == 24);334 //assert(surface->format->BitsPerPixel == 24); 335 335 } 336 336
Note: See TracChangeset
for help on using the changeset viewer.