diff --git a/Src/Graphics/New3D/New3D.cpp b/Src/Graphics/New3D/New3D.cpp index 1757c2e..f6d8801 100644 --- a/Src/Graphics/New3D/New3D.cpp +++ b/Src/Graphics/New3D/New3D.cpp @@ -10,8 +10,13 @@ #include "R3DFloat.h" #include "Util/BitCast.h" +#ifdef __ANDROID__ +#define MAX_RAM_VERTS 150000 +#define MAX_ROM_VERTS 500000 +#else #define MAX_RAM_VERTS 300000 #define MAX_ROM_VERTS 1500000 +#endif #define BYTE_TO_FLOAT(B) ((2.0f * (B) + 1.0f) * (float)(1.0/255.0)) diff --git a/Src/Graphics/New3D/R3DShaderTriangles.h b/Src/Graphics/New3D/R3DShaderTriangles.h index 3f61497..25e0bf6 100644 --- a/Src/Graphics/New3D/R3DShaderTriangles.h +++ b/Src/Graphics/New3D/R3DShaderTriangles.h @@ -7,12 +7,13 @@ static const char *vertexShaderR3D = R"glsl( #version 300 es precision highp float; +precision highp int; // uniforms uniform float modelScale; uniform mat4 modelMat; uniform mat4 projMat; -uniform bool translatorMap; +uniform int translatorMap; // attributes layout(location=0) in vec4 inVertex; @@ -30,7 +31,7 @@ out vec3 vDummy; // keeps attributes alive void main() { vec4 c = inColour; - if (translatorMap) c.rgb *= 16.0; + if (translatorMap != 0) c.rgb *= 16.0; vColor = c; vTexCoord = inTexCoord; vAlpha = c.a; @@ -43,6 +44,7 @@ static const char *fragmentShaderR3D = R"glsl( #version 300 es precision mediump float; +precision mediump int; in vec2 vTexCoord; in vec4 vColor; @@ -50,10 +52,10 @@ in float vAlpha; in vec3 vDummy; uniform sampler2D tex1; -uniform bool textureEnabled; -uniform bool textureAlpha; -uniform bool alphaTest; -uniform bool discardAlpha; +uniform int textureEnabled; +uniform int textureAlpha; +uniform int alphaTest; +uniform int discardAlpha; out vec4 oColor; @@ -61,9 +63,9 @@ void main() { vec4 col = vColor; - if (textureEnabled) { + if (textureEnabled != 0) { vec4 t = texture(tex1, vTexCoord); - if (textureAlpha) { + if (textureAlpha != 0) { col *= t; } else { col.rgb *= t.rgb; @@ -73,8 +75,8 @@ void main() // keep vDummy "used" col.rgb += vDummy * 0.0; - if (alphaTest && col.a < 0.5) discard; - if (discardAlpha && col.a < 0.99) discard; + if (alphaTest != 0 && col.a < 0.5) discard; + if (discardAlpha != 0 && col.a < 0.99) discard; oColor = col; } diff --git a/Src/Graphics/New3D/Texture.cpp b/Src/Graphics/New3D/Texture.cpp index 8a9cbaa..89dba24 100644 --- a/Src/Graphics/New3D/Texture.cpp +++ b/Src/Graphics/New3D/Texture.cpp @@ -271,7 +271,7 @@ void Texture::UploadTextureMip(int level, const UINT16* src, UINT8* scratch, int break; } - glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); + glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, subWidth, subHeight, GL_RGBA, GL_UNSIGNED_BYTE, scratch); } diff --git a/android/app/src/main/cpp/gles_presenter.cpp b/android/app/src/main/cpp/gles_presenter.cpp index 284e706..2f48319 100644 --- a/android/app/src/main/cpp/gles_presenter.cpp +++ b/android/app/src/main/cpp/gles_presenter.cpp @@ -140,7 +140,7 @@ void GlesPresenter::UpdateFrameARGB(const uint32_t* pixelsARGB, int width, int h m_srcW = width; m_srcH = height; glBindTexture(GL_TEXTURE_2D, m_tex); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_srcW, m_srcH, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_srcW, m_srcH, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glBindTexture(GL_TEXTURE_2D, 0); UpdateQuadVerts(); } diff --git a/android/app/src/main/cpp/native-lib.cpp b/android/app/src/main/cpp/native-lib.cpp index 1533e19..2142d12 100644 --- a/android/app/src/main/cpp/native-lib.cpp +++ b/android/app/src/main/cpp/native-lib.cpp @@ -639,25 +639,51 @@ extern "C" int SDL_main(int argc, char* argv[]) { SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); - SDL_Window* window = SDL_CreateWindow( - "Super3 (SDL bootstrap)", - SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, - 1280, - 720, - SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL - ); + struct GlConfig { + int depth; + int stencil; + }; + const GlConfig configs[] = { + {24, 8}, + {24, 0}, + {16, 8}, + {16, 0}, + }; - if (!window) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_CreateWindow failed: %s", SDL_GetError()); - SDL_Quit(); - return 1; + SDL_Window* window = nullptr; + SDL_GLContext gl = nullptr; + for (const auto& cfg : configs) { + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, cfg.depth); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, cfg.stencil); + + window = SDL_CreateWindow( + "Super3 (SDL bootstrap)", + SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, + 1280, + 720, + SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL + ); + + if (!window) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_CreateWindow failed: %s", SDL_GetError()); + SDL_Quit(); + return 1; + } + + gl = SDL_GL_CreateContext(window); + if (gl) { + SDL_Log("SDL GL context created (depth=%d, stencil=%d)", cfg.depth, cfg.stencil); + break; + } + + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext failed (depth=%d stencil=%d): %s", + cfg.depth, cfg.stencil, SDL_GetError()); + SDL_DestroyWindow(window); + window = nullptr; } - SDL_GLContext gl = SDL_GL_CreateContext(window); if (!gl) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext failed: %s", SDL_GetError()); - SDL_DestroyWindow(window); SDL_Quit(); return 1; } @@ -665,6 +691,11 @@ extern "C" int SDL_main(int argc, char* argv[]) { SDL_GL_MakeCurrent(window, gl); SDL_GL_SetSwapInterval(1); + SDL_Log("GL_VENDOR=%s", reinterpret_cast(glGetString(GL_VENDOR))); + SDL_Log("GL_RENDERER=%s", reinterpret_cast(glGetString(GL_RENDERER))); + SDL_Log("GL_VERSION=%s", reinterpret_cast(glGetString(GL_VERSION))); + SDL_Log("GLSL_VERSION=%s", reinterpret_cast(glGetString(GL_SHADING_LANGUAGE_VERSION))); + GlesPresenter presenter; if (!presenter.Init()) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "GlesPresenter.Init failed");