Merge branch 'master' into glsl-pp-rework-2
[mesa.git] / src / mesa / tnl / t_vb_light.c
index 9cf0032f962a964cdaf01136506d32922dc095fe..8a0fe63fd8b75ab60feaa3042c883ae093aa79b8 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.3
+ * Version:  6.5
  *
- * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
 
 
 
-#include "glheader.h"
-#include "colormac.h"
-#include "light.h"
-#include "macros.h"
-#include "imports.h"
-#include "simple_list.h"
-#include "mtypes.h"
+#include "main/glheader.h"
+#include "main/colormac.h"
+#include "main/light.h"
+#include "main/macros.h"
+#include "main/imports.h"
+#include "main/simple_list.h"
+#include "main/mtypes.h"
 
 #include "math/m_translate.h"
 
@@ -127,7 +127,7 @@ prepare_materials(GLcontext *ctx,
       const GLuint bitmask = ctx->Light.ColorMaterialBitmask;
       for (i = 0 ; i < MAT_ATTRIB_MAX ; i++)
         if (bitmask & (1<<i))
-           VB->AttribPtr[_TNL_ATTRIB_MAT_FRONT_AMBIENT + i] = VB->ColorPtr[0];
+           VB->AttribPtr[_TNL_ATTRIB_MAT_FRONT_AMBIENT + i] = VB->AttribPtr[_TNL_ATTRIB_COLOR0];
    }
 
    /* Now, for each material attribute that's tracking vertex color, save
@@ -135,7 +135,7 @@ prepare_materials(GLcontext *ctx,
     * update_materials(), above, that'll actually copy the vertex color to
     * the material attribute(s).
     */
-   for (i = _TNL_ATTRIB_MAT_FRONT_AMBIENT ; i < _TNL_ATTRIB_INDEX ; i++) {
+   for (i = _TNL_FIRST_MAT; i <= _TNL_LAST_MAT; i++) {
       if (VB->AttribPtr[i]->stride) {
         const GLuint j = store->mat_count++;
         const GLuint attr = i - _TNL_ATTRIB_MAT_FRONT_AMBIENT;
@@ -180,7 +180,7 @@ static light_func _tnl_light_ci_tab[MAX_LIGHT_FUNC];
 #include "t_vb_lighttmp.h"
 
 
-static void init_lighting( void )
+static void init_lighting_tables( void )
 {
    static int done;
 
@@ -200,36 +200,37 @@ static GLboolean run_lighting( GLcontext *ctx,
    struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
    TNLcontext *tnl = TNL_CONTEXT(ctx);
    struct vertex_buffer *VB = &tnl->vb;
-   GLvector4f *input = ctx->_NeedEyeCoords ? VB->EyePtr : VB->ObjPtr;
+   GLvector4f *input = ctx->_NeedEyeCoords ? VB->EyePtr : VB->AttribPtr[_TNL_ATTRIB_POS];
    GLuint idx;
 
+   if (!ctx->Light.Enabled || ctx->VertexProgram._Current)
+      return GL_TRUE;
+
    /* Make sure we can talk about position x,y and z:
     */
-   if (stage->changed_inputs & _TNL_BIT_POS) {
-      if (input->size <= 2 && input == VB->ObjPtr) {
-
-        _math_trans_4f( store->Input.data,
-                        VB->ObjPtr->data,
-                        VB->ObjPtr->stride,
-                        GL_FLOAT,
-                        VB->ObjPtr->size,
-                        0,
-                        VB->Count );
-
-        if (input->size <= 2) {
-           /* Clean z.
-            */
-           _mesa_vector4f_clean_elem(&store->Input, VB->Count, 2);
-        }
+   if (input->size <= 2 && input == VB->AttribPtr[_TNL_ATTRIB_POS]) {
+
+      _math_trans_4f( store->Input.data,
+                     VB->AttribPtr[_TNL_ATTRIB_POS]->data,
+                     VB->AttribPtr[_TNL_ATTRIB_POS]->stride,
+                     GL_FLOAT,
+                     VB->AttribPtr[_TNL_ATTRIB_POS]->size,
+                     0,
+                     VB->Count );
+
+      if (input->size <= 2) {
+        /* Clean z.
+         */
+        _mesa_vector4f_clean_elem(&store->Input, VB->Count, 2);
+      }
         
-        if (input->size <= 1) {
-           /* Clean y.
-            */
-           _mesa_vector4f_clean_elem(&store->Input, VB->Count, 1);
-        }
-
-        input = &store->Input;
+      if (input->size <= 1) {
+        /* Clean y.
+         */
+        _mesa_vector4f_clean_elem(&store->Input, VB->Count, 1);
       }
+
+      input = &store->Input;
    }
    
    idx = 0;
@@ -245,21 +246,20 @@ static GLboolean run_lighting( GLcontext *ctx,
     */
    store->light_func_tab[idx]( ctx, VB, stage, input );
 
-   VB->AttribPtr[_TNL_ATTRIB_COLOR0] = VB->ColorPtr[0];
-   VB->AttribPtr[_TNL_ATTRIB_COLOR1] = VB->SecondaryColorPtr[0];
-   VB->AttribPtr[_TNL_ATTRIB_INDEX] = VB->IndexPtr[0];
-
    return GL_TRUE;
 }
 
 
 /* Called in place of do_lighting when the light table may have changed.
  */
-static GLboolean run_validate_lighting( GLcontext *ctx,
+static void validate_lighting( GLcontext *ctx,
                                        struct tnl_pipeline_stage *stage )
 {
    light_func *tab;
 
+   if (!ctx->Light.Enabled || ctx->VertexProgram._Current)
+      return;
+
    if (ctx->Visual.rgbMode) {
       if (ctx->Light._NeedVertices) {
         if (ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)
@@ -283,11 +283,6 @@ static GLboolean run_validate_lighting( GLcontext *ctx,
    /* This and the above should only be done on _NEW_LIGHT:
     */
    TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange( ctx );
-
-   /* Now run the stage...
-    */
-   stage->run = run_lighting;
-   return stage->run( ctx, stage );
 }
 
 
@@ -295,8 +290,8 @@ static GLboolean run_validate_lighting( GLcontext *ctx,
 /* Called the first time stage->run is called.  In effect, don't
  * allocate data until the first time the stage is run.
  */
-static GLboolean run_init_lighting( GLcontext *ctx,
-                                   struct tnl_pipeline_stage *stage )
+static GLboolean init_lighting( GLcontext *ctx,
+                               struct tnl_pipeline_stage *stage )
 {
    TNLcontext *tnl = TNL_CONTEXT(ctx);
    struct light_stage_data *store;
@@ -309,7 +304,7 @@ static GLboolean run_init_lighting( GLcontext *ctx,
 
    /* Do onetime init.
     */
-   init_lighting();
+   init_lighting_tables();
 
    _mesa_vector4f_alloc( &store->Input, 0, size, 32 );
    _mesa_vector4f_alloc( &store->LitColor[0], 0, size, 32 );
@@ -329,36 +324,11 @@ static GLboolean run_init_lighting( GLcontext *ctx,
    store->LitIndex[1].size = 1;
    store->LitIndex[1].stride = sizeof(GLfloat);
 
-   /* Now validate the stage derived data...
-    */
-   stage->run = run_validate_lighting;
-   return stage->run( ctx, stage );
+   return GL_TRUE;
 }
 
 
 
-/*
- * Check if lighting is enabled.  If so, configure the pipeline stage's
- * type, inputs, and outputs.
- */
-static void check_lighting( GLcontext *ctx, struct tnl_pipeline_stage *stage )
-{
-   stage->active = ctx->Light.Enabled && !ctx->VertexProgram._Enabled;
-   if (stage->active) {
-      if (stage->privatePtr)
-        stage->run = run_validate_lighting;
-      stage->inputs = _TNL_BIT_NORMAL|_TNL_BITS_MAT_ANY;
-      if (ctx->Light._NeedVertices)
-        stage->inputs |= _TNL_BIT_POS; 
-      if (ctx->Light.ColorMaterialEnabled)
-        stage->inputs |= _TNL_BIT_COLOR0;
-
-      stage->outputs = _TNL_BIT_COLOR0;
-      if (ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)
-        stage->outputs |= _TNL_BIT_COLOR1;
-   }
-}
-
 
 static void dtr( struct tnl_pipeline_stage *stage )
 {
@@ -380,16 +350,9 @@ static void dtr( struct tnl_pipeline_stage *stage )
 const struct tnl_pipeline_stage _tnl_lighting_stage =
 {
    "lighting",                 /* name */
-   _NEW_LIGHT|_NEW_PROGRAM,    /* recheck */
-   _NEW_LIGHT|_NEW_MODELVIEW,  /* recalc -- modelview dependency
-                                * otherwise not captured by inputs
-                                * (which may be _TNL_BIT_POS) */
-   GL_FALSE,                   /* active? */
-   0,                          /* inputs */
-   0,                          /* outputs */
-   0,                          /* changed_inputs */
    NULL,                       /* private_data */
+   init_lighting,
    dtr,                                /* destroy */
-   check_lighting,             /* check */
-   run_init_lighting           /* run -- initially set to ctr */
+   validate_lighting,
+   run_lighting
 };