Module: wine
Branch: master
Commit: 0d749e8e265363e8b69b6ceaff09c20916c7bbde
URL: http://source.winehq.org/git/wine.git/?a=commit;h=0d749e8e265363e8b69b6ceaf…
Author: Stefan Dösinger <stefan(a)codeweavers.com>
Date: Tue Aug 21 22:46:52 2007 +0200
wined3d: Clear unused channels on R32F and R16F textures on readback.
---
dlls/wined3d/surface.c | 37 +++++++++++++++++++++++++++++++++++++
1 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 2abb277..f8becfe 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -1963,6 +1963,41 @@ static BOOL palette9_changed(IWineD3DSurfaceImpl *This) {
return TRUE;
}
+static inline void clear_unused_channels(IWineD3DSurfaceImpl *This) {
+ GLboolean oldwrite[4];
+
+ /* Some formats have only some color channels, and the others are 1.0.
+ * since our rendering renders to all channels, and those pixel formats
+ * are emulated by using a full texture with the other channels set to 1.0
+ * manually, clear the unused channels.
+ *
+ * This could be done with hacking colorwriteenable to mask the colors,
+ * but before drawing the buffer would have to be cleared too, so there's
+ * no gain in that
+ */
+ switch(This->resource.format) {
+ case WINED3DFMT_R16F:
+ case WINED3DFMT_R32F:
+ TRACE("R16F or R32F format, clearing green, blue and alpha to 1.0\n");
+ /* Do not activate a context, the correct drawable is active already
+ * though just the read buffer is set, make sure to have the correct draw
+ * buffer too
+ */
+ glDrawBuffer(This->resource.wineD3DDevice->offscreenBuffer);
+ glDisable(GL_SCISSOR_TEST);
+ glGetBooleanv(GL_COLOR_WRITEMASK, oldwrite);
+ glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
+ glClearColor(0.0, 1.0, 1.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glColorMask(oldwrite[0], oldwrite[1], oldwrite[2], oldwrite[3]);
+ if(!This->resource.wineD3DDevice->render_offscreen) glDrawBuffer(GL_BACK);
+ checkGLcall("Unused channel clear\n");
+ break;
+
+ default: break;
+ }
+}
+
static HRESULT WINAPI IWineD3DSurfaceImpl_LoadTexture(IWineD3DSurface *iface, BOOL srgb_mode) {
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
@@ -2027,6 +2062,8 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LoadTexture(IWineD3DSurface *iface, BO
This->pow2Height, format, type);
}
+ clear_unused_channels(This);
+
glCopyTexSubImage2D(This->glDescription.target,
This->glDescription.level,
0, 0, 0, 0,
Module: wine
Branch: master
Commit: 8c9c084004356d9605c33ca013192a395dce8127
URL: http://source.winehq.org/git/wine.git/?a=commit;h=8c9c084004356d9605c33ca01…
Author: Stefan Dösinger <stefan(a)codeweavers.com>
Date: Tue Aug 21 18:05:27 2007 +0200
wined3d: Use 0/0/0 as normal if no normal is supplied.
---
dlls/wined3d/drawprim.c | 2 +-
dlls/wined3d/state.c | 18 +++++++++++++++---
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c
index 3b45db3..0cc6789 100644
--- a/dlls/wined3d/drawprim.c
+++ b/dlls/wined3d/drawprim.c
@@ -350,7 +350,7 @@ static void drawStridedSlow(IWineD3DDevice *iface, WineDirect3DVertexStridedData
/* Default settings for data that is not passed */
if (sd->u.s.normal.lpData == NULL) {
- glNormal3f(0, 0, 1);
+ glNormal3f(0, 0, 0);
}
if(sd->u.s.diffuse.lpData == NULL) {
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index 4b38e40..fe25e4b 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -1196,7 +1196,16 @@ static void state_zbias(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3D
static void state_normalize(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
- if (stateblock->renderState[WINED3DRS_NORMALIZENORMALS]) {
+ if(isStateDirty(context, STATE_VDECL)) {
+ return;
+ }
+ /* Without vertex normals, we set the current normal to 0/0/0 to remove the diffuse factor
+ * from the opengl lighting equation, as d3d does. Normalization of 0/0/0 can lead to a division
+ * by zero and is not properly defined in opengl, so avoid it
+ */
+ if (stateblock->renderState[WINED3DRS_NORMALIZENORMALS] && (
+ stateblock->wineD3DDevice->strided_streams.u.s.normal.lpData ||
+ stateblock->wineD3DDevice->strided_streams.u.s.normal.VBO)) {
glEnable(GL_NORMALIZE);
checkGLcall("glEnable(GL_NORMALIZE);");
} else {
@@ -3031,8 +3040,8 @@ static void loadVertexData(IWineD3DStateBlockImpl *stateblock, WineDirect3DVerte
checkGLcall("glEnableClientState(GL_NORMAL_ARRAY)");
} else {
- glNormal3f(0, 0, 1);
- checkGLcall("glNormal3f(0, 0, 1)");
+ glNormal3f(0, 0, 0);
+ checkGLcall("glNormal3f(0, 0, 0)");
}
/* Diffuse Colour --------------------------------------------*/
@@ -3307,6 +3316,9 @@ static void vertexdeclaration(DWORD state, IWineD3DStateBlockImpl *stateblock, W
if(context->last_was_vshader && !isStateDirty(context, STATE_RENDER(WINED3DRS_CLIPPLANEENABLE))) {
state_clipping(STATE_RENDER(WINED3DRS_CLIPPLANEENABLE), stateblock, context);
}
+ if(!isStateDirty(context, STATE_RENDER(WINED3DRS_NORMALIZENORMALS))) {
+ state_normalize(STATE_RENDER(WINED3DRS_NORMALIZENORMALS), stateblock, context);
+ }
} else {
/* We compile the shader here because we need the vertex declaration
* in order to determine if we need to do any swizzling for D3DCOLOR