wined3d: WINED3DFMT_U8V8 is signed.

Plain OpenGL does not provide any signed pixel formats, so the
unsigned GL_RGB is used for loading perturbation data into pixel
shaders that use texbem. For correct loading, the signedness has to be
considered.
This commit is contained in:
Stefan Dösinger 2007-03-05 21:40:47 +01:00 committed by Alexandre Julliard
parent e0a271ee0c
commit ae57138eae
2 changed files with 20 additions and 16 deletions

View File

@ -693,17 +693,6 @@ void pshader_hw_texreg2gb(SHADER_OPCODE_ARG* arg) {
} }
void pshader_hw_texbem(SHADER_OPCODE_ARG* arg) { void pshader_hw_texbem(SHADER_OPCODE_ARG* arg) {
#if 0
SHADER_BUFFER* buffer = arg->buffer;
DWORD reg1 = arg->dst & WINED3DSP_REGNUM_MASK;
DWORD reg2 = arg->src[0] & WINED3DSP_REGNUM_MASK;
char dst_str[8];
/* FIXME: Should apply the BUMPMAPENV matrix */
sprintf(dst_str, "T%u", reg1);
shader_addline(buffer, "ADD TMP.rg, fragment.texcoord[%u], T%u;\n", reg1, reg2);
shader_hw_sample(arg, reg1, dst_str, "TMP");
#endif
IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader; IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
DWORD dst = arg->dst; DWORD dst = arg->dst;
@ -720,6 +709,17 @@ void pshader_hw_texbem(SHADER_OPCODE_ARG* arg) {
if(This->bumpenvmatconst) { if(This->bumpenvmatconst) {
/*shader_addline(buffer, "MOV T%u, fragment.texcoord[%u];\n", 1, 1); Not needed - done already */ /*shader_addline(buffer, "MOV T%u, fragment.texcoord[%u];\n", 1, 1); Not needed - done already */
/* Plain GL does not have any signed formats suitable for that instruction.
* So the surface loading code converts the -128 ... 127 signed integers to
* 0 ... 255 unsigned ones. The following line undoes that.
*
* TODO: Both GL_NV_texture_shader and GL_ATI_envmap_bumpmap provide pixel formats
* suitable for loading the Direct3D perturbation data. If one of them is used, do
* not correct the signedness
*/
shader_addline(buffer, "MAD T%u, T%u, coefmul.x, -one;\n", src, src);
shader_addline(buffer, "SWZ TMP2, bumpenvmat, x, z, 0, 0;\n"); shader_addline(buffer, "SWZ TMP2, bumpenvmat, x, z, 0, 0;\n");
shader_addline(buffer, "DP3 TMP.r, TMP2, T%u;\n", src); shader_addline(buffer, "DP3 TMP.r, TMP2, T%u;\n", src);
shader_addline(buffer, "SWZ TMP2, bumpenvmat, y, w, 0, 0;\n"); shader_addline(buffer, "SWZ TMP2, bumpenvmat, y, w, 0, 0;\n");

View File

@ -1451,6 +1451,10 @@ HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_
break; break;
case WINED3DFMT_V8U8: case WINED3DFMT_V8U8:
/* TODO: GL_NV_texture_shader and GL_ATI_envmap_bumpmap provide suitable formats.
* use one of them instead of converting
* Remember to adjust the texbem instruction in the shader
*/
*convert = CONVERT_V8U8; *convert = CONVERT_V8U8;
*format = GL_BGR; *format = GL_BGR;
*internal = GL_RGB8; *internal = GL_RGB8;
@ -1581,15 +1585,15 @@ HRESULT d3dfmt_convert_surface(BYTE *src, BYTE *dst, UINT pitch, UINT width, UIN
{ {
unsigned int x, y; unsigned int x, y;
short *Source; short *Source;
char *Dest; unsigned char *Dest;
for(y = 0; y < height; y++) { for(y = 0; y < height; y++) {
Source = (short *) (src + y * pitch); Source = (short *) (src + y * pitch);
Dest = (char *) (dst + y * outpitch); Dest = (unsigned char *) (dst + y * outpitch);
for (x = 0; x < width; x++ ) { for (x = 0; x < width; x++ ) {
long color = (*Source++); long color = (*Source++);
Dest[0] = color >> 8; /* B */ Dest[0] = 0xff;
Dest[1] = color; /* G */ Dest[1] = (color >> 8) + 128; /* V */
Dest[2] = 0xff; /* R */ Dest[2] = (color) + 128; /* U */
Dest += 3; Dest += 3;
} }
} }