diff options
author | Roland Scheidegger <[email protected]> | 2009-03-12 15:01:16 +0100 |
---|---|---|
committer | Roland Scheidegger <[email protected]> | 2009-03-12 15:01:16 +0100 |
commit | 114152e068ec919feb0a57a1259c2ada970b9f02 (patch) | |
tree | f424d1c9f88ddf36c94991906879f3a71ca1c36a /src/mesa/main/texenvprogram.c | |
parent | b7d841b59e9087c0ba8c2726897ab1506375e4e6 (diff) |
mesa: add support for ATI_envmap_bumpmap
add new entrypoints, new texture format, etc
translate in texenvprogram.c for drivers using the mesa-generated tex env
fragment program
also handled in swrast, but not tested (cannot work due to negative texel
results not handled correctly)
Diffstat (limited to 'src/mesa/main/texenvprogram.c')
-rw-r--r-- | src/mesa/main/texenvprogram.c | 99 |
1 files changed, 90 insertions, 9 deletions
diff --git a/src/mesa/main/texenvprogram.c b/src/mesa/main/texenvprogram.c index 51c13a563d6..3fbd119b347 100644 --- a/src/mesa/main/texenvprogram.c +++ b/src/mesa/main/texenvprogram.c @@ -94,11 +94,11 @@ struct state_key { GLuint ScaleShiftA:2; GLuint NumArgsRGB:3; - GLuint ModeRGB:4; + GLuint ModeRGB:5; struct mode_opt OptRGB[MAX_TERMS]; GLuint NumArgsA:3; - GLuint ModeA:4; + GLuint ModeA:5; struct mode_opt OptA[MAX_TERMS]; } unit[8]; }; @@ -194,7 +194,8 @@ static GLuint translate_source( GLenum src ) #define MODE_MODULATE_SUBTRACT_ATI 12 /* r = a0 * a2 - a1 */ #define MODE_ADD_PRODUCTS 13 /* r = a0 * a1 + a2 * a3 */ #define MODE_ADD_PRODUCTS_SIGNED 14 /* r = a0 * a1 + a2 * a3 - 0.5 */ -#define MODE_UNKNOWN 15 +#define MODE_BUMP_ENVMAP_ATI 15 /* special */ +#define MODE_UNKNOWN 16 /** * Translate GL combiner state into a MODE_x value @@ -223,6 +224,7 @@ static GLuint translate_mode( GLenum envMode, GLenum mode ) case GL_MODULATE_ADD_ATI: return MODE_MODULATE_ADD_ATI; case GL_MODULATE_SIGNED_ADD_ATI: return MODE_MODULATE_SIGNED_ADD_ATI; case GL_MODULATE_SUBTRACT_ATI: return MODE_MODULATE_SUBTRACT_ATI; + case GL_BUMP_ENVMAP_ATI: return MODE_BUMP_ENVMAP_ATI; default: assert(0); return MODE_UNKNOWN; @@ -383,7 +385,7 @@ static void make_state_key( GLcontext *ctx, struct state_key *key ) translate_mode(texUnit->EnvMode, texUnit->_CurrentCombine->ModeRGB); key->unit[i].ModeA = translate_mode(texUnit->EnvMode, texUnit->_CurrentCombine->ModeA); - + key->unit[i].ScaleShiftRGB = texUnit->_CurrentCombine->ScaleShiftRGB; key->unit[i].ScaleShiftA = texUnit->_CurrentCombine->ScaleShiftA; @@ -397,8 +399,18 @@ static void make_state_key( GLcontext *ctx, struct state_key *key ) key->unit[i].OptA[j].Source = translate_source(texUnit->_CurrentCombine->SourceA[j]); } + + if (key->unit[i].ModeRGB == MODE_BUMP_ENVMAP_ATI) { + /* requires some special translation */ + key->unit[i].NumArgsRGB = 2; + key->unit[i].ScaleShiftRGB = 0; + key->unit[i].OptRGB[0].Operand = OPR_SRC_COLOR; + key->unit[i].OptRGB[0].Source = SRC_TEXTURE; + key->unit[i].OptRGB[1].Operand = OPR_SRC_COLOR; + key->unit[i].OptRGB[1].Source = texUnit->BumpTarget - GL_TEXTURE0 + SRC_TEXTURE0; + } } - + if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) { key->separate_specular = 1; inputs_referenced |= FRAG_BIT_COL1; @@ -464,6 +476,11 @@ struct texenv_fragment_program { * else undef. */ + struct ureg texcoord_tex[MAX_TEXTURE_COORD_UNITS]; + /* Reg containing texcoord for a texture unit, + * needed for bump mapping, else undef. + */ + struct ureg src_previous; /**< Reg containing color from previous * stage. May need to be decl'd. */ @@ -756,6 +773,7 @@ static struct ureg emit_texld( struct texenv_fragment_program *p, */ reserve_temp(p, dest); +#if 0 /* Is this a texture indirection? */ if ((coord.file == PROGRAM_TEMPORARY && @@ -767,6 +785,7 @@ static struct ureg emit_texld( struct texenv_fragment_program *p, p->alu_temps = 0; assert(0); /* KW: texture env crossbar */ } +#endif return dest; } @@ -1052,6 +1071,10 @@ static struct ureg emit_combine( struct texenv_fragment_program *p, emit_arith( p, OPCODE_SUB, dest, mask, saturate, tmp0, half, undef ); } return dest; + case MODE_BUMP_ENVMAP_ATI: + /* special - not handled here */ + assert(0); + return src[0]; default: assert(0); return src[0]; @@ -1074,6 +1097,10 @@ emit_texenv(struct texenv_fragment_program *p, GLuint unit) if (!key->unit[unit].enabled) { return get_source(p, SRC_PREVIOUS, 0); } + if (key->unit[unit].ModeRGB == MODE_BUMP_ENVMAP_ATI) { + /* this isn't really a env stage delivering a color and handled elsewhere */ + return get_source(p, SRC_PREVIOUS, 0); + } switch (key->unit[unit].ModeRGB) { case MODE_DOT3_RGB_EXT: @@ -1163,9 +1190,17 @@ static void load_texture( struct texenv_fragment_program *p, GLuint unit ) { if (is_undef(p->src_texture[unit])) { GLuint texTarget = p->state->unit[unit].source_index; - struct ureg texcoord = register_input(p, FRAG_ATTRIB_TEX0+unit); + struct ureg texcoord; struct ureg tmp = get_tex_temp( p ); + if (is_undef(p->texcoord_tex[unit])) { + texcoord = register_input(p, FRAG_ATTRIB_TEX0+unit); + } + else { + /* might want to reuse this reg for tex output actually */ + texcoord = p->texcoord_tex[unit]; + } + if (texTarget == TEXTURE_UNKNOWN_INDEX) program_error(p, "TexSrcBit"); @@ -1233,7 +1268,7 @@ load_texunit_sources( struct texenv_fragment_program *p, int unit ) GLuint i; for (i = 0; i < key->unit[unit].NumArgsRGB; i++) { - load_texenv_source( p, key->unit[unit].OptRGB[i].Source, unit); + load_texenv_source( p, key->unit[unit].OptRGB[i].Source, unit ); } for (i = 0; i < key->unit[unit].NumArgsA; i++) { @@ -1243,6 +1278,40 @@ load_texunit_sources( struct texenv_fragment_program *p, int unit ) return GL_TRUE; } +/** + * Generate instructions for loading bump map textures. + */ +static GLboolean +load_texunit_bumpmap( struct texenv_fragment_program *p, int unit ) +{ + struct state_key *key = p->state; + GLuint bumpedUnitNr = key->unit[unit].OptRGB[1].Source - SRC_TEXTURE0; + struct ureg texcDst, bumpMapRes; + struct ureg constdudvcolor = register_const4f(p, 0.0, 0.0, 0.0, 1.0); + struct ureg texcSrc = register_input(p, FRAG_ATTRIB_TEX0 + bumpedUnitNr); + struct ureg rotMat0 = register_param3( p, STATE_INTERNAL, STATE_ROT_MATRIX_0, unit ); + struct ureg rotMat1 = register_param3( p, STATE_INTERNAL, STATE_ROT_MATRIX_1, unit ); + + load_texenv_source( p, unit + SRC_TEXTURE0, unit ); + + bumpMapRes = get_source(p, key->unit[unit].OptRGB[0].Source, unit); + texcDst = get_tex_temp( p ); + p->texcoord_tex[bumpedUnitNr] = texcDst; + + /* apply rot matrix and add coords to be available in next phase */ + /* dest = (Arg0.xxxx * rotMat0 + Arg1) + (Arg0.yyyy * rotMat1) */ + /* note only 2 coords are affected the rest are left unchanged (mul by 0) */ + emit_arith( p, OPCODE_MAD, texcDst, WRITEMASK_XYZW, 0, + swizzle1(bumpMapRes, SWIZZLE_X), rotMat0, texcSrc ); + emit_arith( p, OPCODE_MAD, texcDst, WRITEMASK_XYZW, 0, + swizzle1(bumpMapRes, SWIZZLE_Y), rotMat1, texcDst ); + + /* move 0,0,0,1 into bumpmap src if someone (crossbar) is foolish + enough to access this later, should optimize away */ + emit_arith( p, OPCODE_MOV, bumpMapRes, WRITEMASK_XYZW, 0, constdudvcolor, undef, undef ); + + return GL_TRUE; +} /** * Generate a new fragment program which implements the context's @@ -1267,7 +1336,7 @@ create_new_program(GLcontext *ctx, struct state_key *key, */ p.program->Base.Instructions = instBuffer; p.program->Base.Target = GL_FRAGMENT_PROGRAM_ARB; - p.program->Base.NumTexIndirections = 1; /* correct? */ + p.program->Base.NumTexIndirections = 1; p.program->Base.NumTexInstructions = 0; p.program->Base.NumAluInstructions = 0; p.program->Base.String = NULL; @@ -1280,8 +1349,10 @@ create_new_program(GLcontext *ctx, struct state_key *key, p.program->Base.InputsRead = 0; p.program->Base.OutputsWritten = 1 << FRAG_RESULT_COLOR; - for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) + for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { p.src_texture[unit] = undef; + p.texcoord_tex[unit] = undef; + } p.src_previous = undef; p.half = undef; @@ -1292,6 +1363,16 @@ create_new_program(GLcontext *ctx, struct state_key *key, release_temps(ctx, &p); if (key->enabled_units) { + GLboolean needbumpstage = GL_FALSE; + /* Zeroth pass - bump map textures first */ + for (unit = 0 ; unit < ctx->Const.MaxTextureUnits ; unit++) + if (key->unit[unit].enabled && key->unit[unit].ModeRGB == MODE_BUMP_ENVMAP_ATI) { + needbumpstage = GL_TRUE; + load_texunit_bumpmap( &p, unit ); + } + if (needbumpstage) + p.program->Base.NumTexIndirections++; + /* First pass - to support texture_env_crossbar, first identify * all referenced texture sources and emit texld instructions * for each: |