question about fixing D3DRENDERSTATE_TEXTUREMAPBLEND

Alexander Dorofeyev alexd4 at inbox.lv
Mon Jan 7 00:55:08 CST 2008


Hi.

I found some problems with D3DRENDERSTATE_TEXTUREMAPBLEND state =
D3DTBLEND_MODULATE in ddraw and handling the alpha channel. This old state is
currently mapped to texture stage states, with alpha part done as

IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0,
WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0,
WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1);

This isn't correct, I believe, because in some cases it should be taken from
diffuse color (Aliens vs Predator 1 depends on it). But the latter behavior
isn't correct in all cases either.

I found this description of this state on some random website via google:

"D3DTBLEND_MODULATE Modulate texture-blending is supported. In this mode, the
RGB values of the texture are multiplied with the RGB values that would have
been used with no texturing. Any alpha values in the texture replace the alpha
values that would have been used with no texturing."

http://www.hi.is/~snorri/SDK-docs/x/exten203.htm

I guess, this means that it either takes alpha from texture or from diffuse
color, depending on whether the current texture has alpha channel (which takes
priority). I've submitted a test for this to wine-patches that includes checks
with both kinds of textures. It passes on XP and thus supports that this is the
way it is supposed to happen. Unfortunately, this doesn't easily translate to
available texture stage states. So it looks like something more hacky is needed
to make it work correctly in all cases in wine. There are two approaches I can
think of:

1) introduce an internal D3DTOP_ value in wined3d that will map to texture alpha
or diffuse alpha, depending on the pixel format of the currently selected texture.

2) move D3DRENDERSTATE_TEXTUREMAPBLEND handling to wined3d;

So it would be nice if Stefan Dösinger or maybe somebody else of d3d devs gave
me some directions - which approach (if any) is ok and acceptable for wine
project. I'll attach a diff with my current hacks that show how 1st approach is
about to look.

BTW, this worked in wine around 0.9.15

http://source.winehq.org/git/wine.git/?a=blob;f=dlls/ddraw/opengl_utils.c;h=a2b021985acfe3fbae888cb0e954b8fb47c86db3;hb=0fa7170dc318a6624f960c49e459cb521d2ae999

There it wasn't mapping to texture stage states, but instead was using such call:

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

 From what I read about GL_MODULATE, I'm not sure it always does exactly the
thing TEXTUREMAPBLEND=MODULATE is supposed to do, but with Aliens vs Predator it
worked better.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: avp1_texmapblend_fixes.diff.txt
Url: http://www.winehq.org/pipermail/wine-devel/attachments/20080106/82c38220/attachment.txt 


More information about the wine-devel mailing list