@@ -58,7 +58,6 @@ static GLuint get_light_id(
5858 )
5959{
6060 GLuint id ;
61-
6261 switch (ind ) {
6362 case 1 : id = GL_LIGHT1 ; break ;
6463 case 2 : id = GL_LIGHT2 ; break ;
@@ -93,13 +92,16 @@ static void setup_ambient_light(
9392 amb [2 ] = rec -> colr .val .general .z ;
9493 amb [3 ] = 1.0 ;
9594
96- #ifdef DEBUG
95+ #ifdef DEBUGL
9796 printf ("Ambient light: %f %f %f\n" , amb [0 ], amb [1 ], amb [2 ]);
9897#endif
9998#ifdef GLEW
10099 if (wsgl_use_shaders && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shader_objects ){
101100#else
102101 if (wsgl_use_shaders ){
102+ #endif
103+ #ifdef DEBUGL
104+ printf ("Ambient light Using shaders %d\n" , ind );
103105#endif
104106 switch (ind ){
105107 case 0 :
@@ -176,7 +178,7 @@ static void setup_directional_light(
176178 pos [2 ] = rec -> dir .delta_z ;
177179 pos [3 ] = 1.0 ;
178180
179- #ifdef DEBUG
181+ #ifdef DEBUGL
180182 printf ("Directional light: %f %f %f @(%f, %f %f)\n" ,
181183 dif [0 ], dif [1 ], dif [2 ],
182184 pos [0 ], pos [1 ], pos [2 ]);
@@ -185,6 +187,9 @@ static void setup_directional_light(
185187 if (wsgl_use_shaders && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shader_objects ){
186188#else
187189 if (wsgl_use_shaders ){
190+ #endif
191+ #ifdef DEBUGL
192+ printf ("Directional light Using shaders %d\n" , ind );
188193#endif
189194 switch (ind ){
190195 case 0 :
@@ -275,7 +280,7 @@ static void setup_positional_light(
275280 coef [2 ] = 0.0 ;
276281 coef [3 ] = 0.0 ;
277282
278- #ifdef DEBUG
283+ #ifdef DEBUGL
279284 printf ("Positional light: %f %f %f @(%f, %f %f) with %f %f\n" ,
280285 dif [0 ], dif [1 ], dif [2 ],
281286 pos [0 ], pos [1 ], pos [2 ],
@@ -285,6 +290,9 @@ static void setup_positional_light(
285290 if (wsgl_use_shaders && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shader_objects ){
286291#else
287292 if (wsgl_use_shaders ){
293+ #endif
294+ #ifdef DEBUGL
295+ printf ("Positional light Using shaders %d\n" , ind );
288296#endif
289297 switch (ind ){
290298 case 0 :
@@ -358,83 +366,92 @@ static void setup_positional_light(
358366 */
359367
360368void wsgl_update_light_src_state (
361- Ws * ws
362- )
369+ Ws * ws
370+ )
363371{
364- Pint i ;
365- Phg_ret ret ;
366- Wsgl * wsgl = ws -> render_context ;
367-
368- glPushMatrix ();
369- glLoadIdentity ();
370-
371- /* Activate light sources */
372- for (i = 0 ; i < WS_MAX_LIGHT_SRC ; i ++ ) {
373- if (phg_nset_name_is_set (& wsgl -> cur_struct .lightstat , i )) {
374- #ifdef DEBUG
375- printf ("Setup light source: %d\n" , i );
372+ Pint i ;
373+ Phg_ret ret ;
374+ Wsgl * wsgl = ws -> render_context ;
375+
376+ glPushMatrix ();
377+ glLoadIdentity ();
378+
379+ /* Activate light sources */
380+ for (i = 0 ; i < WS_MAX_LIGHT_SRC ; i ++ ) {
381+ if (phg_nset_name_is_set (& wsgl -> cur_struct .lightstat , i )) {
382+ #ifdef DEBUGL
383+ printf ("Setup light source: %d\n" , i );
376384#endif
377- (* ws -> inq_representation )(ws ,
378- i ,
379- PINQ_REALIZED ,
380- PHG_ARGS_LIGHTSRCREP ,
381- & ret );
382- if (ret .err == 0 ) {
383- switch (ret .data .rep .lightsrcrep .type ) {
384- case PLIGHT_AMBIENT :
385- setup_ambient_light (i , & ret .data .rep .lightsrcrep .rec .ambient );
386- break ;
387-
388- case PLIGHT_DIRECTIONAL :
389- setup_directional_light (i , & ret .data .rep .lightsrcrep .rec .directional );
390- break ;
391-
392- case PLIGHT_POSITIONAL :
393- setup_positional_light (i , & ret .data .rep .lightsrcrep .rec .positional );
394- break ;
395- /* FIXME
396- case PLIGHT_SPOT:
397- setup_spot_light(i, &ret.data.rep.lightsrcrep.rec.spot);
398- break;
399- */
400- default :
401- break ;
402- }
403- }
404- } else {
385+ (* ws -> inq_representation )(ws ,
386+ i ,
387+ PINQ_REALIZED ,
388+ PHG_ARGS_LIGHTSRCREP ,
389+ & ret );
390+ if (ret .err == 0 ) {
391+ switch (ret .data .rep .lightsrcrep .type ) {
392+ case PLIGHT_AMBIENT :
393+ #ifdef DEBUGL
394+ printf ("Configure abient light\n" );
395+ #endif
396+ setup_ambient_light (i , & ret .data .rep .lightsrcrep .rec .ambient );
397+ break ;
398+
399+ case PLIGHT_DIRECTIONAL :
400+ #ifdef DEBUGL
401+ printf ("Configure directional light\n" );
402+ #endif
403+ setup_directional_light (i , & ret .data .rep .lightsrcrep .rec .directional );
404+ break ;
405+
406+ case PLIGHT_POSITIONAL :
407+ #ifdef DEBUGL
408+ printf ("Configure positional light\n" );
409+ #endif
410+ setup_positional_light (i , & ret .data .rep .lightsrcrep .rec .positional );
411+ break ;
412+ /* FIXME
413+ case PLIGHT_SPOT:
414+ setup_spot_light(i, &ret.data.rep.lightsrcrep.rec.spot);
415+ break;
416+ */
417+ default :
418+ break ;
419+ }
420+ }
421+ } else {
405422#ifdef GLEW
406- if (wsgl_use_shaders && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shader_objects ){
423+ if (wsgl_use_shaders && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shader_objects ){
407424#else
408- if (wsgl_use_shaders ){
425+ if (wsgl_use_shaders ){
409426#endif
410- switch (i ){
411- case 1 :
412- glUniform1i (lightSource0 , 0 );
413- break ;
414- case 2 :
415- glUniform1i (lightSource1 , 0 );
416- break ;
417- case 3 :
418- glUniform1i (lightSource2 , 0 );
419- break ;
420- case 4 :
421- glUniform1i (lightSource3 , 0 );
422- break ;
423- case 5 :
424- glUniform1i (lightSource4 , 0 );
425- break ;
426- case 6 :
427- glUniform1i (lightSource5 , 0 );
428- break ;
429- case 7 :
430- glUniform1i (lightSource6 , 0 );
431- break ;
432- }
433- } else {
434- glDisable (get_light_id (i ));
435- }
427+ switch (i ){
428+ case 1 :
429+ glUniform1i (lightSource0 , 0 );
430+ break ;
431+ case 2 :
432+ glUniform1i (lightSource1 , 0 );
433+ break ;
434+ case 3 :
435+ glUniform1i (lightSource2 , 0 );
436+ break ;
437+ case 4 :
438+ glUniform1i (lightSource3 , 0 );
439+ break ;
440+ case 5 :
441+ glUniform1i (lightSource4 , 0 );
442+ break ;
443+ case 6 :
444+ glUniform1i (lightSource5 , 0 );
445+ break ;
446+ case 7 :
447+ glUniform1i (lightSource6 , 0 );
448+ break ;
449+ }
450+ } else {
451+ glDisable (get_light_id (i ));
436452 }
437- }
453+ }
454+ }
438455#ifdef GLEW
439456 if (!wsgl_use_shaders || !GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader || !GLEW_ARB_shader_objects ) glPopMatrix ();
440457#else
@@ -480,7 +497,7 @@ void wsgl_set_light_src_state(
480497 wsgl -> cur_struct .lighting = TRUE;
481498 }
482499
483- #ifdef DEBUG
500+ #ifdef DEBUGL
484501 printf ("Lighting nameset: " );
485502 phg_nset_print (& wsgl -> cur_struct .lightstat );
486503 printf ("Lighting is %s\n" , (wsgl -> cur_struct .lighting ) ? "On" : "Off" );
0 commit comments