From 38db8612fcd0e50c02451021a0ee6c704b366c65 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 8 May 2008 17:40:49 -0400 Subject: [PATCH] First shot at TEXLD opcode in GLSL profile. --HG-- branch : trunk --- mojoshader.c | 58 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/mojoshader.c b/mojoshader.c index 669abda4..cd9b8ddb 100644 --- a/mojoshader.c +++ b/mojoshader.c @@ -2887,14 +2887,56 @@ static void emit_GLSL_TEXKILL(Context *ctx) static void emit_GLSL_TEXLD(Context *ctx) { - // this opcode looks and acts differently depending on the shader model. - //if (shader_version_atleast(ctx, 2, 0)) - // emit_D3D_opcode_dss(ctx, "texld"); - //else if (shader_version_atleast(ctx, 1, 4)) - // emit_D3D_opcode_ds(ctx, "texld"); - //else - // emit_D3D_opcode_d(ctx, "tex"); - fail(ctx, "TEXLD unimplemented."); // !!! FIXME + // !!! FIXME: do non-RGBA textures map to same default values as D3D? + + if (!shader_version_atleast(ctx, 2, 0)) + { + // ps_1_0 and ps_1_4 are both different, too! + fail(ctx, "TEXLD <= Shader Model 2.0 unimplemented."); // !!! FIXME + return; + } // if + else + { + const SourceArgInfo *samp_arg = &ctx->source_args[1]; + RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER, + samp_arg->regnum); + const char *funcname = NULL; + const char *src0 = NULL; + const char *src1 = get_GLSL_srcarg_varname(ctx, 1); + char swiz_str[6]; + + if (sreg == NULL) + { + fail(ctx, "TEXLD using undeclared sampler"); + return; + } // if + + switch ((const TextureType) sreg->index) + { + case TEXTURE_TYPE_2D: + funcname = "texture2D"; + src0 = make_GLSL_srcarg_string_vec2(ctx, 0); + break; + case TEXTURE_TYPE_CUBE: + funcname = "textureCube"; + src0 = make_GLSL_srcarg_string_vec3(ctx, 0); + break; + case TEXTURE_TYPE_VOLUME: + funcname = "texture3D"; + src0 = make_GLSL_srcarg_string_vec3(ctx, 0); + break; + default: + fail(ctx, "unknown texture type"); + return; + } // switch + + make_GLSL_swizzle_string(swiz_str, sizeof (swiz_str), + samp_arg->swizzle, ctx->dest_arg.writemask); + + const char *code = make_GLSL_destarg_assign(ctx, + "%s(%s, %s)%s", funcname, src1, src0, swiz_str); + output_line(ctx, "%s", code); + } // else } // emit_GLSL_TEXLD static void emit_GLSL_TEXBEM(Context *ctx)