Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

patch grid fixes for new rendering system

  • Loading branch information...
commit 62ebdf864c7593d31e195518c65baeab41b50d6f 1 parent 86d34b5
jonklein authored
View
36 breve/include/breve/patch.h
@@ -21,12 +21,8 @@
#ifndef _PATCH_H
#define _PATCH_H
-/**
- * \brief Data associated with a certain region of 3D space.
- */
-
#include "bigMatrix.hh"
-#include "glIncludes.h"
+#include "render.h"
#include "texture.h"
class slPatchGrid;
@@ -102,11 +98,14 @@ class slPatch {
std::vector< slPatch* > _neighbors;
};
-/*!
- \brief A grid of \ref slPatch objects.
-*/
+/**
+ * \brief A grid of \ref slPatch objects, data associated with a certain region of 3D space.
+ */
+
class slPatchGrid {
+ friend class slPatch;
+
public:
slPatchGrid();
@@ -118,10 +117,9 @@ class slPatchGrid {
~slPatchGrid();
- void compileCubeList();
- void draw(slCamera *camera);
- void drawWithout3DTexture(slCamera *camera);
+ void draw( slRenderGL &inRenderer, slCamera *camera );
+ void drawWithout3DTexture( slRenderGL &inRenderer, slCamera *camera );
void setSmoothDrawing( bool inSmooth ) { drawSmooth = inSmooth; }
@@ -141,6 +139,7 @@ class slPatchGrid {
*/
void setDrawWithTexture(bool t);
+ protected:
// below should be private/protected
unsigned int _xSize;
@@ -155,16 +154,19 @@ class slPatchGrid {
// colors holds all of the color information for the patches. it is a raw
// array of char values so that we can use it as texture data if desired.
- unsigned char *colors;
+ unsigned char *colors;
- unsigned int _textureX;
- unsigned int _textureY;
- unsigned int _textureZ;
+ unsigned int _textureX;
+ unsigned int _textureY;
+ unsigned int _textureZ;
- bool drawSmooth;
+ private:
+ bool drawSmooth;
+ void fillCubeBuffer();
slTexture2D* _texture;
- int _cubeDrawList;
+ slVertexBufferGL _cubeBuffer;
+ slVertexBufferGL _quadBuffer;
bool _drawWithTexture;
bool _textureNeedsUpdate;
View
27 breve/include/breve/world.h
@@ -152,7 +152,6 @@ class slWorld {
slCamera *getLightExposureCamera() { return &_lightExposureCamera; }
void drawObjects( slRenderGL& inRenderer );
- void draw( slRenderGL& inRenderer, slCamera *inCamera );
/**
* Indicates that collision detection structures must be reinitialized.
@@ -187,41 +186,43 @@ class slWorld {
void setCFM( double inCFM ) {
if( _odeWorldID )
dWorldSetCFM( _odeWorldID, inCFM );
- }
+ }
+
+ void drawPatchGrids( slRenderGL& inRenderer, slCamera *inCamera );
+ void draw( slRenderGL& inRenderer, slCamera *inCamera );
// integration vectors -- DV_VECTOR_COUNT depends on the requirements
// of the integration algorithm we're using... mbEuler requires only
// a single derivation vector, while RK4 needs about 6.
- double *dv[ DV_VECTOR_COUNT ];
-
- int (*integrator)(slWorld *w, slLink *m, double *dt, int skip);
+ double *dv[ DV_VECTOR_COUNT ];
+ int (*integrator)( slWorld *w, slLink *m, double *dt, int skip );
// the collision callback is called when the collision is detected --
// at the estimated time of collision.
- void (*_collisionCallback)(void *body1, void *body2, int type, slVector *position, slVector *face);
+ void (*_collisionCallback)(void *body1, void *body2, int type, slVector *position, slVector *face);
// the collisionCheckCallback is a callback defined by the program
// using the physics engine. it takes two userData (see slWorldObject)
// pointers and returns whether collision detection should be preformed
// on the objects or not.
- int (*_collisionCheckCallback)(void *body1, void *body2, int type);
+ int (*_collisionCheckCallback)(void *body1, void *body2, int type);
- slObjectLine *addObjectLine( slWorldObject*, slWorldObject*, int, slVector* );
+ slObjectLine *addObjectLine( slWorldObject*, slWorldObject*, int, slVector* );
- slPatchGrid *addPatchGrid( slVector *center, slVector *patchSize, int x, int y, int z );
- void removePatchGrid( slPatchGrid *g );
+ slPatchGrid *addPatchGrid( slVector *center, slVector *patchSize, int x, int y, int z );
+ void removePatchGrid( slPatchGrid *g );
- slGISData* loadTigerFile( char *, slTerrain * );
+ slGISData* loadTigerFile( char *, slTerrain * );
// age is the simulation time of the world.
- double _age;
+ double _age;
std::vector< slWorldObject* > _objects;
std::vector< slPatchGrid* > _patches;
- std::vector< slCamera* > _cameras;
+ std::vector< slCamera* > _cameras;
std::vector< slObjectConnection* > _connections;
std::vector< slDrawCommandList* > _drawings;
View
14 breve/include/breve/worldObject.h
@@ -95,14 +95,14 @@ class slWorldObject {
int _lightExposure;
bool _drawAsPoint;
- bool _drawShadow;
+ bool _drawShadow;
slTexture2D* _texture;
- char _textureMode;
- unsigned char _drawMode;
- float _billboardRotation;
- float _alpha;
+ char _textureMode;
+ unsigned char _drawMode;
+ float _billboardRotation;
+ float _alpha;
- float _textureScaleX, _textureScaleY;
+ float _textureScaleX, _textureScaleY;
// bounding box information here is used for "proximity" data
@@ -112,7 +112,7 @@ class slWorldObject {
double _mu;
std::vector<slWorldObject*> _neighbors;
- std::vector< void* > _neighborData;
+ std::vector< void* > _neighborData;
// the list of lines that this object makes to other objects
View
33 breve/kernel/internalFunctions/breveFunctionsFile.cc
@@ -190,7 +190,6 @@ int brIReadLine( brEval args[], brEval *target, brInstance *i ) {
slFgets( line, sizeof( line ) - 1, p->file );
char *last = &line[ strlen( line ) - 1 ];
-
if( *last == '\n' || *last == '\r' ) *last = '\0';
target->set( line );
@@ -198,41 +197,29 @@ int brIReadLine( brEval args[], brEval *target, brInstance *i ) {
return EC_OK;
}
-/*!
- \brief Reads list data delimited with a specified string.
-*/
+/**
+ * \brief Reads list data delimited with a specified string.
+ */
int brIReadDelimitedList( brEval args[], brEval *target, brInstance *i ) {
brEval eval;
brEvalListHead *head;
- brFilePointer *p;
- int n;
- char line[ 10240 ];
-
- p = BRFILEPOINTER( &args[0] );
-
- head = new brEvalListHead();
-
- target->set( head );
-
- if ( !p || !p->file ) {
- slMessage( DEBUG_ALL, "readDelimitedList called with uninitialized file\n" );
- return EC_ERROR;
- }
+ char *str;
+ int n = 0;
- slFgets( line, sizeof( line ) - 1, p->file );
- if( line[ strlen( line ) - 1 ] == '\n' ) line[ strlen( line ) - 1 ] = 0;
+ // reuse the single line reading code
+ brIReadLine( args, target, i );
- n = 0;
- char *str;
+ head = new brEvalListHead();
- while ( ( str = slSplit( line, BRSTRING( &args[1] ), n++ ) ) ) {
+ while ( ( str = slSplit( BRSTRING( target ), BRSTRING( &args[1] ), n++ ) ) ) {
eval.set( str );
brEvalListInsert( head, head->_vector.size(), &eval );
delete[] str;
}
+ target->set( head );
return EC_OK;
}
View
25 breve/lib/classes/breve/Control.py
@@ -242,12 +242,6 @@ def disableShadows( self ):
self.shadowFlag = 0
breve.breveInternalFunctionFinder.setDrawShadow( self, self.shadowFlag )
- def disableSmoothDrawing( self ):
- '''Disable smooth drawing for the main camera. See METHOD(enable-smooth-drawing) for more information.'''
-
- self.smoothFlag = 0
- breve.breveInternalFunctionFinder.cameraSetDrawSmooth( self, self.cameraPointer, self.smoothFlag )
- self.drawMenu.uncheck()
def disableText( self ):
'''Disable the timestamp and camera position texts (which appear when changing the camera angle or position). The text is on by default. The text can be re-enabled using METHOD(enable-text).'''
@@ -333,13 +327,6 @@ def enableShadows( self ):
self.shadowFlag = 1
breve.breveInternalFunctionFinder.setDrawShadow( self, self.shadowFlag )
- def enableSmoothDrawing( self ):
- '''Enable smooth drawing for the main camera. Smooth drawing enables a smoother blending of colors, textures and lighting. This feature is especially noticeable when dealing with spheres or large objects. <p> It is strongly recommended that smooth drawing be enabled whenever lighting is enabled (see METHOD(enable-lighting)). Otherwise, major artifacts may be visible, especially on larger polygons. <p> The disadvantage of smooth drawing is a potential performance hit. The degree of this performance hit depends on the number of polygons in the scene. If speed is an issue, it is often best to disable both lighting and smooth drawing.'''
-
- self.smoothFlag = 1
- breve.breveInternalFunctionFinder.cameraSetDrawSmooth( self, self.cameraPointer, self.smoothFlag )
- self.drawMenu.check()
-
def enableText( self ):
'''enables the timestamp and camera position texts (which appear when changing the camera angle or position). This is the default setting. The text can be disabled using METHOD(disable-text).'''
@@ -483,7 +470,6 @@ def init( self ):
self.addMenu( '''End Simulation''', 'endSimulation' )
self.addMenuSeparator()
self.lightMenu = self.addMenu( '''Use Lighting''', 'toggleLighting' )
- self.drawMenu = self.addMenu( '''Use Smooth Shading''', 'toggleSmooth' )
self.shadowMenu = self.addMenu( '''Draw Shadows''', 'toggleShadows' )
self.fogMenu = self.addMenu( '''Draw Fog''', 'toggleFog' )
self.reflectMenu = self.addMenu( '''Draw Reflections''', 'toggleReflections' )
@@ -491,7 +477,6 @@ def init( self ):
self.addMenuSeparator()
self.movieMenu = self.addMenu( '''Record Movie to "simulation.mpeg"''', 'toggleRecordingToMovie' )
self.addMenu( '''Save Snapshot to "simulation.png"''', 'saveSnapshotToFile' )
- self.enableSmoothDrawing()
self.disableLighting()
self.addMenuSeparator()
self.genericShape = breve.createInstances( breve.Sphere, 1 ).initWith( 1.000000 )
@@ -876,16 +861,6 @@ def toggleShadows( self ):
else:
self.enableShadowVolumes()
-
- def toggleSmooth( self ):
- '''Toggle smooth drawing for the main camera. See METHOD(enable-smooth-drawing) and METHOD(disable-smooth-drawing) for more information.'''
-
- if ( self.smoothFlag == 1 ):
- self.disableSmoothDrawing()
- else:
- self.enableSmoothDrawing()
-
-
def uniqueColor( self, n ):
'''Returns a unique color for each different value of n up to 198. These colors are allocated according to an algorithm which attempts to give distinguishable colors, though this is subjective and not always possible.'''
View
167 breve/simulation/patch.cc
@@ -76,11 +76,11 @@ void slPatch::setColor( slVector *color ) {
if ( color->z > 1.0 ) color->z = 1.0;
else if ( color->z < 0.0 ) color->z = 0.0;
- grid->colors[ this->colorOffset ] = ( unsigned char )( 255 * color->x );
- grid->colors[ this->colorOffset + 1 ] = ( unsigned char )( 255 * color->y );
- grid->colors[ this->colorOffset + 2 ] = ( unsigned char )( 255 * color->z );
+ grid -> colors[ this->colorOffset ] = ( unsigned char )( 255 * color->x );
+ grid -> colors[ this->colorOffset + 1 ] = ( unsigned char )( 255 * color->y );
+ grid -> colors[ this->colorOffset + 2 ] = ( unsigned char )( 255 * color->z );
- grid->_textureNeedsUpdate = true;
+ grid -> _textureNeedsUpdate = true;
}
/**
@@ -128,9 +128,7 @@ void slPatch::getLocation( slVector *location ) {
slPatchGrid::slPatchGrid() {
_drawWithTexture = 1;
- _cubeDrawList = -1;
_texture = NULL;
- _cubeDrawList = -1;
_textureNeedsUpdate = true;
}
@@ -148,10 +146,10 @@ slPatchGrid::slPatchGrid( const slVector *center, const slVector *patchSize, con
_zSize( z ) {
int a, b, c;
- _drawWithTexture = 1;
- _cubeDrawList = -1;
+ _drawWithTexture = true;
_texture = NULL;
- _cubeDrawList = -1;
+
+ fillCubeBuffer();
#ifdef WINDOWS
// oh windows, why do you have to be such a douchebag about everything?!
@@ -355,20 +353,13 @@ void slPatchGrid::copyColorFrom3DMatrix( slBigMatrix3DGSL *m, int channel, doubl
* \brief Draws the patch grid without using 3D textures.
*/
-void slPatchGrid::drawWithout3DTexture( slCamera *camera ) {
-#ifndef OPENGLES
+void slPatchGrid::drawWithout3DTexture( slRenderGL &inRenderer, slCamera *camera ) {
int z, y, x;
unsigned int zVal, yVal, xVal;
int zMid = 0, yMid = 0, xMid = 0;
slPatch *patch;
slVector translation, origin;
-
- glDisable( GL_LIGHTING );
- glDisable(GL_CULL_FACE);
- glDepthMask( GL_FALSE );
-
- if ( _cubeDrawList == -1 ) this->compileCubeList();
-
+
// we want to always draw from back to front for the
// alpha blending to work. figure out the points
// closest to the camera.
@@ -387,8 +378,8 @@ void slPatchGrid::drawWithout3DTexture( slCamera *camera ) {
if ( zMid < 0 ) zMid = 0;
if ( zMid >= (int)_zSize ) zMid = _zSize - 1;
- glEnable( GL_BLEND );
-
+ inRenderer.SetBlendMode( slBlendAlpha );
+
for ( z = 0; z < ( int )_zSize; z++ ) {
if ( z < ( int )zMid ) zVal = z;
else zVal = ( _zSize - 1 ) - ( z - zMid );
@@ -408,25 +399,23 @@ void slPatchGrid::drawWithout3DTexture( slCamera *camera ) {
patch = &patches[ zVal ][ xVal ][ yVal ];
if ( colors[ patch->colorOffset + 3 ] != 255 ) {
- glPushMatrix();
-
translation.y = startPosition.y + patchSize.y * yVal;
- glColor4ubv( &colors[patch->colorOffset] );
- glTranslatef( translation.x, translation.y, translation.z );
- glScalef( patchSize.x, patchSize.y, patchSize.z );
+ inRenderer.PushMatrix( slMatrixGeometry );
+
+ inRenderer.SetBlendColor( &colors[ patch->colorOffset ] );
+ inRenderer.Translate( slMatrixGeometry, translation.x, translation.y, translation.z );
+ inRenderer.Scale( slMatrixGeometry, patchSize.x, patchSize.y, patchSize.z );
- glCallList( _cubeDrawList );
+ _cubeBuffer.bind();
+ _cubeBuffer.draw( VB_TRIANGLE_STRIP );
+ _cubeBuffer.unbind();
- glPopMatrix();
+ inRenderer.PopMatrix( slMatrixGeometry );
}
}
}
}
-
- glDepthMask( GL_TRUE );
- glEnable( GL_CULL_FACE );
-#endif
}
@@ -443,19 +432,23 @@ void slPatchGrid::setDrawWithTexture( bool t ) {
* is slower than drawing with a 3D texture.
*/
-void slPatchGrid::draw( slCamera *camera ) {
-#ifndef OPENGLES
+void slPatchGrid::draw( slRenderGL &inRenderer, slCamera *camera ) {
slVector origin, diff, adiff, size;
- if ( !_drawWithTexture ) return drawWithout3DTexture( camera );
-
- glDisable( GL_LIGHTING );
-
#ifdef WINDOWS
if( !glTexImage3D || !glTexSubImage3D )
- return drawWithout3DTexture( camera );
+ _drawWithTexture = false;
+#endif
+
+
+#ifdef OPENGLES
+ // No GL_TEXTURE_3D support with OpenGL ES
+ _drawWithTexture = false;
#endif
+ if ( !_drawWithTexture )
+ return drawWithout3DTexture( inRenderer, camera );
+
if ( !_texture ) {
_texture = new slTexture2D();
_texture -> createTextureID();
@@ -496,7 +489,6 @@ void slPatchGrid::draw( slCamera *camera ) {
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
if( _textureNeedsUpdate ) {
- // glPixelStorei( GL_UNPACK_ROW_LENGTH, _ySize );
glPixelTransferf( GL_ALPHA_SCALE, 3.0f );
glTexSubImage3D( GL_TEXTURE_3D, 0, 0, 0, 0, _ySize, _xSize, _zSize, GL_RGBA, GL_UNSIGNED_BYTE, colors );
glPixelTransferf( GL_ALPHA_SCALE, 1.0f );
@@ -504,6 +496,7 @@ void slPatchGrid::draw( slCamera *camera ) {
_textureNeedsUpdate = false;
}
+ _quadBuffer.bind();
glBegin( GL_QUADS );
size.x = patchSize.x * _xSize;
@@ -519,12 +512,11 @@ void slPatchGrid::draw( slCamera *camera ) {
glEnd();
- glDisable( GL_TEXTURE_3D );
+ _quadBuffer.unbind();
- glDisable( GL_LIGHTING );
+ glDisable( GL_TEXTURE_3D );
return;
-#endif
}
void slPatchGrid::textureDrawYPass( slVector &size, int dir ) {
@@ -644,30 +636,71 @@ void slPatchGrid::setDataAtIndex( int x, int y, int z, void *data ) {
this->patches[ z ][ x ][ y ].data = data;
}
-void slPatchGrid::compileCubeList() {
-#ifndef OPENGLES
- _cubeDrawList = glGenLists( 1 );
-
- glNewList( _cubeDrawList, GL_COMPILE );
-
- glBegin( GL_TRIANGLE_STRIP );
- glVertex3f( 0.0, 0.0, 0.0 );
- glVertex3f( 1.0, 0.0, 0.0 );
- glVertex3f( 0.0, 0.0, 1.0 );
- glVertex3f( 1.0, 0.0, 1.0 );
- glVertex3f( 1.0, 1.0, 1.0 );
- glVertex3f( 1.0, 0.0, 0.0 );
- glVertex3f( 1.0, 1.0, 0.0 );
- glVertex3f( 0.0, 0.0, 0.0 );
- glVertex3f( 0.0, 1.0, 0.0 );
- glVertex3f( 0.0, 0.0, 1.0 );
- glVertex3f( 0.0, 1.0, 1.0 );
- glVertex3f( 1.0, 1.0, 1.0 );
- glVertex3f( 0.0, 1.0, 0.0 );
- glVertex3f( 1.0, 1.0, 0.0 );
-
- glEnd();
+void slPatchGrid::fillCubeBuffer() {
+ _cubeBuffer.resize( 14, VB_XYZ );
+
+ float *v;
+
+ v = _cubeBuffer.vertex( 0 );
+ v[ 0 ] = -.5; v[ 1 ] = -.5; v[ 2 ] = -.5;
+
+ v = _cubeBuffer.vertex( 1 );
+ v[ 0 ] = .5; v[ 1 ] = -.5; v[ 2 ] = -.5;
+
+ v = _cubeBuffer.vertex( 2 );
+ v[ 0 ] = -.5; v[ 1 ] = -.5; v[ 2 ] = .5;
+
+ v = _cubeBuffer.vertex( 3 );
+ v[ 0 ] = .5; v[ 1 ] = -.5; v[ 2 ] = .5;
+
+ v = _cubeBuffer.vertex( 4 );
+ v[ 0 ] = .5; v[ 1 ] = .5; v[ 2 ] = .5;
+
+ v = _cubeBuffer.vertex( 5 );
+ v[ 0 ] = .5; v[ 1 ] = -.5; v[ 2 ] = -.5;
+
+ v = _cubeBuffer.vertex( 6 );
+ v[ 0 ] = .5; v[ 1 ] = .5; v[ 2 ] = -.5;
+
+ v = _cubeBuffer.vertex( 7 );
+ v[ 0 ] = -.5; v[ 1 ] = -.5; v[ 2 ] = -.5;
+
+ v = _cubeBuffer.vertex( 8 );
+ v[ 0 ] = -.5; v[ 1 ] = .5; v[ 2 ] = -.5;
+
+ v = _cubeBuffer.vertex( 9 );
+ v[ 0 ] = -.5; v[ 1 ] = -.5; v[ 2 ] = .5;
+
+ v = _cubeBuffer.vertex( 10 );
+ v[ 0 ] = -.5; v[ 1 ] = .5; v[ 2 ] = .5;
+
+ v = _cubeBuffer.vertex( 11 );
+ v[ 0 ] = .5; v[ 1 ] = .5; v[ 2 ] = .5;
+
+ v = _cubeBuffer.vertex( 12 );
+ v[ 0 ] = -.5; v[ 1 ] = .5; v[ 2 ] = -.5;
+
+ v = _cubeBuffer.vertex( 13 );
+ v[ 0 ] = .5; v[ 1 ] = .5; v[ 2 ] = -.5;
+
+
+ _quadBuffer.resize( 6, VB_XY );
+ v = _quadBuffer.vertex( 0 );
+ v[ 0 ] = -.5; v[ 1 ] = -.5;
+
+ v = _quadBuffer.vertex( 1 );
+ v[ 0 ] = -.5; v[ 1 ] = .5;
+
+ v = _quadBuffer.vertex( 2 );
+ v[ 0 ] = .5; v[ 1 ] = .5;
+
+ v = _quadBuffer.vertex( 3 );
+ v[ 0 ] = .5; v[ 1 ] = .5;
+
+ v = _quadBuffer.vertex( 4 );
+ v[ 0 ] = .5; v[ 1 ] = -.5;
+
+ v = _quadBuffer.vertex( 5 );
+ v[ 0 ] = -.5; v[ 1 ] = -.5;
- glEndList();
-#endif
}
View
10 breve/simulation/world.cc
@@ -212,6 +212,7 @@ void slWorld::draw( slRenderGL& inRenderer, slCamera *inCamera ) {
_skybox.draw( inRenderer, inCamera );
+ drawPatchGrids( inRenderer, inCamera );
if( inCamera -> _drawLights ) {
for( int n = 0; n < MAX_LIGHTS; n++ ) {
@@ -247,6 +248,15 @@ void slWorld::draw( slRenderGL& inRenderer, slCamera *inCamera ) {
}
+void slWorld::drawPatchGrids( slRenderGL& inRenderer, slCamera *inCamera ) {
+ for ( unsigned int n = 0; n < _patches.size(); n++ ) {
+ slPatchGrid *pg = _patches[ n ];
+
+ if( pg )
+ pg -> draw( inRenderer, inCamera );
+ }
+}
+
void slWorld::drawObjects( slRenderGL& inRenderer ) {
for ( unsigned int n = 0; n < _objects.size(); n++ ) {
slWorldObject *wo = _objects[ n ];
Please sign in to comment.
Something went wrong with that request. Please try again.