mirror of
https://github.com/izzy2lost/Super3.git
synced 2026-07-05 15:18:38 -07:00
@@ -407,42 +407,6 @@ void CNew3D::RenderFrame(void)
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef __ANDROID__
|
||||
struct ScopedAndroidGlState
|
||||
{
|
||||
GLboolean scissorEnabled = GL_FALSE;
|
||||
GLint scissorBox[4] = {0, 0, 0, 0};
|
||||
GLfloat clearColor[4] = {0.f, 0.f, 0.f, 0.f};
|
||||
|
||||
ScopedAndroidGlState()
|
||||
{
|
||||
scissorEnabled = glIsEnabled(GL_SCISSOR_TEST);
|
||||
glGetIntegerv(GL_SCISSOR_BOX, scissorBox);
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE, clearColor);
|
||||
}
|
||||
|
||||
void DisableScissor() const { glDisable(GL_SCISSOR_TEST); }
|
||||
|
||||
void RestoreScissor() const
|
||||
{
|
||||
if (scissorEnabled) {
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(scissorBox[0], scissorBox[1], scissorBox[2], scissorBox[3]);
|
||||
} else {
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
void SetTransparentClear() const { glClearColor(0.f, 0.f, 0.f, 0.f); }
|
||||
|
||||
~ScopedAndroidGlState()
|
||||
{
|
||||
glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
|
||||
RestoreScissor();
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
m_nfPairs[i].zNear = -std::numeric_limits<float>::max();
|
||||
m_nfPairs[i].zFar = std::numeric_limits<float>::max();
|
||||
@@ -489,28 +453,7 @@ void CNew3D::RenderFrame(void)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
ScopedAndroidGlState glState;
|
||||
// Use transparent clears for FBO bookkeeping (alpha==0 means "no pixel written").
|
||||
glState.SetTransparentClear();
|
||||
glState.DisableScissor(); // scissor from outer SDL code would break FBO clears and cause flickering edges
|
||||
#endif
|
||||
|
||||
if (!m_r3dFrameBuffers) return;
|
||||
|
||||
#ifdef __ANDROID__
|
||||
// The desktop New3D path assumes the default framebuffer starts cleared each frame.
|
||||
// Without this, any pixels discarded during compositing (alpha==0 areas) can reveal stale
|
||||
// contents which show up as thin lines/flicker (notably during FMVs).
|
||||
m_r3dFrameBuffers->SetFBO(Layer::none);
|
||||
glViewport(0, 0, (GLsizei)m_totalXRes, (GLsizei)m_totalYRes);
|
||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
// Restore transparent clear for offscreen layers.
|
||||
glState.SetTransparentClear();
|
||||
#endif
|
||||
|
||||
glViewport(0, 0, (GLsizei)m_totalXRes, (GLsizei)m_totalYRes);
|
||||
m_r3dFrameBuffers->SetFBO(Layer::trans12);
|
||||
glClear(GL_COLOR_BUFFER_BIT); // wipe both trans layers
|
||||
|
||||
@@ -522,7 +465,6 @@ void CNew3D::RenderFrame(void)
|
||||
|
||||
bool renderOverlay = (i == 1);
|
||||
|
||||
glViewport(0, 0, (GLsizei)m_totalXRes, (GLsizei)m_totalYRes);
|
||||
m_r3dFrameBuffers->SetFBO(Layer::colour);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
@@ -537,12 +479,7 @@ void CNew3D::RenderFrame(void)
|
||||
|
||||
DisableRenderStates();
|
||||
|
||||
#ifdef __ANDROID__
|
||||
// DrawOverTransLayers writes to the offscreen trans buffers.
|
||||
glState.DisableScissor();
|
||||
#endif
|
||||
m_r3dFrameBuffers->DrawOverTransLayers(); // mask trans layer with opaque pixels
|
||||
|
||||
m_r3dFrameBuffers->CompositeBaseLayer(); // copy opaque pixels to back buffer
|
||||
|
||||
SetRenderStates();
|
||||
|
||||
@@ -226,7 +226,7 @@ void R3DFrameBuffers::AllocShaderBase()
|
||||
const char *fragmentShader = R"glsl(
|
||||
|
||||
#version 300 es
|
||||
precision highp float;
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D tex1;
|
||||
in vec2 fsTexCoord;
|
||||
@@ -234,12 +234,7 @@ void R3DFrameBuffers::AllocShaderBase()
|
||||
|
||||
void main()
|
||||
{
|
||||
// Clamp to half-texel to avoid sampling outside the FBO due to precision/edge interpolation,
|
||||
// which can show up as thin lines/flicker on some GLES drivers (e.g., FMVs).
|
||||
vec2 texSize = vec2(textureSize(tex1, 0));
|
||||
vec2 halfTexel = 0.5 / max(texSize, vec2(1.0));
|
||||
vec2 uv = clamp(fsTexCoord, halfTexel, vec2(1.0) - halfTexel);
|
||||
vec4 colBase = texture(tex1, uv);
|
||||
vec4 colBase = texture(tex1, fsTexCoord);
|
||||
if(colBase.a < 1.0) discard;
|
||||
oColor = colBase;
|
||||
}
|
||||
@@ -313,7 +308,7 @@ void R3DFrameBuffers::AllocShaderTrans()
|
||||
const char *fragmentShader = R"glsl(
|
||||
|
||||
#version 300 es
|
||||
precision highp float;
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D tex1;
|
||||
uniform sampler2D tex2;
|
||||
@@ -323,11 +318,8 @@ void R3DFrameBuffers::AllocShaderTrans()
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texSize = vec2(textureSize(tex1, 0));
|
||||
vec2 halfTexel = 0.5 / max(texSize, vec2(1.0));
|
||||
vec2 uv = clamp(fsTexCoord, halfTexel, vec2(1.0) - halfTexel);
|
||||
vec4 colTrans1 = texture(tex1, uv);
|
||||
vec4 colTrans2 = texture(tex2, uv);
|
||||
vec4 colTrans1 = texture(tex1, fsTexCoord);
|
||||
vec4 colTrans2 = texture(tex2, fsTexCoord);
|
||||
|
||||
if(colTrans1.a + colTrans2.a > 0.0) {
|
||||
vec3 col1 = colTrans1.rgb * colTrans1.a;
|
||||
@@ -420,7 +412,7 @@ void R3DFrameBuffers::AllocShaderWipe()
|
||||
const char *fragmentShader = R"glsl(
|
||||
|
||||
#version 300 es
|
||||
precision highp float;
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texColor;
|
||||
in vec2 fsTexCoord;
|
||||
@@ -430,10 +422,7 @@ void R3DFrameBuffers::AllocShaderWipe()
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texSize = vec2(textureSize(texColor, 0));
|
||||
vec2 halfTexel = 0.5 / max(texSize, vec2(1.0));
|
||||
vec2 uv = clamp(fsTexCoord, halfTexel, vec2(1.0) - halfTexel);
|
||||
vec4 colBase = texture(texColor, uv);
|
||||
vec4 colBase = texture(texColor, fsTexCoord);
|
||||
if(colBase.a == 0.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ void main()
|
||||
static const char *fragmentShaderR3D = R"glsl(
|
||||
|
||||
#version 300 es
|
||||
precision highp float;
|
||||
precision mediump float;
|
||||
|
||||
in vec2 vTexCoord;
|
||||
in vec4 vColor;
|
||||
@@ -54,73 +54,27 @@ uniform bool textureEnabled;
|
||||
uniform bool textureAlpha;
|
||||
uniform bool alphaTest;
|
||||
uniform bool discardAlpha;
|
||||
uniform vec2 baseTexSize;
|
||||
uniform ivec2 textureWrapMode;
|
||||
|
||||
out vec4 oColor;
|
||||
|
||||
float WrapCoord1D(float u, int wrapMode, float halfTexel)
|
||||
{
|
||||
// Matches desktop shader wrap modes:
|
||||
// 0 = repeat, 1 = repeat+clamp, 2/3 = mirror/mirror+clamp.
|
||||
if (wrapMode == 0) {
|
||||
return fract(u);
|
||||
}
|
||||
if (wrapMode == 1) {
|
||||
u = fract(u);
|
||||
return clamp(u, halfTexel, 1.0 - halfTexel);
|
||||
}
|
||||
|
||||
float m = mod(u, 2.0);
|
||||
u = (m < 1.0) ? m : (2.0 - m);
|
||||
return clamp(u, halfTexel, 1.0 - halfTexel);
|
||||
}
|
||||
|
||||
vec2 WrapTexCoord(vec2 uv)
|
||||
{
|
||||
vec2 texSize = max(baseTexSize, vec2(1.0));
|
||||
vec2 halfTexel = 0.5 / texSize;
|
||||
uv.x = WrapCoord1D(uv.x, textureWrapMode.x, halfTexel.x);
|
||||
uv.y = WrapCoord1D(uv.y, textureWrapMode.y, halfTexel.y);
|
||||
return uv;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 col = vColor;
|
||||
vec4 t = vec4(1.0);
|
||||
|
||||
if (textureEnabled) {
|
||||
vec2 uv = WrapTexCoord(vTexCoord);
|
||||
t = texture(tex1, uv);
|
||||
vec4 t = texture(tex1, vTexCoord);
|
||||
if (textureAlpha) {
|
||||
col *= t;
|
||||
} else {
|
||||
col.rgb *= t.rgb;
|
||||
}
|
||||
}
|
||||
|
||||
// keep vDummy "used"
|
||||
col.rgb += vDummy * 0.0;
|
||||
|
||||
// Match Supermodel's per-pixel alpha rules as closely as possible:
|
||||
// - alphaTest is based on texture alpha
|
||||
// - discardAlpha separates opaque vs translucent passes based on texture alpha (and vertex alpha in 2nd pass)
|
||||
if (alphaTest && t.a < (32.0/255.0)) discard;
|
||||
if (textureAlpha) {
|
||||
if (discardAlpha) {
|
||||
if (t.a < 1.0) discard;
|
||||
} else {
|
||||
if ((t.a * col.a) >= 1.0) discard;
|
||||
}
|
||||
}
|
||||
|
||||
if (textureEnabled) {
|
||||
col.rgb *= t.rgb;
|
||||
if (textureAlpha) {
|
||||
col.a *= t.a;
|
||||
}
|
||||
}
|
||||
|
||||
if (discardAlpha) {
|
||||
// Opaque pass: force alpha to 1.0 so FBO compositing can treat "written"
|
||||
// pixels as fully opaque (avoids black speckles/lines from alpha < 1).
|
||||
col.a = 1.0;
|
||||
}
|
||||
if (alphaTest && col.a < 0.5) discard;
|
||||
if (discardAlpha && col.a < 0.99) discard;
|
||||
|
||||
oColor = col;
|
||||
}
|
||||
|
||||
@@ -90,20 +90,6 @@ if(TO_REMOVE)
|
||||
list(REMOVE_ITEM SUPER3_SOURCES ${TO_REMOVE})
|
||||
endif()
|
||||
|
||||
# --- New3D (Real3D renderer) ---
|
||||
# Desktop builds compile additional OpenGL2.1/GLEW renderers under Src/Graphics,
|
||||
# but Android uses GLES3 with a custom presenter, so we only include New3D.
|
||||
file(GLOB NEW3D_SOURCES "${REPO_ROOT}/Src/Graphics/New3D/*.cpp")
|
||||
|
||||
# Normalize paths to forward slashes so downstream tooling behaves consistently.
|
||||
set(NEW3D_SOURCES_NORM "")
|
||||
foreach(src ${NEW3D_SOURCES})
|
||||
string(REPLACE "\\" "/" src_norm "${src}")
|
||||
list(APPEND NEW3D_SOURCES_NORM "${src_norm}")
|
||||
endforeach()
|
||||
set(NEW3D_SOURCES "${NEW3D_SOURCES_NORM}")
|
||||
list(SORT NEW3D_SOURCES)
|
||||
|
||||
# --- SDL2 (for future Android OSD wiring) ---
|
||||
# Prefer a local checkout if provided via -DSDL2_LOCAL_DIR, otherwise fetch the
|
||||
# latest release tarball.
|
||||
@@ -129,7 +115,19 @@ add_library(super3 SHARED
|
||||
gles_presenter.cpp
|
||||
gles_stub_render3d.cpp
|
||||
render2d_android.cpp
|
||||
${NEW3D_SOURCES}
|
||||
"${REPO_ROOT}/Src/Graphics/New3D/Mat4.cpp"
|
||||
"${REPO_ROOT}/Src/Graphics/New3D/GLSLShader.cpp"
|
||||
"${REPO_ROOT}/Src/Graphics/New3D/Model.cpp"
|
||||
"${REPO_ROOT}/Src/Graphics/New3D/New3D.cpp"
|
||||
"${REPO_ROOT}/Src/Graphics/New3D/PolyHeader.cpp"
|
||||
"${REPO_ROOT}/Src/Graphics/New3D/R3DFloat.cpp"
|
||||
"${REPO_ROOT}/Src/Graphics/New3D/R3DFrameBuffers.cpp"
|
||||
"${REPO_ROOT}/Src/Graphics/New3D/R3DShader.cpp"
|
||||
"${REPO_ROOT}/Src/Graphics/New3D/R3DScrollFog.cpp"
|
||||
"${REPO_ROOT}/Src/Graphics/New3D/Texture.cpp"
|
||||
"${REPO_ROOT}/Src/Graphics/New3D/TextureSheet.cpp"
|
||||
"${REPO_ROOT}/Src/Graphics/New3D/VBO.cpp"
|
||||
"${REPO_ROOT}/Src/Graphics/New3D/Vec.cpp"
|
||||
${SUPER3_SOURCES}
|
||||
${M68K_GENERATED_SOURCES}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user