Merge branch 'llvm-cliptest-viewport'
[mesa.git] / src / mesa / drivers / dri / nouveau / nv10_state_tnl.c
index 406e24c455d3d73bb658b072080cb046af26d774..175abfca5c1a8764e0d22bf5c1481e36476405ab 100644 (file)
@@ -32,7 +32,7 @@
 #include "nv10_driver.h"
 
 void
-nv10_emit_clip_plane(GLcontext *ctx, int emit)
+nv10_emit_clip_plane(struct gl_context *ctx, int emit)
 {
 }
 
@@ -54,7 +54,7 @@ get_material_bitmask(unsigned m)
 }
 
 void
-nv10_emit_color_material(GLcontext *ctx, int emit)
+nv10_emit_color_material(struct gl_context *ctx, int emit)
 {
        struct nouveau_channel *chan = context_chan(ctx);
        struct nouveau_grobj *celsius = context_eng3d(ctx);
@@ -93,7 +93,7 @@ get_fog_source(unsigned source)
 }
 
 void
-nv10_get_fog_coeff(GLcontext *ctx, float k[3])
+nv10_get_fog_coeff(struct gl_context *ctx, float k[3])
 {
        struct gl_fog_attrib *f = &ctx->Fog;
 
@@ -121,7 +121,7 @@ nv10_get_fog_coeff(GLcontext *ctx, float k[3])
 }
 
 void
-nv10_emit_fog(GLcontext *ctx, int emit)
+nv10_emit_fog(struct gl_context *ctx, int emit)
 {
        struct nouveau_context *nctx = to_nouveau_context(ctx);
        struct nouveau_channel *chan = context_chan(ctx);
@@ -140,9 +140,7 @@ nv10_emit_fog(GLcontext *ctx, int emit)
        OUT_RING(chan, pack_rgba_f(MESA_FORMAT_RGBA8888_REV, f->Color));
 
        BEGIN_RING(chan, celsius, NV10TCL_FOG_EQUATION_CONSTANT, 3);
-       OUT_RINGf(chan, k[0]);
-       OUT_RINGf(chan, k[1]);
-       OUT_RINGf(chan, k[2]);
+       OUT_RINGp(chan, k, 3);
 
        context_dirty(ctx, FRAG);
 }
@@ -163,7 +161,7 @@ get_light_mode(struct gl_light *l)
 }
 
 void
-nv10_emit_light_enable(GLcontext *ctx, int emit)
+nv10_emit_light_enable(struct gl_context *ctx, int emit)
 {
        struct nouveau_context *nctx = to_nouveau_context(ctx);
        struct nouveau_channel *chan = context_chan(ctx);
@@ -189,7 +187,7 @@ nv10_emit_light_enable(GLcontext *ctx, int emit)
 }
 
 void
-nv10_emit_light_model(GLcontext *ctx, int emit)
+nv10_emit_light_model(struct gl_context *ctx, int emit)
 {
        struct nouveau_channel *chan = context_chan(ctx);
        struct nouveau_grobj *celsius = context_eng3d(ctx);
@@ -275,7 +273,7 @@ nv10_get_spot_coeff(struct gl_light *l, float k[7])
 }
 
 void
-nv10_emit_light_source(GLcontext *ctx, int emit)
+nv10_emit_light_source(struct gl_context *ctx, int emit)
 {
        const int i = emit - NOUVEAU_STATE_LIGHT_SOURCE0;
        struct nouveau_channel *chan = context_chan(ctx);
@@ -284,9 +282,7 @@ nv10_emit_light_source(GLcontext *ctx, int emit)
 
        if (l->_Flags & LIGHT_POSITIONAL) {
                BEGIN_RING(chan, celsius, NV10TCL_LIGHT_POSITION_X(i), 3);
-               OUT_RINGf(chan, l->_Position[0]);
-               OUT_RINGf(chan, l->_Position[1]);
-               OUT_RINGf(chan, l->_Position[2]);
+               OUT_RINGp(chan, l->_Position, 3);
 
                BEGIN_RING(chan, celsius,
                           NV10TCL_LIGHT_ATTENUATION_CONSTANT(i), 3);
@@ -296,14 +292,10 @@ nv10_emit_light_source(GLcontext *ctx, int emit)
 
        } else {
                BEGIN_RING(chan, celsius, NV10TCL_LIGHT_DIRECTION_X(i), 3);
-               OUT_RINGf(chan, l->_VP_inf_norm[0]);
-               OUT_RINGf(chan, l->_VP_inf_norm[1]);
-               OUT_RINGf(chan, l->_VP_inf_norm[2]);
+               OUT_RINGp(chan, l->_VP_inf_norm, 3);
 
                BEGIN_RING(chan, celsius, NV10TCL_LIGHT_HALF_VECTOR_X(i), 3);
-               OUT_RINGf(chan, l->_h_inf_norm[0]);
-               OUT_RINGf(chan, l->_h_inf_norm[1]);
-               OUT_RINGf(chan, l->_h_inf_norm[2]);
+               OUT_RINGp(chan, l->_h_inf_norm, 3);
        }
 
        if (l->_Flags & LIGHT_SPOT) {
@@ -312,13 +304,7 @@ nv10_emit_light_source(GLcontext *ctx, int emit)
                nv10_get_spot_coeff(l, k);
 
                BEGIN_RING(chan, celsius, NV10TCL_LIGHT_SPOT_CUTOFF_A(i), 7);
-               OUT_RINGf(chan, k[0]);
-               OUT_RINGf(chan, k[1]);
-               OUT_RINGf(chan, k[2]);
-               OUT_RINGf(chan, k[3]);
-               OUT_RINGf(chan, k[4]);
-               OUT_RINGf(chan, k[5]);
-               OUT_RINGf(chan, k[6]);
+               OUT_RINGp(chan, k, 7);
        }
 }
 
@@ -327,7 +313,7 @@ nv10_emit_light_source(GLcontext *ctx, int emit)
         ctx->Light.ColorMaterialBitmask & (1 << MAT_ATTRIB_FRONT_##attr))
 
 void
-nv10_emit_material_ambient(GLcontext *ctx, int emit)
+nv10_emit_material_ambient(struct gl_context *ctx, int emit)
 {
        struct nouveau_channel *chan = context_chan(ctx);
        struct nouveau_grobj *celsius = context_eng3d(ctx);
@@ -350,15 +336,11 @@ nv10_emit_material_ambient(GLcontext *ctx, int emit)
        }
 
        BEGIN_RING(chan, celsius, NV10TCL_LIGHT_MODEL_AMBIENT_R, 3);
-       OUT_RINGf(chan, c_scene[0]);
-       OUT_RINGf(chan, c_scene[1]);
-       OUT_RINGf(chan, c_scene[2]);
+       OUT_RINGp(chan, c_scene, 3);
 
        if (ctx->Light.ColorMaterialEnabled) {
                BEGIN_RING(chan, celsius, NV10TCL_MATERIAL_FACTOR_R, 3);
-               OUT_RINGf(chan, c_factor[0]);
-               OUT_RINGf(chan, c_factor[1]);
-               OUT_RINGf(chan, c_factor[2]);
+               OUT_RINGp(chan, c_factor, 3);
        }
 
        foreach(l, &ctx->Light.EnabledList) {
@@ -368,14 +350,12 @@ nv10_emit_material_ambient(GLcontext *ctx, int emit)
                                  l->_MatAmbient[0]);
 
                BEGIN_RING(chan, celsius, NV10TCL_LIGHT_AMBIENT_R(i), 3);
-               OUT_RINGf(chan, c_light[0]);
-               OUT_RINGf(chan, c_light[1]);
-               OUT_RINGf(chan, c_light[2]);
+               OUT_RINGp(chan, c_light, 3);
        }
 }
 
 void
-nv10_emit_material_diffuse(GLcontext *ctx, int emit)
+nv10_emit_material_diffuse(struct gl_context *ctx, int emit)
 {
        struct nouveau_channel *chan = context_chan(ctx);
        struct nouveau_grobj *celsius = context_eng3d(ctx);
@@ -392,14 +372,12 @@ nv10_emit_material_diffuse(GLcontext *ctx, int emit)
                                  l->_MatDiffuse[0]);
 
                BEGIN_RING(chan, celsius, NV10TCL_LIGHT_DIFFUSE_R(i), 3);
-               OUT_RINGf(chan, c_light[0]);
-               OUT_RINGf(chan, c_light[1]);
-               OUT_RINGf(chan, c_light[2]);
+               OUT_RINGp(chan, c_light, 3);
        }
 }
 
 void
-nv10_emit_material_specular(GLcontext *ctx, int emit)
+nv10_emit_material_specular(struct gl_context *ctx, int emit)
 {
        struct nouveau_channel *chan = context_chan(ctx);
        struct nouveau_grobj *celsius = context_eng3d(ctx);
@@ -412,9 +390,7 @@ nv10_emit_material_specular(GLcontext *ctx, int emit)
                                  l->_MatSpecular[0]);
 
                BEGIN_RING(chan, celsius, NV10TCL_LIGHT_SPECULAR_R(i), 3);
-               OUT_RINGf(chan, c_light[0]);
-               OUT_RINGf(chan, c_light[1]);
-               OUT_RINGf(chan, c_light[2]);
+               OUT_RINGp(chan, c_light, 3);
        }
 }
 
@@ -443,7 +419,7 @@ nv10_get_shininess_coeff(float s, float k[6])
 }
 
 void
-nv10_emit_material_shininess(GLcontext *ctx, int emit)
+nv10_emit_material_shininess(struct gl_context *ctx, int emit)
 {
        struct nouveau_channel *chan = context_chan(ctx);
        struct nouveau_grobj *celsius = context_eng3d(ctx);
@@ -455,16 +431,11 @@ nv10_emit_material_shininess(GLcontext *ctx, int emit)
                k);
 
        BEGIN_RING(chan, celsius, NV10TCL_MATERIAL_SHININESS(0), 6);
-       OUT_RINGf(chan, k[0]);
-       OUT_RINGf(chan, k[1]);
-       OUT_RINGf(chan, k[2]);
-       OUT_RINGf(chan, k[3]);
-       OUT_RINGf(chan, k[4]);
-       OUT_RINGf(chan, k[5]);
+       OUT_RINGp(chan, k, 6);
 }
 
 void
-nv10_emit_modelview(GLcontext *ctx, int emit)
+nv10_emit_modelview(struct gl_context *ctx, int emit)
 {
        struct nouveau_context *nctx = to_nouveau_context(ctx);
        struct nouveau_channel *chan = context_chan(ctx);
@@ -474,12 +445,14 @@ nv10_emit_modelview(GLcontext *ctx, int emit)
        if (nctx->fallback != HWTNL)
                return;
 
-       if (ctx->Light._NeedEyeCoords || ctx->Fog.Enabled) {
+       if (ctx->Light._NeedEyeCoords || ctx->Fog.Enabled ||
+           (ctx->Texture._GenFlags & TEXGEN_NEED_EYE_COORD)) {
                BEGIN_RING(chan, celsius, NV10TCL_MODELVIEW0_MATRIX(0), 16);
                OUT_RINGm(chan, m->m);
        }
 
-       if (ctx->Light.Enabled) {
+       if (ctx->Light.Enabled ||
+           (ctx->Texture._GenFlags & TEXGEN_NEED_EYE_COORD)) {
                int i, j;
 
                BEGIN_RING(chan, celsius,
@@ -491,12 +464,12 @@ nv10_emit_modelview(GLcontext *ctx, int emit)
 }
 
 void
-nv10_emit_point_parameter(GLcontext *ctx, int emit)
+nv10_emit_point_parameter(struct gl_context *ctx, int emit)
 {
 }
 
 void
-nv10_emit_projection(GLcontext *ctx, int emit)
+nv10_emit_projection(struct gl_context *ctx, int emit)
 {
        struct nouveau_context *nctx = to_nouveau_context(ctx);
        struct nouveau_channel *chan = context_chan(ctx);
@@ -506,6 +479,9 @@ nv10_emit_projection(GLcontext *ctx, int emit)
        _math_matrix_ctr(&m);
        get_viewport_scale(ctx, m.m);
 
+       if (nv10_use_viewport_zclear(ctx))
+               m.m[MAT_SZ] /= 8;
+
        if (nctx->fallback == HWTNL)
                _math_matrix_mul_matrix(&m, &m, &ctx->_ModelProjectMatrix);