From 8273cfdf019179970d34b279f10726c517f538f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20D=C3=B6singer?= Date: Thu, 13 Sep 2007 12:25:29 +0200 Subject: [PATCH] wined3d: Fix texdp3tex in glsl. --- dlls/wined3d/glsl_shader.c | 28 ++++++++++++++++++++++++++-- dlls/wined3d/wined3d_private.h | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index 1b79f4d1e54..f36884c8914 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -1762,15 +1762,39 @@ void pshader_glsl_texcoord(SHADER_OPCODE_ARG* arg) { void pshader_glsl_texdp3tex(SHADER_OPCODE_ARG* arg) { glsl_src_param_t src0_param; char dst_mask[6]; + glsl_sample_function_t sample_function; DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK; DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; + DWORD sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param); shader_glsl_append_dst(arg->buffer, arg); shader_glsl_get_write_mask(arg->dst, dst_mask); - shader_addline(arg->buffer, "texture2D(Psampler%u, vec2(dot(gl_TexCoord[%u].xyz, %s), 0.5))%s);\n", - sampler_idx, sampler_idx, src0_param.param_str, dst_mask); + + /* Do I have to take care about the projected bit? I don't think so, since the dp3 returns only one + * scalar, and projected sampling would require 4 + */ + shader_glsl_get_sample_function(sampler_type, FALSE, &sample_function); + + switch(count_bits(sample_function.coord_mask)) { + case 1: + shader_addline(arg->buffer, "%s(Psampler%u, dot(gl_TexCoord[%u].xyz, %s))%s);\n", + sample_function.name, sampler_idx, sampler_idx, src0_param.param_str, dst_mask); + break; + + case 2: + shader_addline(arg->buffer, "%s(Psampler%u, vec2(dot(gl_TexCoord[%u].xyz, %s), 0.0))%s);\n", + sample_function.name, sampler_idx, sampler_idx, src0_param.param_str, dst_mask); + break; + + case 3: + shader_addline(arg->buffer, "%s(Psampler%u, vec3(dot(gl_TexCoord[%u].xyz, %s), 0.0, 0.0))%s);\n", + sample_function.name, sampler_idx, sampler_idx, src0_param.param_str, dst_mask); + break; + default: + FIXME("Unexpected mask bitcount %d\n", count_bits(sample_function.coord_mask)); + } } /** Process the WINED3DSIO_TEXDP3 instruction in GLSL: diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index b6f4bee872a..86b11de1292 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1554,6 +1554,7 @@ BOOL getDepthStencilBits(WINED3DFORMAT fmt, short *depthSize, short *stencilSize /* Math utils */ void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2); +unsigned int count_bits(unsigned int mask); /***************************************************************************** * To enable calling of inherited functions, requires prototypes