2013-03-15 20:22:17 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2013-10-30 22:08:03 +00:00
|
|
|
|
|
|
|
// Alpha/stencil is a convoluted mess. Some good comments are here:
|
|
|
|
// https://github.com/hrydgard/ppsspp/issues/3768
|
|
|
|
|
2021-03-03 04:57:25 +00:00
|
|
|
#include "ppsspp_config.h"
|
2017-01-21 21:16:30 +00:00
|
|
|
#include "StateMappingGLES.h"
|
2020-10-04 08:04:01 +00:00
|
|
|
#include "Common/Profiler/Profiler.h"
|
2020-10-04 21:24:14 +00:00
|
|
|
#include "Common/GPU/OpenGL/GLDebugLog.h"
|
|
|
|
#include "Common/GPU/OpenGL/GLRenderManager.h"
|
2020-11-08 22:17:06 +00:00
|
|
|
#include "Common/Data/Convert/SmallDataConvert.h"
|
2012-12-21 15:49:42 +00:00
|
|
|
|
2013-02-04 22:39:09 +00:00
|
|
|
#include "GPU/Math3D.h"
|
|
|
|
#include "GPU/GPUState.h"
|
|
|
|
#include "GPU/ge_constants.h"
|
|
|
|
#include "Core/System.h"
|
|
|
|
#include "Core/Config.h"
|
2016-04-10 08:27:28 +00:00
|
|
|
#include "GPU/GLES/GPU_GLES.h"
|
2017-01-21 21:16:30 +00:00
|
|
|
#include "GPU/GLES/ShaderManagerGLES.h"
|
|
|
|
#include "GPU/GLES/TextureCacheGLES.h"
|
|
|
|
#include "GPU/GLES/FramebufferManagerGLES.h"
|
2020-10-31 17:56:44 +00:00
|
|
|
#include "GPU/Common/FragmentShaderGenerator.h"
|
2012-11-24 14:19:29 +00:00
|
|
|
|
2015-11-08 19:09:30 +00:00
|
|
|
static const GLushort glBlendFactorLookup[(size_t)BlendFactor::COUNT] = {
|
|
|
|
GL_ZERO,
|
|
|
|
GL_ONE,
|
2012-11-24 14:19:29 +00:00
|
|
|
GL_SRC_COLOR,
|
|
|
|
GL_ONE_MINUS_SRC_COLOR,
|
2015-11-08 19:09:30 +00:00
|
|
|
GL_DST_COLOR,
|
|
|
|
GL_ONE_MINUS_DST_COLOR,
|
2012-11-24 14:19:29 +00:00
|
|
|
GL_SRC_ALPHA,
|
|
|
|
GL_ONE_MINUS_SRC_ALPHA,
|
|
|
|
GL_DST_ALPHA,
|
|
|
|
GL_ONE_MINUS_DST_ALPHA,
|
2015-11-08 19:09:30 +00:00
|
|
|
GL_CONSTANT_COLOR,
|
|
|
|
GL_ONE_MINUS_CONSTANT_COLOR,
|
|
|
|
GL_CONSTANT_ALPHA,
|
|
|
|
GL_ONE_MINUS_CONSTANT_ALPHA,
|
2016-12-26 22:59:42 +00:00
|
|
|
#if !defined(USING_GLES2) // TODO: Remove when we have better headers
|
2016-12-26 22:51:17 +00:00
|
|
|
GL_SRC1_COLOR,
|
|
|
|
GL_ONE_MINUS_SRC1_COLOR,
|
2015-11-08 19:09:30 +00:00
|
|
|
GL_SRC1_ALPHA,
|
|
|
|
GL_ONE_MINUS_SRC1_ALPHA,
|
2021-03-03 04:57:25 +00:00
|
|
|
#elif !PPSSPP_PLATFORM(IOS)
|
2016-12-26 22:59:42 +00:00
|
|
|
GL_SRC1_COLOR_EXT,
|
|
|
|
GL_ONE_MINUS_SRC1_COLOR_EXT,
|
2015-11-28 00:01:25 +00:00
|
|
|
GL_SRC1_ALPHA_EXT,
|
|
|
|
GL_ONE_MINUS_SRC1_ALPHA_EXT,
|
2015-11-08 19:09:30 +00:00
|
|
|
#else
|
|
|
|
GL_INVALID_ENUM,
|
|
|
|
GL_INVALID_ENUM,
|
2016-12-26 22:59:42 +00:00
|
|
|
GL_INVALID_ENUM,
|
|
|
|
GL_INVALID_ENUM,
|
2015-11-08 19:09:30 +00:00
|
|
|
#endif
|
|
|
|
GL_INVALID_ENUM,
|
2013-09-30 08:10:34 +00:00
|
|
|
};
|
|
|
|
|
2015-11-08 19:09:30 +00:00
|
|
|
static const GLushort glBlendEqLookup[(size_t)BlendEq::COUNT] = {
|
2012-11-24 14:19:29 +00:00
|
|
|
GL_FUNC_ADD,
|
2013-09-30 08:10:34 +00:00
|
|
|
GL_FUNC_SUBTRACT,
|
|
|
|
GL_FUNC_REVERSE_SUBTRACT,
|
2015-11-08 19:09:30 +00:00
|
|
|
GL_MIN,
|
|
|
|
GL_MAX,
|
2012-11-24 14:19:29 +00:00
|
|
|
};
|
|
|
|
|
2013-03-15 20:22:17 +00:00
|
|
|
static const GLushort cullingMode[] = {
|
2012-11-24 14:19:29 +00:00
|
|
|
GL_FRONT,
|
2015-10-31 22:59:23 +00:00
|
|
|
GL_BACK,
|
2012-11-24 14:19:29 +00:00
|
|
|
};
|
|
|
|
|
2015-10-10 14:41:19 +00:00
|
|
|
static const GLushort compareOps[] = {
|
2012-11-24 14:19:29 +00:00
|
|
|
GL_NEVER, GL_ALWAYS, GL_EQUAL, GL_NOTEQUAL,
|
|
|
|
GL_LESS, GL_LEQUAL, GL_GREATER, GL_GEQUAL,
|
2012-11-26 03:25:14 +00:00
|
|
|
};
|
2012-12-21 15:49:42 +00:00
|
|
|
|
2013-03-15 20:22:17 +00:00
|
|
|
static const GLushort stencilOps[] = {
|
2013-01-12 16:20:00 +00:00
|
|
|
GL_KEEP,
|
|
|
|
GL_ZERO,
|
|
|
|
GL_REPLACE,
|
|
|
|
GL_INVERT,
|
2013-12-03 08:02:07 +00:00
|
|
|
GL_INCR,
|
|
|
|
GL_DECR,
|
2013-01-12 16:20:00 +00:00
|
|
|
GL_KEEP, // reserved
|
|
|
|
GL_KEEP, // reserved
|
|
|
|
};
|
2012-12-21 15:49:42 +00:00
|
|
|
|
2013-08-06 09:24:48 +00:00
|
|
|
#if !defined(USING_GLES2)
|
2013-08-06 08:30:58 +00:00
|
|
|
static const GLushort logicOps[] = {
|
|
|
|
GL_CLEAR,
|
2013-08-06 08:46:35 +00:00
|
|
|
GL_AND,
|
|
|
|
GL_AND_REVERSE,
|
2013-08-06 08:30:58 +00:00
|
|
|
GL_COPY,
|
2013-08-06 08:46:35 +00:00
|
|
|
GL_AND_INVERTED,
|
2013-08-06 08:30:58 +00:00
|
|
|
GL_NOOP,
|
2013-08-06 08:46:35 +00:00
|
|
|
GL_XOR,
|
2013-08-06 08:30:58 +00:00
|
|
|
GL_OR,
|
|
|
|
GL_NOR,
|
|
|
|
GL_EQUIV,
|
2013-08-06 08:46:35 +00:00
|
|
|
GL_INVERT,
|
2013-08-06 08:30:58 +00:00
|
|
|
GL_OR_REVERSE,
|
2013-08-06 08:46:35 +00:00
|
|
|
GL_COPY_INVERTED,
|
2013-08-06 08:30:58 +00:00
|
|
|
GL_OR_INVERTED,
|
2013-08-06 08:46:35 +00:00
|
|
|
GL_NAND,
|
|
|
|
GL_SET,
|
2013-08-06 08:30:58 +00:00
|
|
|
};
|
2013-08-06 09:24:48 +00:00
|
|
|
#endif
|
2013-08-06 08:14:36 +00:00
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void DrawEngineGLES::ApplyDrawState(int prim) {
|
2017-11-18 23:43:58 +00:00
|
|
|
GLRenderManager *renderManager = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
|
|
|
|
|
2017-01-30 11:22:35 +00:00
|
|
|
if (!gstate_c.IsDirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE)) {
|
|
|
|
// Nothing to do, let's early-out
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-13 21:07:19 +00:00
|
|
|
// Start profiling here to skip SetTexture which is already accounted for
|
|
|
|
PROFILE_THIS_SCOPE("applydrawstate");
|
|
|
|
|
2022-08-28 15:34:48 +00:00
|
|
|
uint64_t dirtyRequiresRecheck_ = 0;
|
2020-04-04 17:51:47 +00:00
|
|
|
bool useBufferedRendering = framebufferManager_->UseBufferedRendering();
|
2015-11-14 07:11:06 +00:00
|
|
|
|
2017-01-30 10:56:14 +00:00
|
|
|
if (gstate_c.IsDirty(DIRTY_BLEND_STATE)) {
|
2017-01-30 10:56:14 +00:00
|
|
|
if (gstate.isModeClear()) {
|
|
|
|
// Color Test
|
|
|
|
bool colorMask = gstate.isClearModeColorMask();
|
|
|
|
bool alphaMask = gstate.isClearModeAlphaMask();
|
2017-11-18 23:43:58 +00:00
|
|
|
renderManager->SetNoBlendAndMask((colorMask ? 7 : 0) | (alphaMask ? 8 : 0));
|
2015-11-08 20:47:08 +00:00
|
|
|
} else {
|
2022-10-10 15:51:32 +00:00
|
|
|
pipelineState_.Convert(draw_->GetShaderLanguageDesc().bitwiseOps);
|
2022-09-02 19:07:29 +00:00
|
|
|
GenericMaskState &maskState = pipelineState_.maskState;
|
|
|
|
GenericBlendState &blendState = pipelineState_.blendState;
|
2022-09-03 22:00:33 +00:00
|
|
|
GenericLogicState &logicState = pipelineState_.logicState;
|
2022-04-24 22:06:21 +00:00
|
|
|
|
2022-09-04 20:52:24 +00:00
|
|
|
if (pipelineState_.FramebufferRead()) {
|
2022-02-19 19:40:27 +00:00
|
|
|
FBOTexState fboTexBindState = FBO_TEX_NONE;
|
|
|
|
ApplyFramebufferRead(&fboTexBindState);
|
2022-05-01 10:49:19 +00:00
|
|
|
// The shader takes over the responsibility for blending, so recompute.
|
|
|
|
ApplyStencilReplaceAndLogicOpIgnoreBlend(blendState.replaceAlphaWithStencil, blendState);
|
|
|
|
|
|
|
|
// We copy the framebuffer here, as doing so will wipe any blend state if we do it later.
|
2022-02-19 19:40:27 +00:00
|
|
|
// fboTexNeedsBind_ won't be set if we can read directly from the target.
|
|
|
|
if (fboTexBindState == FBO_TEX_COPY_BIND_TEX) {
|
2022-05-01 10:49:19 +00:00
|
|
|
// Note that this is positions, not UVs, that we need the copy from.
|
2023-05-11 10:04:29 +00:00
|
|
|
framebufferManager_->BindFramebufferAsColorTexture(1, framebufferManager_->GetCurrentRenderVFB(), BINDFBCOLOR_MAY_COPY | BINDFBCOLOR_UNCACHED, 0);
|
2022-05-01 10:49:19 +00:00
|
|
|
// If we are rendering at a higher resolution, linear is probably best for the dest color.
|
|
|
|
renderManager->SetTextureSampler(1, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_LINEAR, GL_LINEAR, 0.0f);
|
|
|
|
fboTexBound_ = true;
|
|
|
|
|
|
|
|
framebufferManager_->RebindFramebuffer("RebindFramebuffer - ApplyDrawState");
|
|
|
|
// Must dirty blend state here so we re-copy next time. Example: Lunar's spell effects.
|
2022-08-28 15:34:48 +00:00
|
|
|
dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE;
|
2022-05-01 10:49:19 +00:00
|
|
|
gstate_c.Dirty(DIRTY_BLEND_STATE);
|
2022-02-19 19:40:27 +00:00
|
|
|
} else if (fboTexBindState == FBO_TEX_READ_FRAMEBUFFER) {
|
|
|
|
// No action needed here.
|
|
|
|
fboTexBindState = FBO_TEX_NONE;
|
2017-01-30 10:56:14 +00:00
|
|
|
}
|
2022-08-28 15:34:48 +00:00
|
|
|
dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE;
|
2020-11-08 12:14:23 +00:00
|
|
|
gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE);
|
2022-09-03 12:47:47 +00:00
|
|
|
} else {
|
|
|
|
if (fboTexBound_) {
|
|
|
|
GLRenderManager *renderManager = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
|
|
|
|
renderManager->BindTexture(TEX_SLOT_SHADERBLEND_SRC, nullptr);
|
|
|
|
fboTexBound_ = false;
|
|
|
|
dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE;
|
|
|
|
gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE);
|
|
|
|
}
|
2017-01-30 10:56:14 +00:00
|
|
|
}
|
2015-11-08 19:09:30 +00:00
|
|
|
|
2022-09-02 19:07:29 +00:00
|
|
|
if (blendState.blendEnabled) {
|
2020-11-08 11:49:06 +00:00
|
|
|
if (blendState.dirtyShaderBlendFixValues) {
|
|
|
|
// Not quite sure how necessary this is.
|
2022-08-28 15:34:48 +00:00
|
|
|
dirtyRequiresRecheck_ |= DIRTY_SHADERBLEND;
|
2017-01-30 10:56:14 +00:00
|
|
|
gstate_c.Dirty(DIRTY_SHADERBLEND);
|
|
|
|
}
|
|
|
|
if (blendState.useBlendColor) {
|
|
|
|
uint32_t color = blendState.blendColor;
|
2020-11-08 22:17:06 +00:00
|
|
|
float col[4];
|
|
|
|
Uint8x4ToFloat4(col, color);
|
2017-11-18 23:43:58 +00:00
|
|
|
renderManager->SetBlendFactor(col);
|
2017-01-30 10:56:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-03 20:51:50 +00:00
|
|
|
int mask = (int)maskState.channelMask;
|
2022-09-02 19:07:29 +00:00
|
|
|
if (blendState.blendEnabled) {
|
|
|
|
renderManager->SetBlendAndMask(mask, blendState.blendEnabled,
|
2017-11-19 11:25:57 +00:00
|
|
|
glBlendFactorLookup[(size_t)blendState.srcColor], glBlendFactorLookup[(size_t)blendState.dstColor],
|
|
|
|
glBlendFactorLookup[(size_t)blendState.srcAlpha], glBlendFactorLookup[(size_t)blendState.dstAlpha],
|
|
|
|
glBlendEqLookup[(size_t)blendState.eqColor], glBlendEqLookup[(size_t)blendState.eqAlpha]);
|
|
|
|
} else {
|
|
|
|
renderManager->SetNoBlendAndMask(mask);
|
|
|
|
}
|
2022-09-03 22:00:33 +00:00
|
|
|
|
|
|
|
// TODO: Get rid of the ifdef
|
2017-01-30 11:02:14 +00:00
|
|
|
#ifndef USING_GLES2
|
2022-10-17 06:30:27 +00:00
|
|
|
if (gstate_c.Use(GPU_USE_LOGIC_OP)) {
|
2022-09-03 22:00:33 +00:00
|
|
|
renderManager->SetLogicOp(logicState.logicOpEnabled, logicOps[(int)logicState.logicOp]);
|
2017-01-30 11:02:14 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-11-08 21:29:43 +00:00
|
|
|
}
|
2015-11-08 19:09:30 +00:00
|
|
|
}
|
2014-06-17 06:47:21 +00:00
|
|
|
|
2017-01-30 11:07:26 +00:00
|
|
|
if (gstate_c.IsDirty(DIRTY_RASTER_STATE)) {
|
2017-04-03 14:19:10 +00:00
|
|
|
// Dither
|
2017-11-18 23:43:58 +00:00
|
|
|
bool dither = gstate.isDitherEnabled();
|
|
|
|
bool cullEnable;
|
|
|
|
GLenum cullMode = cullingMode[gstate.getCullMode() ^ !useBufferedRendering];
|
2017-04-03 14:19:10 +00:00
|
|
|
|
2015-12-14 01:17:21 +00:00
|
|
|
cullEnable = !gstate.isModeClear() && prim != GE_PRIM_RECTANGLES && prim > GE_PRIM_LINE_STRIP && gstate.isCullEnabled();
|
2020-11-10 22:30:24 +00:00
|
|
|
|
|
|
|
bool depthClampEnable = false;
|
|
|
|
if (gstate.isModeClear() || gstate.isModeThrough()) {
|
|
|
|
// TODO: Might happen in clear mode if not through...
|
|
|
|
depthClampEnable = false;
|
|
|
|
} else {
|
|
|
|
if (gstate.getDepthRangeMin() == 0 || gstate.getDepthRangeMax() == 65535) {
|
|
|
|
// TODO: Still has a bug where we clamp to depth range if one is not the full range.
|
|
|
|
// But the alternate is not clamping in either direction...
|
2022-10-17 06:30:27 +00:00
|
|
|
depthClampEnable = gstate.isDepthClampEnabled() && gstate_c.Use(GPU_USE_DEPTH_CLAMP);
|
2020-11-10 22:30:24 +00:00
|
|
|
} else {
|
|
|
|
// We just want to clip in this case, the clamp would be clipped anyway.
|
|
|
|
depthClampEnable = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderManager->SetRaster(cullEnable, GL_CCW, cullMode, dither, depthClampEnable);
|
2017-01-30 11:02:14 +00:00
|
|
|
}
|
2013-10-30 21:44:01 +00:00
|
|
|
|
2017-01-30 11:02:14 +00:00
|
|
|
if (gstate_c.IsDirty(DIRTY_DEPTHSTENCIL_STATE)) {
|
2023-06-12 09:49:44 +00:00
|
|
|
ConvertStencilFuncState(stencilState_);
|
2021-01-24 23:54:13 +00:00
|
|
|
|
2022-08-17 09:31:02 +00:00
|
|
|
if (gstate.isModeClear()) {
|
2023-05-16 19:49:18 +00:00
|
|
|
renderManager->SetStencil(
|
|
|
|
gstate.isClearModeAlphaMask(), GL_ALWAYS, 0xFF, 0xFF,
|
2023-06-12 09:49:44 +00:00
|
|
|
stencilState_.writeMask, GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
2017-11-18 23:43:58 +00:00
|
|
|
renderManager->SetDepth(true, gstate.isClearModeDepthMask() ? true : false, GL_ALWAYS);
|
2013-10-30 21:44:01 +00:00
|
|
|
} else {
|
2017-01-30 11:02:14 +00:00
|
|
|
// Depth Test
|
2022-11-08 04:40:14 +00:00
|
|
|
bool depthTestUsed = !IsDepthTestEffectivelyDisabled();
|
|
|
|
renderManager->SetDepth(depthTestUsed, gstate.isDepthWriteEnabled(), compareOps[gstate.getDepthTestFunction()]);
|
|
|
|
if (depthTestUsed)
|
2022-11-08 04:07:57 +00:00
|
|
|
UpdateEverUsedEqualDepth(gstate.getDepthTestFunction());
|
2013-10-30 21:44:01 +00:00
|
|
|
|
2017-01-30 11:02:14 +00:00
|
|
|
// Stencil Test
|
2023-06-12 09:49:44 +00:00
|
|
|
if (stencilState_.enabled) {
|
2023-05-16 19:49:18 +00:00
|
|
|
renderManager->SetStencil(
|
2023-06-12 09:49:44 +00:00
|
|
|
stencilState_.enabled, compareOps[stencilState_.testFunc], stencilState_.testRef, stencilState_.testMask,
|
|
|
|
stencilState_.writeMask, stencilOps[stencilState_.sFail], stencilOps[stencilState_.zFail], stencilOps[stencilState_.zPass]);
|
2022-08-27 17:37:28 +00:00
|
|
|
|
2022-08-27 08:05:57 +00:00
|
|
|
// Nasty special case for Spongebob and similar where it tries to write zeros to alpha/stencil during
|
|
|
|
// depth-fail. We can't write to alpha then because the pixel is killed. However, we can invert the depth
|
|
|
|
// test and modify the alpha function...
|
2023-06-12 09:49:44 +00:00
|
|
|
if (SpongebobDepthInverseConditions(stencilState_)) {
|
2022-08-27 12:40:42 +00:00
|
|
|
renderManager->SetBlendAndMask(0x8, true, GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, GL_FUNC_ADD, GL_FUNC_ADD);
|
2022-08-27 08:05:57 +00:00
|
|
|
renderManager->SetDepth(true, false, GL_LESS);
|
2023-05-16 19:49:18 +00:00
|
|
|
renderManager->SetStencil(true, GL_ALWAYS, 0xFF, 0xFF, 0xFF, GL_ZERO, GL_KEEP, GL_ZERO);
|
2022-08-27 08:05:57 +00:00
|
|
|
|
2022-08-28 15:39:05 +00:00
|
|
|
dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE;
|
|
|
|
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE);
|
2022-08-27 08:05:57 +00:00
|
|
|
}
|
2022-08-27 17:37:28 +00:00
|
|
|
} else {
|
2017-11-19 11:25:57 +00:00
|
|
|
renderManager->SetStencilDisabled();
|
|
|
|
}
|
2013-12-06 10:15:13 +00:00
|
|
|
}
|
2013-02-21 20:52:12 +00:00
|
|
|
}
|
2012-12-21 15:49:42 +00:00
|
|
|
|
2017-01-30 11:22:35 +00:00
|
|
|
if (gstate_c.IsDirty(DIRTY_VIEWPORTSCISSOR_STATE)) {
|
2017-01-30 11:02:14 +00:00
|
|
|
ConvertViewportAndScissor(useBufferedRendering,
|
|
|
|
framebufferManager_->GetRenderWidth(), framebufferManager_->GetRenderHeight(),
|
|
|
|
framebufferManager_->GetTargetBufferWidth(), framebufferManager_->GetTargetBufferHeight(),
|
2023-06-12 09:49:44 +00:00
|
|
|
vpAndScissor_);
|
|
|
|
UpdateCachedViewportState(vpAndScissor_);
|
2017-01-30 11:02:14 +00:00
|
|
|
|
2023-06-12 09:49:44 +00:00
|
|
|
renderManager->SetScissor(GLRect2D{ vpAndScissor_.scissorX, vpAndScissor_.scissorY, vpAndScissor_.scissorW, vpAndScissor_.scissorH });
|
2017-11-18 23:43:58 +00:00
|
|
|
renderManager->SetViewport({
|
2023-06-12 09:49:44 +00:00
|
|
|
vpAndScissor_.viewportX, vpAndScissor_.viewportY,
|
|
|
|
vpAndScissor_.viewportW, vpAndScissor_.viewportH,
|
|
|
|
vpAndScissor_.depthRangeMin, vpAndScissor_.depthRangeMax });
|
2016-01-03 20:11:05 +00:00
|
|
|
}
|
2022-08-27 08:05:57 +00:00
|
|
|
|
|
|
|
gstate_c.Clean(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_BLEND_STATE);
|
2022-08-28 15:34:48 +00:00
|
|
|
gstate_c.Dirty(dirtyRequiresRecheck_);
|
|
|
|
dirtyRequiresRecheck_ = 0;
|
2012-12-21 15:49:42 +00:00
|
|
|
}
|
2014-09-11 06:43:48 +00:00
|
|
|
|
2020-05-24 18:27:58 +00:00
|
|
|
void DrawEngineGLES::ApplyDrawStateLate(bool setStencilValue, int stencilValue) {
|
|
|
|
if (setStencilValue) {
|
2023-06-12 09:49:44 +00:00
|
|
|
render_->SetStencil(stencilState_.writeMask, GL_ALWAYS, stencilValue, 255, 0xFF, GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
2023-05-16 19:49:18 +00:00
|
|
|
gstate_c.Dirty(DIRTY_DEPTHSTENCIL_STATE); // For the next time.
|
2017-12-12 14:04:46 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 06:43:48 +00:00
|
|
|
// At this point, we know if the vertices are full alpha or not.
|
|
|
|
// TODO: Set the nearest/linear here (since we correctly know if alpha/color tests are needed)?
|
2022-10-17 06:27:49 +00:00
|
|
|
if (!gstate.isModeClear() && gstate_c.Use(GPU_USE_FRAGMENT_TEST_CACHE)) {
|
2016-09-11 18:03:03 +00:00
|
|
|
// Apply last, once we know the alpha params of the texture.
|
|
|
|
if (gstate.isAlphaTestEnabled() || gstate.isColorTestEnabled()) {
|
2018-04-13 07:11:08 +00:00
|
|
|
fragmentTestCache_->BindTestTexture(TEX_SLOT_ALPHATEST);
|
2016-09-11 18:03:03 +00:00
|
|
|
}
|
2014-09-11 06:43:48 +00:00
|
|
|
}
|
|
|
|
}
|