Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gl_light.h File Reference
#include "gfxlib.h"
#include "hashtable_3d.h"
#include "gl_globals.h"

Go to the source code of this file.

Classes

class  gfx_light
 
struct  OpenGLLights
 
struct  LineCollideStar
 A sortable line collide object that will sort by object addr for dup elim. More...
 

Namespaces

 OpenGLL
 

Constant Groups

 OpenGLL
 

Macros

#define GFX_ATTENUATED   1
 
#define GFX_LIGHT_ENABLED   32
 
#define GFX_LOCAL_LIGHT   64
 
#define CTACC   40000
 

Functions

void light_rekey_frame ()
 Rekeys a frame, remembering trashing old lights activated last frame. More...
 
void unpicklights ()
 picks doubtless changed position More...
 
void removelightfromnewpick (int whichlight)
 
int findLocalClobberable ()
 Finds the local lights that are clobberable for new lights (permanent perhaps) More...
 

Variables

GLint GFX_MAX_LIGHTS
 
GLint GFX_OPTIMAL_LIGHTS
 
GFXBOOL GFXLIGHTING
 
const unsigned int lighthuge = 20*20*20
 
const char OpenGLL::GLL_OFF = 0
 If a light is off. More...
 
const char OpenGLL::GLL_ON = 1
 If a light is on. More...
 
const char OpenGLL::GLL_LOCAL = 2
 If a light is local or not. More...
 
const char OpenGLL::GL_ENABLED = 4
 If a light is enabled for OpenGL. More...
 
int _currentContext
 The curren tlight context. More...
 
vector< vector< gfx_light > > _local_lights_dat
 The light data _llights points to one of these. More...
 
vector< GFXColor_ambient_light
 The ambient lights that are around. More...
 
vector< gfx_light > * _llights
 The lights existing in a certain context. Points to _local_lights_dat. More...
 
int _GLLightsEnabled
 How many lights are enabled (for fast picking) More...
 
OpenGLLightsGLLights
 currently stored GL lights! More...
 
Hashtable3d< LineCollideStar,
20, CTACC, lighthuge
lighttable
 table to store local lights, numerical pointers to _llights (eg indices) More...
 
float intensity_cutoff
 something that would normally round down More...
 
float optintense
 optimization globals More...
 
float optsat
 

Macro Definition Documentation

#define CTACC   40000

Definition at line 161 of file gl_light.h.

#define GFX_ATTENUATED   1

Definition at line 9 of file gl_light.h.

Referenced by GFXLight::apply_attenuate().

#define GFX_LIGHT_ENABLED   32

Definition at line 14 of file gl_light.h.

Referenced by GFXLight::disable(), GFXLight::enable(), and gfx_light::enabled().

#define GFX_LOCAL_LIGHT   64

Definition at line 15 of file gl_light.h.

Referenced by gfx_light::Create(), and gfx_light::LocalLight().

Function Documentation

int findLocalClobberable ( )

Finds the local lights that are clobberable for new lights (permanent perhaps)

Definition at line 161 of file gl_light_state.cpp.

References GFX_MAX_LIGHTS, OpenGLL::GLL_ON, GLLights, i, and index.

Referenced by gfx_light::Create(), and gfx_light::dopickenables().

162 {
163  int clobberdisabled = -1;
164  for (int i = 0; i < GFX_MAX_LIGHTS; i++) {
165  if (GLLights[i].index == -1)
166  return i;
167  if ( !(GLLights[i].options&OpenGLL::GLL_ON) )
168  clobberdisabled = i;
169  }
170  return clobberdisabled;
171 }
void light_rekey_frame ( )

Rekeys a frame, remembering trashing old lights activated last frame.

Definition at line 498 of file gl_light_state.cpp.

References _llights, GFX_MAX_LIGHTS, OpenGLL::GL_ENABLED, GLLights, i, OpenGLLights::index, index, OpenGLLights::options, and unpicklights().

Referenced by GFXBeginScene().

499 {
500  unpicklights(); //picks doubtless changed position
501  for (int i = 0; i < GFX_MAX_LIGHTS; i++) {
502  if (GLLights[i].options&OpenGLL::GL_ENABLED) {
503  if (GLLights[i].index >= 0) {
504  if ( (*_llights)[GLLights[i].index].Target() == i ) {
505  (*_llights)[GLLights[i].index].SendGLPosition( GL_LIGHT0+i ); //send position transformed by current cam matrix
506  } else {
507  unsigned int li = GLLights[i].index;
508  if ( (*_llights)[li].enabled() && ( (*_llights)[li].Target() == -1 ) ) {
509  (*_llights)[li].ClobberGLLight( i );
510  } else {
511  glDisable( GL_LIGHT0+i );
512  GLLights[i].index = -1;
513  }
514  }
515  } else {
516  glDisable( GL_LIGHT0+i );
517  GLLights[i].options &= (~OpenGLL::GL_ENABLED);
518  }
519  }
520  }
521 }
void removelightfromnewpick ( int  whichlight)

Definition at line 44 of file gl_light_pick.cpp.

References i, and pickedlights.

Referenced by gfx_light::TrashFromGLLights().

44  {
45  std::vector<int>::iterator where;
46  for (int i=0;i<2;++i) {
47  while ((where=std::find(pickedlights[i].begin(),pickedlights[i].end(),index))!=pickedlights[i].end()) {
48  pickedlights[i].erase(where);
49  }
50  }
51 }
void unpicklights ( )

picks doubtless changed position

Definition at line 69 of file gl_light_pick.cpp.

References _llights, OpenGLL::GL_ENABLED, OpenGLL::GLL_LOCAL, GLLights, i, OpenGLLights::index, newpicked, oldpicked, OpenGLLights::options, and VSFileSystem::vs_fprintf().

Referenced by GFXPushGlobalEffects(), GFXSetLightContext(), and light_rekey_frame().

70 {
71  for (std::vector< int >::iterator i = newpicked->begin(); i != newpicked->end(); i++) {
72  if (*i>=(int)_llights->size()) {
73  VSFileSystem::vs_fprintf (stderr,"GFXLIGHT FAILURE %d is beyond array of size %d",(int)*i,(int)_llights->size());
74  }
75  if (GLLights[(*_llights)[*i].Target()].index != *i) {
76  VSFileSystem::vs_fprintf (stderr,"GFXLIGHT uh oh");
77  (*_llights)[*i].Target() = -1;
78  continue; //a lengthy operation... Since picked lights may have been smashed
79  }
80  int targ = (*_llights)[*i].Target();
81  if (GLLights[targ].options&OpenGLL::GL_ENABLED) {
82  glDisable( GL_LIGHT0+targ );
84  GLLights[targ].index = -1;
85  (*_llights)[*i].Target() = -1; //unref
86  }
87  }
88  newpicked->clear();
89  oldpicked->clear();
90 }

Variable Documentation

vector< GFXColor > _ambient_light

The ambient lights that are around.

Definition at line 36 of file gl_light.cpp.

Referenced by GFXCreateLightContext(), GFXGetLightContextAmbient(), GFXLightContextAmbient(), GFXPushGlobalEffects(), and GFXSetLightContext().

int _currentContext
int _GLLightsEnabled

How many lights are enabled (for fast picking)

Definition at line 144 of file gl_light_state.cpp.

Referenced by gfx_light::Create(), gfx_light::Disable(), gfx_light::Enable(), and GFXPickLights().

vector< gfx_light >* _llights

The lights existing in a certain context. Points to _local_lights_dat.

Definition at line 37 of file gl_light.cpp.

Referenced by gfx_light::dopickenables(), GFXCreateLight(), GFXDisableLight(), GFXEnableLight(), GFXSetLight(), GFXSetLightContext(), light_rekey_frame(), gfx_light::lightNum(), gfx_light::TrashFromGLLights(), and unpicklights().

vector< vector< gfx_light > > _local_lights_dat

The light data _llights points to one of these.

Definition at line 35 of file gl_light.cpp.

Referenced by GFXCreateLightContext(), GFXDeleteLightContext(), and GFXSetLightContext().

GLint GFX_OPTIMAL_LIGHTS

Definition at line 31 of file gl_light.cpp.

Referenced by GFXSetOptimalNumLights().

GFXBOOL GFXLIGHTING

Definition at line 32 of file gl_light.cpp.

float intensity_cutoff

something that would normally round down

Definition at line 14 of file gl_light_pick.cpp.

Referenced by gfx_light::CalculateBounds(), and GFXSetCutoff().

const unsigned int lighthuge = 20*20*20

Definition at line 16 of file gl_light.h.

table to store local lights, numerical pointers to _llights (eg indices)

Definition at line 145 of file gl_light_state.cpp.

Referenced by GFXDestroyAllLights(), GFXPickLights(), and GFXSetLightContext().

float optintense

optimization globals

Definition at line 15 of file gl_light_pick.cpp.

Referenced by GFXSetOptimalIntensity().

float optsat

Definition at line 16 of file gl_light_pick.cpp.

Referenced by GFXSetOptimalIntensity().