mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-12 00:59:41 +01:00
Merge pull request #10596 from hrydgard/further-gl-fixes
Further GL fixes
This commit is contained in:
12 files changed
+27
-53
No files matched your search
@@ -690,7 +690,6 @@ void FramebufferManagerCommon::UpdateFromMemory(u32 addr, int size, bool safe) {
|
||||
FlushBeforeCopy();
|
||||
|
||||
if (useBufferedRendering_ && vfb->fbo) {
|
||||
DisableState();
|
||||
GEBufferFormat fmt = vfb->format;
|
||||
if (vfb->last_frame_render + 1 < gpuStats.numFlips && isDisplayBuf) {
|
||||
// If we're not rendering to it, format may be wrong. Use displayFormat_ instead.
|
||||
@@ -731,7 +730,6 @@ void FramebufferManagerCommon::DrawPixels(VirtualFramebuffer *vfb, int dstX, int
|
||||
SetViewport2D(x, y, w, h);
|
||||
draw_->SetScissorRect(0, 0, pixelWidth_, pixelHeight_);
|
||||
}
|
||||
DisableState();
|
||||
|
||||
MakePixelTexture(srcPixels, srcPixelFormat, srcStride, width, height, u1, v1);
|
||||
|
||||
@@ -775,8 +773,6 @@ void FramebufferManagerCommon::DrawFramebufferToOutput(const u8 *srcPixels, GEBu
|
||||
float v0 = 0.0f, v1 = 1.0f;
|
||||
MakePixelTexture(srcPixels, srcPixelFormat, srcStride, 512, 272, u1, v1);
|
||||
|
||||
DisableState();
|
||||
|
||||
struct CardboardSettings cardboardSettings;
|
||||
GetCardboardSettings(&cardboardSettings);
|
||||
|
||||
@@ -951,7 +947,6 @@ void FramebufferManagerCommon::CopyDisplayToOutput() {
|
||||
|
||||
if (vfb->fbo) {
|
||||
DEBUG_LOG(FRAMEBUF, "Displaying FBO %08x", vfb->fb_address);
|
||||
DisableState();
|
||||
|
||||
int uvRotation = useBufferedRendering_ ? g_Config.iInternalScreenRotation : ROTATION_LOCKED_HORIZONTAL;
|
||||
|
||||
|
||||
@@ -150,6 +150,7 @@ enum DrawTextureFlags {
|
||||
DRAWTEX_NEAREST = 0,
|
||||
DRAWTEX_LINEAR = 1,
|
||||
DRAWTEX_KEEP_TEX = 2,
|
||||
DRAWTEX_KEEP_STENCIL = 4,
|
||||
};
|
||||
|
||||
inline Draw::DataFormat GEFormatToThin3D(int geFormat) {
|
||||
@@ -312,7 +313,6 @@ protected:
|
||||
bool UpdateSize();
|
||||
void SetNumExtraFBOs(int num);
|
||||
|
||||
virtual void DisableState() = 0;
|
||||
void FlushBeforeCopy();
|
||||
virtual void DecimateFBOs(); // keeping it virtual to let D3D do a little extra
|
||||
|
||||
|
||||
@@ -197,13 +197,6 @@ void FramebufferManagerD3D11::SetDrawEngine(DrawEngineD3D11 *td) {
|
||||
drawEngine_ = td;
|
||||
}
|
||||
|
||||
void FramebufferManagerD3D11::DisableState() {
|
||||
context_->OMSetBlendState(stockD3D11.blendStateDisabledWithColorMask[0xF], nullptr, 0xFFFFFFFF);
|
||||
context_->RSSetState(stockD3D11.rasterStateNoCull);
|
||||
context_->OMSetDepthStencilState(stockD3D11.depthStencilDisabled, 0xFF);
|
||||
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE);
|
||||
}
|
||||
|
||||
void FramebufferManagerD3D11::CompilePostShader() {
|
||||
std::string vsSource;
|
||||
std::string psSource;
|
||||
@@ -731,8 +724,6 @@ void FramebufferManagerD3D11::DestroyAllFBOs() {
|
||||
tempFBOs_.clear();
|
||||
|
||||
SetNumExtraFBOs(0);
|
||||
|
||||
DisableState();
|
||||
}
|
||||
|
||||
void FramebufferManagerD3D11::Resized() {
|
||||
|
||||
@@ -65,8 +65,6 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void DisableState() override;
|
||||
|
||||
// Used by ReadFramebufferToMemory and later framebuffer block copies
|
||||
void BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int dstY, VirtualFramebuffer *src, int srcX, int srcY, int w, int h, int bpp) override;
|
||||
|
||||
|
||||
@@ -81,17 +81,6 @@ static const D3DVERTEXELEMENT9 g_FramebufferVertexElements[] = {
|
||||
D3DDECL_END()
|
||||
};
|
||||
|
||||
void FramebufferManagerDX9::DisableState() {
|
||||
dxstate.blend.disable();
|
||||
dxstate.cullMode.set(false, false);
|
||||
dxstate.depthTest.disable();
|
||||
dxstate.scissorTest.disable();
|
||||
dxstate.stencilTest.disable();
|
||||
dxstate.colorMask.set(true, true, true, true);
|
||||
dxstate.stencilMask.set(0xFF);
|
||||
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_VIEWPORTSCISSOR_STATE);
|
||||
}
|
||||
|
||||
FramebufferManagerDX9::FramebufferManagerDX9(Draw::DrawContext *draw)
|
||||
: FramebufferManagerCommon(draw),
|
||||
drawPixelsTex_(0),
|
||||
@@ -249,7 +238,7 @@ static const D3DVERTEXELEMENT9 g_FramebufferVertexElements[] = {
|
||||
}
|
||||
|
||||
void FramebufferManagerDX9::DrawActiveTexture(float x, float y, float w, float h, float destW, float destH, float u0, float v0, float u1, float v1, int uvRotation, int flags) {
|
||||
// TODO: StretchRect instead?
|
||||
// TODO: StretchRect instead when possible?
|
||||
float coord[20] = {
|
||||
x,y,0, u0,v0,
|
||||
x+w,y,0, u1,v0,
|
||||
@@ -297,7 +286,13 @@ static const D3DVERTEXELEMENT9 g_FramebufferVertexElements[] = {
|
||||
}
|
||||
dxstate.texMipLodBias.set(0.0f);
|
||||
dxstate.texMaxMipLevel.set(0);
|
||||
device_->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
|
||||
dxstate.blend.disable();
|
||||
dxstate.cullMode.set(false, false);
|
||||
dxstate.depthTest.disable();
|
||||
dxstate.scissorTest.disable();
|
||||
dxstate.stencilTest.disable();
|
||||
dxstate.colorMask.set(true, true, true, true);
|
||||
dxstate.stencilMask.set(0xFF);
|
||||
HRESULT hr = device_->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, coord, 5 * sizeof(float));
|
||||
if (FAILED(hr)) {
|
||||
ERROR_LOG_REPORT(G3D, "DrawActiveTexture() failed: %08x", hr);
|
||||
@@ -725,8 +720,6 @@ static const D3DVERTEXELEMENT9 g_FramebufferVertexElements[] = {
|
||||
offscreenSurfaces_.clear();
|
||||
|
||||
SetNumExtraFBOs(0);
|
||||
|
||||
DisableState();
|
||||
}
|
||||
|
||||
void FramebufferManagerDX9::Resized() {
|
||||
|
||||
@@ -73,7 +73,6 @@ protected:
|
||||
void Bind2DShader() override;
|
||||
void BindPostShader(const PostShaderUniforms &uniforms) override;
|
||||
void SetViewport2D(int x, int y, int w, int h) override;
|
||||
void DisableState() override;
|
||||
void DecimateFBOs() override;
|
||||
|
||||
// Used by ReadFramebufferToMemory and later framebuffer block copies
|
||||
|
||||
@@ -181,7 +181,6 @@ bool FramebufferManagerDX9::NotifyStencilUpload(u32 addr, int size, bool skipZer
|
||||
|
||||
shaderManagerDX9_->DirtyLastShader();
|
||||
|
||||
DisableState();
|
||||
dxstate.colorMask.set(false, false, false, true);
|
||||
dxstate.stencilTest.enable();
|
||||
dxstate.stencilOp.set(D3DSTENCILOP_REPLACE, D3DSTENCILOP_REPLACE, D3DSTENCILOP_REPLACE);
|
||||
|
||||
@@ -80,10 +80,6 @@ const int MAX_PBO = 2;
|
||||
|
||||
void ConvertFromRGBA8888(u8 *dst, const u8 *src, u32 dstStride, u32 srcStride, u32 width, u32 height, GEBufferFormat format);
|
||||
|
||||
void FramebufferManagerGLES::DisableState() {
|
||||
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_VIEWPORTSCISSOR_STATE);
|
||||
}
|
||||
|
||||
void FramebufferManagerGLES::CompileDraw2DProgram() {
|
||||
if (!draw2dprogram_) {
|
||||
std::string errorString;
|
||||
@@ -423,6 +419,14 @@ void FramebufferManagerGLES::DrawActiveTexture(float x, float y, float w, float
|
||||
pos[i * 3 + 1] = pos[i * 3 + 1] * invDestH - 1.0f;
|
||||
}
|
||||
|
||||
// We always want a plain state here, well, except for when it's used by the stencil stuff...
|
||||
render_->SetNoBlendAndMask(0xF);
|
||||
render_->SetDepth(false, false, GL_ALWAYS);
|
||||
render_->SetRaster(false, GL_CCW, GL_FRONT, GL_FALSE);
|
||||
if (!(flags & DRAWTEX_KEEP_STENCIL)) {
|
||||
render_->SetStencilDisabled();
|
||||
}
|
||||
|
||||
// Upscaling postshaders don't look well with linear
|
||||
if (flags & DRAWTEX_LINEAR) {
|
||||
render_->SetTextureSampler(0, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_LINEAR, GL_LINEAR, 0.0f);
|
||||
@@ -778,8 +782,6 @@ void FramebufferManagerGLES::DestroyAllFBOs() {
|
||||
tempFBOs_.clear();
|
||||
|
||||
SetNumExtraFBOs(0);
|
||||
|
||||
DisableState();
|
||||
}
|
||||
|
||||
void FramebufferManagerGLES::Resized() {
|
||||
|
||||
@@ -69,7 +69,6 @@ public:
|
||||
|
||||
protected:
|
||||
void SetViewport2D(int x, int y, int w, int h) override;
|
||||
void DisableState() override;
|
||||
|
||||
// Used by ReadFramebufferToMemory and later framebuffer block copies
|
||||
void BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int dstY, VirtualFramebuffer *src, int srcX, int srcY, int w, int h, int bpp) override;
|
||||
|
||||
@@ -142,8 +142,6 @@ bool FramebufferManagerGLES::NotifyStencilUpload(u32 addr, int size, bool skipZe
|
||||
|
||||
shaderManagerGL_->DirtyLastShader();
|
||||
|
||||
DisableState();
|
||||
|
||||
bool useBlit = gstate_c.Supports(GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT | GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT);
|
||||
|
||||
// Our fragment shader (and discard) is slow. Since the source is 1x, we can stencil to 1x.
|
||||
@@ -169,8 +167,10 @@ bool FramebufferManagerGLES::NotifyStencilUpload(u32 addr, int size, bool skipZe
|
||||
textureCacheGL_->ForgetLastTexture();
|
||||
|
||||
// We must bind the program after starting the render pass, and set the color mask after clearing.
|
||||
render_->SetDepth(false, false, GL_ALWAYS);
|
||||
render_->Clear(0, 0, 0, GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, 0x8, 0, 0, 0, 0);
|
||||
render_->SetStencilFunc(GL_TRUE, GL_ALWAYS, 0xFF, 0xFF);
|
||||
render_->SetRaster(false, GL_CCW, GL_FRONT, GL_FALSE);
|
||||
render_->BindProgram(stencilUploadProgram_);
|
||||
render_->SetNoBlendAndMask(0x8);
|
||||
|
||||
@@ -189,14 +189,14 @@ bool FramebufferManagerGLES::NotifyStencilUpload(u32 addr, int size, bool skipZe
|
||||
render_->SetStencilOp(i, GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
||||
render_->SetUniformF1(&u_stencilValue, i * (1.0f / 255.0f));
|
||||
}
|
||||
DrawActiveTexture(0, 0, dstBuffer->width, dstBuffer->height, dstBuffer->bufferWidth, dstBuffer->bufferHeight, 0.0f, 0.0f, u1, v1, ROTATION_LOCKED_HORIZONTAL, DRAWTEX_NEAREST);
|
||||
DrawActiveTexture(0, 0, dstBuffer->width, dstBuffer->height, dstBuffer->bufferWidth, dstBuffer->bufferHeight, 0.0f, 0.0f, u1, v1, ROTATION_LOCKED_HORIZONTAL, DRAWTEX_NEAREST | DRAWTEX_KEEP_STENCIL);
|
||||
}
|
||||
|
||||
if (useBlit) {
|
||||
draw_->BlitFramebuffer(blitFBO, 0, 0, w, h, dstBuffer->fbo, 0, 0, dstBuffer->renderWidth, dstBuffer->renderHeight, Draw::FB_STENCIL_BIT, Draw::FB_BLIT_NEAREST);
|
||||
}
|
||||
|
||||
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_VIEWPORTSCISSOR_STATE);
|
||||
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_VIEWPORTSCISSOR_STATE);
|
||||
RebindFramebuffer();
|
||||
return true;
|
||||
}
|
||||
@@ -89,7 +89,6 @@ protected:
|
||||
void Bind2DShader() override;
|
||||
void BindPostShader(const PostShaderUniforms &uniforms) override;
|
||||
void SetViewport2D(int x, int y, int w, int h) override;
|
||||
void DisableState() override {}
|
||||
|
||||
// Used by ReadFramebufferToMemory and later framebuffer block copies
|
||||
void BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int dstY, VirtualFramebuffer *src, int srcX, int srcY, int w, int h, int bpp) override;
|
||||
|
||||
@@ -588,11 +588,12 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) {
|
||||
#endif
|
||||
break;
|
||||
case GLRRenderCommand::CLEAR:
|
||||
if (c.clear.scissorW > 0) {
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(c.clear.scissorX, c.clear.scissorY, c.clear.scissorW, c.clear.scissorH);
|
||||
} else {
|
||||
// Scissor test is on, and should be on after leaving this case. If we disable it,
|
||||
// we re-enable it at the end.
|
||||
if (c.clear.scissorW == 0) {
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
} else {
|
||||
glScissor(c.clear.scissorX, c.clear.scissorY, c.clear.scissorW, c.clear.scissorH);
|
||||
}
|
||||
if (c.clear.colorMask != colorMask) {
|
||||
glColorMask(c.clear.colorMask & 1, (c.clear.colorMask >> 1) & 1, (c.clear.colorMask >> 2) & 1, (c.clear.colorMask >> 3) & 1);
|
||||
@@ -614,9 +615,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) {
|
||||
glClearStencil(c.clear.clearStencil);
|
||||
}
|
||||
glClear(c.clear.clearMask);
|
||||
if (c.clear.scissorW > 0) {
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
} else {
|
||||
if (c.clear.scissorW == 0) {
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user