Commit 7ad84a02 authored by Marek Olšák's avatar Marek Olšák Committed by Marge Bot

mesa: eliminate the switch statement for STATE_TEXGEN

The memory layout of texgen planes must be adjusted to allow
the elimination of switch statements in fetch_state.

v2: change the static asserts to compile on MSVC

Reviewed-by: Eric Anholt <eric@anholt.net> (v1)
Reviewed-by: Zoltán Böszörményi's avatarZoltán Böszörményi <zboszor@gmail.com>
Part-of: <!8183>
parent 0eccba1a
......@@ -200,12 +200,12 @@ get_texgen_coord(struct gl_fixedfunc_texture_unit *u, int i)
}
static inline float *
get_texgen_coeff(struct gl_texgen *c)
get_texgen_coeff(struct gl_fixedfunc_texture_unit *u, GLenum mode, unsigned chan)
{
if (c->Mode == GL_OBJECT_LINEAR)
return c->ObjectPlane;
else if (c->Mode == GL_EYE_LINEAR)
return c->EyePlane;
if (mode == GL_OBJECT_LINEAR)
return u->ObjectPlane[chan];
else if (mode == GL_EYE_LINEAR)
return u->EyePlane[chan];
else
return NULL;
}
......
......@@ -46,7 +46,7 @@ nv10_emit_tex_gen(struct gl_context *ctx, int emit)
for (j = 0; j < 4; j++) {
if (nctx->fallback == HWTNL && (unit->TexGenEnabled & 1 << j)) {
struct gl_texgen *coord = get_texgen_coord(unit, j);
float *k = get_texgen_coeff(coord);
float *k = get_texgen_coeff(unit, coord->Mode, j);
if (k) {
BEGIN_NV04(push, NV10_3D(TEX_GEN_COEFF(i, j)), 4);
......
......@@ -46,7 +46,7 @@ nv20_emit_tex_gen(struct gl_context *ctx, int emit)
for (j = 0; j < 4; j++) {
if (nctx->fallback == HWTNL && (unit->TexGenEnabled & 1 << j)) {
struct gl_texgen *coord = get_texgen_coord(unit, j);
float *k = get_texgen_coeff(coord);
float *k = get_texgen_coeff(unit, coord->Mode, j);
if (k) {
BEGIN_NV04(push, NV20_3D(TEX_GEN_COEFF(i, j)), 4);
......
......@@ -1161,10 +1161,10 @@ static GLboolean r200_validate_texgen( struct gl_context *ctx, GLuint unit )
switch (mode) {
case GL_OBJECT_LINEAR: {
GLuint needtgenable = r200_need_dis_texgen( texUnit->TexGenEnabled,
texUnit->GenS.ObjectPlane,
texUnit->GenT.ObjectPlane,
texUnit->GenR.ObjectPlane,
texUnit->GenQ.ObjectPlane );
texUnit->ObjectPlane[GEN_S],
texUnit->ObjectPlane[GEN_T],
texUnit->ObjectPlane[GEN_R],
texUnit->ObjectPlane[GEN_Q] );
if (needtgenable & (S_BIT | T_BIT)) {
if (R200_DEBUG & RADEON_FALLBACKS)
fprintf(stderr, "fallback mixed texgen / obj plane, 0x%x\n",
......@@ -1180,19 +1180,19 @@ static GLboolean r200_validate_texgen( struct gl_context *ctx, GLuint unit )
tgi |= R200_TEXGEN_INPUT_OBJ << inputshift;
set_texgen_matrix( rmesa, unit,
(texUnit->TexGenEnabled & S_BIT) ? texUnit->GenS.ObjectPlane : I,
(texUnit->TexGenEnabled & T_BIT) ? texUnit->GenT.ObjectPlane : I + 4,
(texUnit->TexGenEnabled & R_BIT) ? texUnit->GenR.ObjectPlane : I + 8,
(texUnit->TexGenEnabled & Q_BIT) ? texUnit->GenQ.ObjectPlane : I + 12);
(texUnit->TexGenEnabled & S_BIT) ? texUnit->ObjectPlane[GEN_S] : I,
(texUnit->TexGenEnabled & T_BIT) ? texUnit->ObjectPlane[GEN_T] : I + 4,
(texUnit->TexGenEnabled & R_BIT) ? texUnit->ObjectPlane[GEN_R] : I + 8,
(texUnit->TexGenEnabled & Q_BIT) ? texUnit->ObjectPlane[GEN_Q] : I + 12);
}
break;
case GL_EYE_LINEAR: {
GLuint needtgenable = r200_need_dis_texgen( texUnit->TexGenEnabled,
texUnit->GenS.EyePlane,
texUnit->GenT.EyePlane,
texUnit->GenR.EyePlane,
texUnit->GenQ.EyePlane );
texUnit->EyePlane[GEN_S],
texUnit->EyePlane[GEN_T],
texUnit->EyePlane[GEN_R],
texUnit->EyePlane[GEN_Q] );
if (needtgenable & (S_BIT | T_BIT)) {
if (R200_DEBUG & RADEON_FALLBACKS)
fprintf(stderr, "fallback mixed texgen / eye plane, 0x%x\n",
......@@ -1207,10 +1207,10 @@ static GLboolean r200_validate_texgen( struct gl_context *ctx, GLuint unit )
}
tgi |= R200_TEXGEN_INPUT_EYE << inputshift;
set_texgen_matrix( rmesa, unit,
(texUnit->TexGenEnabled & S_BIT) ? texUnit->GenS.EyePlane : I,
(texUnit->TexGenEnabled & T_BIT) ? texUnit->GenT.EyePlane : I + 4,
(texUnit->TexGenEnabled & R_BIT) ? texUnit->GenR.EyePlane : I + 8,
(texUnit->TexGenEnabled & Q_BIT) ? texUnit->GenQ.EyePlane : I + 12);
(texUnit->TexGenEnabled & S_BIT) ? texUnit->EyePlane[GEN_S] : I,
(texUnit->TexGenEnabled & T_BIT) ? texUnit->EyePlane[GEN_T] : I + 4,
(texUnit->TexGenEnabled & R_BIT) ? texUnit->EyePlane[GEN_R] : I + 8,
(texUnit->TexGenEnabled & Q_BIT) ? texUnit->EyePlane[GEN_Q] : I + 12);
}
break;
......
......@@ -855,19 +855,19 @@ static GLboolean radeon_validate_texgen( struct gl_context *ctx, GLuint unit )
case GL_OBJECT_LINEAR:
rmesa->TexGenEnabled |= RADEON_TEXGEN_INPUT_OBJ << inputshift;
set_texgen_matrix( rmesa, unit,
texUnit->GenS.ObjectPlane,
texUnit->GenT.ObjectPlane,
texUnit->GenR.ObjectPlane,
texUnit->GenQ.ObjectPlane);
texUnit->ObjectPlane[GEN_S],
texUnit->ObjectPlane[GEN_T],
texUnit->ObjectPlane[GEN_R],
texUnit->ObjectPlane[GEN_Q]);
break;
case GL_EYE_LINEAR:
rmesa->TexGenEnabled |= RADEON_TEXGEN_INPUT_EYE << inputshift;
set_texgen_matrix( rmesa, unit,
texUnit->GenS.EyePlane,
texUnit->GenT.EyePlane,
texUnit->GenR.EyePlane,
texUnit->GenQ.EyePlane);
texUnit->EyePlane[GEN_S],
texUnit->EyePlane[GEN_T],
texUnit->EyePlane[GEN_R],
texUnit->EyePlane[GEN_Q]);
break;
case GL_REFLECTION_MAP_NV:
......
......@@ -531,22 +531,22 @@ pop_texture_group(struct gl_context *ctx, struct gl_texture_attrib_node *texstat
_mesa_TexGeni(GL_T, GL_TEXTURE_GEN_MODE, unit->GenT.Mode);
_mesa_TexGeni(GL_R, GL_TEXTURE_GEN_MODE, unit->GenR.Mode);
_mesa_TexGeni(GL_Q, GL_TEXTURE_GEN_MODE, unit->GenQ.Mode);
_mesa_TexGenfv(GL_S, GL_OBJECT_PLANE, unit->GenS.ObjectPlane);
_mesa_TexGenfv(GL_T, GL_OBJECT_PLANE, unit->GenT.ObjectPlane);
_mesa_TexGenfv(GL_R, GL_OBJECT_PLANE, unit->GenR.ObjectPlane);
_mesa_TexGenfv(GL_Q, GL_OBJECT_PLANE, unit->GenQ.ObjectPlane);
_mesa_TexGenfv(GL_S, GL_OBJECT_PLANE, unit->ObjectPlane[GEN_S]);
_mesa_TexGenfv(GL_T, GL_OBJECT_PLANE, unit->ObjectPlane[GEN_T]);
_mesa_TexGenfv(GL_R, GL_OBJECT_PLANE, unit->ObjectPlane[GEN_R]);
_mesa_TexGenfv(GL_Q, GL_OBJECT_PLANE, unit->ObjectPlane[GEN_Q]);
/* Eye plane done differently to avoid re-transformation */
{
COPY_4FV(destUnit->GenS.EyePlane, unit->GenS.EyePlane);
COPY_4FV(destUnit->GenT.EyePlane, unit->GenT.EyePlane);
COPY_4FV(destUnit->GenR.EyePlane, unit->GenR.EyePlane);
COPY_4FV(destUnit->GenQ.EyePlane, unit->GenQ.EyePlane);
COPY_4FV(destUnit->EyePlane[GEN_S], unit->EyePlane[GEN_S]);
COPY_4FV(destUnit->EyePlane[GEN_T], unit->EyePlane[GEN_T]);
COPY_4FV(destUnit->EyePlane[GEN_R], unit->EyePlane[GEN_R]);
COPY_4FV(destUnit->EyePlane[GEN_Q], unit->EyePlane[GEN_Q]);
if (ctx->Driver.TexGen) {
ctx->Driver.TexGen(ctx, GL_S, GL_EYE_PLANE, unit->GenS.EyePlane);
ctx->Driver.TexGen(ctx, GL_T, GL_EYE_PLANE, unit->GenT.EyePlane);
ctx->Driver.TexGen(ctx, GL_R, GL_EYE_PLANE, unit->GenR.EyePlane);
ctx->Driver.TexGen(ctx, GL_Q, GL_EYE_PLANE, unit->GenQ.EyePlane);
ctx->Driver.TexGen(ctx, GL_S, GL_EYE_PLANE, unit->EyePlane[GEN_S]);
ctx->Driver.TexGen(ctx, GL_T, GL_EYE_PLANE, unit->EyePlane[GEN_T]);
ctx->Driver.TexGen(ctx, GL_R, GL_EYE_PLANE, unit->EyePlane[GEN_R]);
ctx->Driver.TexGen(ctx, GL_Q, GL_EYE_PLANE, unit->EyePlane[GEN_Q]);
}
}
_mesa_set_enable(ctx, GL_TEXTURE_GEN_S, !!(unit->TexGenEnabled & S_BIT));
......
......@@ -1210,8 +1210,6 @@ struct gl_texgen
{
GLenum16 Mode; /**< GL_EYE_LINEAR, GL_SPHERE_MAP, etc */
GLbitfield8 _ModeBit; /**< TEXGEN_x bit corresponding to Mode */
GLfloat ObjectPlane[4];
GLfloat EyePlane[4];
};
......@@ -1235,6 +1233,13 @@ struct gl_texture_unit
struct gl_texture_object *_Current;
};
enum {
GEN_S,
GEN_T,
GEN_R,
GEN_Q,
NUM_GEN,
};
/**
* Fixed-function-related subset of a texture unit, like enable flags,
......@@ -1252,6 +1257,10 @@ struct gl_fixedfunc_texture_unit
struct gl_texgen GenT;
struct gl_texgen GenR;
struct gl_texgen GenQ;
GLfloat EyePlane[NUM_GEN][4];
GLfloat ObjectPlane[NUM_GEN][4];
GLbitfield8 TexGenEnabled; /**< Bitwise-OR of [STRQ]_BIT values */
GLbitfield8 _GenFlags; /**< Bitwise-OR of Gen[STRQ]._ModeBit */
......
......@@ -305,10 +305,10 @@ compute_texgen(struct gl_context *ctx, const GLfloat vObj[4], const GLfloat vEye
if (texUnit->TexGenEnabled & S_BIT) {
switch (texUnit->GenS.Mode) {
case GL_OBJECT_LINEAR:
texcoord[0] = DOT4(vObj, texUnit->GenS.ObjectPlane);
texcoord[0] = DOT4(vObj, texUnit->ObjectPlane[GEN_S]);
break;
case GL_EYE_LINEAR:
texcoord[0] = DOT4(vEye, texUnit->GenS.EyePlane);
texcoord[0] = DOT4(vEye, texUnit->EyePlane[GEN_S]);
break;
case GL_SPHERE_MAP:
texcoord[0] = rx * mInv + 0.5F;
......@@ -328,10 +328,10 @@ compute_texgen(struct gl_context *ctx, const GLfloat vObj[4], const GLfloat vEye
if (texUnit->TexGenEnabled & T_BIT) {
switch (texUnit->GenT.Mode) {
case GL_OBJECT_LINEAR:
texcoord[1] = DOT4(vObj, texUnit->GenT.ObjectPlane);
texcoord[1] = DOT4(vObj, texUnit->ObjectPlane[GEN_T]);
break;
case GL_EYE_LINEAR:
texcoord[1] = DOT4(vEye, texUnit->GenT.EyePlane);
texcoord[1] = DOT4(vEye, texUnit->EyePlane[GEN_T]);
break;
case GL_SPHERE_MAP:
texcoord[1] = ry * mInv + 0.5F;
......@@ -351,10 +351,10 @@ compute_texgen(struct gl_context *ctx, const GLfloat vObj[4], const GLfloat vEye
if (texUnit->TexGenEnabled & R_BIT) {
switch (texUnit->GenR.Mode) {
case GL_OBJECT_LINEAR:
texcoord[2] = DOT4(vObj, texUnit->GenR.ObjectPlane);
texcoord[2] = DOT4(vObj, texUnit->ObjectPlane[GEN_R]);
break;
case GL_EYE_LINEAR:
texcoord[2] = DOT4(vEye, texUnit->GenR.EyePlane);
texcoord[2] = DOT4(vEye, texUnit->EyePlane[GEN_R]);
break;
case GL_REFLECTION_MAP:
texcoord[2] = rz;
......@@ -371,10 +371,10 @@ compute_texgen(struct gl_context *ctx, const GLfloat vObj[4], const GLfloat vEye
if (texUnit->TexGenEnabled & Q_BIT) {
switch (texUnit->GenQ.Mode) {
case GL_OBJECT_LINEAR:
texcoord[3] = DOT4(vObj, texUnit->GenQ.ObjectPlane);
texcoord[3] = DOT4(vObj, texUnit->ObjectPlane[GEN_Q]);
break;
case GL_EYE_LINEAR:
texcoord[3] = DOT4(vEye, texUnit->GenQ.EyePlane);
texcoord[3] = DOT4(vEye, texUnit->EyePlane[GEN_Q]);
break;
default:
_mesa_problem(ctx, "Bad Q texgen in compute_texgen()");
......
......@@ -87,6 +87,9 @@ texgenfv( GLuint texunitIndex, GLenum coord, GLenum pname,
return;
}
struct gl_fixedfunc_texture_unit *unit = &ctx->Texture.FixedFuncUnit[texunitIndex];
int index = coord == GL_TEXTURE_GEN_STR_OES ? 0 : (coord - GL_S);
switch (pname) {
case GL_TEXTURE_GEN_MODE:
{
......@@ -138,10 +141,10 @@ texgenfv( GLuint texunitIndex, GLenum coord, GLenum pname,
_mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
return;
}
if (TEST_EQ_4V(texgen->ObjectPlane, params))
if (TEST_EQ_4V(unit->ObjectPlane[index], params))
return;
FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
COPY_4FV(texgen->ObjectPlane, params);
COPY_4FV(unit->ObjectPlane[index], params);
}
break;
......@@ -160,10 +163,10 @@ texgenfv( GLuint texunitIndex, GLenum coord, GLenum pname,
}
_mesa_transform_vector(tmp, params,
ctx->ModelviewMatrixStack.Top->inv);
if (TEST_EQ_4V(texgen->EyePlane, tmp))
if (TEST_EQ_4V(unit->EyePlane[index], tmp))
return;
FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
COPY_4FV(texgen->EyePlane, tmp);
COPY_4FV(unit->EyePlane[index], tmp);
}
break;
......@@ -191,15 +194,18 @@ gettexgendv( GLuint texunitIndex, GLenum coord, GLenum pname,
return;
}
struct gl_fixedfunc_texture_unit *unit = &ctx->Texture.FixedFuncUnit[texunitIndex];
int index = coord == GL_TEXTURE_GEN_STR_OES ? 0 : (coord - GL_S);
switch (pname) {
case GL_TEXTURE_GEN_MODE:
params[0] = ENUM_TO_DOUBLE(texgen->Mode);
break;
case GL_OBJECT_PLANE:
COPY_4V(params, texgen->ObjectPlane);
COPY_4V(params, unit->ObjectPlane[index]);
break;
case GL_EYE_PLANE:
COPY_4V(params, texgen->EyePlane);
COPY_4V(params, unit->EyePlane[index]);
break;
default:
_mesa_error( ctx, GL_INVALID_ENUM, "%s(pname)", caller );
......@@ -221,6 +227,9 @@ gettexgenfv( GLenum texunitIndex, GLenum coord, GLenum pname,
return;
}
struct gl_fixedfunc_texture_unit *unit = &ctx->Texture.FixedFuncUnit[texunitIndex];
int index = coord == GL_TEXTURE_GEN_STR_OES ? 0 : (coord - GL_S);
switch (pname) {
case GL_TEXTURE_GEN_MODE:
params[0] = ENUM_TO_FLOAT(texgen->Mode);
......@@ -230,14 +239,14 @@ gettexgenfv( GLenum texunitIndex, GLenum coord, GLenum pname,
_mesa_error( ctx, GL_INVALID_ENUM, "%s(param)", caller );
return;
}
COPY_4V(params, texgen->ObjectPlane);
COPY_4V(params, unit->ObjectPlane[index]);
break;
case GL_EYE_PLANE:
if (ctx->API != API_OPENGL_COMPAT) {
_mesa_error( ctx, GL_INVALID_ENUM, "%s(param)", caller );
return;
}
COPY_4V(params, texgen->EyePlane);
COPY_4V(params, unit->EyePlane[index]);
break;
default:
_mesa_error( ctx, GL_INVALID_ENUM, "%s(pname)", caller );
......@@ -259,6 +268,9 @@ gettexgeniv( GLenum texunitIndex, GLenum coord, GLenum pname,
return;
}
struct gl_fixedfunc_texture_unit *unit = &ctx->Texture.FixedFuncUnit[texunitIndex];
int index = coord == GL_TEXTURE_GEN_STR_OES ? 0 : (coord - GL_S);
switch (pname) {
case GL_TEXTURE_GEN_MODE:
params[0] = texgen->Mode;
......@@ -268,20 +280,20 @@ gettexgeniv( GLenum texunitIndex, GLenum coord, GLenum pname,
_mesa_error( ctx, GL_INVALID_ENUM, "%s(param)" , caller);
return;
}
params[0] = (GLint) texgen->ObjectPlane[0];
params[1] = (GLint) texgen->ObjectPlane[1];
params[2] = (GLint) texgen->ObjectPlane[2];
params[3] = (GLint) texgen->ObjectPlane[3];
params[0] = (GLint) unit->ObjectPlane[index][0];
params[1] = (GLint) unit->ObjectPlane[index][1];
params[2] = (GLint) unit->ObjectPlane[index][2];
params[3] = (GLint) unit->ObjectPlane[index][3];
break;
case GL_EYE_PLANE:
if (ctx->API != API_OPENGL_COMPAT) {
_mesa_error( ctx, GL_INVALID_ENUM, "%s(param)" , caller);
return;
}
params[0] = (GLint) texgen->EyePlane[0];
params[1] = (GLint) texgen->EyePlane[1];
params[2] = (GLint) texgen->EyePlane[2];
params[3] = (GLint) texgen->EyePlane[3];
params[0] = (GLint) unit->EyePlane[index][0];
params[1] = (GLint) unit->EyePlane[index][1];
params[2] = (GLint) unit->EyePlane[index][2];
params[3] = (GLint) unit->EyePlane[index][3];
break;
default:
_mesa_error( ctx, GL_INVALID_ENUM, "%s(pname)" , caller);
......
......@@ -112,6 +112,12 @@ _mesa_copy_texture_state( const struct gl_context *src, struct gl_context *dst )
dst->Texture.FixedFuncUnit[u].GenT = src->Texture.FixedFuncUnit[u].GenT;
dst->Texture.FixedFuncUnit[u].GenR = src->Texture.FixedFuncUnit[u].GenR;
dst->Texture.FixedFuncUnit[u].GenQ = src->Texture.FixedFuncUnit[u].GenQ;
memcpy(dst->Texture.FixedFuncUnit[u].ObjectPlane,
src->Texture.FixedFuncUnit[u].ObjectPlane,
sizeof(src->Texture.FixedFuncUnit[u].ObjectPlane));
memcpy(dst->Texture.FixedFuncUnit[u].EyePlane,
src->Texture.FixedFuncUnit[u].EyePlane,
sizeof(src->Texture.FixedFuncUnit[u].EyePlane));
/* GL_EXT_texture_env_combine */
dst->Texture.FixedFuncUnit[u].Combine = src->Texture.FixedFuncUnit[u].Combine;
......@@ -1054,14 +1060,14 @@ _mesa_init_texture(struct gl_context *ctx)
texUnit->GenQ._ModeBit = TEXGEN_EYE_LINEAR;
/* Yes, these plane coefficients are correct! */
ASSIGN_4V( texUnit->GenS.ObjectPlane, 1.0, 0.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->GenT.ObjectPlane, 0.0, 1.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->GenR.ObjectPlane, 0.0, 0.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->GenQ.ObjectPlane, 0.0, 0.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->GenS.EyePlane, 1.0, 0.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->GenT.EyePlane, 0.0, 1.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->GenR.EyePlane, 0.0, 0.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->GenQ.EyePlane, 0.0, 0.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->ObjectPlane[GEN_S], 1.0, 0.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->ObjectPlane[GEN_T], 0.0, 1.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->ObjectPlane[GEN_R], 0.0, 0.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->ObjectPlane[GEN_Q], 0.0, 0.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->EyePlane[GEN_S], 1.0, 0.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->EyePlane[GEN_T], 0.0, 1.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->EyePlane[GEN_R], 0.0, 0.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->EyePlane[GEN_Q], 0.0, 0.0, 0.0, 0.0 );
}
/* After we're done initializing the context's texture state the default
......
......@@ -183,35 +183,27 @@ fetch_state(struct gl_context *ctx, const gl_state_index16 state[],
/* state[1] is the texture unit */
const GLuint unit = (GLuint) state[1];
/* state[2] is the texgen attribute */
switch (state[2]) {
case STATE_TEXGEN_EYE_S:
COPY_4V(value, ctx->Texture.FixedFuncUnit[unit].GenS.EyePlane);
return;
case STATE_TEXGEN_EYE_T:
COPY_4V(value, ctx->Texture.FixedFuncUnit[unit].GenT.EyePlane);
return;
case STATE_TEXGEN_EYE_R:
COPY_4V(value, ctx->Texture.FixedFuncUnit[unit].GenR.EyePlane);
return;
case STATE_TEXGEN_EYE_Q:
COPY_4V(value, ctx->Texture.FixedFuncUnit[unit].GenQ.EyePlane);
return;
case STATE_TEXGEN_OBJECT_S:
COPY_4V(value, ctx->Texture.FixedFuncUnit[unit].GenS.ObjectPlane);
return;
case STATE_TEXGEN_OBJECT_T:
COPY_4V(value, ctx->Texture.FixedFuncUnit[unit].GenT.ObjectPlane);
return;
case STATE_TEXGEN_OBJECT_R:
COPY_4V(value, ctx->Texture.FixedFuncUnit[unit].GenR.ObjectPlane);
return;
case STATE_TEXGEN_OBJECT_Q:
COPY_4V(value, ctx->Texture.FixedFuncUnit[unit].GenQ.ObjectPlane);
return;
default:
unreachable("Invalid texgen state in fetch_state");
return;
}
/* Assertions for the expected memory layout. */
#define MEMBER_SIZEOF(type, member) sizeof(((type *)0)->member)
STATIC_ASSERT(MEMBER_SIZEOF(struct gl_fixedfunc_texture_unit,
EyePlane[0]) == 4 * sizeof(float));
STATIC_ASSERT(MEMBER_SIZEOF(struct gl_fixedfunc_texture_unit,
ObjectPlane[0]) == 4 * sizeof(float));
#undef MEMBER_SIZEOF
STATIC_ASSERT(STATE_TEXGEN_EYE_T - STATE_TEXGEN_EYE_S == GEN_T - GEN_S);
STATIC_ASSERT(STATE_TEXGEN_EYE_R - STATE_TEXGEN_EYE_S == GEN_R - GEN_S);
STATIC_ASSERT(STATE_TEXGEN_EYE_Q - STATE_TEXGEN_EYE_S == GEN_Q - GEN_S);
STATIC_ASSERT(offsetof(struct gl_fixedfunc_texture_unit, ObjectPlane) -
offsetof(struct gl_fixedfunc_texture_unit, EyePlane) ==
(STATE_TEXGEN_OBJECT_S - STATE_TEXGEN_EYE_S) * 4 * sizeof(float));
STATIC_ASSERT(STATE_TEXGEN_OBJECT_T - STATE_TEXGEN_OBJECT_S == GEN_T - GEN_S);
STATIC_ASSERT(STATE_TEXGEN_OBJECT_R - STATE_TEXGEN_OBJECT_S == GEN_R - GEN_S);
STATIC_ASSERT(STATE_TEXGEN_OBJECT_Q - STATE_TEXGEN_OBJECT_S == GEN_Q - GEN_S);
const float *attr = (float*)ctx->Texture.FixedFuncUnit[unit].EyePlane +
(state[2] - STATE_TEXGEN_EYE_S) * 4;
COPY_4V(value, attr);
return;
}
case STATE_TEXENV_COLOR:
{
......
......@@ -111,6 +111,9 @@ typedef enum gl_state_index_ {
STATE_EMISSION,
STATE_SHININESS,
/* These 8 enums must be in the same order as the memory layout of
* gl_fixedfunc_texture_unit::EyePlane/ObjectPlane.
*/
STATE_TEXGEN_EYE_S,
STATE_TEXGEN_EYE_T,
STATE_TEXGEN_EYE_R,
......
......@@ -370,12 +370,12 @@ static void texgen( struct gl_context *ctx,
case GL_OBJECT_LINEAR:
_mesa_dotprod_tab[obj->size]( (GLfloat *)out->data,
sizeof(out->data[0]), obj,
texUnit->GenS.ObjectPlane );
texUnit->ObjectPlane[GEN_S] );
break;
case GL_EYE_LINEAR:
_mesa_dotprod_tab[eye->size]( (GLfloat *)out->data,
sizeof(out->data[0]), eye,
texUnit->GenS.EyePlane );
texUnit->EyePlane[GEN_S] );
break;
case GL_SPHERE_MAP:
for (i = 0; i < count; i++)
......@@ -403,12 +403,12 @@ static void texgen( struct gl_context *ctx,
case GL_OBJECT_LINEAR:
_mesa_dotprod_tab[obj->size]( &(out->data[0][1]),
sizeof(out->data[0]), obj,
texUnit->GenT.ObjectPlane );
texUnit->ObjectPlane[GEN_T] );
break;
case GL_EYE_LINEAR:
_mesa_dotprod_tab[eye->size]( &(out->data[0][1]),
sizeof(out->data[0]), eye,
texUnit->GenT.EyePlane );
texUnit->EyePlane[GEN_T] );
break;
case GL_SPHERE_MAP:
for (i = 0; i < count; i++)
......@@ -436,12 +436,12 @@ static void texgen( struct gl_context *ctx,
case GL_OBJECT_LINEAR:
_mesa_dotprod_tab[obj->size]( &(out->data[0][2]),
sizeof(out->data[0]), obj,
texUnit->GenR.ObjectPlane );
texUnit->ObjectPlane[GEN_R] );
break;
case GL_EYE_LINEAR:
_mesa_dotprod_tab[eye->size]( &(out->data[0][2]),
sizeof(out->data[0]), eye,
texUnit->GenR.EyePlane );
texUnit->EyePlane[GEN_R] );
break;
case GL_REFLECTION_MAP_NV:
for (i=0;i<count;i++)
......@@ -464,12 +464,12 @@ static void texgen( struct gl_context *ctx,
case GL_OBJECT_LINEAR:
_mesa_dotprod_tab[obj->size]( &(out->data[0][3]),
sizeof(out->data[0]), obj,
texUnit->GenQ.ObjectPlane );
texUnit->ObjectPlane[GEN_Q] );
break;
case GL_EYE_LINEAR:
_mesa_dotprod_tab[eye->size]( &(out->data[0][3]),
sizeof(out->data[0]), eye,
texUnit->GenQ.EyePlane );
texUnit->EyePlane[GEN_Q] );
break;
default:
_mesa_problem(ctx, "Bad Q texgen");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment