diff --git a/src/mesa/drivers/dri/r300/r300_context.c b/src/mesa/drivers/dri/r300/r300_context.c index 3743627..9498082 100644 --- a/src/mesa/drivers/dri/r300/r300_context.c +++ b/src/mesa/drivers/dri/r300/r300_context.c @@ -84,7 +84,7 @@ int hw_tcl_on = 1; #define need_GL_ARB_vertex_buffer_object #define need_GL_ARB_vertex_program #define need_GL_EXT_blend_minmax -//#define need_GL_EXT_fog_coord +#define need_GL_EXT_fog_coord #define need_GL_EXT_multi_draw_arrays #define need_GL_EXT_secondary_color #define need_GL_EXT_blend_equation_separate @@ -116,7 +116,7 @@ const struct dri_extension card_extensions[] = { {"GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions}, {"GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions}, {"GL_EXT_blend_subtract", NULL}, -// {"GL_EXT_fog_coord", GL_EXT_fog_coord_functions }, +{"GL_EXT_fog_coord", GL_EXT_fog_coord_functions }, {"GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions}, {"GL_EXT_gpu_program_parameters", GL_EXT_gpu_program_parameters_functions}, {"GL_EXT_secondary_color", GL_EXT_secondary_color_functions}, diff --git a/src/mesa/drivers/dri/r300/r300_emit.c b/src/mesa/drivers/dri/r300/r300_emit.c index 80bd338..67a94c8 100644 --- a/src/mesa/drivers/dri/r300/r300_emit.c +++ b/src/mesa/drivers/dri/r300/r300_emit.c @@ -388,6 +388,11 @@ int r300EmitArrays(GLcontext * ctx) OutputsWritten |= 1 << VERT_RESULT_COL1; } + if (RENDERINPUTS_TEST(render_inputs_bitset, _TNL_ATTRIB_FOG)) { + InputsRead |= 1 << VERT_ATTRIB_FOG; + OutputsWritten |= 1 << VERT_RESULT_FOGC; + } + for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { if (RENDERINPUTS_TEST(render_inputs_bitset, _TNL_ATTRIB_TEX(i))) { InputsRead |= 1 << (VERT_ATTRIB_TEX0 + i); @@ -415,6 +420,8 @@ int r300EmitArrays(GLcontext * ctx) for (i = VERT_ATTRIB_TEX0; i <= VERT_ATTRIB_TEX7; i++) if (InputsRead & (1 << i)) inputs[i] = 6 + (i - VERT_ATTRIB_TEX0); + if (InputsRead & (1 << VERT_ATTRIB_FOG)) + inputs[VERT_ATTRIB_FOG] = 14; RENDERINPUTS_COPY(rmesa->state.render_inputs_bitset, render_inputs_bitset); } diff --git a/src/mesa/drivers/dri/r300/r300_fragprog.c b/src/mesa/drivers/dri/r300/r300_fragprog.c index 4ef7f2b..ce08d5f 100644 --- a/src/mesa/drivers/dri/r300/r300_fragprog.c +++ b/src/mesa/drivers/dri/r300/r300_fragprog.c @@ -259,7 +259,7 @@ static void insert_WPOS_trailer(struct r300_fragment_program_compiler *compiler) { GLuint InputsRead = compiler->fp->mesa_program.Base.InputsRead; - if (!(InputsRead & FRAG_BIT_WPOS)) + if (!(InputsRead & (FRAG_BIT_WPOS | FRAG_BIT_FOGC))) return; static gl_state_index tokens[STATE_LENGTH] = { @@ -270,7 +270,7 @@ static void insert_WPOS_trailer(struct r300_fragment_program_compiler *compiler) int i = 0; GLuint tempregi = _mesa_find_free_register(compiler->program, PROGRAM_TEMPORARY); - _mesa_insert_instructions(compiler->program, 0, 3); + _mesa_insert_instructions(compiler->program, 0, 4); fpi = compiler->program->Instructions; /* perspective divide */ @@ -328,6 +328,21 @@ static void insert_WPOS_trailer(struct r300_fragment_program_compiler *compiler) MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ZERO); i++; + GLuint tempregf = _mesa_find_free_register(compiler->program, PROGRAM_TEMPORARY); + + /* Prepare fragment.fogcoord as (f, 0, 0, 1) */ + fpi[i].Opcode = OPCODE_MOV; + + fpi[i].DstReg.File = PROGRAM_TEMPORARY; + fpi[i].DstReg.Index = tempregf; + fpi[i].DstReg.WriteMask = WRITEMASK_XYZW; + fpi[i].DstReg.CondMask = COND_TR; + + fpi[i].SrcReg[0].File = PROGRAM_INPUT; + fpi[i].SrcReg[0].Index = FRAG_ATTRIB_WPOS; + fpi[i].SrcReg[0].Swizzle = + MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ONE); + for (; i < compiler->program->NumInstructions; ++i) { int reg; for (reg = 0; reg < 3; reg++) { @@ -335,6 +350,10 @@ static void insert_WPOS_trailer(struct r300_fragment_program_compiler *compiler) fpi[i].SrcReg[reg].Index == FRAG_ATTRIB_WPOS) { fpi[i].SrcReg[reg].File = PROGRAM_TEMPORARY; fpi[i].SrcReg[reg].Index = tempregi; + } else if (fpi[i].SrcReg[reg].File == PROGRAM_INPUT + && fpi[i].SrcReg[reg].Index == FRAG_ATTRIB_FOGC) { + fpi[i].SrcReg[reg].File = PROGRAM_TEMPORARY; + fpi[i].SrcReg[reg].Index = tempregf; } } } diff --git a/src/mesa/drivers/dri/r300/r300_state.c b/src/mesa/drivers/dri/r300/r300_state.c index 6a5c363..8f3df61 100644 --- a/src/mesa/drivers/dri/r300/r300_state.c +++ b/src/mesa/drivers/dri/r300/r300_state.c @@ -1643,6 +1643,11 @@ static void r300SetupRSUnit(GLcontext * ctx) r300->hw.rr.cmd[R300_RR_INST_1] = 0; + if (InputsRead & FRAG_BIT_FOGC) { + InputsRead |= FRAG_BIT_WPOS; + InputsRead &= ~FRAG_BIT_FOGC; + } + if (InputsRead & FRAG_BIT_WPOS) { for (i = 0; i < ctx->Const.MaxTextureUnits; i++) if (!(InputsRead & (FRAG_BIT_TEX0 << i))) @@ -1791,6 +1796,11 @@ static void r500SetupRSUnit(GLcontext * ctx) r300->hw.rr.cmd[R300_RR_INST_1] = 0; + if (InputsRead & FRAG_BIT_FOGC) { + InputsRead |= FRAG_BIT_WPOS; + InputsRead &= ~FRAG_BIT_FOGC; + } + if (InputsRead & FRAG_BIT_WPOS) { for (i = 0; i < ctx->Const.MaxTextureUnits; i++) if (!(InputsRead & (FRAG_BIT_TEX0 << i))) @@ -2619,7 +2629,7 @@ static void r500SetupPixelShader(r300ContextPtr rmesa) return; } code = &fp->code; - +#if 0 if (fp->mesa_program.FogOption != GL_NONE) { /* Enable HW fog. Try not to squish GL context. * (Anybody sane remembered to set glFog() opts first!) */ @@ -2629,7 +2639,7 @@ static void r500SetupPixelShader(r300ContextPtr rmesa) } else /* Make sure HW is matching GL context. */ r300SetFogState(ctx, ctx->Fog.Enabled); - +#endif r300SetupTextures(ctx); R300_STATECHANGE(rmesa, fp); diff --git a/src/mesa/drivers/dri/r300/r300_vertprog.c b/src/mesa/drivers/dri/r300/r300_vertprog.c index c4e325e..a25b82e 100644 --- a/src/mesa/drivers/dri/r300/r300_vertprog.c +++ b/src/mesa/drivers/dri/r300/r300_vertprog.c @@ -1345,7 +1345,7 @@ static void insert_wpos(struct r300_vertex_program *vp, struct gl_program *prog, vpi_insert[i].DstReg.File = PROGRAM_OUTPUT; vpi_insert[i].DstReg.Index = VERT_RESULT_TEX0 + vp->wpos_idx; - vpi_insert[i].DstReg.WriteMask = WRITEMASK_XYZW; + vpi_insert[i].DstReg.WriteMask = WRITEMASK_XYW; vpi_insert[i].DstReg.CondMask = COND_TR; vpi_insert[i].SrcReg[0].File = PROGRAM_TEMPORARY; @@ -1381,6 +1381,27 @@ static void pos_as_texcoord(struct r300_vertex_program *vp, insert_wpos(vp, prog, tempregi); } +static void fogc_to_wpos(struct r300_vertex_program *vp, + struct gl_program *prog) +{ + struct prog_instruction *vpi; + int i; + GLuint swiz; + + for (vpi = prog->Instructions; vpi->Opcode != OPCODE_END; vpi++) { + if (vpi->DstReg.File == PROGRAM_OUTPUT + && vpi->DstReg.Index == VERT_RESULT_FOGC) { + vpi->DstReg.Index = VERT_RESULT_TEX0 + vp->wpos_idx; + vpi->DstReg.WriteMask = WRITEMASK_Z; + for (i = 0; i < 3; i++) { + swiz = GET_SWZ(vpi->SrcReg[i].Swizzle, 0); + vpi->SrcReg[i].Swizzle = MAKE_SWIZZLE4(swiz, + swiz, swiz, swiz); + } + } + } +} + static struct r300_vertex_program *build_program(struct r300_vertex_program_key *wanted_key, struct gl_vertex_program *mesa_vp, GLint wpos_idx) @@ -1395,7 +1416,11 @@ static struct r300_vertex_program *build_program(struct r300_vertex_program_key position_invariant(&mesa_vp->Base); } + if (wpos_idx > -1) { + if (mesa_vp->Base.OutputsWritten & VERT_RESULT_FOGC) { + fogc_to_wpos(vp, &mesa_vp->Base); + } pos_as_texcoord(vp, &mesa_vp->Base); } @@ -1431,7 +1456,7 @@ void r300SelectVertexShader(r300ContextPtr r300) InputsRead = ctx->FragmentProgram._Current->Base.InputsRead; wpos_idx = -1; - if (InputsRead & FRAG_BIT_WPOS) { + if (InputsRead & (FRAG_BIT_WPOS | FRAG_BIT_FOGC)) { for (i = 0; i < ctx->Const.MaxTextureUnits; i++) if (!(InputsRead & (FRAG_BIT_TEX0 << i))) break; @@ -1472,7 +1497,7 @@ void r300SelectVertexShader(r300ContextPtr r300) r300->selected_vp = vp; return; } - //_mesa_print_program(&vpc->mesa_program.Base); + _mesa_print_program(&vpc->mesa_program.Base); vp = build_program(&wanted_key, &vpc->mesa_program, wpos_idx); vp->next = vpc->progs; diff --git a/src/mesa/drivers/dri/r300/r500_fragprog.c b/src/mesa/drivers/dri/r300/r500_fragprog.c index 75dae86..4fcfc67 100644 --- a/src/mesa/drivers/dri/r300/r500_fragprog.c +++ b/src/mesa/drivers/dri/r300/r500_fragprog.c @@ -195,7 +195,7 @@ static void insert_WPOS_trailer(struct r500_fragment_program_compiler *compiler) { GLuint InputsRead = compiler->fp->mesa_program.Base.InputsRead; - if (!(InputsRead & FRAG_BIT_WPOS)) + if (!(InputsRead & (FRAG_BIT_WPOS | FRAG_BIT_FOGC))) return; static gl_state_index tokens[STATE_LENGTH] = { @@ -206,7 +206,7 @@ static void insert_WPOS_trailer(struct r500_fragment_program_compiler *compiler) int i = 0; GLuint tempregi = _mesa_find_free_register(compiler->program, PROGRAM_TEMPORARY); - _mesa_insert_instructions(compiler->program, 0, 3); + _mesa_insert_instructions(compiler->program, 0, 4); fpi = compiler->program->Instructions; /* perspective divide */ @@ -264,6 +264,21 @@ static void insert_WPOS_trailer(struct r500_fragment_program_compiler *compiler) MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ZERO); i++; + GLuint tempregf = _mesa_find_free_register(compiler->program, PROGRAM_TEMPORARY); + + /* Prepare fragment.fogcoord as (f, 0, 0, 1) */ + fpi[i].Opcode = OPCODE_MOV; + + fpi[i].DstReg.File = PROGRAM_TEMPORARY; + fpi[i].DstReg.Index = tempregf; + fpi[i].DstReg.WriteMask = WRITEMASK_XYZW; + fpi[i].DstReg.CondMask = COND_TR; + + fpi[i].SrcReg[0].File = PROGRAM_INPUT; + fpi[i].SrcReg[0].Index = FRAG_ATTRIB_WPOS; + fpi[i].SrcReg[0].Swizzle = + MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ONE); + for (; i < compiler->program->NumInstructions; ++i) { int reg; for (reg = 0; reg < 3; reg++) { @@ -271,6 +286,10 @@ static void insert_WPOS_trailer(struct r500_fragment_program_compiler *compiler) fpi[i].SrcReg[reg].Index == FRAG_ATTRIB_WPOS) { fpi[i].SrcReg[reg].File = PROGRAM_TEMPORARY; fpi[i].SrcReg[reg].Index = tempregi; + } else if (fpi[i].SrcReg[reg].File == PROGRAM_INPUT + && fpi[i].SrcReg[reg].Index == FRAG_ATTRIB_FOGC) { + fpi[i].SrcReg[reg].File = PROGRAM_TEMPORARY; + fpi[i].SrcReg[reg].Index = tempregf; } } } diff --git a/src/mesa/drivers/dri/r300/radeon_program_pair.c b/src/mesa/drivers/dri/r300/radeon_program_pair.c index 5ad50d2..31838ff 100644 --- a/src/mesa/drivers/dri/r300/radeon_program_pair.c +++ b/src/mesa/drivers/dri/r300/radeon_program_pair.c @@ -463,6 +463,11 @@ static void allocate_input_registers(struct pair_state *s) alloc_hw_reg(s, PROGRAM_INPUT, FRAG_ATTRIB_WPOS, hwindex++); InputsRead &= ~FRAG_BIT_WPOS; + /* Fog coordinate */ + if (InputsRead & FRAG_BIT_FOGC) + alloc_hw_reg(s, PROGRAM_INPUT, FRAG_ATTRIB_FOGC, hwindex++); + InputsRead &= ~FRAG_BIT_FOGC; + /* Then primary colour */ if (InputsRead & FRAG_BIT_COL0) alloc_hw_reg(s, PROGRAM_INPUT, FRAG_ATTRIB_COL0, hwindex++);