mirror of
https://github.com/izzy2lost/Super3.git
synced 2026-07-05 15:18:38 -07:00
small gl improvements
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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<const char*>(glGetString(GL_VENDOR)));
|
||||
SDL_Log("GL_RENDERER=%s", reinterpret_cast<const char*>(glGetString(GL_RENDERER)));
|
||||
SDL_Log("GL_VERSION=%s", reinterpret_cast<const char*>(glGetString(GL_VERSION)));
|
||||
SDL_Log("GLSL_VERSION=%s", reinterpret_cast<const char*>(glGetString(GL_SHADING_LANGUAGE_VERSION)));
|
||||
|
||||
GlesPresenter presenter;
|
||||
if (!presenter.Init()) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "GlesPresenter.Init failed");
|
||||
|
||||
Reference in New Issue
Block a user