Tweaks and optimizations by Norman Vine.
This commit is contained in:
parent
6438a27244
commit
f7e6fca7dd
4 changed files with 90 additions and 89 deletions
|
@ -65,14 +65,13 @@ fgMATERIAL::fgMATERIAL ( void )
|
|||
}
|
||||
|
||||
|
||||
int fgMATERIAL::append_sort_list( fgFRAGMENT *object ) {
|
||||
if ( list_size < FG_MAX_MATERIAL_FRAGS )
|
||||
{
|
||||
int
|
||||
fgMATERIAL::append_sort_list( fgFRAGMENT *object )
|
||||
{
|
||||
if ( list_size < FG_MAX_MATERIAL_FRAGS ) {
|
||||
list[ list_size++ ] = object;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -82,8 +81,7 @@ operator >> ( istream& in, fgMATERIAL& m )
|
|||
{
|
||||
string token;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
for (;;) {
|
||||
in >> token;
|
||||
if ( token == "texture" )
|
||||
{
|
||||
|
@ -134,8 +132,6 @@ operator >> ( istream& in, fgMATERIAL& m )
|
|||
void
|
||||
fgMATERIAL::load_texture()
|
||||
{
|
||||
if ( current_options.get_textures() )
|
||||
{
|
||||
GLubyte *texbuf;
|
||||
int width, height;
|
||||
|
||||
|
@ -215,7 +211,6 @@ fgMATERIAL::load_texture()
|
|||
xglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, texbuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -226,6 +221,7 @@ fgMATERIAL::~fgMATERIAL ( void ) {
|
|||
|
||||
// Constructor
|
||||
fgMATERIAL_MGR::fgMATERIAL_MGR ( void ) {
|
||||
textures_loaded = false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -271,7 +267,9 @@ fgMATERIAL::render_fragments()
|
|||
|
||||
|
||||
// Load a library of material properties
|
||||
int fgMATERIAL_MGR::load_lib ( void ) {
|
||||
int
|
||||
fgMATERIAL_MGR::load_lib ( void )
|
||||
{
|
||||
string material_name;
|
||||
|
||||
// build the path name to the material db
|
||||
|
@ -297,23 +295,27 @@ int fgMATERIAL_MGR::load_lib ( void ) {
|
|||
printf( " Loading material %s\n", material_name.c_str() );
|
||||
fgMATERIAL m;
|
||||
in.stream() >> m;
|
||||
m.load_texture();
|
||||
|
||||
if ( current_options.get_textures() ) {
|
||||
m.load_texture();
|
||||
}
|
||||
|
||||
material_mgr.material_map[material_name] = m;
|
||||
}
|
||||
}
|
||||
|
||||
// iterator last = end();
|
||||
// for ( iterator it = begin(); it != last; ++it )
|
||||
// {
|
||||
// (*it).second.load_texture();
|
||||
// }
|
||||
if ( current_options.get_textures() ) {
|
||||
textures_loaded = true;
|
||||
}
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
// Initialize the transient list of fragments for each material property
|
||||
void fgMATERIAL_MGR::init_transient_material_lists( void ) {
|
||||
void
|
||||
fgMATERIAL_MGR::init_transient_material_lists( void )
|
||||
{
|
||||
iterator last = end();
|
||||
for ( iterator it = begin(); it != last; ++it )
|
||||
{
|
||||
|
@ -321,6 +323,7 @@ void fgMATERIAL_MGR::init_transient_material_lists( void ) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
fgMATERIAL_MGR::find( const string& material, fgMATERIAL*& mtl_ptr )
|
||||
{
|
||||
|
@ -351,6 +354,9 @@ fgMATERIAL_MGR::render_fragments()
|
|||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.7 1998/09/17 18:35:52 curt
|
||||
// Tweaks and optimizations by Norman Vine.
|
||||
//
|
||||
// Revision 1.6 1998/09/15 01:35:05 curt
|
||||
// cleaned up my fragment.num_faces hack :-) to use the STL (no need in
|
||||
// duplicating work.)
|
||||
|
|
|
@ -131,6 +131,8 @@ public:
|
|||
// Load a library of material properties
|
||||
int load_lib ( void );
|
||||
|
||||
bool get_textures_loaded() { return textures_loaded; }
|
||||
|
||||
// Initialize the transient list of fragments for each material property
|
||||
void init_transient_material_lists( void );
|
||||
|
||||
|
@ -143,6 +145,9 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
// Have textures been loaded
|
||||
bool textures_loaded;
|
||||
|
||||
container material_map;
|
||||
};
|
||||
|
||||
|
@ -155,6 +160,9 @@ extern fgMATERIAL_MGR material_mgr;
|
|||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.4 1998/09/17 18:35:53 curt
|
||||
// Tweaks and optimizations by Norman Vine.
|
||||
//
|
||||
// Revision 1.3 1998/09/10 19:07:12 curt
|
||||
// /Simulator/Objects/fragment.hxx
|
||||
// Nested fgFACE inside fgFRAGMENT since its not used anywhere else.
|
||||
|
|
|
@ -86,6 +86,40 @@ public:
|
|||
|
||||
// Destructor
|
||||
~fgTILE ( void );
|
||||
|
||||
// Calculate this tile's offset
|
||||
void
|
||||
fgTILE::SetOffset( fgPoint3d *off)
|
||||
{
|
||||
offset.x = center.x - off->x;
|
||||
offset.y = center.y - off->y;
|
||||
offset.z = center.z - off->z;
|
||||
}
|
||||
|
||||
|
||||
// Calculate the model_view transformation matrix for this tile
|
||||
inline void
|
||||
fgTILE::UpdateViewMatrix(GLdouble *MODEL_VIEW)
|
||||
{
|
||||
|
||||
#ifdef WIN32
|
||||
memcpy( model_view, MODEL_VIEW, 16*sizeof(GLdouble) );
|
||||
#else
|
||||
bcopy( MODEL_VIEW, model_view, 16*sizeof(GLdouble) );
|
||||
#endif
|
||||
|
||||
// This is equivalent to doing a glTranslatef(x, y, z);
|
||||
model_view[12] += (model_view[0]*offset.x + model_view[4]*offset.y +
|
||||
model_view[8]*offset.z);
|
||||
model_view[13] += (model_view[1]*offset.x + model_view[5]*offset.y +
|
||||
model_view[9]*offset.z);
|
||||
model_view[14] += (model_view[2]*offset.x + model_view[6]*offset.y +
|
||||
model_view[10]*offset.z);
|
||||
// m[15] += (m[3]*x + m[7]*y + m[11]*z);
|
||||
// m[3] m7[] m[11] are 0.0 see LookAt() in views.cxx
|
||||
// so m[15] is unchanged
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -93,6 +127,9 @@ public:
|
|||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.19 1998/09/17 18:36:17 curt
|
||||
// Tweaks and optimizations by Norman Vine.
|
||||
//
|
||||
// Revision 1.18 1998/08/25 16:52:42 curt
|
||||
// material.cxx material.hxx obj.cxx obj.hxx texload.c texload.h moved to
|
||||
// ../Objects
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include <Weather/weather.h>
|
||||
|
||||
#include "scenery.hxx"
|
||||
#include "tile.hxx"
|
||||
#include "tilecache.hxx"
|
||||
|
||||
|
||||
|
@ -415,9 +416,9 @@ double fgTileMgrCurElev( double lon, double lat, fgPoint3d *abs_view_pos ) {
|
|||
MAT3vec local_up;
|
||||
list < fgFRAGMENT > :: iterator current;
|
||||
list < fgFRAGMENT > :: iterator last;
|
||||
double dist, min_dist, lat_geod, alt, sea_level_r;
|
||||
double dist, lat_geod, alt, sea_level_r;
|
||||
// double x, y, z;
|
||||
int index, tile_diameter, i;
|
||||
int index;
|
||||
|
||||
c = &global_tile_cache;
|
||||
// v = ¤t_view;
|
||||
|
@ -431,9 +432,9 @@ double fgTileMgrCurElev( double lon, double lat, fgPoint3d *abs_view_pos ) {
|
|||
index = c->exists(&p);
|
||||
t = c->get_tile(index);
|
||||
|
||||
// scenery.next_center.x = t->center.x;
|
||||
// scenery.next_center.y = t->center.y;
|
||||
// scenery.next_center.z = t->center.z;
|
||||
scenery.next_center.x = t->center.x;
|
||||
scenery.next_center.y = t->center.y;
|
||||
scenery.next_center.z = t->center.z;
|
||||
|
||||
earth_center.x = 0.0;
|
||||
earth_center.y = 0.0;
|
||||
|
@ -527,59 +528,33 @@ update_tile_geometry( fgTILE *t, GLdouble *MODEL_VIEW)
|
|||
|
||||
// Render the local tiles
|
||||
void fgTileMgrRender( void ) {
|
||||
fgTILECACHE *c;
|
||||
fgFLIGHT *f;
|
||||
fgTILE *t, *last_tile_ptr;
|
||||
fgTILECACHE *c;
|
||||
fgTILE *t;
|
||||
fgVIEW *v;
|
||||
fgBUCKET p;
|
||||
fgPoint3d frag_offset, pp;
|
||||
fgPoint3d earth_center, result;
|
||||
fgPoint3d frag_offset;
|
||||
fgFRAGMENT *frag_ptr;
|
||||
fgMATERIAL *mtl_ptr;
|
||||
GLdouble *m;
|
||||
double dist, min_dist, lat_geod, alt, sea_level_r;
|
||||
double x, y, z;
|
||||
list < fgFRAGMENT > :: iterator current;
|
||||
list < fgFRAGMENT > :: iterator last;
|
||||
int i, j, size;
|
||||
int tile_diameter, textures;
|
||||
int i;
|
||||
int tile_diameter;
|
||||
int index;
|
||||
int culled = 0;
|
||||
int drawn = 0;
|
||||
int total_faces = 0;
|
||||
|
||||
c = &global_tile_cache;
|
||||
f = current_aircraft.flight;
|
||||
v = ¤t_view;
|
||||
|
||||
tile_diameter = current_options.get_tile_diameter();
|
||||
textures = current_options.get_textures();
|
||||
|
||||
// Find current translation offset
|
||||
fgBucketFind(FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, &p);
|
||||
index = c->exists(&p);
|
||||
t = c->get_tile(index);
|
||||
|
||||
scenery.next_center.x = t->center.x;
|
||||
scenery.next_center.y = t->center.y;
|
||||
scenery.next_center.z = t->center.z;
|
||||
|
||||
earth_center.x = 0.0;
|
||||
earth_center.y = 0.0;
|
||||
earth_center.z = 0.0;
|
||||
|
||||
fgPrintf( FG_TERRAIN, FG_DEBUG,
|
||||
"Pos = (%.2f, %.2f) Current bucket = %d %d %d %d Index = %ld\n",
|
||||
FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG,
|
||||
p.lon, p.lat, p.x, p.y, fgBucketGenIndex(&p) );
|
||||
|
||||
// initialize the transient per-material fragment lists
|
||||
material_mgr.init_transient_material_lists();
|
||||
min_dist = 100000.0;
|
||||
|
||||
scenery.cur_elev = fgTileMgrCurElev( FG_Longitude, FG_Latitude,
|
||||
&(v->abs_view_pos) );
|
||||
|
||||
|
||||
// initialize the transient per-material fragment lists
|
||||
material_mgr.init_transient_material_lists();
|
||||
|
||||
// Pass 1
|
||||
// traverse the potentially viewable tile list
|
||||
for ( i = 0; i < (tile_diameter * tile_diameter); i++ ) {
|
||||
|
@ -588,34 +563,15 @@ void fgTileMgrRender( void ) {
|
|||
t = c->get_tile(index);
|
||||
|
||||
// calculate tile offset
|
||||
x = (t->offset.x = t->center.x - scenery.center.x);
|
||||
y = (t->offset.y = t->center.y - scenery.center.y);
|
||||
z = (t->offset.z = t->center.z - scenery.center.z);
|
||||
|
||||
#if defined( TEST_FOV_CLIP )
|
||||
if( viewable(&(t->offset), t->bounding_radius) !=
|
||||
viewable2(&(t->offset), t->bounding_radius) )
|
||||
{
|
||||
printf("FOV PROBLEM\n");
|
||||
exit(10);
|
||||
}
|
||||
#endif // defined( TEST_FOV_CLIP )
|
||||
t->SetOffset( &(scenery.center) );
|
||||
|
||||
// Course (tile based) culling
|
||||
if ( viewable(&(t->offset), t->bounding_radius) ) {
|
||||
// at least a portion of this tile could be viewable
|
||||
|
||||
m = t->model_view;
|
||||
for ( j = 0; j < 16; j++ ) {
|
||||
m[j] = v->MODEL_VIEW[j];
|
||||
}
|
||||
|
||||
// Calculate the model_view transformation matrix for this tile
|
||||
// This is equivalent to doing a glTranslatef(x, y, z);
|
||||
m[12] = m[0] * x + m[4] * y + m[8] * z + m[12];
|
||||
m[13] = m[1] * x + m[5] * y + m[9] * z + m[13];
|
||||
m[14] = m[2] * x + m[6] * y + m[10] * z + m[14];
|
||||
m[15] = m[3] * x + m[7] * y + m[11] * z + m[15];
|
||||
t->UpdateViewMatrix( v->MODEL_VIEW );
|
||||
|
||||
// xglPushMatrix();
|
||||
// xglTranslatef(t->offset.x, t->offset.y, t->offset.z);
|
||||
|
@ -633,15 +589,6 @@ void fgTileMgrRender( void ) {
|
|||
frag_offset.y = frag_ptr->center.y - scenery.center.y;
|
||||
frag_offset.z = frag_ptr->center.z - scenery.center.z;
|
||||
|
||||
#if defined( TEST_FOV_CLIP )
|
||||
radius = frag_ptr->bounding_radius*2;
|
||||
if ( viewable(&frag_offset, radius) !=
|
||||
viewable2(&frag_offset, radius) ) {
|
||||
printf("FOV PROBLEM\n");
|
||||
exit(10);
|
||||
}
|
||||
#endif // defined( TEST_FOV_CLIP )
|
||||
|
||||
if ( viewable(&frag_offset, frag_ptr->bounding_radius*2) ) {
|
||||
// add to transient per-material property fragment list
|
||||
// frag_ptr->tile_offset.x = t->offset.x;
|
||||
|
@ -690,6 +637,9 @@ void fgTileMgrRender( void ) {
|
|||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.38 1998/09/17 18:36:18 curt
|
||||
// Tweaks and optimizations by Norman Vine.
|
||||
//
|
||||
// Revision 1.37 1998/09/15 01:36:45 curt
|
||||
// cleaned up my fragment.num_faces hack :-) to use the STL (no need in
|
||||
// duplicating work.)
|
||||
|
|
Loading…
Add table
Reference in a new issue