Stefan Dösinger : wined3d: Test clearing regarding the scissor test and colorwrite.

Alexandre Julliard julliard at winehq.org
Thu Dec 6 08:26:49 CST 2007


Module: wine
Branch: master
Commit: f4d244924421a25c34c3855fd0855026e0200a9d
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f4d244924421a25c34c3855fd0855026e0200a9d

Author: Stefan Dösinger <stefan at codeweavers.com>
Date:   Wed Dec  5 21:35:32 2007 +0100

wined3d: Test clearing regarding the scissor test and colorwrite.

---

 dlls/d3d9/tests/visual.c |   85 ++++++++++++++++++++++++++++++++++++++++++++++
 dlls/wined3d/device.c    |   40 ++++++++++++----------
 2 files changed, 107 insertions(+), 18 deletions(-)

diff --git a/dlls/d3d9/tests/visual.c b/dlls/d3d9/tests/visual.c
index 2403881..09f24b2 100644
--- a/dlls/d3d9/tests/visual.c
+++ b/dlls/d3d9/tests/visual.c
@@ -277,6 +277,8 @@ static void clear_test(IDirect3DDevice9 *device)
     D3DRECT rect_negneg;
     DWORD color;
     D3DVIEWPORT9 old_vp, vp;
+    RECT scissor;
+    DWORD oldColorWrite;
 
     hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
     ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr));
@@ -379,6 +381,89 @@ static void clear_test(IDirect3DDevice9 *device)
     ok(color == 0x00ffffff, "(478,362) has color %08x\n", color);
     color = getPixelColor(device, 482, 362);
     ok(color == 0x00ffffff, "(482,362) has color %08x\n", color);
+
+    hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
+    ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr));
+
+    scissor.left = 160;
+    scissor.right = 480;
+    scissor.top = 120;
+    scissor.bottom = 360;
+    hr = IDirect3DDevice9_SetScissorRect(device, &scissor);
+    ok(hr == D3D_OK, "IDirect3DDevice_SetScissorRect failed with %s\n", DXGetErrorString9(hr));
+    hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SCISSORTESTENABLE, TRUE);
+    ok(hr == D3D_OK, "IDirect3DDevice_SetScissorRect failed with %s\n", DXGetErrorString9(hr));
+
+    hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
+    ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr));
+    hr = IDirect3DDevice9_Clear(device, 1, &rect[1], D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
+    ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr));
+
+    hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SCISSORTESTENABLE, FALSE);
+    ok(hr == D3D_OK, "IDirect3DDevice_SetScissorRect failed with %s\n", DXGetErrorString9(hr));
+
+    IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
+    color = getPixelColor(device, 158, 118);
+    ok(color == 0x00ffffff, "Pixel 158/118 has color %08x\n", color);
+    color = getPixelColor(device, 162, 118);
+    ok(color == 0x00ffffff, "Pixel 162/118 has color %08x\n", color);
+    color = getPixelColor(device, 158, 122);
+    ok(color == 0x00ffffff, "Pixel 158/122 has color %08x\n", color);
+    color = getPixelColor(device, 162, 122);
+    ok(color == 0x00ff0000, "Pixel 162/122 has color %08x\n", color);
+
+    color = getPixelColor(device, 158, 358);
+    ok(color == 0x00ffffff, "Pixel 158/358 has color %08x\n", color);
+    color = getPixelColor(device, 162, 358);
+    ok(color == 0x0000ff00, "Pixel 162/358 has color %08x\n", color);
+    color = getPixelColor(device, 158, 358);
+    ok(color == 0x00ffffff, "Pixel 158/358 has color %08x\n", color);
+    color = getPixelColor(device, 162, 362);
+    ok(color == 0x00ffffff, "Pixel 162/362 has color %08x\n", color);
+
+    color = getPixelColor(device, 478, 118);
+    ok(color == 0x00ffffff, "Pixel 158/118 has color %08x\n", color);
+    color = getPixelColor(device, 478, 122);
+    ok(color == 0x0000ff00, "Pixel 162/118 has color %08x\n", color);
+    color = getPixelColor(device, 482, 122);
+    ok(color == 0x00ffffff, "Pixel 158/122 has color %08x\n", color);
+    color = getPixelColor(device, 482, 358);
+    ok(color == 0x00ffffff, "Pixel 162/122 has color %08x\n", color);
+
+    color = getPixelColor(device, 478, 358);
+    ok(color == 0x0000ff00, "Pixel 478/358 has color %08x\n", color);
+    color = getPixelColor(device, 478, 362);
+    ok(color == 0x00ffffff, "Pixel 478/118 has color %08x\n", color);
+    color = getPixelColor(device, 482, 358);
+    ok(color == 0x00ffffff, "Pixel 482/122 has color %08x\n", color);
+    color = getPixelColor(device, 482, 362);
+    ok(color == 0x00ffffff, "Pixel 482/122 has color %08x\n", color);
+
+    color = getPixelColor(device, 318, 238);
+    ok(color == 0x00ff0000, "Pixel 318/238 has color %08x\n", color);
+    color = getPixelColor(device, 318, 242);
+    ok(color == 0x0000ff00, "Pixel 318/242 has color %08x\n", color);
+    color = getPixelColor(device, 322, 238);
+    ok(color == 0x0000ff00, "Pixel 322/238 has color %08x\n", color);
+    color = getPixelColor(device, 322, 242);
+    ok(color == 0x0000ff00, "Pixel 322/242 has color %08x\n", color);
+
+    hr = IDirect3DDevice9_GetRenderState(device, D3DRS_COLORWRITEENABLE, &oldColorWrite);
+    ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderState failed with %s\n", DXGetErrorString9(hr));
+    hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED);
+    ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with %s\n", DXGetErrorString9(hr));
+
+    hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
+    ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr));
+
+    hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, oldColorWrite);
+    ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with %s\n", DXGetErrorString9(hr));
+
+    IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
+
+    /* Colorwriteenable does not affect the clear */
+    color = getPixelColor(device, 320, 240);
+    ok(color == 0x00ffffff, "Color write protected clear returned color %08x\n", color);
 }
 
 typedef struct {
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 1e53bcc..e5f1c96 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -4816,6 +4816,13 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Clear(IWineD3DDevice *iface, DWORD Coun
                 IWineD3DSurface_LoadLocation((IWineD3DSurface *) target, SFLAG_INDRAWABLE, NULL);
                 break;
             }
+            if(This->stateBlock->renderState[WINED3DRS_SCISSORTESTENABLE] && (
+               This->stateBlock->scissorRect.left > 0 || This->stateBlock->scissorRect.top > 0 ||
+               This->stateBlock->scissorRect.right < target->currentDesc.Width ||
+               This->stateBlock->scissorRect.bottom < target->currentDesc.Height)) {
+                IWineD3DSurface_LoadLocation((IWineD3DSurface *) target, SFLAG_INDRAWABLE, NULL);
+                break;
+            }
             if(Count > 0 && pRects && (
                pRects[0].x1 > 0 || pRects[0].y1 > 0 ||
                pRects[0].x2 < target->currentDesc.Width ||
@@ -4868,35 +4875,32 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Clear(IWineD3DDevice *iface, DWORD Coun
         glMask = glMask | GL_COLOR_BUFFER_BIT;
     }
 
+    vp_rect.left = vp->X;
+    vp_rect.top = vp->Y;
+    vp_rect.right = vp->X + vp->Width;
+    vp_rect.bottom = vp->Y + vp->Height;
     if (!(Count > 0 && pRects)) {
-        if (This->render_offscreen) {
-            glScissor(This->stateBlock->viewport.X,
-                       This->stateBlock->viewport.Y,
-                       This->stateBlock->viewport.Width,
-                       This->stateBlock->viewport.Height);
+        if(This->stateBlock->renderState[WINED3DRS_SCISSORTESTENABLE]) {
+            IntersectRect(&vp_rect, &vp_rect, &This->stateBlock->scissorRect);
+        }
+        if(This->render_offscreen) {
+            glScissor(vp_rect.left, vp_rect.top,
+                        vp_rect.right - vp_rect.left, vp_rect.bottom - vp_rect.top);
         } else {
-            glScissor(This->stateBlock->viewport.X,
-                      (drawable_height -
-                      (This->stateBlock->viewport.Y + This->stateBlock->viewport.Height)),
-                       This->stateBlock->viewport.Width,
-                       This->stateBlock->viewport.Height);
+            glScissor(vp_rect.left, drawable_height - vp_rect.bottom,
+                        vp_rect.right - vp_rect.left, vp_rect.bottom - vp_rect.top);
         }
         checkGLcall("glScissor");
         glClear(glMask);
         checkGLcall("glClear");
     } else {
-        /* The viewport cap still applies, we have to intersect each clear rect with the viewport
-         * range because glClear ignores the viewport(and the viewport isn't even applied in this state)
-         */
-        vp_rect.left = vp->X;
-        vp_rect.top = vp->Y;
-        vp_rect.right = vp->X + vp->Width;
-        vp_rect.bottom = vp->Y + vp->Height;
-
         /* Now process each rect in turn */
         for (i = 0; i < Count; i++) {
             /* Note gl uses lower left, width/height */
             IntersectRect((RECT *) &curRect, &vp_rect, (RECT *) &pRects[i]);
+            if(This->stateBlock->renderState[WINED3DRS_SCISSORTESTENABLE]) {
+                IntersectRect((RECT *) &curRect, (RECT *) &curRect, &This->stateBlock->scissorRect);
+            }
             TRACE("(%p) Rect=(%d,%d)->(%d,%d) glRect=(%d,%d), len=%d, hei=%d\n", This,
                   pRects[i].x1, pRects[i].y1, pRects[i].x2, pRects[i].y2,
                   curRect.x1, (target->currentDesc.Height - curRect.y2),




More information about the wine-cvs mailing list