diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index 2f2cccf75..a21ebf108 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -128,7 +128,7 @@ void PolyRenderState::SetScissor(int x, int y, int w, int h) w = fb->GetCanvas()->GetWidth(); h = fb->GetCanvas()->GetHeight(); } - PolyTriangleDrawer::SetScissor(fb->GetDrawCommands(), x, y, w, h); + PolyTriangleDrawer::SetScissor(fb->GetDrawCommands(), x, fb->GetCanvas()->GetHeight() - y - h, w, h); } void PolyRenderState::SetViewport(int x, int y, int w, int h) @@ -141,7 +141,7 @@ void PolyRenderState::SetViewport(int x, int y, int w, int h) w = fb->GetCanvas()->GetWidth(); h = fb->GetCanvas()->GetHeight(); } - PolyTriangleDrawer::SetViewport(fb->GetDrawCommands(), x, y, w, h, fb->GetCanvas()); + PolyTriangleDrawer::SetViewport(fb->GetDrawCommands(), x, fb->GetCanvas()->GetHeight() - y - h, w, h, fb->GetCanvas()); } void PolyRenderState::EnableDepthTest(bool on) diff --git a/src/rendering/polyrenderer/drawers/poly_triangle.cpp b/src/rendering/polyrenderer/drawers/poly_triangle.cpp index ba4741d59..914004485 100644 --- a/src/rendering/polyrenderer/drawers/poly_triangle.cpp +++ b/src/rendering/polyrenderer/drawers/poly_triangle.cpp @@ -71,19 +71,7 @@ void PolyTriangleDrawer::SetViewport(const DrawerCommandQueuePtr &queue, int x, bool dest_bgra = canvas->IsBgra(); isBgraRenderTarget = dest_bgra; - int offsetx = clamp(x, 0, dest_width); - int pixelsize = dest_bgra ? 4 : 1; - - int viewport_x = x - offsetx; - int viewport_y = y; - int viewport_width = width; - int viewport_height = height; - - dest += offsetx * pixelsize; - dest_width = clamp(viewport_x + viewport_width, 0, dest_width - offsetx); - dest_height = clamp(viewport_y + viewport_height, 0, dest_height); - - queue->Push(viewport_x, viewport_y, viewport_width, viewport_height, dest, dest_width, dest_height, dest_pitch, dest_bgra); + queue->Push(x, y, width, height, dest, dest_width, dest_height, dest_pitch, dest_bgra); } void PolyTriangleDrawer::SetInputAssembly(const DrawerCommandQueuePtr &queue, PolyInputAssembly *input) @@ -276,8 +264,24 @@ void PolyTriangleThreadData::SetViewport(int x, int y, int width, int height, ui dest_height = new_dest_height; dest_pitch = new_dest_pitch; dest_bgra = new_dest_bgra; - ccw = true; - weaponScene = false; + UpdateClip(); +} + +void PolyTriangleThreadData::SetScissor(int x, int y, int w, int h) +{ + scissor.left = x; + scissor.right = x + w; + scissor.top = y; + scissor.bottom = y + h; + UpdateClip(); +} + +void PolyTriangleThreadData::UpdateClip() +{ + clip.left = MAX(MAX(viewport_x, scissor.left), 0); + clip.top = MAX(MAX(viewport_y, scissor.top), 0); + clip.right = MIN(MIN(viewport_x + viewport_width, scissor.right), dest_width); + clip.bottom = MIN(MIN(viewport_y + viewport_height, scissor.bottom), dest_height); } void PolyTriangleThreadData::SetTransform(const Mat4f *newObjectToClip, const Mat4f *newObjectToWorld) @@ -378,10 +382,6 @@ void PolyTriangleThreadData::EnableStencil(bool on) drawargs.SetWriteStencil(on && drawargs.StencilTestValue() != drawargs.StencilWriteValue(), drawargs.StencilWriteValue()); } -void PolyTriangleThreadData::SetScissor(int x, int y, int w, int h) -{ -} - void PolyTriangleThreadData::EnableDepthTest(bool on) { drawargs.SetDepthTest(on); diff --git a/src/rendering/polyrenderer/drawers/poly_triangle.h b/src/rendering/polyrenderer/drawers/poly_triangle.h index 17a55e93c..a14216cae 100644 --- a/src/rendering/polyrenderer/drawers/poly_triangle.h +++ b/src/rendering/polyrenderer/drawers/poly_triangle.h @@ -143,6 +143,8 @@ public: void SetRenderStyle(FRenderStyle style); void SetTexture(void *pixels, int width, int height); + void UpdateClip(); + void PushDrawArgs(const PolyDrawArgs &args); void PushStreamData(const StreamData &data, const PolyPushConstants &constants); void PushMatrices(const VSMatrix &modelMatrix, const VSMatrix &normalModelMatrix, const VSMatrix &textureMatrix); @@ -197,6 +199,14 @@ public: int viewport_y = 0; + struct ClipRect + { + int left = 0; + int top = 0; + int right = 0; + int bottom = 0; + } clip, scissor; + PolyDrawArgs drawargs; const void *vertices = nullptr; diff --git a/src/rendering/polyrenderer/drawers/screen_triangle.cpp b/src/rendering/polyrenderer/drawers/screen_triangle.cpp index 413b63d3d..5f37e3b87 100644 --- a/src/rendering/polyrenderer/drawers/screen_triangle.cpp +++ b/src/rendering/polyrenderer/drawers/screen_triangle.cpp @@ -60,10 +60,10 @@ void ScreenTriangle::Draw(const TriDrawTriangleArgs *args, PolyTriangleThreadDat ScreenTriVertex *sortedVertices[3]; SortVertices(args, sortedVertices); - int clipleft = 0; - int cliptop = MAX(thread->viewport_y, thread->numa_start_y); - int clipright = thread->dest_width; - int clipbottom = MIN(thread->dest_height, thread->numa_end_y); + int clipleft = thread->clip.left; + int cliptop = MAX(thread->clip.top, thread->numa_start_y); + int clipright = thread->clip.right; + int clipbottom = MIN(thread->clip.bottom, thread->numa_end_y); int topY = (int)(sortedVertices[0]->y + 0.5f); int midY = (int)(sortedVertices[1]->y + 0.5f); diff --git a/src/rendering/swrenderer/scene/r_scene.cpp b/src/rendering/swrenderer/scene/r_scene.cpp index 76fbec103..7bd5dcea3 100644 --- a/src/rendering/swrenderer/scene/r_scene.cpp +++ b/src/rendering/swrenderer/scene/r_scene.cpp @@ -276,6 +276,7 @@ namespace swrenderer PolyTriangleDrawer::ClearStencil(MainThread()->DrawQueue, 0); PolyTriangleDrawer::SetViewport(thread->DrawQueue, viewwindowx, viewwindowy, viewwidth, viewheight, thread->Viewport->RenderTarget); + PolyTriangleDrawer::SetScissor(thread->DrawQueue, viewwindowx, viewwindowy, viewwidth, viewheight); // Cull things outside the range seen by this thread VisibleSegmentRenderer visitor;