Update spot light params also for nv20 and nv30
authorPatrice Mandin <pmandin@freedesktop.org>
Fri, 8 Dec 2006 18:56:51 +0000 (18:56 +0000)
committerPatrice Mandin <pmandin@freedesktop.org>
Fri, 8 Dec 2006 18:56:51 +0000 (18:56 +0000)
src/mesa/drivers/dri/nouveau/nv10_state.c
src/mesa/drivers/dri/nouveau/nv20_state.c
src/mesa/drivers/dri/nouveau/nv30_state.c

index ed688a076bc5d0ed5fb65e73ec59ff3762007467..e88ac2bfe65f3d898c8a84c2c99afd587e603758 100644 (file)
@@ -406,7 +406,7 @@ static void nv10Lightfv(GLcontext *ctx, GLenum light, GLenum pname, const GLfloa
                case SPOTLIGHT_UPDATE_EXPONENT:
                        {
                                GLfloat cc,lc,qc;
-                               cc = 1.0;       /* These need to be correctly computed */
+                               cc = 1.0;       /* FIXME: These need to be correctly computed */
                                lc = 0.0;
                                qc = 2.0;
                                BEGIN_RING_CACHE(NvSub3D, NV10_TCL_PRIMITIVE_3D_LIGHT_SPOT_CUTOFF_A(p), 3);
@@ -418,7 +418,7 @@ static void nv10Lightfv(GLcontext *ctx, GLenum light, GLenum pname, const GLfloa
                case SPOTLIGHT_UPDATE_ALL:
                        {
                                GLfloat cc,lc,qc, x,y,z, c;
-                               cc = 1.0;       /* These need to be correctly computed */
+                               cc = 1.0;       /* FIXME: These need to be correctly computed */
                                lc = 0.0;
                                qc = 2.0;
                                x = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[0];
index 082dc64b830e7e703adac44a6f047bc21460a92f..ff06d481ee595c88bdaba946237bd08e3f6f5bb9 100644 (file)
@@ -337,11 +337,18 @@ static void nv20Hint(GLcontext *ctx, GLenum target, GLenum mode)
 
 // void (*IndexMask)(GLcontext *ctx, GLuint mask);
 
+enum {
+       SPOTLIGHT_UPDATE_EXPONENT,
+       SPOTLIGHT_UPDATE_DIRECTION,
+       SPOTLIGHT_UPDATE_ALL
+};
+
 static void nv20Lightfv(GLcontext *ctx, GLenum light, GLenum pname, const GLfloat *params )
 {
        nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx);
        GLint p = light - GL_LIGHT0;
        struct gl_light *l = &ctx->Light.Light[p];
+       int spotlightUpdate = -1;
 
        /* not sure where the fourth param value goes...*/
        switch(pname)
@@ -364,41 +371,20 @@ static void nv20Lightfv(GLcontext *ctx, GLenum light, GLenum pname, const GLfloa
                        OUT_RING_CACHEf(params[1]);
                        OUT_RING_CACHEf(params[2]);
                        break;
-               case GL_SPOT_DIRECTION:
-                       {
-                               GLfloat x,y,z;
-                               x = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[0];
-                               y = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[1];
-                               z = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[2];
-                               BEGIN_RING_CACHE(NvSub3D, NV20_TCL_PRIMITIVE_3D_LIGHT_SPOT_DIR_X(p), 3);
-                               OUT_RING_CACHEf(x);
-                               OUT_RING_CACHEf(y);
-                               OUT_RING_CACHEf(z);
-                       }
-                       break;
                case GL_POSITION:
                        BEGIN_RING_CACHE(NvSub3D, NV20_TCL_PRIMITIVE_3D_LIGHT_POSITION_X(p), 3);
                        OUT_RING_CACHEf(params[0]);
                        OUT_RING_CACHEf(params[1]);
                        OUT_RING_CACHEf(params[2]);
                        break;
+               case GL_SPOT_DIRECTION:
+                       spotlightUpdate = SPOTLIGHT_UPDATE_DIRECTION;
+                       break;
                case GL_SPOT_EXPONENT:
-                       BEGIN_RING_CACHE(NvSub3D, NV20_TCL_PRIMITIVE_3D_LIGHT_SPOT_EXPONENT(p), 1);
-                       OUT_RING_CACHEf(*params);
+                       spotlightUpdate = SPOTLIGHT_UPDATE_EXPONENT;
                        break;
                case GL_SPOT_CUTOFF:
-                       /* you can't factor these */
-                       {
-                               GLfloat c;
-                               c = -2.0 * (0.5 + l->_CosCutoff);
-
-                               BEGIN_RING_CACHE(NvSub3D, NV20_TCL_PRIMITIVE_3D_LIGHT_SPOT_CUTOFF_A(p), 1);
-                               OUT_RING_CACHEf(params[0]);
-                               BEGIN_RING_CACHE(NvSub3D, NV20_TCL_PRIMITIVE_3D_LIGHT_SPOT_CUTOFF_B(p), 1);
-                               OUT_RING_CACHEf(params[1]);
-                               BEGIN_RING_CACHE(NvSub3D, NV20_TCL_PRIMITIVE_3D_LIGHT_SPOT_CUTOFF_C(p), 1);
-                               OUT_RING_CACHEf(c);
-                       }
+                       spotlightUpdate = SPOTLIGHT_UPDATE_ALL;
                        break;
                case GL_CONSTANT_ATTENUATION:
                        BEGIN_RING_CACHE(NvSub3D, NV20_TCL_PRIMITIVE_3D_LIGHT_CONSTANT_ATTENUATION(p), 1);
@@ -415,6 +401,55 @@ static void nv20Lightfv(GLcontext *ctx, GLenum light, GLenum pname, const GLfloa
                default:
                        break;
        }
+
+       switch(spotlightUpdate) {
+               case SPOTLIGHT_UPDATE_DIRECTION:
+                       {
+                               GLfloat x,y,z;
+                               x = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[0];
+                               y = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[1];
+                               z = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[2];
+                               BEGIN_RING_CACHE(NvSub3D, NV20_TCL_PRIMITIVE_3D_LIGHT_SPOT_DIR_X(p), 3);
+                               OUT_RING_CACHEf(x);
+                               OUT_RING_CACHEf(y);
+                               OUT_RING_CACHEf(z);
+                       }
+                       break;
+               case SPOTLIGHT_UPDATE_EXPONENT:
+                       {
+                               GLfloat cc,lc,qc;
+                               cc = 1.0;       /* FIXME: These need to be correctly computed */
+                               lc = 0.0;
+                               qc = 2.0;
+                               BEGIN_RING_CACHE(NvSub3D, NV20_TCL_PRIMITIVE_3D_LIGHT_SPOT_CUTOFF_A(p), 3);
+                               OUT_RING_CACHEf(cc);
+                               OUT_RING_CACHEf(lc);
+                               OUT_RING_CACHEf(qc);
+                       }
+                       break;
+               case SPOTLIGHT_UPDATE_ALL:
+                       {
+                               GLfloat cc,lc,qc, x,y,z, c;
+                               cc = 1.0;       /* FIXME: These need to be correctly computed */
+                               lc = 0.0;
+                               qc = 2.0;
+                               x = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[0];
+                               y = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[1];
+                               z = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[2];
+                               c = -2.0 * (0.5 + l->_CosCutoff);
+                               BEGIN_RING_CACHE(NvSub3D, NV20_TCL_PRIMITIVE_3D_LIGHT_SPOT_CUTOFF_A(p), 7);
+                               OUT_RING_CACHEf(cc);
+                               OUT_RING_CACHEf(lc);
+                               OUT_RING_CACHEf(qc);
+                               OUT_RING_CACHEf(x);
+                               OUT_RING_CACHEf(y);
+                               OUT_RING_CACHEf(z);
+                               OUT_RING_CACHEf(c);
+                       }
+                       break;
+               default:
+                       break;
+       }
 }
 
 /** Set the lighting model parameters */
index f0b37a76f5b9e016cb401792c4bc91eeb900c897..e30dc8a37c360e6849a7e71b335b4b40d5cb818a 100644 (file)
@@ -366,11 +366,18 @@ static void nv30Hint(GLcontext *ctx, GLenum target, GLenum mode)
 
 // void (*IndexMask)(GLcontext *ctx, GLuint mask);
 
+enum {
+       SPOTLIGHT_UPDATE_EXPONENT,
+       SPOTLIGHT_UPDATE_DIRECTION,
+       SPOTLIGHT_UPDATE_ALL
+};
+
 static void nv30Lightfv(GLcontext *ctx, GLenum light, GLenum pname, const GLfloat *params )
 {
        nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx);
        GLint p = light - GL_LIGHT0;
        struct gl_light *l = &ctx->Light.Light[p];
+       int spotlightUpdate = -1;
 
        if (NOUVEAU_CARD_USING_SHADERS)
           return;
@@ -396,41 +403,20 @@ static void nv30Lightfv(GLcontext *ctx, GLenum light, GLenum pname, const GLfloa
                        OUT_RING_CACHEf(params[1]);
                        OUT_RING_CACHEf(params[2]);
                        break;
-               case GL_SPOT_DIRECTION:
-                       {
-                               GLfloat x,y,z;
-                               x = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[0];
-                               y = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[1];
-                               z = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[2];
-                               BEGIN_RING_CACHE(NvSub3D, NV30_TCL_PRIMITIVE_3D_LIGHT_SPOT_DIR_X(p), 3);
-                               OUT_RING_CACHEf(x);
-                               OUT_RING_CACHEf(y);
-                               OUT_RING_CACHEf(z);
-                       }
-                       break;
                case GL_POSITION:
                        BEGIN_RING_CACHE(NvSub3D, NV30_TCL_PRIMITIVE_3D_LIGHT_POSITION_X(p), 3);
                        OUT_RING_CACHEf(params[0]);
                        OUT_RING_CACHEf(params[1]);
                        OUT_RING_CACHEf(params[2]);
                        break;
+               case GL_SPOT_DIRECTION:
+                       spotlightUpdate = SPOTLIGHT_UPDATE_DIRECTION;
+                       break;
                case GL_SPOT_EXPONENT:
-                       BEGIN_RING_CACHE(NvSub3D, NV30_TCL_PRIMITIVE_3D_LIGHT_SPOT_EXPONENT(p), 1);
-                       OUT_RING_CACHEf(*params);
+                       spotlightUpdate = SPOTLIGHT_UPDATE_EXPONENT;
                        break;
                case GL_SPOT_CUTOFF:
-                       /* you can't factor these */
-                       {
-                               GLfloat c;
-                               c = -2.0 * (0.5 + l->_CosCutoff);
-
-                               BEGIN_RING_CACHE(NvSub3D, NV30_TCL_PRIMITIVE_3D_LIGHT_SPOT_CUTOFF_A(p), 1);
-                               OUT_RING_CACHEf(params[0]);
-                               BEGIN_RING_CACHE(NvSub3D, NV30_TCL_PRIMITIVE_3D_LIGHT_SPOT_CUTOFF_B(p), 1);
-                               OUT_RING_CACHEf(params[1]);
-                               BEGIN_RING_CACHE(NvSub3D, NV30_TCL_PRIMITIVE_3D_LIGHT_SPOT_CUTOFF_C(p), 1);
-                               OUT_RING_CACHEf(c);
-                       }
+                       spotlightUpdate = SPOTLIGHT_UPDATE_ALL;
                        break;
                case GL_CONSTANT_ATTENUATION:
                        BEGIN_RING_CACHE(NvSub3D, NV30_TCL_PRIMITIVE_3D_LIGHT_CONSTANT_ATTENUATION(p), 1);
@@ -447,6 +433,55 @@ static void nv30Lightfv(GLcontext *ctx, GLenum light, GLenum pname, const GLfloa
                default:
                        break;
        }
+
+       switch(spotlightUpdate) {
+               case SPOTLIGHT_UPDATE_DIRECTION:
+                       {
+                               GLfloat x,y,z;
+                               x = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[0];
+                               y = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[1];
+                               z = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[2];
+                               BEGIN_RING_CACHE(NvSub3D, NV30_TCL_PRIMITIVE_3D_LIGHT_SPOT_DIR_X(p), 3);
+                               OUT_RING_CACHEf(x);
+                               OUT_RING_CACHEf(y);
+                               OUT_RING_CACHEf(z);
+                       }
+                       break;
+               case SPOTLIGHT_UPDATE_EXPONENT:
+                       {
+                               GLfloat cc,lc,qc;
+                               cc = 1.0;       /* FIXME: These need to be correctly computed */
+                               lc = 0.0;
+                               qc = 2.0;
+                               BEGIN_RING_CACHE(NvSub3D, NV30_TCL_PRIMITIVE_3D_LIGHT_SPOT_CUTOFF_A(p), 3);
+                               OUT_RING_CACHEf(cc);
+                               OUT_RING_CACHEf(lc);
+                               OUT_RING_CACHEf(qc);
+                       }
+                       break;
+               case SPOTLIGHT_UPDATE_ALL:
+                       {
+                               GLfloat cc,lc,qc, x,y,z, c;
+                               cc = 1.0;       /* FIXME: These need to be correctly computed */
+                               lc = 0.0;
+                               qc = 2.0;
+                               x = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[0];
+                               y = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[1];
+                               z = -2.0 * (1.0 + l->_CosCutoff) * l->_NormDirection[2];
+                               c = -2.0 * (0.5 + l->_CosCutoff);
+                               BEGIN_RING_CACHE(NvSub3D, NV30_TCL_PRIMITIVE_3D_LIGHT_SPOT_CUTOFF_A(p), 7);
+                               OUT_RING_CACHEf(cc);
+                               OUT_RING_CACHEf(lc);
+                               OUT_RING_CACHEf(qc);
+                               OUT_RING_CACHEf(x);
+                               OUT_RING_CACHEf(y);
+                               OUT_RING_CACHEf(z);
+                               OUT_RING_CACHEf(c);
+                       }
+                       break;
+               default:
+                       break;
+       }
 }
 
 /** Set the lighting model parameters */