From cf458dba60e8985f084eb0878374651127bf9c15 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Fri, 15 Mar 2013 22:24:16 +0100 Subject: [PATCH] gpu: Add support for scissor rectangle --- GPU/GLES/DisplayListInterpreter.cpp | 2 ++ GPU/GLES/Framebuffer.cpp | 4 ---- GPU/GLES/StateMapping.cpp | 29 ++++++++++++++++++++++++----- GPU/GLES/TransformPipeline.cpp | 1 - GPU/GLES/TransformPipeline.h | 1 - native | 2 +- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/GPU/GLES/DisplayListInterpreter.cpp b/GPU/GLES/DisplayListInterpreter.cpp index dbe55338d4..29742a0a3b 100644 --- a/GPU/GLES/DisplayListInterpreter.cpp +++ b/GPU/GLES/DisplayListInterpreter.cpp @@ -109,6 +109,8 @@ static const u8 flushOnChangedBeforeCommandList[] = { GE_CMD_TEXMODE, GE_CMD_TEXFORMAT, GE_CMD_TEXWRAP, + GE_CMD_SCISSOR1, + GE_CMD_SCISSOR2, GE_CMD_ZTESTENABLE, GE_CMD_ZWRITEDISABLE, GE_CMD_STENCILTESTENABLE, diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index cf4cdff0f4..e9324d70ab 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -273,10 +273,6 @@ void FramebufferManager::SetRenderFrameBuffer() { u32 z_address = (gstate.zbptr & 0xFFE000) | ((gstate.zbwidth & 0xFF0000) << 8); int z_stride = gstate.zbwidth & 0x3C0; - // We guess that the viewport size during the first draw call is an appropriate - // size for a render target. - //UpdateViewportAndProjection(); - // Yeah this is not completely right. but it'll do for now. //int drawing_width = ((gstate.region2) & 0x3FF) + 1; //int drawing_height = ((gstate.region2 >> 10) & 0x3FF) + 1; diff --git a/GPU/GLES/StateMapping.cpp b/GPU/GLES/StateMapping.cpp index dc8e51ec47..0f0aac5051 100644 --- a/GPU/GLES/StateMapping.cpp +++ b/GPU/GLES/StateMapping.cpp @@ -185,6 +185,7 @@ void TransformDrawEngine::ApplyDrawState(int prim) { // Set Dither glstate.dither.set(gstate.isDitherEnabled()); + // Set ColorMask/Stencil/Depth if (gstate.isModeClear()) { bool colorMask = (gstate.clearmode >> 8) & 1; @@ -230,9 +231,7 @@ void TransformDrawEngine::ApplyDrawState(int prim) { glstate.stencilTest.disable(); } } -} -void TransformDrawEngine::UpdateViewportAndProjection() { float renderWidthFactor, renderHeightFactor; float renderWidth, renderHeight; float renderX, renderY; @@ -254,8 +253,24 @@ void TransformDrawEngine::UpdateViewportAndProjection() { bool throughmode = (gstate.vertType & GE_VTYPE_THROUGH_MASK) != 0; - // We can probably use these to simply set scissors? Maybe we need to offset by regionX1/Y1 - + // Scissor + int scissorX1 = gstate.scissor1 & 0x3FF; + int scissorY1 = (gstate.scissor1 >> 10) & 0x3FF; + int scissorX2 = gstate.scissor2 & 0x3FF; + int scissorY2 = (gstate.scissor2 >> 10) & 0x3FF; + + // This is a bit of a hack as the render buffer isn't always that size + if (scissorX1 == 0 && scissorY1 == 0 && scissorX2 == 480 && scissorY2 == 272) { + glstate.scissorTest.disable(); + } else { + glstate.scissorTest.enable(); + glstate.scissorRect.set( + renderX + scissorX1 * renderWidthFactor, + renderY + renderHeight - (scissorY2 * renderHeightFactor), + (scissorX2 - scissorX1) * renderWidthFactor, + (scissorY2 - scissorY1) * renderHeightFactor); + } + /* int regionX1 = gstate.region1 & 0x3FF; int regionY1 = (gstate.region1 >> 10) & 0x3FF; @@ -272,7 +287,11 @@ void TransformDrawEngine::UpdateViewportAndProjection() { if (throughmode) { // No viewport transform here. Let's experiment with using region. - glstate.viewport.set(renderX + (0 + regionX1) * renderWidthFactor, renderY + (0 - regionY1) * renderHeightFactor, (regionX2 - regionX1) * renderWidthFactor, (regionY2 - regionY1) * renderHeightFactor); + glstate.viewport.set( + renderX + (0 + regionX1) * renderWidthFactor, + renderY + (0 - regionY1) * renderHeightFactor, + (regionX2 - regionX1) * renderWidthFactor, + (regionY2 - regionY1) * renderHeightFactor); glstate.depthRange.set(0.0f, 1.0f); } else { // These we can turn into a glViewport call, offset by offsetX and offsetY. Math after. diff --git a/GPU/GLES/TransformPipeline.cpp b/GPU/GLES/TransformPipeline.cpp index 30909d6957..d00cdde942 100644 --- a/GPU/GLES/TransformPipeline.cpp +++ b/GPU/GLES/TransformPipeline.cpp @@ -937,7 +937,6 @@ void TransformDrawEngine::Flush() { int prim = prevPrim_; ApplyDrawState(prim); - UpdateViewportAndProjection(); LinkedShader *program = shaderManager_->ApplyShader(prim); diff --git a/GPU/GLES/TransformPipeline.h b/GPU/GLES/TransformPipeline.h index 816440427d..4c37b8b9ba 100644 --- a/GPU/GLES/TransformPipeline.h +++ b/GPU/GLES/TransformPipeline.h @@ -120,7 +120,6 @@ public: private: void SoftwareTransformAndDraw(int prim, u8 *decoded, LinkedShader *program, int vertexCount, u32 vertexType, void *inds, int indexType, const DecVtxFormat &decVtxFormat, int maxIndex); void ApplyDrawState(int prim); - void UpdateViewportAndProjection(); // drawcall ID u32 ComputeFastDCID(); diff --git a/native b/native index b9486d43e9..21a7ee80fb 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit b9486d43e999d5de403e36cd981842fa575a5488 +Subproject commit 21a7ee80fb2f31bfff1a739bce80ac8e5047952b