mesa: restructure gl_light vars to match the layout of gl_LightSource uniforms
this will make uploads faster Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6946>
This commit is contained in:
@@ -164,7 +164,7 @@ void
|
||||
nv10_get_fog_coeff(struct gl_context *ctx, float k[3]);
|
||||
|
||||
void
|
||||
nv10_get_spot_coeff(struct gl_light *l, float k[7]);
|
||||
nv10_get_spot_coeff(struct gl_light *l, struct gl_light_uniforms *lu, float k[7]);
|
||||
|
||||
void
|
||||
nv10_get_shininess_coeff(float s, float k[6]);
|
||||
|
@@ -238,9 +238,9 @@ static const float nv10_spot_params[2][16] = {
|
||||
};
|
||||
|
||||
void
|
||||
nv10_get_spot_coeff(struct gl_light *l, float k[7])
|
||||
nv10_get_spot_coeff(struct gl_light *l, struct gl_light_uniforms *lu, float k[7])
|
||||
{
|
||||
float e = l->SpotExponent;
|
||||
float e = lu->SpotExponent;
|
||||
float a0, b0, a1, a2, b2, a3;
|
||||
|
||||
if (e > 0)
|
||||
@@ -256,8 +256,8 @@ nv10_get_spot_coeff(struct gl_light *l, float k[7])
|
||||
|
||||
a3 = 0.9 + 0.278 * e;
|
||||
|
||||
if (l->SpotCutoff > 0) {
|
||||
float cutoff = MAX2(a3, 1 / (1 - l->_CosCutoff));
|
||||
if (lu->SpotCutoff > 0) {
|
||||
float cutoff = MAX2(a3, 1 / (1 - lu->_CosCutoff));
|
||||
|
||||
k[0] = MAX2(0, a0 + b0 * cutoff);
|
||||
k[1] = a1;
|
||||
@@ -284,15 +284,16 @@ nv10_emit_light_source(struct gl_context *ctx, int emit)
|
||||
const int i = emit - NOUVEAU_STATE_LIGHT_SOURCE0;
|
||||
struct nouveau_pushbuf *push = context_push(ctx);
|
||||
struct gl_light *l = &ctx->Light.Light[i];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
|
||||
if (l->_Flags & LIGHT_POSITIONAL) {
|
||||
BEGIN_NV04(push, NV10_3D(LIGHT_POSITION_X(i)), 3);
|
||||
PUSH_DATAp(push, l->_Position, 3);
|
||||
|
||||
BEGIN_NV04(push, NV10_3D(LIGHT_ATTENUATION_CONSTANT(i)), 3);
|
||||
PUSH_DATAf(push, l->ConstantAttenuation);
|
||||
PUSH_DATAf(push, l->LinearAttenuation);
|
||||
PUSH_DATAf(push, l->QuadraticAttenuation);
|
||||
PUSH_DATAf(push, lu->ConstantAttenuation);
|
||||
PUSH_DATAf(push, lu->LinearAttenuation);
|
||||
PUSH_DATAf(push, lu->QuadraticAttenuation);
|
||||
|
||||
} else {
|
||||
BEGIN_NV04(push, NV10_3D(LIGHT_DIRECTION_X(i)), 3);
|
||||
@@ -305,7 +306,7 @@ nv10_emit_light_source(struct gl_context *ctx, int emit)
|
||||
if (l->_Flags & LIGHT_SPOT) {
|
||||
float k[7];
|
||||
|
||||
nv10_get_spot_coeff(l, k);
|
||||
nv10_get_spot_coeff(l, lu, k);
|
||||
|
||||
BEGIN_NV04(push, NV10_3D(LIGHT_SPOT_CUTOFF(i, 0)), 7);
|
||||
PUSH_DATAp(push, k, 7);
|
||||
@@ -350,8 +351,9 @@ nv10_emit_material_ambient(struct gl_context *ctx, int emit)
|
||||
while (mask) {
|
||||
const int i = u_bit_scan(&mask);
|
||||
struct gl_light *l = &ctx->Light.Light[i];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
float *c_light = (USE_COLOR_MATERIAL(AMBIENT) ?
|
||||
l->Ambient :
|
||||
lu->Ambient :
|
||||
l->_MatAmbient[0]);
|
||||
|
||||
BEGIN_NV04(push, NV10_3D(LIGHT_AMBIENT_R(i)), 3);
|
||||
@@ -373,8 +375,9 @@ nv10_emit_material_diffuse(struct gl_context *ctx, int emit)
|
||||
while (mask) {
|
||||
const int i = u_bit_scan(&mask);
|
||||
struct gl_light *l = &ctx->Light.Light[i];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
float *c_light = (USE_COLOR_MATERIAL(DIFFUSE) ?
|
||||
l->Diffuse :
|
||||
lu->Diffuse :
|
||||
l->_MatDiffuse[0]);
|
||||
|
||||
BEGIN_NV04(push, NV10_3D(LIGHT_DIFFUSE_R(i)), 3);
|
||||
@@ -392,8 +395,9 @@ nv10_emit_material_specular(struct gl_context *ctx, int emit)
|
||||
while (mask) {
|
||||
const int i = u_bit_scan(&mask);
|
||||
struct gl_light *l = &ctx->Light.Light[i];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
float *c_light = (USE_COLOR_MATERIAL(SPECULAR) ?
|
||||
l->Specular :
|
||||
lu->Specular :
|
||||
l->_MatSpecular[0]);
|
||||
|
||||
BEGIN_NV04(push, NV10_3D(LIGHT_SPECULAR_R(i)), 3);
|
||||
|
@@ -200,15 +200,16 @@ nv20_emit_light_source(struct gl_context *ctx, int emit)
|
||||
const int i = emit - NOUVEAU_STATE_LIGHT_SOURCE0;
|
||||
struct nouveau_pushbuf *push = context_push(ctx);
|
||||
struct gl_light *l = &ctx->Light.Light[i];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
|
||||
if (l->_Flags & LIGHT_POSITIONAL) {
|
||||
BEGIN_NV04(push, NV20_3D(LIGHT_POSITION_X(i)), 3);
|
||||
PUSH_DATAp(push, l->_Position, 3);
|
||||
|
||||
BEGIN_NV04(push, NV20_3D(LIGHT_ATTENUATION_CONSTANT(i)), 3);
|
||||
PUSH_DATAf(push, l->ConstantAttenuation);
|
||||
PUSH_DATAf(push, l->LinearAttenuation);
|
||||
PUSH_DATAf(push, l->QuadraticAttenuation);
|
||||
PUSH_DATAf(push, lu->ConstantAttenuation);
|
||||
PUSH_DATAf(push, lu->LinearAttenuation);
|
||||
PUSH_DATAf(push, lu->QuadraticAttenuation);
|
||||
|
||||
} else {
|
||||
BEGIN_NV04(push, NV20_3D(LIGHT_DIRECTION_X(i)), 3);
|
||||
@@ -221,7 +222,7 @@ nv20_emit_light_source(struct gl_context *ctx, int emit)
|
||||
if (l->_Flags & LIGHT_SPOT) {
|
||||
float k[7];
|
||||
|
||||
nv10_get_spot_coeff(l, k);
|
||||
nv10_get_spot_coeff(l, lu, k);
|
||||
|
||||
BEGIN_NV04(push, NV20_3D(LIGHT_SPOT_CUTOFF(i, 0)), 7);
|
||||
PUSH_DATAp(push, k, 7);
|
||||
@@ -267,8 +268,9 @@ nv20_emit_material_ambient(struct gl_context *ctx, int emit)
|
||||
while (mask) {
|
||||
const int i = u_bit_scan(&mask);
|
||||
struct gl_light *l = &ctx->Light.Light[i];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
float *c_light = (USE_COLOR_MATERIAL(AMBIENT, side) ?
|
||||
l->Ambient :
|
||||
lu->Ambient :
|
||||
l->_MatAmbient[side]);
|
||||
|
||||
BEGIN_NV04(push, SUBC_3D(LIGHT_AMBIENT_R(side, i)), 3);
|
||||
@@ -291,8 +293,9 @@ nv20_emit_material_diffuse(struct gl_context *ctx, int emit)
|
||||
while (mask) {
|
||||
const int i = u_bit_scan(&mask);
|
||||
struct gl_light *l = &ctx->Light.Light[i];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
float *c_light = (USE_COLOR_MATERIAL(DIFFUSE, side) ?
|
||||
l->Diffuse :
|
||||
lu->Diffuse :
|
||||
l->_MatDiffuse[side]);
|
||||
|
||||
BEGIN_NV04(push, SUBC_3D(LIGHT_DIFFUSE_R(side, i)), 3);
|
||||
@@ -311,8 +314,9 @@ nv20_emit_material_specular(struct gl_context *ctx, int emit)
|
||||
while (mask) {
|
||||
const int i = u_bit_scan(&mask);
|
||||
struct gl_light *l = &ctx->Light.Light[i];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
float *c_light = (USE_COLOR_MATERIAL(SPECULAR, side) ?
|
||||
l->Specular :
|
||||
lu->Specular :
|
||||
l->_MatSpecular[side]);
|
||||
|
||||
BEGIN_NV04(push, SUBC_3D(LIGHT_SPECULAR_R(side, i)), 3);
|
||||
|
@@ -867,6 +867,7 @@ static void update_global_ambient( struct gl_context *ctx )
|
||||
static void update_light_colors( struct gl_context *ctx, GLuint p )
|
||||
{
|
||||
struct gl_light *l = &ctx->Light.Light[p];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[p];
|
||||
|
||||
/* fprintf(stderr, "%s\n", __func__); */
|
||||
|
||||
@@ -874,9 +875,9 @@ static void update_light_colors( struct gl_context *ctx, GLuint p )
|
||||
r200ContextPtr rmesa = R200_CONTEXT(ctx);
|
||||
float *fcmd = (float *)R200_DB_STATE( lit[p] );
|
||||
|
||||
COPY_4V( &fcmd[LIT_AMBIENT_RED], l->Ambient );
|
||||
COPY_4V( &fcmd[LIT_DIFFUSE_RED], l->Diffuse );
|
||||
COPY_4V( &fcmd[LIT_SPECULAR_RED], l->Specular );
|
||||
COPY_4V( &fcmd[LIT_AMBIENT_RED], lu->Ambient );
|
||||
COPY_4V( &fcmd[LIT_DIFFUSE_RED], lu->Diffuse );
|
||||
COPY_4V( &fcmd[LIT_SPECULAR_RED], lu->Specular );
|
||||
|
||||
R200_DB_STATECHANGE( rmesa, &rmesa->hw.lit[p] );
|
||||
}
|
||||
@@ -1118,9 +1119,10 @@ static void update_light( struct gl_context *ctx )
|
||||
while (mask) {
|
||||
const int p = u_bit_scan(&mask);
|
||||
struct gl_light *l = &ctx->Light.Light[p];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[p];
|
||||
GLfloat *fcmd = (GLfloat *)R200_DB_STATE( lit[p] );
|
||||
|
||||
if (l->EyePosition[3] == 0.0) {
|
||||
if (lu->EyePosition[3] == 0.0) {
|
||||
COPY_3FV( &fcmd[LIT_POSITION_X], l->_VP_inf_norm );
|
||||
COPY_3FV( &fcmd[LIT_DIRECTION_X], l->_h_inf_norm );
|
||||
fcmd[LIT_POSITION_W] = 0;
|
||||
@@ -1143,7 +1145,7 @@ static void r200Lightfv( struct gl_context *ctx, GLenum light,
|
||||
{
|
||||
r200ContextPtr rmesa = R200_CONTEXT(ctx);
|
||||
GLint p = light - GL_LIGHT0;
|
||||
struct gl_light *l = &ctx->Light.Light[p];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[p];
|
||||
GLfloat *fcmd = (GLfloat *)rmesa->hw.lit[p].cmd;
|
||||
|
||||
|
||||
@@ -1164,7 +1166,7 @@ static void r200Lightfv( struct gl_context *ctx, GLenum light,
|
||||
GLuint idx = TCL_PER_LIGHT_CTL_0 + p/2;
|
||||
|
||||
R200_STATECHANGE(rmesa, tcl);
|
||||
if (l->EyePosition[3] != 0.0F)
|
||||
if (lu->EyePosition[3] != 0.0F)
|
||||
rmesa->hw.tcl.cmd[idx] |= flag;
|
||||
else
|
||||
rmesa->hw.tcl.cmd[idx] &= ~flag;
|
||||
@@ -1181,10 +1183,10 @@ static void r200Lightfv( struct gl_context *ctx, GLenum light,
|
||||
GLuint idx = TCL_PER_LIGHT_CTL_0 + p/2;
|
||||
|
||||
R200_STATECHANGE(rmesa, lit[p]);
|
||||
fcmd[LIT_SPOT_CUTOFF] = l->_CosCutoff;
|
||||
fcmd[LIT_SPOT_CUTOFF] = lu->_CosCutoff;
|
||||
|
||||
R200_STATECHANGE(rmesa, tcl);
|
||||
if (l->SpotCutoff != 180.0F)
|
||||
if (lu->SpotCutoff != 180.0F)
|
||||
rmesa->hw.tcl.cmd[idx] |= flag;
|
||||
else
|
||||
rmesa->hw.tcl.cmd[idx] &= ~flag;
|
||||
@@ -1225,7 +1227,7 @@ static void r200Lightfv( struct gl_context *ctx, GLenum light,
|
||||
GLuint atten_const_flag = ( p&1 ) ? R200_LIGHT_1_CONSTANT_RANGE_ATTEN
|
||||
: R200_LIGHT_0_CONSTANT_RANGE_ATTEN;
|
||||
|
||||
if ( l->EyePosition[3] == 0.0F ||
|
||||
if ( lu->EyePosition[3] == 0.0F ||
|
||||
( ( fcmd[LIT_ATTEN_CONST] == 0.0 || fcmd[LIT_ATTEN_CONST] == 1.0 ) &&
|
||||
fcmd[LIT_ATTEN_QUADRATIC] == 0.0 && fcmd[LIT_ATTEN_LINEAR] == 0.0 ) ) {
|
||||
/* Disable attenuation */
|
||||
|
@@ -1218,23 +1218,23 @@ void r200InitState( r200ContextPtr rmesa )
|
||||
|
||||
|
||||
for (i = 0 ; i < 8; i++) {
|
||||
struct gl_light *l = &ctx->Light.Light[i];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
GLenum p = GL_LIGHT0 + i;
|
||||
*(float *)&(rmesa->hw.lit[i].cmd[LIT_RANGE_CUTOFF]) = FLT_MAX;
|
||||
|
||||
ctx->Driver.Lightfv( ctx, p, GL_AMBIENT, l->Ambient );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_DIFFUSE, l->Diffuse );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_SPECULAR, l->Specular );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_AMBIENT, lu->Ambient );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_DIFFUSE, lu->Diffuse );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_SPECULAR, lu->Specular );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_POSITION, NULL );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_SPOT_DIRECTION, NULL );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_SPOT_EXPONENT, &l->SpotExponent );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_SPOT_CUTOFF, &l->SpotCutoff );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_SPOT_EXPONENT, &lu->SpotExponent );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_SPOT_CUTOFF, &lu->SpotCutoff );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_CONSTANT_ATTENUATION,
|
||||
&l->ConstantAttenuation );
|
||||
&lu->ConstantAttenuation );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_LINEAR_ATTENUATION,
|
||||
&l->LinearAttenuation );
|
||||
&lu->LinearAttenuation );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_QUADRATIC_ATTENUATION,
|
||||
&l->QuadraticAttenuation );
|
||||
&lu->QuadraticAttenuation );
|
||||
*(float *)&(rmesa->hw.lit[i].cmd[LIT_ATTEN_XXX]) = 0.0;
|
||||
}
|
||||
|
||||
|
@@ -680,6 +680,7 @@ static void update_global_ambient( struct gl_context *ctx )
|
||||
static void update_light_colors( struct gl_context *ctx, GLuint p )
|
||||
{
|
||||
struct gl_light *l = &ctx->Light.Light[p];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[p];
|
||||
|
||||
/* fprintf(stderr, "%s\n", __func__); */
|
||||
|
||||
@@ -687,9 +688,9 @@ static void update_light_colors( struct gl_context *ctx, GLuint p )
|
||||
r100ContextPtr rmesa = R100_CONTEXT(ctx);
|
||||
float *fcmd = (float *)RADEON_DB_STATE( lit[p] );
|
||||
|
||||
COPY_4V( &fcmd[LIT_AMBIENT_RED], l->Ambient );
|
||||
COPY_4V( &fcmd[LIT_DIFFUSE_RED], l->Diffuse );
|
||||
COPY_4V( &fcmd[LIT_SPECULAR_RED], l->Specular );
|
||||
COPY_4V( &fcmd[LIT_AMBIENT_RED], lu->Ambient );
|
||||
COPY_4V( &fcmd[LIT_DIFFUSE_RED], lu->Diffuse );
|
||||
COPY_4V( &fcmd[LIT_SPECULAR_RED], lu->Specular );
|
||||
|
||||
RADEON_DB_STATECHANGE( rmesa, &rmesa->hw.lit[p] );
|
||||
}
|
||||
@@ -894,9 +895,10 @@ static void update_light( struct gl_context *ctx )
|
||||
while (mask) {
|
||||
const int p = u_bit_scan(&mask);
|
||||
struct gl_light *l = &ctx->Light.Light[p];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[p];
|
||||
GLfloat *fcmd = (GLfloat *)RADEON_DB_STATE( lit[p] );
|
||||
|
||||
if (l->EyePosition[3] == 0.0) {
|
||||
if (lu->EyePosition[3] == 0.0) {
|
||||
COPY_3FV( &fcmd[LIT_POSITION_X], l->_VP_inf_norm );
|
||||
COPY_3FV( &fcmd[LIT_DIRECTION_X], l->_h_inf_norm );
|
||||
fcmd[LIT_POSITION_W] = 0;
|
||||
@@ -919,7 +921,7 @@ static void radeonLightfv( struct gl_context *ctx, GLenum light,
|
||||
{
|
||||
r100ContextPtr rmesa = R100_CONTEXT(ctx);
|
||||
GLint p = light - GL_LIGHT0;
|
||||
struct gl_light *l = &ctx->Light.Light[p];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[p];
|
||||
GLfloat *fcmd = (GLfloat *)rmesa->hw.lit[p].cmd;
|
||||
|
||||
|
||||
@@ -946,7 +948,7 @@ static void radeonLightfv( struct gl_context *ctx, GLenum light,
|
||||
flag = RADEON_LIGHT_0_IS_LOCAL;
|
||||
|
||||
RADEON_STATECHANGE(rmesa, tcl);
|
||||
if (l->EyePosition[3] != 0.0F)
|
||||
if (lu->EyePosition[3] != 0.0F)
|
||||
rmesa->hw.tcl.cmd[idx] |= flag;
|
||||
else
|
||||
rmesa->hw.tcl.cmd[idx] &= ~flag;
|
||||
@@ -963,10 +965,10 @@ static void radeonLightfv( struct gl_context *ctx, GLenum light,
|
||||
GLuint idx = TCL_PER_LIGHT_CTL_0 + p/2;
|
||||
|
||||
RADEON_STATECHANGE(rmesa, lit[p]);
|
||||
fcmd[LIT_SPOT_CUTOFF] = l->_CosCutoff;
|
||||
fcmd[LIT_SPOT_CUTOFF] = lu->_CosCutoff;
|
||||
|
||||
RADEON_STATECHANGE(rmesa, tcl);
|
||||
if (l->SpotCutoff != 180.0F)
|
||||
if (lu->SpotCutoff != 180.0F)
|
||||
rmesa->hw.tcl.cmd[idx] |= flag;
|
||||
else
|
||||
rmesa->hw.tcl.cmd[idx] &= ~flag;
|
||||
@@ -1008,7 +1010,7 @@ static void radeonLightfv( struct gl_context *ctx, GLenum light,
|
||||
GLuint atten_const_flag = ( p&1 ) ? RADEON_LIGHT_1_CONSTANT_RANGE_ATTEN
|
||||
: RADEON_LIGHT_0_CONSTANT_RANGE_ATTEN;
|
||||
|
||||
if ( l->EyePosition[3] == 0.0F ||
|
||||
if ( lu->EyePosition[3] == 0.0F ||
|
||||
( ( fcmd[LIT_ATTEN_CONST] == 0.0 || fcmd[LIT_ATTEN_CONST] == 1.0 ) &&
|
||||
fcmd[LIT_ATTEN_QUADRATIC] == 0.0 && fcmd[LIT_ATTEN_LINEAR] == 0.0 ) ) {
|
||||
/* Disable attenuation */
|
||||
|
@@ -872,23 +872,23 @@ void radeonInitState( r100ContextPtr rmesa )
|
||||
(RADEON_LM_SOURCE_STATE_MULT << RADEON_SPECULAR_SOURCE_SHIFT));
|
||||
|
||||
for (i = 0 ; i < 8; i++) {
|
||||
struct gl_light *l = &ctx->Light.Light[i];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
GLenum p = GL_LIGHT0 + i;
|
||||
*(float *)&(rmesa->hw.lit[i].cmd[LIT_RANGE_CUTOFF]) = FLT_MAX;
|
||||
|
||||
ctx->Driver.Lightfv( ctx, p, GL_AMBIENT, l->Ambient );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_DIFFUSE, l->Diffuse );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_SPECULAR, l->Specular );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_AMBIENT, lu->Ambient );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_DIFFUSE, lu->Diffuse );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_SPECULAR, lu->Specular );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_POSITION, NULL );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_SPOT_DIRECTION, NULL );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_SPOT_EXPONENT, &l->SpotExponent );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_SPOT_CUTOFF, &l->SpotCutoff );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_SPOT_EXPONENT, &lu->SpotExponent );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_SPOT_CUTOFF, &lu->SpotCutoff );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_CONSTANT_ATTENUATION,
|
||||
&l->ConstantAttenuation );
|
||||
&lu->ConstantAttenuation );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_LINEAR_ATTENUATION,
|
||||
&l->LinearAttenuation );
|
||||
&lu->LinearAttenuation );
|
||||
ctx->Driver.Lightfv( ctx, p, GL_QUADRATIC_ATTENUATION,
|
||||
&l->QuadraticAttenuation );
|
||||
&lu->QuadraticAttenuation );
|
||||
*(float *)&(rmesa->hw.lit[i].cmd[LIT_ATTEN_XXX]) = 0.0;
|
||||
}
|
||||
|
||||
|
@@ -1219,36 +1219,37 @@ _mesa_PopAttrib(void)
|
||||
_math_matrix_analyse(ctx->ModelviewMatrixStack.Top);
|
||||
|
||||
for (i = 0; i < ctx->Const.MaxLights; i++) {
|
||||
const struct gl_light_uniforms *lu = &light->LightSource[i];
|
||||
const struct gl_light *l = &light->Light[i];
|
||||
_mesa_set_enable(ctx, GL_LIGHT0 + i, l->Enabled);
|
||||
_mesa_light(ctx, i, GL_AMBIENT, l->Ambient);
|
||||
_mesa_light(ctx, i, GL_DIFFUSE, l->Diffuse);
|
||||
_mesa_light(ctx, i, GL_SPECULAR, l->Specular);
|
||||
_mesa_light(ctx, i, GL_POSITION, l->EyePosition);
|
||||
_mesa_light(ctx, i, GL_SPOT_DIRECTION, l->SpotDirection);
|
||||
_mesa_light(ctx, i, GL_AMBIENT, lu->Ambient);
|
||||
_mesa_light(ctx, i, GL_DIFFUSE, lu->Diffuse);
|
||||
_mesa_light(ctx, i, GL_SPECULAR, lu->Specular);
|
||||
_mesa_light(ctx, i, GL_POSITION, lu->EyePosition);
|
||||
_mesa_light(ctx, i, GL_SPOT_DIRECTION, lu->SpotDirection);
|
||||
{
|
||||
GLfloat p[4] = { 0 };
|
||||
p[0] = l->SpotExponent;
|
||||
p[0] = lu->SpotExponent;
|
||||
_mesa_light(ctx, i, GL_SPOT_EXPONENT, p);
|
||||
}
|
||||
{
|
||||
GLfloat p[4] = { 0 };
|
||||
p[0] = l->SpotCutoff;
|
||||
p[0] = lu->SpotCutoff;
|
||||
_mesa_light(ctx, i, GL_SPOT_CUTOFF, p);
|
||||
}
|
||||
{
|
||||
GLfloat p[4] = { 0 };
|
||||
p[0] = l->ConstantAttenuation;
|
||||
p[0] = lu->ConstantAttenuation;
|
||||
_mesa_light(ctx, i, GL_CONSTANT_ATTENUATION, p);
|
||||
}
|
||||
{
|
||||
GLfloat p[4] = { 0 };
|
||||
p[0] = l->LinearAttenuation;
|
||||
p[0] = lu->LinearAttenuation;
|
||||
_mesa_light(ctx, i, GL_LINEAR_ATTENUATION, p);
|
||||
}
|
||||
{
|
||||
GLfloat p[4] = { 0 };
|
||||
p[0] = l->QuadraticAttenuation;
|
||||
p[0] = lu->QuadraticAttenuation;
|
||||
_mesa_light(ctx, i, GL_QUADRATIC_ATTENUATION, p);
|
||||
}
|
||||
}
|
||||
|
@@ -189,19 +189,19 @@ static void make_state_key( struct gl_context *ctx, struct state_key *key )
|
||||
mask = ctx->Light._EnabledLights;
|
||||
while (mask) {
|
||||
const int i = u_bit_scan(&mask);
|
||||
struct gl_light *light = &ctx->Light.Light[i];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
|
||||
key->unit[i].light_enabled = 1;
|
||||
|
||||
if (light->EyePosition[3] == 0.0F)
|
||||
if (lu->EyePosition[3] == 0.0F)
|
||||
key->unit[i].light_eyepos3_is_zero = 1;
|
||||
|
||||
if (light->SpotCutoff == 180.0F)
|
||||
if (lu->SpotCutoff == 180.0F)
|
||||
key->unit[i].light_spotcutoff_is_180 = 1;
|
||||
|
||||
if (light->ConstantAttenuation != 1.0F ||
|
||||
light->LinearAttenuation != 0.0F ||
|
||||
light->QuadraticAttenuation != 0.0F)
|
||||
if (lu->ConstantAttenuation != 1.0F ||
|
||||
lu->LinearAttenuation != 0.0F ||
|
||||
lu->QuadraticAttenuation != 0.0F)
|
||||
key->unit[i].light_attenuated = 1;
|
||||
}
|
||||
|
||||
|
@@ -104,32 +104,34 @@ _mesa_light(struct gl_context *ctx, GLuint lnum, GLenum pname, const GLfloat *pa
|
||||
assert(lnum < MAX_LIGHTS);
|
||||
light = &ctx->Light.Light[lnum];
|
||||
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[lnum];
|
||||
|
||||
switch (pname) {
|
||||
case GL_AMBIENT:
|
||||
if (TEST_EQ_4V(light->Ambient, params))
|
||||
if (TEST_EQ_4V(lu->Ambient, params))
|
||||
return;
|
||||
FLUSH_VERTICES(ctx, _NEW_LIGHT);
|
||||
COPY_4V( light->Ambient, params );
|
||||
COPY_4V( lu->Ambient, params );
|
||||
break;
|
||||
case GL_DIFFUSE:
|
||||
if (TEST_EQ_4V(light->Diffuse, params))
|
||||
if (TEST_EQ_4V(lu->Diffuse, params))
|
||||
return;
|
||||
FLUSH_VERTICES(ctx, _NEW_LIGHT);
|
||||
COPY_4V( light->Diffuse, params );
|
||||
COPY_4V( lu->Diffuse, params );
|
||||
break;
|
||||
case GL_SPECULAR:
|
||||
if (TEST_EQ_4V(light->Specular, params))
|
||||
if (TEST_EQ_4V(lu->Specular, params))
|
||||
return;
|
||||
FLUSH_VERTICES(ctx, _NEW_LIGHT);
|
||||
COPY_4V( light->Specular, params );
|
||||
COPY_4V( lu->Specular, params );
|
||||
break;
|
||||
case GL_POSITION: {
|
||||
/* NOTE: position has already been transformed by ModelView! */
|
||||
if (TEST_EQ_4V(light->EyePosition, params))
|
||||
if (TEST_EQ_4V(lu->EyePosition, params))
|
||||
return;
|
||||
FLUSH_VERTICES(ctx, _NEW_LIGHT);
|
||||
COPY_4V(light->EyePosition, params);
|
||||
if (light->EyePosition[3] != 0.0F)
|
||||
COPY_4V(lu->EyePosition, params);
|
||||
if (lu->EyePosition[3] != 0.0F)
|
||||
light->_Flags |= LIGHT_POSITIONAL;
|
||||
else
|
||||
light->_Flags &= ~LIGHT_POSITIONAL;
|
||||
@@ -144,59 +146,59 @@ _mesa_light(struct gl_context *ctx, GLuint lnum, GLenum pname, const GLfloat *pa
|
||||
NORMALIZE_3FV(p);
|
||||
ADD_3V(p, p, eye_z);
|
||||
NORMALIZE_3FV(p);
|
||||
COPY_3V(light->_HalfVector, p);
|
||||
light->_HalfVector[3] = 1.0;
|
||||
COPY_3V(lu->_HalfVector, p);
|
||||
lu->_HalfVector[3] = 1.0;
|
||||
break;
|
||||
}
|
||||
case GL_SPOT_DIRECTION:
|
||||
/* NOTE: Direction already transformed by inverse ModelView! */
|
||||
if (TEST_EQ_3V(light->SpotDirection, params))
|
||||
if (TEST_EQ_3V(lu->SpotDirection, params))
|
||||
return;
|
||||
FLUSH_VERTICES(ctx, _NEW_LIGHT);
|
||||
COPY_3V(light->SpotDirection, params);
|
||||
COPY_3V(lu->SpotDirection, params);
|
||||
break;
|
||||
case GL_SPOT_EXPONENT:
|
||||
assert(params[0] >= 0.0F);
|
||||
assert(params[0] <= ctx->Const.MaxSpotExponent);
|
||||
if (light->SpotExponent == params[0])
|
||||
if (lu->SpotExponent == params[0])
|
||||
return;
|
||||
FLUSH_VERTICES(ctx, _NEW_LIGHT);
|
||||
light->SpotExponent = params[0];
|
||||
lu->SpotExponent = params[0];
|
||||
break;
|
||||
case GL_SPOT_CUTOFF:
|
||||
assert(params[0] == 180.0F || (params[0] >= 0.0F && params[0] <= 90.0F));
|
||||
if (light->SpotCutoff == params[0])
|
||||
if (lu->SpotCutoff == params[0])
|
||||
return;
|
||||
FLUSH_VERTICES(ctx, _NEW_LIGHT);
|
||||
light->SpotCutoff = params[0];
|
||||
light->_CosCutoff = (cosf(light->SpotCutoff * M_PI / 180.0));
|
||||
if (light->_CosCutoff < 0)
|
||||
light->_CosCutoff = 0;
|
||||
if (light->SpotCutoff != 180.0F)
|
||||
lu->SpotCutoff = params[0];
|
||||
lu->_CosCutoff = (cosf(lu->SpotCutoff * M_PI / 180.0));
|
||||
if (lu->_CosCutoff < 0)
|
||||
lu->_CosCutoff = 0;
|
||||
if (lu->SpotCutoff != 180.0F)
|
||||
light->_Flags |= LIGHT_SPOT;
|
||||
else
|
||||
light->_Flags &= ~LIGHT_SPOT;
|
||||
break;
|
||||
case GL_CONSTANT_ATTENUATION:
|
||||
assert(params[0] >= 0.0F);
|
||||
if (light->ConstantAttenuation == params[0])
|
||||
if (lu->ConstantAttenuation == params[0])
|
||||
return;
|
||||
FLUSH_VERTICES(ctx, _NEW_LIGHT);
|
||||
light->ConstantAttenuation = params[0];
|
||||
lu->ConstantAttenuation = params[0];
|
||||
break;
|
||||
case GL_LINEAR_ATTENUATION:
|
||||
assert(params[0] >= 0.0F);
|
||||
if (light->LinearAttenuation == params[0])
|
||||
if (lu->LinearAttenuation == params[0])
|
||||
return;
|
||||
FLUSH_VERTICES(ctx, _NEW_LIGHT);
|
||||
light->LinearAttenuation = params[0];
|
||||
lu->LinearAttenuation = params[0];
|
||||
break;
|
||||
case GL_QUADRATIC_ATTENUATION:
|
||||
assert(params[0] >= 0.0F);
|
||||
if (light->QuadraticAttenuation == params[0])
|
||||
if (lu->QuadraticAttenuation == params[0])
|
||||
return;
|
||||
FLUSH_VERTICES(ctx, _NEW_LIGHT);
|
||||
light->QuadraticAttenuation = params[0];
|
||||
lu->QuadraticAttenuation = params[0];
|
||||
break;
|
||||
default:
|
||||
unreachable("Unexpected pname in _mesa_light()");
|
||||
@@ -343,34 +345,34 @@ _mesa_GetLightfv( GLenum light, GLenum pname, GLfloat *params )
|
||||
|
||||
switch (pname) {
|
||||
case GL_AMBIENT:
|
||||
COPY_4V( params, ctx->Light.Light[l].Ambient );
|
||||
COPY_4V( params, ctx->Light.LightSource[l].Ambient );
|
||||
break;
|
||||
case GL_DIFFUSE:
|
||||
COPY_4V( params, ctx->Light.Light[l].Diffuse );
|
||||
COPY_4V( params, ctx->Light.LightSource[l].Diffuse );
|
||||
break;
|
||||
case GL_SPECULAR:
|
||||
COPY_4V( params, ctx->Light.Light[l].Specular );
|
||||
COPY_4V( params, ctx->Light.LightSource[l].Specular );
|
||||
break;
|
||||
case GL_POSITION:
|
||||
COPY_4V( params, ctx->Light.Light[l].EyePosition );
|
||||
COPY_4V( params, ctx->Light.LightSource[l].EyePosition );
|
||||
break;
|
||||
case GL_SPOT_DIRECTION:
|
||||
COPY_3V( params, ctx->Light.Light[l].SpotDirection );
|
||||
COPY_3V( params, ctx->Light.LightSource[l].SpotDirection );
|
||||
break;
|
||||
case GL_SPOT_EXPONENT:
|
||||
params[0] = ctx->Light.Light[l].SpotExponent;
|
||||
params[0] = ctx->Light.LightSource[l].SpotExponent;
|
||||
break;
|
||||
case GL_SPOT_CUTOFF:
|
||||
params[0] = ctx->Light.Light[l].SpotCutoff;
|
||||
params[0] = ctx->Light.LightSource[l].SpotCutoff;
|
||||
break;
|
||||
case GL_CONSTANT_ATTENUATION:
|
||||
params[0] = ctx->Light.Light[l].ConstantAttenuation;
|
||||
params[0] = ctx->Light.LightSource[l].ConstantAttenuation;
|
||||
break;
|
||||
case GL_LINEAR_ATTENUATION:
|
||||
params[0] = ctx->Light.Light[l].LinearAttenuation;
|
||||
params[0] = ctx->Light.LightSource[l].LinearAttenuation;
|
||||
break;
|
||||
case GL_QUADRATIC_ATTENUATION:
|
||||
params[0] = ctx->Light.Light[l].QuadraticAttenuation;
|
||||
params[0] = ctx->Light.LightSource[l].QuadraticAttenuation;
|
||||
break;
|
||||
default:
|
||||
_mesa_error( ctx, GL_INVALID_ENUM, "glGetLightfv" );
|
||||
@@ -392,48 +394,48 @@ _mesa_GetLightiv( GLenum light, GLenum pname, GLint *params )
|
||||
|
||||
switch (pname) {
|
||||
case GL_AMBIENT:
|
||||
params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[0]);
|
||||
params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[1]);
|
||||
params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[2]);
|
||||
params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Ambient[3]);
|
||||
params[0] = FLOAT_TO_INT(ctx->Light.LightSource[l].Ambient[0]);
|
||||
params[1] = FLOAT_TO_INT(ctx->Light.LightSource[l].Ambient[1]);
|
||||
params[2] = FLOAT_TO_INT(ctx->Light.LightSource[l].Ambient[2]);
|
||||
params[3] = FLOAT_TO_INT(ctx->Light.LightSource[l].Ambient[3]);
|
||||
break;
|
||||
case GL_DIFFUSE:
|
||||
params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[0]);
|
||||
params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[1]);
|
||||
params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[2]);
|
||||
params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Diffuse[3]);
|
||||
params[0] = FLOAT_TO_INT(ctx->Light.LightSource[l].Diffuse[0]);
|
||||
params[1] = FLOAT_TO_INT(ctx->Light.LightSource[l].Diffuse[1]);
|
||||
params[2] = FLOAT_TO_INT(ctx->Light.LightSource[l].Diffuse[2]);
|
||||
params[3] = FLOAT_TO_INT(ctx->Light.LightSource[l].Diffuse[3]);
|
||||
break;
|
||||
case GL_SPECULAR:
|
||||
params[0] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[0]);
|
||||
params[1] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[1]);
|
||||
params[2] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[2]);
|
||||
params[3] = FLOAT_TO_INT(ctx->Light.Light[l].Specular[3]);
|
||||
params[0] = FLOAT_TO_INT(ctx->Light.LightSource[l].Specular[0]);
|
||||
params[1] = FLOAT_TO_INT(ctx->Light.LightSource[l].Specular[1]);
|
||||
params[2] = FLOAT_TO_INT(ctx->Light.LightSource[l].Specular[2]);
|
||||
params[3] = FLOAT_TO_INT(ctx->Light.LightSource[l].Specular[3]);
|
||||
break;
|
||||
case GL_POSITION:
|
||||
params[0] = (GLint) ctx->Light.Light[l].EyePosition[0];
|
||||
params[1] = (GLint) ctx->Light.Light[l].EyePosition[1];
|
||||
params[2] = (GLint) ctx->Light.Light[l].EyePosition[2];
|
||||
params[3] = (GLint) ctx->Light.Light[l].EyePosition[3];
|
||||
params[0] = (GLint) ctx->Light.LightSource[l].EyePosition[0];
|
||||
params[1] = (GLint) ctx->Light.LightSource[l].EyePosition[1];
|
||||
params[2] = (GLint) ctx->Light.LightSource[l].EyePosition[2];
|
||||
params[3] = (GLint) ctx->Light.LightSource[l].EyePosition[3];
|
||||
break;
|
||||
case GL_SPOT_DIRECTION:
|
||||
params[0] = (GLint) ctx->Light.Light[l].SpotDirection[0];
|
||||
params[1] = (GLint) ctx->Light.Light[l].SpotDirection[1];
|
||||
params[2] = (GLint) ctx->Light.Light[l].SpotDirection[2];
|
||||
params[0] = (GLint) ctx->Light.LightSource[l].SpotDirection[0];
|
||||
params[1] = (GLint) ctx->Light.LightSource[l].SpotDirection[1];
|
||||
params[2] = (GLint) ctx->Light.LightSource[l].SpotDirection[2];
|
||||
break;
|
||||
case GL_SPOT_EXPONENT:
|
||||
params[0] = (GLint) ctx->Light.Light[l].SpotExponent;
|
||||
params[0] = (GLint) ctx->Light.LightSource[l].SpotExponent;
|
||||
break;
|
||||
case GL_SPOT_CUTOFF:
|
||||
params[0] = (GLint) ctx->Light.Light[l].SpotCutoff;
|
||||
params[0] = (GLint) ctx->Light.LightSource[l].SpotCutoff;
|
||||
break;
|
||||
case GL_CONSTANT_ATTENUATION:
|
||||
params[0] = (GLint) ctx->Light.Light[l].ConstantAttenuation;
|
||||
params[0] = (GLint) ctx->Light.LightSource[l].ConstantAttenuation;
|
||||
break;
|
||||
case GL_LINEAR_ATTENUATION:
|
||||
params[0] = (GLint) ctx->Light.Light[l].LinearAttenuation;
|
||||
params[0] = (GLint) ctx->Light.LightSource[l].LinearAttenuation;
|
||||
break;
|
||||
case GL_QUADRATIC_ATTENUATION:
|
||||
params[0] = (GLint) ctx->Light.Light[l].QuadraticAttenuation;
|
||||
params[0] = (GLint) ctx->Light.LightSource[l].QuadraticAttenuation;
|
||||
break;
|
||||
default:
|
||||
_mesa_error( ctx, GL_INVALID_ENUM, "glGetLightiv" );
|
||||
@@ -638,7 +640,8 @@ _mesa_update_material( struct gl_context *ctx, GLuint bitmask )
|
||||
while (mask) {
|
||||
const int i = u_bit_scan(&mask);
|
||||
struct gl_light *light = &ctx->Light.Light[i];
|
||||
SCALE_3V( light->_MatAmbient[0], light->Ambient,
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
SCALE_3V( light->_MatAmbient[0], lu->Ambient,
|
||||
mat[MAT_ATTRIB_FRONT_AMBIENT]);
|
||||
}
|
||||
}
|
||||
@@ -648,7 +651,8 @@ _mesa_update_material( struct gl_context *ctx, GLuint bitmask )
|
||||
while (mask) {
|
||||
const int i = u_bit_scan(&mask);
|
||||
struct gl_light *light = &ctx->Light.Light[i];
|
||||
SCALE_3V( light->_MatAmbient[1], light->Ambient,
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
SCALE_3V( light->_MatAmbient[1], lu->Ambient,
|
||||
mat[MAT_ATTRIB_BACK_AMBIENT]);
|
||||
}
|
||||
}
|
||||
@@ -672,7 +676,8 @@ _mesa_update_material( struct gl_context *ctx, GLuint bitmask )
|
||||
while (mask) {
|
||||
const int i = u_bit_scan(&mask);
|
||||
struct gl_light *light = &ctx->Light.Light[i];
|
||||
SCALE_3V( light->_MatDiffuse[0], light->Diffuse,
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
SCALE_3V( light->_MatDiffuse[0], lu->Diffuse,
|
||||
mat[MAT_ATTRIB_FRONT_DIFFUSE] );
|
||||
}
|
||||
}
|
||||
@@ -682,7 +687,8 @@ _mesa_update_material( struct gl_context *ctx, GLuint bitmask )
|
||||
while (mask) {
|
||||
const int i = u_bit_scan(&mask);
|
||||
struct gl_light *light = &ctx->Light.Light[i];
|
||||
SCALE_3V( light->_MatDiffuse[1], light->Diffuse,
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
SCALE_3V( light->_MatDiffuse[1], lu->Diffuse,
|
||||
mat[MAT_ATTRIB_BACK_DIFFUSE] );
|
||||
}
|
||||
}
|
||||
@@ -693,7 +699,8 @@ _mesa_update_material( struct gl_context *ctx, GLuint bitmask )
|
||||
while (mask) {
|
||||
const int i = u_bit_scan(&mask);
|
||||
struct gl_light *light = &ctx->Light.Light[i];
|
||||
SCALE_3V( light->_MatSpecular[0], light->Specular,
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
SCALE_3V( light->_MatSpecular[0], lu->Specular,
|
||||
mat[MAT_ATTRIB_FRONT_SPECULAR]);
|
||||
}
|
||||
}
|
||||
@@ -703,7 +710,8 @@ _mesa_update_material( struct gl_context *ctx, GLuint bitmask )
|
||||
while (mask) {
|
||||
const int i = u_bit_scan(&mask);
|
||||
struct gl_light *light = &ctx->Light.Light[i];
|
||||
SCALE_3V( light->_MatSpecular[1], light->Specular,
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
SCALE_3V( light->_MatSpecular[1], lu->Specular,
|
||||
mat[MAT_ATTRIB_BACK_SPECULAR]);
|
||||
}
|
||||
}
|
||||
@@ -974,15 +982,16 @@ compute_light_positions( struct gl_context *ctx )
|
||||
while (mask) {
|
||||
const int i = u_bit_scan(&mask);
|
||||
struct gl_light *light = &ctx->Light.Light[i];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
|
||||
if (ctx->_NeedEyeCoords) {
|
||||
/* _Position is in eye coordinate space */
|
||||
COPY_4FV( light->_Position, light->EyePosition );
|
||||
COPY_4FV( light->_Position, lu->EyePosition );
|
||||
}
|
||||
else {
|
||||
/* _Position is in object coordinate space */
|
||||
TRANSFORM_POINT( light->_Position, ctx->ModelviewMatrixStack.Top->inv,
|
||||
light->EyePosition );
|
||||
lu->EyePosition );
|
||||
}
|
||||
|
||||
if (!(light->_Flags & LIGHT_POSITIONAL)) {
|
||||
@@ -1009,12 +1018,12 @@ compute_light_positions( struct gl_context *ctx )
|
||||
/* Note: we normalize the spot direction now */
|
||||
|
||||
if (ctx->_NeedEyeCoords) {
|
||||
COPY_3V( light->_NormSpotDirection, light->SpotDirection );
|
||||
COPY_3V( light->_NormSpotDirection, lu->SpotDirection );
|
||||
NORMALIZE_3FV( light->_NormSpotDirection );
|
||||
}
|
||||
else {
|
||||
GLfloat spotDir[3];
|
||||
COPY_3V(spotDir, light->SpotDirection);
|
||||
COPY_3V(spotDir, lu->SpotDirection);
|
||||
NORMALIZE_3FV(spotDir);
|
||||
TRANSFORM_NORMAL( light->_NormSpotDirection,
|
||||
spotDir,
|
||||
@@ -1027,9 +1036,9 @@ compute_light_positions( struct gl_context *ctx )
|
||||
GLfloat PV_dot_dir = - DOT3(light->_VP_inf_norm,
|
||||
light->_NormSpotDirection);
|
||||
|
||||
if (PV_dot_dir > light->_CosCutoff) {
|
||||
if (PV_dot_dir > lu->_CosCutoff) {
|
||||
light->_VP_inf_spot_attenuation =
|
||||
powf(PV_dot_dir, light->SpotExponent);
|
||||
powf(PV_dot_dir, lu->SpotExponent);
|
||||
}
|
||||
else {
|
||||
light->_VP_inf_spot_attenuation = 0;
|
||||
@@ -1134,25 +1143,25 @@ _mesa_allow_light_in_model( struct gl_context *ctx, GLboolean flag )
|
||||
* \note The defaults for light 0 are different than the other lights.
|
||||
*/
|
||||
static void
|
||||
init_light( struct gl_light *l, GLuint n )
|
||||
init_light( struct gl_light *l, struct gl_light_uniforms *lu, GLuint n )
|
||||
{
|
||||
ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
|
||||
ASSIGN_4V( lu->Ambient, 0.0, 0.0, 0.0, 1.0 );
|
||||
if (n==0) {
|
||||
ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
|
||||
ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
|
||||
ASSIGN_4V( lu->Diffuse, 1.0, 1.0, 1.0, 1.0 );
|
||||
ASSIGN_4V( lu->Specular, 1.0, 1.0, 1.0, 1.0 );
|
||||
}
|
||||
else {
|
||||
ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
|
||||
ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
|
||||
ASSIGN_4V( lu->Diffuse, 0.0, 0.0, 0.0, 1.0 );
|
||||
ASSIGN_4V( lu->Specular, 0.0, 0.0, 0.0, 1.0 );
|
||||
}
|
||||
ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
|
||||
ASSIGN_3V( l->SpotDirection, 0.0, 0.0, -1.0 );
|
||||
l->SpotExponent = 0.0;
|
||||
l->SpotCutoff = 180.0;
|
||||
l->_CosCutoff = 0.0; /* KW: -ve values not admitted */
|
||||
l->ConstantAttenuation = 1.0;
|
||||
l->LinearAttenuation = 0.0;
|
||||
l->QuadraticAttenuation = 0.0;
|
||||
ASSIGN_4V( lu->EyePosition, 0.0, 0.0, 1.0, 0.0 );
|
||||
ASSIGN_3V( lu->SpotDirection, 0.0, 0.0, -1.0 );
|
||||
lu->SpotExponent = 0.0;
|
||||
lu->SpotCutoff = 180.0;
|
||||
lu->_CosCutoff = 0.0; /* KW: -ve values not admitted */
|
||||
lu->ConstantAttenuation = 1.0;
|
||||
lu->LinearAttenuation = 0.0;
|
||||
lu->QuadraticAttenuation = 0.0;
|
||||
l->Enabled = GL_FALSE;
|
||||
}
|
||||
|
||||
@@ -1207,7 +1216,7 @@ _mesa_init_lighting( struct gl_context *ctx )
|
||||
/* Lighting group */
|
||||
ctx->Light._EnabledLights = 0;
|
||||
for (i = 0; i < MAX_LIGHTS; i++) {
|
||||
init_light( &ctx->Light.Light[i], i );
|
||||
init_light( &ctx->Light.Light[i], &ctx->Light.LightSource[i], i );
|
||||
}
|
||||
|
||||
init_lightmodel( &ctx->Light.Model );
|
||||
|
@@ -299,27 +299,6 @@ struct gl_material
|
||||
*/
|
||||
struct gl_light
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
/* These must be in the same order as the STATE_* enums,
|
||||
* which should also match the order of gl_LightSource members.
|
||||
*/
|
||||
GLfloat Ambient[4]; /**< STATE_AMBIENT */
|
||||
GLfloat Diffuse[4]; /**< STATE_DIFFUSE */
|
||||
GLfloat Specular[4]; /**< STATE_SPECULAR */
|
||||
GLfloat EyePosition[4]; /**< STATE_POSITION in eye coordinates */
|
||||
GLfloat _HalfVector[4]; /**< STATE_HALF_VECTOR */
|
||||
GLfloat SpotDirection[3]; /**< STATE_SPOT_DIRECTION in eye coordinates */
|
||||
GLfloat _CosCutoff; /**< = MAX(0, cos(SpotCutoff)) */
|
||||
GLfloat ConstantAttenuation; /**< STATE_ATTENUATION */
|
||||
GLfloat LinearAttenuation;
|
||||
GLfloat QuadraticAttenuation;
|
||||
GLfloat SpotExponent;
|
||||
GLfloat SpotCutoff; /**< STATE_SPOT_CUTOFF in degrees */
|
||||
};
|
||||
GLfloat Values[29];
|
||||
};
|
||||
|
||||
GLboolean Enabled; /**< On/off flag */
|
||||
|
||||
/**
|
||||
@@ -616,11 +595,36 @@ struct gl_hint_attrib
|
||||
};
|
||||
|
||||
|
||||
struct gl_light_uniforms {
|
||||
/* These must be in the same order as the STATE_* enums,
|
||||
* which should also match the order of gl_LightSource members.
|
||||
*/
|
||||
GLfloat Ambient[4]; /**< STATE_AMBIENT */
|
||||
GLfloat Diffuse[4]; /**< STATE_DIFFUSE */
|
||||
GLfloat Specular[4]; /**< STATE_SPECULAR */
|
||||
GLfloat EyePosition[4]; /**< STATE_POSITION in eye coordinates */
|
||||
GLfloat _HalfVector[4]; /**< STATE_HALF_VECTOR */
|
||||
GLfloat SpotDirection[3]; /**< STATE_SPOT_DIRECTION in eye coordinates */
|
||||
GLfloat _CosCutoff; /**< = MAX(0, cos(SpotCutoff)) */
|
||||
GLfloat ConstantAttenuation; /**< STATE_ATTENUATION */
|
||||
GLfloat LinearAttenuation;
|
||||
GLfloat QuadraticAttenuation;
|
||||
GLfloat SpotExponent;
|
||||
GLfloat SpotCutoff; /**< STATE_SPOT_CUTOFF in degrees */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Lighting attribute group (GL_LIGHT_BIT).
|
||||
*/
|
||||
struct gl_light_attrib
|
||||
{
|
||||
/* gl_LightSource uniforms */
|
||||
union {
|
||||
struct gl_light_uniforms LightSource[MAX_LIGHTS];
|
||||
GLfloat LightSourceData[(sizeof(struct gl_light_uniforms) / 4) * MAX_LIGHTS];
|
||||
};
|
||||
|
||||
struct gl_light Light[MAX_LIGHTS]; /**< Array of light sources */
|
||||
struct gl_lightmodel Model; /**< Lighting model */
|
||||
|
||||
|
@@ -154,6 +154,7 @@ shade_rastpos(struct gl_context *ctx,
|
||||
while (mask) {
|
||||
const int i = u_bit_scan(&mask);
|
||||
struct gl_light *light = &ctx->Light.Light[i];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[i];
|
||||
GLfloat attenuation = 1.0;
|
||||
GLfloat VP[3]; /* vector from vertex to light pos */
|
||||
GLfloat n_dot_VP;
|
||||
@@ -179,18 +180,18 @@ shade_rastpos(struct gl_context *ctx,
|
||||
}
|
||||
|
||||
/* atti */
|
||||
attenuation = 1.0F / (light->ConstantAttenuation + d *
|
||||
(light->LinearAttenuation + d *
|
||||
light->QuadraticAttenuation));
|
||||
attenuation = 1.0F / (lu->ConstantAttenuation + d *
|
||||
(lu->LinearAttenuation + d *
|
||||
lu->QuadraticAttenuation));
|
||||
|
||||
if (light->_Flags & LIGHT_SPOT) {
|
||||
GLfloat PV_dot_dir = - DOT3(VP, light->_NormSpotDirection);
|
||||
|
||||
if (PV_dot_dir<light->_CosCutoff) {
|
||||
if (PV_dot_dir<lu->_CosCutoff) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
GLfloat spot = powf(PV_dot_dir, light->SpotExponent);
|
||||
GLfloat spot = powf(PV_dot_dir, lu->SpotExponent);
|
||||
attenuation *= spot;
|
||||
}
|
||||
}
|
||||
|
@@ -129,9 +129,9 @@ fetch_state(struct gl_context *ctx, const gl_state_index16 state[],
|
||||
const unsigned index = state[2] - STATE_AMBIENT;
|
||||
assert(index < 8);
|
||||
if (index != STATE_SPOT_CUTOFF)
|
||||
COPY_4V(value, &ctx->Light.Light[ln].Values[index * 4]);
|
||||
COPY_4V(value, (float*)&ctx->Light.LightSource[ln] + index * 4);
|
||||
else
|
||||
value[0] = ctx->Light.Light[ln].Values[index * 4];
|
||||
value[0] = ctx->Light.LightSource[ln].SpotCutoff;
|
||||
return;
|
||||
}
|
||||
case STATE_LIGHTMODEL_AMBIENT:
|
||||
@@ -168,7 +168,7 @@ fetch_state(struct gl_context *ctx, const gl_state_index16 state[],
|
||||
switch (state[3]) {
|
||||
case STATE_AMBIENT:
|
||||
for (i = 0; i < 3; i++) {
|
||||
value[i] = ctx->Light.Light[ln].Ambient[i] *
|
||||
value[i] = ctx->Light.LightSource[ln].Ambient[i] *
|
||||
ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_AMBIENT+face][i];
|
||||
}
|
||||
/* [3] = material alpha */
|
||||
@@ -176,7 +176,7 @@ fetch_state(struct gl_context *ctx, const gl_state_index16 state[],
|
||||
return;
|
||||
case STATE_DIFFUSE:
|
||||
for (i = 0; i < 3; i++) {
|
||||
value[i] = ctx->Light.Light[ln].Diffuse[i] *
|
||||
value[i] = ctx->Light.LightSource[ln].Diffuse[i] *
|
||||
ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE+face][i];
|
||||
}
|
||||
/* [3] = material alpha */
|
||||
@@ -184,7 +184,7 @@ fetch_state(struct gl_context *ctx, const gl_state_index16 state[],
|
||||
return;
|
||||
case STATE_SPECULAR:
|
||||
for (i = 0; i < 3; i++) {
|
||||
value[i] = ctx->Light.Light[ln].Specular[i] *
|
||||
value[i] = ctx->Light.LightSource[ln].Specular[i] *
|
||||
ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SPECULAR+face][i];
|
||||
}
|
||||
/* [3] = material alpha */
|
||||
@@ -552,7 +552,7 @@ fetch_state(struct gl_context *ctx, const gl_state_index16 state[],
|
||||
/* pre-normalize spot dir */
|
||||
const GLuint ln = (GLuint) state[2];
|
||||
COPY_3V(value, ctx->Light.Light[ln]._NormSpotDirection);
|
||||
value[3] = ctx->Light.Light[ln]._CosCutoff;
|
||||
value[3] = ctx->Light.LightSource[ln]._CosCutoff;
|
||||
}
|
||||
return;
|
||||
|
||||
|
@@ -110,6 +110,7 @@ static void TAG(light_rgba_spec)( struct gl_context *ctx,
|
||||
while (mask) {
|
||||
const int l = u_bit_scan(&mask);
|
||||
struct gl_light *light = &ctx->Light.Light[l];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[l];
|
||||
GLfloat n_dot_h;
|
||||
GLfloat correction;
|
||||
GLint side;
|
||||
@@ -137,19 +138,19 @@ static void TAG(light_rgba_spec)( struct gl_context *ctx,
|
||||
SELF_SCALE_SCALAR_3V(VP, invd);
|
||||
}
|
||||
|
||||
attenuation = 1.0F / (light->ConstantAttenuation + d *
|
||||
(light->LinearAttenuation + d *
|
||||
light->QuadraticAttenuation));
|
||||
attenuation = 1.0F / (lu->ConstantAttenuation + d *
|
||||
(lu->LinearAttenuation + d *
|
||||
lu->QuadraticAttenuation));
|
||||
|
||||
/* spotlight attenuation */
|
||||
if (light->_Flags & LIGHT_SPOT) {
|
||||
GLfloat PV_dot_dir = - DOT3(VP, light->_NormSpotDirection);
|
||||
|
||||
if (PV_dot_dir<light->_CosCutoff) {
|
||||
if (PV_dot_dir<lu->_CosCutoff) {
|
||||
continue; /* this light makes no contribution */
|
||||
}
|
||||
else {
|
||||
GLfloat spot = powf(PV_dot_dir, light->SpotExponent);
|
||||
GLfloat spot = powf(PV_dot_dir, lu->SpotExponent);
|
||||
attenuation *= spot;
|
||||
}
|
||||
}
|
||||
@@ -289,6 +290,7 @@ static void TAG(light_rgba)( struct gl_context *ctx,
|
||||
while (mask) {
|
||||
const int l = u_bit_scan(&mask);
|
||||
struct gl_light *light = &ctx->Light.Light[l];
|
||||
struct gl_light_uniforms *lu = &ctx->Light.LightSource[l];
|
||||
GLfloat n_dot_h;
|
||||
GLfloat correction;
|
||||
GLint side;
|
||||
@@ -316,19 +318,19 @@ static void TAG(light_rgba)( struct gl_context *ctx,
|
||||
SELF_SCALE_SCALAR_3V(VP, invd);
|
||||
}
|
||||
|
||||
attenuation = 1.0F / (light->ConstantAttenuation + d *
|
||||
(light->LinearAttenuation + d *
|
||||
light->QuadraticAttenuation));
|
||||
attenuation = 1.0F / (lu->ConstantAttenuation + d *
|
||||
(lu->LinearAttenuation + d *
|
||||
lu->QuadraticAttenuation));
|
||||
|
||||
/* spotlight attenuation */
|
||||
if (light->_Flags & LIGHT_SPOT) {
|
||||
GLfloat PV_dot_dir = - DOT3(VP, light->_NormSpotDirection);
|
||||
|
||||
if (PV_dot_dir<light->_CosCutoff) {
|
||||
if (PV_dot_dir<lu->_CosCutoff) {
|
||||
continue; /* this light makes no contribution */
|
||||
}
|
||||
else {
|
||||
GLfloat spot = powf(PV_dot_dir, light->SpotExponent);
|
||||
GLfloat spot = powf(PV_dot_dir, lu->SpotExponent);
|
||||
attenuation *= spot;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user