From 5127990a435bb9f41c48e076c3c615279c879afe Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 21 Jul 2006 15:45:01 +0000 Subject: [PATCH] Additional functionality for animated point lights (i.e. approach light rabbits, REIL, VASI/PAPI, etc.) This allows the calling layer (i.e. FlightGear) better control over the use of OpenGL point drawing extensions. --- simgear/scene/tgdb/pt_lights.cxx | 79 +++++++++++++++++++++++++++++++- simgear/scene/tgdb/pt_lights.hxx | 7 +++ 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/simgear/scene/tgdb/pt_lights.cxx b/simgear/scene/tgdb/pt_lights.cxx index 76a89d71..21193f9c 100644 --- a/simgear/scene/tgdb/pt_lights.cxx +++ b/simgear/scene/tgdb/pt_lights.cxx @@ -25,18 +25,78 @@ #endif #include +#include #include +#include #include "vasi.hxx" #include "pt_lights.hxx" +// static variables for use in ssg callbacks +static bool extensions_checked = false; +static bool glPointParameterIsSupported = false; +static glPointParameterfProc glPointParameterfPtr; +static glPointParameterfvProc glPointParameterfvPtr; +static bool SGPointLightsUseSprites = false; +static bool SGPointLightsEnhancedLighting = false; +static bool SGPointLightsDistanceAttenuation = false; + + +// Specify the way we want to draw directional point lights (assuming the +// appropriate extensions are available.) + +void sgConfigureDirectionalLights( bool use_point_sprites, + bool enhanced_lighting, + bool distance_attenuation ) { + SGPointLightsUseSprites = use_point_sprites; + SGPointLightsEnhancedLighting = enhanced_lighting; + SGPointLightsDistanceAttenuation = distance_attenuation; +} + + +// runtime check for the availability of various opengl extensions. +static void check_for_extensions() { + // get the address of our OpenGL extensions + if (SGIsOpenGLExtensionSupported("GL_EXT_point_parameters") ) { + glPointParameterIsSupported = true; + glPointParameterfPtr = (glPointParameterfProc) + SGLookupFunction("glPointParameterfEXT"); + glPointParameterfvPtr = (glPointParameterfvProc) + SGLookupFunction("glPointParameterfvEXT"); + } else if ( SGIsOpenGLExtensionSupported("GL_ARB_point_parameters") ) { + glPointParameterIsSupported = true; + glPointParameterfPtr = (glPointParameterfProc) + SGLookupFunction("glPointParameterfARB"); + glPointParameterfvPtr = (glPointParameterfvProc) + SGLookupFunction("glPointParameterfvARB"); + } else { + glPointParameterIsSupported = false; + } +} + + // strobe pre-draw (we want a larger point size) static int StrobePreDraw( ssgEntity *e ) { + // check for the availability of point parameter extension, but + // just once. + if ( !extensions_checked ) { + check_for_extensions(); + extensions_checked = true; + } + glPushAttrib( GL_POINT_BIT ); - glPointSize(4.0); + if ( glPointParameterIsSupported && SGPointLightsEnhancedLighting ) { + if ( SGPointLightsUseSprites ) { + glPointSize(10.0); + } else { + glPointSize(8.0); + } + } else { + glPointSize(4.0); + } glEnable(GL_POINT_SMOOTH); return true; @@ -52,8 +112,23 @@ static int StrobePostDraw( ssgEntity *e ) { // vasi pre-draw (we want a larger point size) static int VASIPreDraw( ssgEntity *e ) { + // check for the availability of point parameter extension, but + // just once. + if ( !extensions_checked ) { + check_for_extensions(); + extensions_checked = true; + } + glPushAttrib( GL_POINT_BIT ); - glPointSize(2.0); + if ( glPointParameterIsSupported && SGPointLightsEnhancedLighting ) { + if ( SGPointLightsUseSprites ) { + glPointSize(10.0); + } else { + glPointSize(8.0); + } + } else { + glPointSize(4.0); + } glEnable(GL_POINT_SMOOTH); return true; diff --git a/simgear/scene/tgdb/pt_lights.hxx b/simgear/scene/tgdb/pt_lights.hxx index 7e5aa5ed..de5240a3 100644 --- a/simgear/scene/tgdb/pt_lights.hxx +++ b/simgear/scene/tgdb/pt_lights.hxx @@ -90,5 +90,12 @@ ssgBranch *sgMakeDirectionalLights( const point_list &nodes, const string &material, sgdVec3 dup ); +// Specify the way we want to draw directional point lights (assuming the +// appropriate extensions are available.) + +void sgConfigureDirectionalLights( bool use_point_sprites, + bool enhanced_lighting, + bool distance_attenuation ); + #endif // _SG_PT_LIGHTS_HXX -- 2.39.5