void GFXVertexList::EndDrawState( GFXBOOL lock ) { if (vbo_data) { #ifndef NO_VBO_SUPPORT if (gl_options.Multitexture) { glClientActiveTextureARB_p( GL_TEXTURE0 ); glDisableClientState( GL_TEXTURE_COORD_ARRAY ); glClientActiveTextureARB_p( GL_TEXTURE1 ); glDisableClientState( GL_TEXTURE_COORD_ARRAY ); glClientActiveTextureARB_p( GL_TEXTURE2 ); glDisableClientState( GL_TEXTURE_COORD_ARRAY ); glClientActiveTextureARB_p( GL_TEXTURE0 ); } else { glDisableClientState( GL_TEXTURE_COORD_ARRAY ); } #endif } else if (display_list != 0) {} else { #ifndef NO_COMPILEDVERTEXARRAY_SUPPORT if (lock && glUnlockArraysEXT_p && numVertices) (*glUnlockArraysEXT_p)(); #endif } if (changed&HAS_COLOR) GFXColor4f( 1, 1, 1, 1 ); }
void Box::ProcessDrawQueue( int ) { if ( !draw_queue[0].size() ) return; GFXBlendMode( SRCALPHA, INVSRCALPHA ); GFXColor( 0.0, .90, .3, .4 ); GFXDisable( LIGHTING ); GFXDisable( TEXTURE0 ); GFXDisable( TEXTURE1 ); GFXDisable( DEPTHWRITE ); GFXDisable( CULLFACE ); //GFXBlendMode(ONE, ONE); while ( draw_queue[0].size() ) { GFXLoadMatrixModel( draw_queue[0].back().mat ); draw_queue[0].pop_back(); GFXBegin( GFXQUAD ); GFXColor4f( 0.0, 1.0, 0.0, 0.2 ); GFXVertex3f( corner_max.i, corner_min.j, corner_max.k ); GFXVertex3f( corner_max.i, corner_max.j, corner_max.k ); GFXVertex3f( corner_min.i, corner_max.j, corner_max.k ); GFXVertex3f( corner_min.i, corner_min.j, corner_max.k ); GFXColor4f( 0.0, 1.0, 0.0, 0.2 ); GFXVertex3f( corner_min.i, corner_min.j, corner_min.k ); GFXVertex3f( corner_min.i, corner_max.j, corner_min.k ); GFXVertex3f( corner_max.i, corner_max.j, corner_min.k ); GFXVertex3f( corner_max.i, corner_min.j, corner_min.k ); GFXColor4f( 0.0, .70, 0.0, 0.2 ); GFXVertex3f( corner_max.i, corner_min.j, corner_max.k ); GFXVertex3f( corner_min.i, corner_min.j, corner_max.k ); GFXVertex3f( corner_min.i, corner_min.j, corner_min.k ); GFXVertex3f( corner_max.i, corner_min.j, corner_min.k ); GFXColor4f( 0.0, .70, 0.0, 0.2 ); GFXVertex3f( corner_max.i, corner_max.j, corner_min.k ); GFXVertex3f( corner_min.i, corner_max.j, corner_min.k ); GFXVertex3f( corner_min.i, corner_max.j, corner_max.k ); GFXVertex3f( corner_max.i, corner_max.j, corner_max.k ); GFXColor4f( 0.0, .90, .3, 0.2 ); GFXVertex3f( corner_max.i, corner_max.j, corner_max.k ); GFXVertex3f( corner_max.i, corner_min.j, corner_max.k ); GFXVertex3f( corner_max.i, corner_min.j, corner_min.k ); GFXVertex3f( corner_max.i, corner_max.j, corner_min.k ); GFXColor4f( 0.0, .90, .3, 0.2 ); GFXVertex3f( corner_min.i, corner_max.j, corner_min.k ); GFXVertex3f( corner_min.i, corner_min.j, corner_min.k ); GFXVertex3f( corner_min.i, corner_min.j, corner_max.k ); GFXVertex3f( corner_min.i, corner_max.j, corner_max.k ); GFXEnd(); /* * vlist->Draw(); * if(quadstrips!=NULL) { * for(int a=0; a<numQuadstrips; a++) * quadstrips[a]->Draw() * ; * } */ } GFXEnable( DEPTHWRITE ); }
//#define UPDATEDEBUG //for hard to track down bugs void GameStarSystem::Draw(bool DrawCockpit) { double starttime=queryTime(); GFXEnable (DEPTHTEST); GFXEnable (DEPTHWRITE); saved_interpolation_blend_factor=interpolation_blend_factor = (1./PHY_NUM)*((PHY_NUM*time)/SIMULATION_ATOM+current_stage); GFXColor4f(1,1,1,1); if (DrawCockpit) { AnimatedTexture::UpdateAllFrame(); } for (unsigned int i=0;i<contterrains.size();++i) { contterrains[i]->AdjustTerrain(this); } Unit * par; bool alreadysetviewport=false; if ((par=_Universe->AccessCockpit()->GetParent())==NULL) { _Universe->AccessCamera()->UpdateGFX (GFXTRUE); } else { if (!par->isSubUnit()) { //now we can assume world is topps par-> cumulative_transformation = linear_interpolate (par->prev_physical_state,par->curr_physical_state,interpolation_blend_factor); Unit * targ = par->Target(); if (targ&&!targ->isSubUnit()) { targ-> cumulative_transformation = linear_interpolate (targ->prev_physical_state,targ->curr_physical_state,interpolation_blend_factor); } _Universe->AccessCockpit()->SetupViewPort(true); alreadysetviewport=true; } } double setupdrawtime=queryTime(); { cam_setup_phase=true; //int numships=0; Unit * saveparent=_Universe->AccessCockpit()->GetSaveParent(); Unit * targ=NULL; if (saveparent) { targ=saveparent->Target(); } //Array containing the two interesting units, so as not to have to copy-paste code Unit * camunits[2]={saveparent,targ}; float backup=SIMULATION_ATOM; unsigned int cur_sim_frame = _Universe->activeStarSystem()->getCurrentSimFrame(); for(int i=0;i<2;++i) { Unit *unit=camunits[i]; // Make sure unit is not null; if(unit&&!unit->isSubUnit()) { interpolation_blend_factor=calc_blend_factor(saved_interpolation_blend_factor,unit->sim_atom_multiplier,unit->cur_sim_queue_slot,cur_sim_frame); SIMULATION_ATOM = backup*unit->sim_atom_multiplier; ((GameUnit<Unit> *)unit)->GameUnit<Unit>::Draw(); } } interpolation_blend_factor=saved_interpolation_blend_factor; SIMULATION_ATOM=backup; //printf("Number of insystem ships: %d (%d FPS)\n",numships,(int)(1.f/GetElapsedTime())); ///this is the final, smoothly calculated cam _Universe->AccessCockpit()->SetupViewPort(true); cam_setup_phase=false; } setupdrawtime=queryTime()-setupdrawtime; GFXDisable (LIGHTING); bg->Draw(); double drawtime=queryTime(); double maxdrawtime=0; //Ballpark estimate of when an object of configurable size first becomes one pixel QVector drawstartpos=_Universe->AccessCamera()->GetPosition(); Collidable key_iterator(0,1,drawstartpos); UnitWithinRangeOfPosition<UnitDrawer> drawer(game_options.precull_dist,0,key_iterator); //Need to draw really big stuff (i.e. planets, deathstars, and other mind-bogglingly big things that shouldn't be culled despited extreme distance Unit* unit; if ((drawer.action.parent=_Universe->AccessCockpit()->GetParent())!=NULL) { drawer.action.parenttarget=drawer.action.parent->Target(); } for(un_iter iter=this->GravitationalUnits.createIterator();(unit=*iter)!=NULL;++iter) { float distance = (drawstartpos-unit->Position()).Magnitude()-unit->rSize(); if(distance < game_options.precull_dist) { drawer.action.grav_acquire(unit); } else { drawer.action.draw(unit); } } // Need to get iterator to approx camera position CollideMap::iterator parent=collidemap[Unit::UNIT_ONLY]->lower_bound(key_iterator); findObjectsFromPosition(this->collidemap[Unit::UNIT_ONLY],parent,&drawer,drawstartpos,0,true); drawer.action.drawParents();//draw units targeted by camera //FIXME maybe we could do bolts & units instead of unit only--and avoid bolt drawing step #if 0 for (unsigned int sim_counter=0;sim_counter<=SIM_QUEUE_SIZE;++sim_counter) { double tmp=queryTime(); Unit *unit; UnitCollection::UnitIterator iter = physics_buffer[sim_counter].createIterator(); float backup=SIMULATION_ATOM; unsigned int cur_sim_frame = _Universe->activeStarSystem()->getCurrentSimFrame(); while((unit = iter.current())!=NULL) { interpolation_blend_factor=calc_blend_factor(saved_interpolation_blend_factor,unit->sim_atom_multiplier,unit->cur_sim_queue_slot,cur_sim_frame); //if (par&&par->Target()==unit) { //printf ("i:%f s:%f m:%d c:%d l:%d\n",interpolation_blend_factor,saved_interpolation_blend_factor,unit->sim_atom_multiplier,sim_counter,current_sim_location); //} SIMULATION_ATOM = backup*unit->sim_atom_multiplier; ((GameUnit<Unit> *)unit)->Draw(); iter.advance(); } interpolation_blend_factor=saved_interpolation_blend_factor; SIMULATION_ATOM=backup; tmp=queryTime()-tmp; if (tmp>maxdrawtime)maxdrawtime=tmp; } #endif drawtime=queryTime()-drawtime; WarpTrailDraw(); GFXFogMode (FOG_OFF); GFXColor tmpcol (0,0,0,1); GFXGetLightContextAmbient(tmpcol); double processmesh=queryTime(); if (!game_options.draw_near_stars_in_front_of_planets) stars->Draw(); Mesh::ProcessZFarMeshes(); if (game_options.draw_near_stars_in_front_of_planets) stars->Draw(); GFXEnable (DEPTHTEST); GFXEnable (DEPTHWRITE); //need to wait for lights to finish GamePlanet::ProcessTerrains(); Terrain::RenderAll(); Mesh::ProcessUndrawnMeshes(true); processmesh=queryTime()-processmesh; Nebula * neb; Matrix ident; Identity(ident); //Atmosphere::ProcessDrawQueue(); GFXPopGlobalEffects(); GFXLightContextAmbient(tmpcol); if ((neb = _Universe->AccessCamera()->GetNebula())) { neb->SetFogState(); } Beam::ProcessDrawQueue(); Bolt::Draw(); // if (_Universe->AccessCamera()->GetNebula()!=NULL) GFXFogMode (FOG_OFF); Animation::ProcessDrawQueue(); Halo::ProcessDrawQueue(); particleTrail.DrawAndUpdate(); GameStarSystem::DrawJumpStars(); ConditionalCursorDraw(false); // static bool doInputDFA = XMLSupport::parse_bool (vs_config->getVariable ("graphics","MouseCursor","false")); if (DrawCockpit) { _Universe->AccessCockpit()->Draw(); // if (doInputDFA) { // GFXHudMode (true); // systemInputDFA->Draw(); // GFXHudMode (false); // } } double fintime=queryTime()-starttime; if (debugPerformance()) { printf("draw: %f setup %f units %f maxunit %f processmesh %f ",fintime,setupdrawtime,drawtime,maxdrawtime,processmesh); } }