aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2011-04-15 19:04:57 -0700
committerIan Romanick <[email protected]>2011-04-21 17:33:29 -0700
commit4d203a01e20dedcfaab09c18922e8ed9dcb39729 (patch)
treedc971f5c91cbca5f7d4f7a6c071baf498db243cc
parentdf7555e763b9a4d989788e9b1cd25e8740649e79 (diff)
mesa: Kill gl_fragment_program::FogOption with fire
All drivers expect this to always be GL_NONE. Don't let there be any opportunity for a bad value to leak out and infect some unsuspecting driver. If any driver for hardware that had fixed-function per-fragment fog (i915 and perhaps some r300-ish) was ever going to add support, it would have done it by now. Reviewed-by: Eric Anholt <[email protected]> Acked-by: Corbin Simpson <[email protected]> Acked-by: Alex Deucher <[email protected]>
-rw-r--r--src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c2
-rw-r--r--src/mesa/main/ff_fragment_shader.cpp9
-rw-r--r--src/mesa/main/mtypes.h1
-rw-r--r--src/mesa/program/arbprogparse.c18
-rw-r--r--src/mesa/program/program.c1
-rw-r--r--src/mesa/program/programopt.c33
-rw-r--r--src/mesa/program/programopt.h4
7 files changed, 31 insertions, 37 deletions
diff --git a/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c b/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c
index 646a415ca51..8b73409136f 100644
--- a/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c
+++ b/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c
@@ -34,8 +34,6 @@
* \author Ben Skeggs <[email protected]>
*
* \author Jerome Glisse <[email protected]>
- *
- * \todo FogOption
*/
#include "r300_fragprog.h"
diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp
index b799b292664..0b53c28f7ae 100644
--- a/src/mesa/main/ff_fragment_shader.cpp
+++ b/src/mesa/main/ff_fragment_shader.cpp
@@ -1549,14 +1549,7 @@ create_new_program(struct gl_context *ctx, struct state_key *key,
* the limits becuase it will potentially add some instructions.
*/
if (key->fog_enabled) {
- /* Pull fog mode from struct gl_context, the value in the state key is
- * a reduced value and not what is expected in FogOption
- */
- p.program->FogOption = ctx->Fog.Mode;
- p.program->Base.InputsRead |= FRAG_BIT_FOGC;
-
- _mesa_append_fog_code(ctx, p.program, GL_FALSE);
- p.program->FogOption = GL_NONE;
+ _mesa_append_fog_code(ctx, p.program, ctx->Fog.Mode, GL_FALSE);
}
if (p.program->Base.NumTexIndirections > ctx->Const.FragmentProgram.MaxTexIndirections)
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 5a25d649a13..160ae9d2622 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1923,7 +1923,6 @@ struct gl_geometry_program
struct gl_fragment_program
{
struct gl_program Base; /**< base class */
- GLenum FogOption;
GLboolean UsesKill; /**< shader uses KIL instruction */
GLboolean OriginUpperLeft;
GLboolean PixelCenterInteger;
diff --git a/src/mesa/program/arbprogparse.c b/src/mesa/program/arbprogparse.c
index 7f778c3c381..dffc8abf735 100644
--- a/src/mesa/program/arbprogparse.c
+++ b/src/mesa/program/arbprogparse.c
@@ -116,20 +116,11 @@ _mesa_parse_arb_fragment_program(struct gl_context* ctx, GLenum target,
program->Base.SamplersUsed |= (1 << i);
}
program->Base.ShadowSamplers = prog.ShadowSamplers;
- switch (state.option.Fog) {
- case OPTION_FOG_EXP: program->FogOption = GL_EXP; break;
- case OPTION_FOG_EXP2: program->FogOption = GL_EXP2; break;
- case OPTION_FOG_LINEAR: program->FogOption = GL_LINEAR; break;
- default: program->FogOption = GL_NONE; break;
- }
program->OriginUpperLeft = state.option.OriginUpperLeft;
program->PixelCenterInteger = state.option.PixelCenterInteger;
program->UsesKill = state.fragment.UsesKill;
- if (program->FogOption)
- program->Base.InputsRead |= FRAG_BIT_FOGC;
-
if (program->Base.Instructions)
free(program->Base.Instructions);
program->Base.Instructions = prog.Instructions;
@@ -143,12 +134,15 @@ _mesa_parse_arb_fragment_program(struct gl_context* ctx, GLenum target,
* there's no hardware that wants to do fog in a discrete stage separate
* from the fragment shader.
*/
- if (program->FogOption != GL_NONE) {
+ if (state.option.Fog != OPTION_NONE) {
+ static const GLenum fog_modes[4] = {
+ GL_NONE, GL_EXP, GL_EXP2, GL_LINEAR
+ };
+
/* XXX: we should somehow recompile this to remove clamping if disabled
* On the ATI driver, this is unclampled if fragment clamping is disabled
*/
- _mesa_append_fog_code(ctx, program, GL_TRUE);
- program->FogOption = GL_NONE;
+ _mesa_append_fog_code(ctx, program, fog_modes[state.option.Fog], GL_TRUE);
}
#if DEBUG_FP
diff --git a/src/mesa/program/program.c b/src/mesa/program/program.c
index 5b014872ed4..78efca9f122 100644
--- a/src/mesa/program/program.c
+++ b/src/mesa/program/program.c
@@ -557,7 +557,6 @@ _mesa_clone_program(struct gl_context *ctx, const struct gl_program *prog)
const struct gl_fragment_program *fp
= (const struct gl_fragment_program *) prog;
struct gl_fragment_program *fpc = (struct gl_fragment_program *) clone;
- fpc->FogOption = fp->FogOption;
fpc->UsesKill = fp->UsesKill;
fpc->OriginUpperLeft = fp->OriginUpperLeft;
fpc->PixelCenterInteger = fp->PixelCenterInteger;
diff --git a/src/mesa/program/programopt.c b/src/mesa/program/programopt.c
index 5ad9571f757..a239da2c609 100644
--- a/src/mesa/program/programopt.c
+++ b/src/mesa/program/programopt.c
@@ -230,15 +230,25 @@ _mesa_insert_mvp_code(struct gl_context *ctx, struct gl_vertex_program *vprog)
/**
- * Append extra instructions onto the given fragment program to implement
- * the fog mode specified by fprog->FogOption.
- * The fragment.fogcoord input is used to compute the fog blend factor.
+ * Append instructions to implement fog
*
- * XXX with a little work, this function could be adapted to add fog code
+ * The \c fragment.fogcoord input is used to compute the fog blend factor.
+ *
+ * \param ctx The GL context
+ * \param fprog Fragment program that fog instructions will be appended to.
+ * \param fog_mode Fog mode. One of \c GL_EXP, \c GL_EXP2, or \c GL_LINEAR.
+ * \param saturate True if writes to color outputs should be clamped to [0, 1]
+ *
+ * \note
+ * This function sets \c FRAG_BIT_FOGC in \c fprog->Base.InputsRead.
+ *
+ * \todo With a little work, this function could be adapted to add fog code
* to vertex programs too.
*/
void
-_mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog, GLboolean saturate)
+_mesa_append_fog_code(struct gl_context *ctx,
+ struct gl_fragment_program *fprog, GLenum fog_mode,
+ GLboolean saturate)
{
static const gl_state_index fogPStateOpt[STATE_LENGTH]
= { STATE_INTERNAL, STATE_FOG_PARAMS_OPTIMIZED, 0, 0, 0 };
@@ -251,9 +261,9 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog,
GLint fogPRefOpt, fogColorRef; /* state references */
GLuint colorTemp, fogFactorTemp; /* temporary registerss */
- if (fprog->FogOption == GL_NONE) {
+ if (fog_mode == GL_NONE) {
_mesa_problem(ctx, "_mesa_append_fog_code() called for fragment program"
- " with FogOption == GL_NONE");
+ " with fog_mode == GL_NONE");
return;
}
@@ -301,7 +311,7 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog,
/* emit instructions to compute fog blending factor */
/* this is always clamped to [0, 1] regardless of fragment clamping */
- if (fprog->FogOption == GL_LINEAR) {
+ if (fog_mode == GL_LINEAR) {
/* MAD fogFactorTemp.x, fragment.fogcoord.x, fogPRefOpt.x, fogPRefOpt.y; */
inst->Opcode = OPCODE_MAD;
inst->DstReg.File = PROGRAM_TEMPORARY;
@@ -320,7 +330,7 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog,
inst++;
}
else {
- ASSERT(fprog->FogOption == GL_EXP || fprog->FogOption == GL_EXP2);
+ ASSERT(fog_mode == GL_EXP || fog_mode == GL_EXP2);
/* fogPRefOpt.z = d/ln(2), fogPRefOpt.w = d/sqrt(ln(2) */
/* EXP: MUL fogFactorTemp.x, fogPRefOpt.z, fragment.fogcoord.x; */
/* EXP2: MUL fogFactorTemp.x, fogPRefOpt.w, fragment.fogcoord.x; */
@@ -331,12 +341,12 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog,
inst->SrcReg[0].File = PROGRAM_STATE_VAR;
inst->SrcReg[0].Index = fogPRefOpt;
inst->SrcReg[0].Swizzle
- = (fprog->FogOption == GL_EXP) ? SWIZZLE_ZZZZ : SWIZZLE_WWWW;
+ = (fog_mode == GL_EXP) ? SWIZZLE_ZZZZ : SWIZZLE_WWWW;
inst->SrcReg[1].File = PROGRAM_INPUT;
inst->SrcReg[1].Index = FRAG_ATTRIB_FOGC;
inst->SrcReg[1].Swizzle = SWIZZLE_XXXX;
inst++;
- if (fprog->FogOption == GL_EXP2) {
+ if (fog_mode == GL_EXP2) {
/* MUL fogFactorTemp.x, fogFactorTemp.x, fogFactorTemp.x; */
inst->Opcode = OPCODE_MUL;
inst->DstReg.File = PROGRAM_TEMPORARY;
@@ -397,7 +407,6 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog,
fprog->Base.Instructions = newInst;
fprog->Base.NumInstructions = inst - newInst;
fprog->Base.InputsRead |= FRAG_BIT_FOGC;
- /* XXX do this? fprog->FogOption = GL_NONE; */
}
diff --git a/src/mesa/program/programopt.h b/src/mesa/program/programopt.h
index 79631aa5843..b9205823c29 100644
--- a/src/mesa/program/programopt.h
+++ b/src/mesa/program/programopt.h
@@ -32,7 +32,9 @@ extern void
_mesa_insert_mvp_code(struct gl_context *ctx, struct gl_vertex_program *vprog);
extern void
-_mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog, GLboolean saturate);
+_mesa_append_fog_code(struct gl_context *ctx,
+ struct gl_fragment_program *fprog, GLenum fog_mode,
+ GLboolean saturate);
extern void
_mesa_count_texture_indirections(struct gl_program *prog);