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
|
|
|
|
|
|
|
|
|
2017-01-21 21:16:30 +00:00
|
|
|
#include "StateMappingGLES.h"
|
2015-05-13 20:28:02 +00:00
|
|
|
#include "profiler/profiler.h"
|
2017-03-03 13:15:27 +00:00
|
|
|
#include "gfx/gl_debug_log.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"
|
2013-04-30 07:04:00 +00:00
|
|
|
#include "Core/Reporting.h"
|
2016-04-10 08:27:28 +00:00
|
|
|
#include "GPU/GLES/GPU_GLES.h"
|
2017-02-04 17:46:12 +00:00
|
|
|
#include "ext/native/gfx/GLStateCache.h"
|
2017-01-21 21:16:30 +00:00
|
|
|
#include "GPU/GLES/ShaderManagerGLES.h"
|
|
|
|
#include "GPU/GLES/TextureCacheGLES.h"
|
|
|
|
#include "GPU/GLES/FramebufferManagerGLES.h"
|
|
|
|
#include "GPU/GLES/FragmentShaderGeneratorGLES.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,
|
2015-11-28 00:01:25 +00:00
|
|
|
#elif !defined(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
|
|
|
inline void DrawEngineGLES::ResetShaderBlending() {
|
2014-06-17 06:47:21 +00:00
|
|
|
if (fboTexBound_) {
|
|
|
|
glActiveTexture(GL_TEXTURE1);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
fboTexBound_ = false;
|
|
|
|
}
|
2014-06-15 20:48:06 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void DrawEngineGLES::ApplyDrawState(int prim) {
|
2017-01-24 08:41:38 +00:00
|
|
|
if (gstate_c.IsDirty(DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS) && !gstate.isModeClear() && gstate.isTextureMapEnabled()) {
|
2014-06-17 06:47:21 +00:00
|
|
|
textureCache_->SetTexture();
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Clean(DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS);
|
2012-12-21 15:49:42 +00:00
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
|
2017-01-30 10:56:14 +00:00
|
|
|
// amask is needed for both stencil and blend state so we keep it outside for now
|
|
|
|
bool amask = (gstate.pmska & 0xFF) < 128;
|
|
|
|
// Let's not write to alpha if stencil isn't enabled.
|
|
|
|
if (!gstate.isStencilTestEnabled()) {
|
|
|
|
amask = false;
|
|
|
|
} else {
|
|
|
|
// If the stencil type is set to KEEP, we shouldn't write to the stencil/alpha channel.
|
|
|
|
if (ReplaceAlphaWithStencilType() == STENCIL_VALUE_KEEP) {
|
|
|
|
amask = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-08 20:47:08 +00:00
|
|
|
bool useBufferedRendering = g_Config.iRenderingMode != FB_NON_BUFFERED_MODE;
|
2015-11-14 07:11:06 +00:00
|
|
|
|
2017-01-30 10:56:14 +00:00
|
|
|
if (gstate_c.IsDirty(DIRTY_BLEND_STATE)) {
|
|
|
|
gstate_c.Clean(DIRTY_BLEND_STATE);
|
2017-04-03 15:04:58 +00:00
|
|
|
gstate_c.SetAllowShaderBlend(!g_Config.bDisableSlowFramebufEffects);
|
2015-11-08 20:47:08 +00:00
|
|
|
|
2017-01-30 10:56:14 +00:00
|
|
|
if (gstate.isModeClear()) {
|
|
|
|
glstate.blend.disable();
|
|
|
|
// Color Test
|
|
|
|
bool colorMask = gstate.isClearModeColorMask();
|
|
|
|
bool alphaMask = gstate.isClearModeAlphaMask();
|
|
|
|
glstate.colorMask.set(colorMask, colorMask, colorMask, alphaMask);
|
2017-01-30 11:02:14 +00:00
|
|
|
#ifndef USING_GLES2
|
|
|
|
if (gstate_c.Supports(GPU_SUPPORTS_LOGIC_OP)) {
|
|
|
|
// Logic Ops
|
|
|
|
glstate.colorLogicOp.disable();
|
|
|
|
}
|
|
|
|
#endif
|
2015-11-08 20:47:08 +00:00
|
|
|
} else {
|
2017-01-30 10:56:14 +00:00
|
|
|
// Do the large chunks of state conversion. We might be able to hide these two behind a dirty-flag each,
|
|
|
|
// to avoid recomputing heavy stuff unnecessarily every draw call.
|
|
|
|
GenericBlendState blendState;
|
|
|
|
ConvertBlendState(blendState, gstate_c.allowShaderBlend);
|
|
|
|
|
|
|
|
if (blendState.applyShaderBlending) {
|
|
|
|
if (ApplyShaderBlending()) {
|
|
|
|
// We may still want to do something about stencil -> alpha.
|
|
|
|
ApplyStencilReplaceAndLogicOp(blendState.replaceAlphaWithStencil, blendState);
|
|
|
|
} else {
|
|
|
|
// Until next time, force it off.
|
|
|
|
ResetShaderBlending();
|
2017-04-03 15:04:58 +00:00
|
|
|
gstate_c.SetAllowShaderBlend(false);
|
2017-01-30 10:56:14 +00:00
|
|
|
}
|
|
|
|
} else if (blendState.resetShaderBlending) {
|
|
|
|
ResetShaderBlending();
|
|
|
|
}
|
2015-11-08 19:09:30 +00:00
|
|
|
|
2017-01-30 10:56:14 +00:00
|
|
|
if (blendState.enabled) {
|
|
|
|
glstate.blend.enable();
|
|
|
|
glstate.blendEquationSeparate.set(glBlendEqLookup[(size_t)blendState.eqColor], glBlendEqLookup[(size_t)blendState.eqAlpha]);
|
|
|
|
glstate.blendFuncSeparate.set(
|
|
|
|
glBlendFactorLookup[(size_t)blendState.srcColor], glBlendFactorLookup[(size_t)blendState.dstColor],
|
|
|
|
glBlendFactorLookup[(size_t)blendState.srcAlpha], glBlendFactorLookup[(size_t)blendState.dstAlpha]);
|
|
|
|
if (blendState.dirtyShaderBlend) {
|
|
|
|
gstate_c.Dirty(DIRTY_SHADERBLEND);
|
|
|
|
}
|
|
|
|
if (blendState.useBlendColor) {
|
|
|
|
uint32_t color = blendState.blendColor;
|
|
|
|
const float col[4] = {
|
|
|
|
(float)((color & 0xFF) >> 0) * (1.0f / 255.0f),
|
|
|
|
(float)((color & 0xFF00) >> 8) * (1.0f / 255.0f),
|
|
|
|
(float)((color & 0xFF0000) >> 16) * (1.0f / 255.0f),
|
|
|
|
(float)((color & 0xFF000000) >> 24) * (1.0f / 255.0f),
|
|
|
|
};
|
|
|
|
glstate.blendColor.set(col);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
glstate.blend.disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
// PSP color/alpha mask is per bit but we can only support per byte.
|
|
|
|
// But let's do that, at least. And let's try a threshold.
|
|
|
|
bool rmask = (gstate.pmskc & 0xFF) < 128;
|
|
|
|
bool gmask = ((gstate.pmskc >> 8) & 0xFF) < 128;
|
|
|
|
bool bmask = ((gstate.pmskc >> 16) & 0xFF) < 128;
|
|
|
|
|
|
|
|
#ifndef MOBILE_DEVICE
|
|
|
|
u8 abits = (gstate.pmska >> 0) & 0xFF;
|
|
|
|
u8 rbits = (gstate.pmskc >> 0) & 0xFF;
|
|
|
|
u8 gbits = (gstate.pmskc >> 8) & 0xFF;
|
|
|
|
u8 bbits = (gstate.pmskc >> 16) & 0xFF;
|
|
|
|
if ((rbits != 0 && rbits != 0xFF) || (gbits != 0 && gbits != 0xFF) || (bbits != 0 && bbits != 0xFF)) {
|
|
|
|
WARN_LOG_REPORT_ONCE(rgbmask, G3D, "Unsupported RGB mask: r=%02x g=%02x b=%02x", rbits, gbits, bbits);
|
|
|
|
}
|
|
|
|
if (abits != 0 && abits != 0xFF) {
|
|
|
|
// The stencil part of the mask is supported.
|
|
|
|
WARN_LOG_REPORT_ONCE(amask, G3D, "Unsupported alpha/stencil mask: %02x", abits);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
glstate.colorMask.set(rmask, gmask, bmask, amask);
|
2017-01-30 11:02:14 +00:00
|
|
|
|
|
|
|
#ifndef USING_GLES2
|
|
|
|
if (gstate_c.Supports(GPU_SUPPORTS_LOGIC_OP)) {
|
|
|
|
// TODO: Make this dynamic
|
|
|
|
// Logic Ops
|
|
|
|
if (gstate.isLogicOpEnabled() && gstate.getLogicOp() != GE_LOGIC_COPY) {
|
|
|
|
glstate.colorLogicOp.enable();
|
|
|
|
glstate.logicOp.set(logicOps[gstate.getLogicOp()]);
|
|
|
|
} else {
|
|
|
|
glstate.colorLogicOp.disable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#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)) {
|
|
|
|
gstate_c.Clean(DIRTY_RASTER_STATE);
|
|
|
|
|
2017-04-03 14:19:10 +00:00
|
|
|
// Dither
|
|
|
|
if (gstate.isDitherEnabled()) {
|
|
|
|
glstate.dither.enable();
|
2017-01-30 10:56:14 +00:00
|
|
|
glstate.dither.set(true);
|
2013-10-30 21:44:01 +00:00
|
|
|
} else {
|
2017-04-03 14:19:10 +00:00
|
|
|
glstate.dither.disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gstate.isModeClear()) {
|
|
|
|
// Culling
|
2013-08-06 14:14:30 +00:00
|
|
|
glstate.cullFace.disable();
|
2017-04-03 14:19:10 +00:00
|
|
|
} else {
|
|
|
|
// Set cull
|
|
|
|
bool cullEnabled = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled();
|
|
|
|
if (cullEnabled) {
|
|
|
|
glstate.cullFace.enable();
|
|
|
|
glstate.cullFaceMode.set(cullingMode[gstate.getCullMode() ^ !useBufferedRendering]);
|
|
|
|
} else {
|
|
|
|
glstate.cullFace.disable();
|
|
|
|
}
|
2013-10-30 21:44:01 +00:00
|
|
|
}
|
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)) {
|
|
|
|
gstate_c.Clean(DIRTY_DEPTHSTENCIL_STATE);
|
2017-01-30 11:02:14 +00:00
|
|
|
bool enableStencilTest = !g_Config.bDisableStencilTest;
|
|
|
|
if (gstate.isModeClear()) {
|
|
|
|
// Depth Test
|
2013-02-23 18:18:18 +00:00
|
|
|
glstate.depthTest.enable();
|
2017-01-30 11:02:14 +00:00
|
|
|
glstate.depthFunc.set(GL_ALWAYS);
|
2017-05-26 08:23:45 +00:00
|
|
|
glstate.depthWrite.set(gstate.isClearModeDepthMask() ? GL_TRUE : GL_FALSE);
|
2017-05-26 14:42:38 +00:00
|
|
|
if (gstate.isClearModeDepthMask()) {
|
2014-04-30 12:00:42 +00:00
|
|
|
framebufferManager_->SetDepthUpdated();
|
|
|
|
}
|
2017-01-30 11:02:14 +00:00
|
|
|
|
|
|
|
// Stencil Test
|
|
|
|
if (gstate.isClearModeAlphaMask() && enableStencilTest) {
|
|
|
|
glstate.stencilTest.enable();
|
|
|
|
glstate.stencilOp.set(GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
|
|
|
// TODO: In clear mode, the stencil value is set to the alpha value of the vertex.
|
|
|
|
// A normal clear will be 2 points, the second point has the color.
|
|
|
|
// We should set "ref" to that value instead of 0.
|
|
|
|
// In case of clear rectangles, we set it again once we know what the color is.
|
|
|
|
glstate.stencilFunc.set(GL_ALWAYS, 255, 0xFF);
|
|
|
|
glstate.stencilMask.set(0xFF);
|
|
|
|
} else {
|
|
|
|
glstate.stencilTest.disable();
|
|
|
|
}
|
2013-10-30 21:44:01 +00:00
|
|
|
} else {
|
2017-01-30 11:02:14 +00:00
|
|
|
// Depth Test
|
|
|
|
if (gstate.isDepthTestEnabled()) {
|
|
|
|
glstate.depthTest.enable();
|
|
|
|
glstate.depthFunc.set(compareOps[gstate.getDepthTestFunction()]);
|
2017-05-26 08:23:45 +00:00
|
|
|
glstate.depthWrite.set(gstate.isDepthWriteEnabled() ? GL_TRUE : GL_FALSE);
|
|
|
|
if (gstate.isDepthWriteEnabled()) {
|
2017-01-30 11:02:14 +00:00
|
|
|
framebufferManager_->SetDepthUpdated();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
glstate.depthTest.disable();
|
|
|
|
}
|
2013-10-30 21:44:01 +00:00
|
|
|
|
2017-01-30 11:02:14 +00:00
|
|
|
GenericStencilFuncState stencilState;
|
|
|
|
ConvertStencilFuncState(stencilState);
|
2015-12-31 09:50:18 +00:00
|
|
|
|
2017-01-30 11:02:14 +00:00
|
|
|
// Stencil Test
|
|
|
|
if (stencilState.enabled) {
|
|
|
|
glstate.stencilTest.enable();
|
|
|
|
glstate.stencilFunc.set(compareOps[stencilState.testFunc], stencilState.testRef, stencilState.testMask);
|
|
|
|
glstate.stencilOp.set(stencilOps[stencilState.sFail], stencilOps[stencilState.zFail], stencilOps[stencilState.zPass]);
|
|
|
|
glstate.stencilMask.set(stencilState.writeMask);
|
|
|
|
} else {
|
|
|
|
glstate.stencilTest.disable();
|
|
|
|
}
|
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)) {
|
|
|
|
gstate_c.Clean(DIRTY_VIEWPORTSCISSOR_STATE);
|
2017-01-30 11:02:14 +00:00
|
|
|
ViewportAndScissor vpAndScissor;
|
|
|
|
ConvertViewportAndScissor(useBufferedRendering,
|
|
|
|
framebufferManager_->GetRenderWidth(), framebufferManager_->GetRenderHeight(),
|
|
|
|
framebufferManager_->GetTargetBufferWidth(), framebufferManager_->GetTargetBufferHeight(),
|
|
|
|
vpAndScissor);
|
|
|
|
|
|
|
|
if (vpAndScissor.scissorEnable) {
|
|
|
|
glstate.scissorTest.enable();
|
|
|
|
if (!useBufferedRendering) {
|
|
|
|
vpAndScissor.scissorY = PSP_CoreParameter().pixelHeight - vpAndScissor.scissorH - vpAndScissor.scissorY;
|
|
|
|
}
|
|
|
|
glstate.scissorRect.set(vpAndScissor.scissorX, vpAndScissor.scissorY, vpAndScissor.scissorW, vpAndScissor.scissorH);
|
|
|
|
} else {
|
|
|
|
glstate.scissorTest.disable();
|
|
|
|
}
|
2017-01-24 08:31:36 +00:00
|
|
|
|
2015-11-08 12:44:21 +00:00
|
|
|
if (!useBufferedRendering) {
|
2017-01-30 11:02:14 +00:00
|
|
|
vpAndScissor.viewportY = PSP_CoreParameter().pixelHeight - vpAndScissor.viewportH - vpAndScissor.viewportY;
|
2015-10-31 22:59:23 +00:00
|
|
|
}
|
2017-01-30 11:02:14 +00:00
|
|
|
glstate.viewport.set(vpAndScissor.viewportX, vpAndScissor.viewportY, vpAndScissor.viewportW, vpAndScissor.viewportH);
|
|
|
|
glstate.depthRange.set(vpAndScissor.depthRangeMin, vpAndScissor.depthRangeMax);
|
2015-04-17 19:52:57 +00:00
|
|
|
|
2017-01-30 11:02:14 +00:00
|
|
|
if (vpAndScissor.dirtyProj) {
|
|
|
|
gstate_c.Dirty(DIRTY_PROJMATRIX);
|
|
|
|
}
|
|
|
|
if (vpAndScissor.dirtyDepth) {
|
|
|
|
gstate_c.Dirty(DIRTY_DEPTHRANGE);
|
|
|
|
}
|
2016-01-03 20:11:05 +00:00
|
|
|
}
|
2017-03-03 13:15:27 +00:00
|
|
|
CHECK_GL_ERROR_IF_DEBUG();
|
2012-12-21 15:49:42 +00:00
|
|
|
}
|
2014-09-11 06:43:48 +00:00
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void DrawEngineGLES::ApplyDrawStateLate() {
|
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)?
|
|
|
|
if (!gstate.isModeClear()) {
|
2015-03-18 05:07:09 +00:00
|
|
|
if (fboTexNeedBind_) {
|
2017-03-03 13:15:27 +00:00
|
|
|
CHECK_GL_ERROR_IF_DEBUG();
|
2015-11-10 07:28:15 +00:00
|
|
|
// Note that this is positions, not UVs, that we need the copy from.
|
2017-02-18 10:10:32 +00:00
|
|
|
framebufferManager_->BindFramebufferAsColorTexture(1, framebufferManager_->GetCurrentRenderVFB(), BINDFBCOLOR_MAY_COPY);
|
2015-09-13 18:14:51 +00:00
|
|
|
framebufferManager_->RebindFramebuffer();
|
2017-03-03 13:15:27 +00:00
|
|
|
CHECK_GL_ERROR_IF_DEBUG();
|
2015-09-13 18:14:51 +00:00
|
|
|
|
2015-03-18 05:07:09 +00:00
|
|
|
glActiveTexture(GL_TEXTURE1);
|
|
|
|
// If we are rendering at a higher resolution, linear is probably best for the dest color.
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
fboTexBound_ = true;
|
|
|
|
fboTexNeedBind_ = false;
|
2017-03-03 13:15:27 +00:00
|
|
|
CHECK_GL_ERROR_IF_DEBUG();
|
2015-03-18 05:07:09 +00:00
|
|
|
}
|
2017-03-03 13:15:27 +00:00
|
|
|
CHECK_GL_ERROR_IF_DEBUG();
|
2015-11-15 21:12:29 +00:00
|
|
|
|
|
|
|
// Apply the texture after the FBO tex, since it might unbind the texture.
|
|
|
|
// TODO: Could use a separate texture unit to be safer?
|
|
|
|
textureCache_->ApplyTexture();
|
2017-03-03 13:15:27 +00:00
|
|
|
CHECK_GL_ERROR_IF_DEBUG();
|
2016-09-11 18:03:03 +00:00
|
|
|
|
|
|
|
// Apply last, once we know the alpha params of the texture.
|
|
|
|
if (gstate.isAlphaTestEnabled() || gstate.isColorTestEnabled()) {
|
|
|
|
fragmentTestCache_->BindTestTexture(GL_TEXTURE2);
|
|
|
|
}
|
2017-03-03 13:15:27 +00:00
|
|
|
CHECK_GL_ERROR_IF_DEBUG();
|
2014-09-11 06:43:48 +00:00
|
|
|
}
|
|
|
|
}
|