- fix viewport location

- add scissor support
This commit is contained in:
Magnus Norddahl 2019-05-27 16:51:54 +02:00
parent 8db5e72254
commit 0d8d50c23e
5 changed files with 36 additions and 25 deletions

View file

@ -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)

View file

@ -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<PolySetViewportCommand>(viewport_x, viewport_y, viewport_width, viewport_height, dest, dest_width, dest_height, dest_pitch, dest_bgra);
queue->Push<PolySetViewportCommand>(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);

View file

@ -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;

View file

@ -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);

View file

@ -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;