Revert to using GL compatibility contexts (and GLES2)

This commit is contained in:
Struma 2020-11-16 21:56:19 -05:00 committed by zzoro
parent a9d7e0783a
commit 94c031b095
22 changed files with 192 additions and 201 deletions

View file

@ -8,27 +8,26 @@ uniform vec4 subRect;
uniform lowp float opacity;
in vec2 v_texCoord;
varying vec2 v_texCoord;
out vec4 fragColor;
void main()
{
vec2 coor = v_texCoord;
vec2 dstCoor = (coor - subRect.xy) * subRect.zw;
void main() {
vec2 coor = v_texCoord;
vec2 dstCoor = (coor - subRect.xy) * subRect.zw;
vec4 srcFrag = texture2D(source, coor);
vec4 dstFrag = texture2D(destination, dstCoor);
vec4 srcFrag = texture(source, coor);
vec4 dstFrag = texture(destination, dstCoor);
vec4 resFrag;
vec4 resFrag;
float co1 = srcFrag.a * opacity;
float co2 = dstFrag.a * (1.0 - co1);
resFrag.a = co1 + co2;
float co1 = srcFrag.a * opacity;
float co2 = dstFrag.a * (1.0 - co1);
resFrag.a = co1 + co2;
if (resFrag.a == 0.0)
resFrag.rgb = srcFrag.rgb;
else
resFrag.rgb = (co1*srcFrag.rgb + co2*dstFrag.rgb) / resFrag.a;
if (resFrag.a == 0.0)
resFrag.rgb = srcFrag.rgb;
else
resFrag.rgb = (co1 * srcFrag.rgb + co2 * dstFrag.rgb) / resFrag.a;
fragColor = resFrag;
gl_FragColor = resFrag;
}

View file

@ -1,17 +1,16 @@
uniform sampler2D v_texture;
uniform sampler2D texture;
in vec2 v_texCoord;
in vec2 v_blurCoord[2];
varying vec2 v_texCoord;
varying vec2 v_blurCoord[2];
out vec4 fragColor;
void main()
{
lowp vec4 frag = vec4(0, 0, 0, 0);
void main() {
lowp vec4 frag = vec4(0, 0, 0, 0);
frag += texture2D(texture, v_texCoord);
frag += texture2D(texture, v_blurCoord[0]);
frag += texture2D(texture, v_blurCoord[1]);
frag += texture(v_texture, v_texCoord);
frag += texture(v_texture, v_blurCoord[0]);
frag += texture(v_texture, v_blurCoord[1]);
fragColor = frag / 3.0;
gl_FragColor = frag / 3.0;
}

View file

@ -1,8 +1,15 @@
#version 330
#define attribute in
#define varying out
#ifdef GLSLES
#ifdef FRAGMENT_SHADER
/* Only the fragment shader has no default float precision */
precision mediump float;
#endif
#else
/* Desktop GLSL doesn't know about these */
#define highp
#define mediump
#define lowp
#endif

View file

@ -1,7 +1,9 @@
uniform lowp float alpha;
in lowp vec4 v_color;
varying lowp vec4 v_color;
out vec4 fragColor;
void main() { fragColor = vec4(v_color.rgb * alpha, 1); }
void main()
{
gl_FragColor = vec4(v_color.rgb * alpha, 1);
}

View file

@ -1,4 +1,7 @@
uniform lowp vec4 color;
out vec4 fragColor;
void main() { fragColor = color; }
void main()
{
gl_FragColor = color;
}

View file

@ -1,19 +1,19 @@
uniform sampler2D v_texture;
uniform sampler2D texture;
uniform lowp float gray;
in vec2 v_texCoord;
varying vec2 v_texCoord;
const vec3 lumaF = vec3(.299, .587, .114);
out vec4 fragColor;
void main() {
/* Sample source color */
vec4 frag = texture(v_texture, v_texCoord);
void main()
{
/* Sample source color */
vec4 frag = texture2D(texture, v_texCoord);
/* Apply gray */
float luma = dot(frag.rgb, lumaF);
frag.rgb = mix(frag.rgb, vec3(luma), gray);
/* Apply gray */
float luma = dot(frag.rgb, lumaF);
frag.rgb = mix(frag.rgb, vec3(luma), gray);
fragColor = frag;
gl_FragColor = frag;
}

View file

@ -1,39 +1,40 @@
uniform sampler2D v_texture;
uniform sampler2D texture;
uniform mediump float hueAdjust;
in vec2 v_texCoord;
out vec4 fragColor;
varying vec2 v_texCoord;
/* Source: gamedev.stackexchange.com/a/59808/24839 */
vec3 rgb2hsv(vec3 c) {
const vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
vec3 rgb2hsv(vec3 c)
{
const vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float d = q.x - min(q.w, q.y);
/* Avoid divide-by-zero situations by adding a very tiny delta.
* Since we always deal with underlying 8-Bit color values, this
* should never mask a real value */
const float eps = 1.0e-10;
/* Avoid divide-by-zero situations by adding a very tiny delta.
* Since we always deal with underlying 8-Bit color values, this
* should never mask a real value */
const float eps = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + eps)), d / (q.x + eps), q.x);
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + eps)), d / (q.x + eps), q.x);
}
vec3 hsv2rgb(vec3 c) {
const vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
vec3 hsv2rgb(vec3 c)
{
const vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void main() {
vec4 color = texture(v_texture, v_texCoord.xy);
vec3 hsv = rgb2hsv(color.rgb);
void main ()
{
vec4 color = texture2D (texture, v_texCoord.xy);
vec3 hsv = rgb2hsv(color.rgb);
hsv.x += hueAdjust;
color.rgb = hsv2rgb(hsv);
hsv.x += hueAdjust;
color.rgb = hsv2rgb(hsv);
fragColor = color;
gl_FragColor = color;
}

View file

@ -2,4 +2,7 @@
uniform mat4 projMat;
attribute vec2 position;
void main() { gl_Position = projMat * vec4(position, 0, 1); }
void main()
{
gl_Position = projMat * vec4(position, 0, 1);
}

View file

@ -1,5 +1,5 @@
uniform sampler2D v_texture;
uniform sampler2D texture;
uniform lowp vec4 tone;
@ -7,31 +7,30 @@ uniform lowp float opacity;
uniform lowp vec4 color;
uniform lowp vec4 flash;
in vec2 v_texCoord;
varying vec2 v_texCoord;
const vec3 lumaF = vec3(.299, .587, .114);
out vec4 fragColor;
void main()
{
/* Sample source color */
vec4 frag = texture2D(texture, v_texCoord);
/* Apply gray */
float luma = dot(frag.rgb, lumaF);
frag.rgb = mix(frag.rgb, vec3(luma), tone.w);
/* Apply tone */
frag.rgb += tone.rgb;
void main() {
/* Sample source color */
vec4 frag = texture(v_texture, v_texCoord);
/* Apply opacity */
frag.a *= opacity;
/* Apply color */
frag.rgb = mix(frag.rgb, color.rgb, color.a);
/* Apply gray */
float luma = dot(frag.rgb, lumaF);
frag.rgb = mix(frag.rgb, vec3(luma), tone.w);
/* Apply tone */
frag.rgb += tone.rgb;
/* Apply opacity */
frag.a *= opacity;
/* Apply color */
frag.rgb = mix(frag.rgb, color.rgb, color.a);
/* Apply flash */
frag.rgb = mix(frag.rgb, flash.rgb, flash.a);
fragColor = frag;
/* Apply flash */
frag.rgb = mix(frag.rgb, flash.rgb, flash.a);
gl_FragColor = frag;
}

View file

@ -1,7 +1,9 @@
uniform sampler2D v_texture;
uniform sampler2D texture;
in vec2 v_texCoord;
varying vec2 v_texCoord;
out vec4 fragColor;
void main() { fragColor = texture(v_texture, v_texCoord); }
void main()
{
gl_FragColor = texture2D(texture, v_texCoord);
}

View file

@ -1,11 +1,11 @@
uniform sampler2D v_texture;
uniform sampler2D texture;
in vec2 v_texCoord;
in lowp vec4 v_color;
varying vec2 v_texCoord;
varying lowp vec4 v_color;
out vec4 fragColor;
void main() {
fragColor = texture(v_texture, v_texCoord);
fragColor.a *= v_color.a;
void main()
{
gl_FragColor = texture2D(texture, v_texCoord);
gl_FragColor.a *= v_color.a;
}

View file

@ -1,11 +1,11 @@
uniform sampler2D v_texture;
uniform sampler2D texture;
uniform lowp float alpha;
in vec2 v_texCoord;
out vec4 fragColor;
varying vec2 v_texCoord;
void main() {
fragColor = texture(v_texture, v_texCoord);
fragColor.a *= alpha;
void main()
{
gl_FragColor = texture2D(texture, v_texCoord);
gl_FragColor.a *= alpha;
}

View file

@ -1,4 +1,7 @@
in lowp vec4 v_color;
out vec4 fragColor;
void main() { fragColor = v_color; }
varying lowp vec4 v_color;
void main()
{
gl_FragColor = v_color;
}

View file

@ -1,5 +1,5 @@
uniform sampler2D v_texture;
uniform sampler2D texture;
uniform lowp vec4 tone;
@ -9,32 +9,31 @@ uniform lowp vec4 color;
uniform float bushDepth;
uniform lowp float bushOpacity;
in vec2 v_texCoord;
varying vec2 v_texCoord;
const vec3 lumaF = vec3(.299, .587, .114);
out vec4 fragColor;
void main()
{
/* Sample source color */
vec4 frag = texture2D(texture, v_texCoord);
/* Apply gray */
float luma = dot(frag.rgb, lumaF);
frag.rgb = mix(frag.rgb, vec3(luma), tone.w);
/* Apply tone */
frag.rgb += tone.rgb;
void main() {
/* Sample source color */
vec4 frag = texture(v_texture, v_texCoord);
/* Apply opacity */
frag.a *= opacity;
/* Apply color */
frag.rgb = mix(frag.rgb, color.rgb, color.a);
/* Apply gray */
float luma = dot(frag.rgb, lumaF);
frag.rgb = mix(frag.rgb, vec3(luma), tone.w);
/* Apply tone */
frag.rgb += tone.rgb;
/* Apply opacity */
frag.a *= opacity;
/* Apply color */
frag.rgb = mix(frag.rgb, color.rgb, color.a);
/* Apply bush alpha by mathematical if */
lowp float underBush = float(v_texCoord.y < bushDepth);
frag.a *= clamp(bushOpacity + underBush, 0.0, 1.0);
fragColor = frag;
/* Apply bush alpha by mathematical if */
lowp float underBush = float(v_texCoord.y < bushDepth);
frag.a *= clamp(bushOpacity + underBush, 0.0, 1.0);
gl_FragColor = frag;
}

View file

@ -1,20 +1,17 @@
uniform sampler2D v_texture;
uniform sampler2D texture;
uniform lowp vec4 tone;
uniform lowp float opacity;
uniform lowp vec4 color;
in vec2 v_texCoord;
varying vec2 v_texCoord;
const vec3 lumaF = vec3(.299, .587, .114);
out vec4 fragColor;
void main() {
/* Sample source color */
vec4 frag = texture(v_texture, v_texCoord);
vec4 frag = texture2D(texture, v_texCoord);
/* Apply gray */
float luma = dot(frag.rgb, lumaF);
@ -29,5 +26,5 @@ void main() {
/* Apply color */
frag.rgb = mix(frag.rgb, color.rgb, color.a);
fragColor = frag;
}
gl_FragColor = frag;
}

View file

@ -1,4 +1,3 @@
uniform mat4 projMat;
uniform vec2 texSizeInv;
@ -17,7 +16,7 @@ const float tileH = 32.0;
const float autotileW = 3.0*tileW;
const float autotileH = 4.0*tileW;
const float atAreaW = autotileW;
const float atAreaH = autotileH*nAutotiles;
const float atAreaH = autotileH*float(nAutotiles);
const float atAniOffsetX = 3.0*tileW;
const float atAniOffsetY = tileH;
@ -25,17 +24,17 @@ uniform lowp int atFrames[nAutotiles];
void main()
{
vec2 tex = texCoord;
lowp uint atIndex = uint(tex.y / autotileH);
vec2 tex = texCoord;
lowp int atIndex = int(tex.y / autotileH);
lowp uint pred = uint(tex.x <= atAreaW && tex.y <= atAreaH);
lowp uint frame = uint(aniIndex % atFrames[atIndex]);
lowp uint col = frame % 8u;
lowp uint row = frame / 8u;
tex.x += atAniOffsetX * (col * pred);
tex.y += atAniOffsetY * (row * pred);
lowp int pred = int(tex.x <= atAreaW && tex.y <= atAreaH);
lowp int frame = int(aniIndex - atFrames[atIndex] * (aniIndex / atFrames[atIndex]));
lowp int row = frame / 8;
lowp int col = frame - 8 * row;
tex.x += atAniOffsetX * float(col * pred);
tex.y += atAniOffsetY * float(row * pred);
gl_Position = projMat * vec4(position + translation, 0, 1);
gl_Position = projMat * vec4(position + translation, 0, 1);
v_texCoord = tex * texSizeInv;
v_texCoord = tex * texSizeInv;
}

View file

@ -8,17 +8,16 @@ uniform float prog;
/* Vague [0, 512] normalized */
uniform float vague;
in vec2 v_texCoord;
varying vec2 v_texCoord;
out vec4 fragColor;
void main() {
float transV = texture(transMap, v_texCoord).r;
float cTransV = clamp(transV, prog, prog + vague);
lowp float alpha = (cTransV - prog) / vague;
vec4 newFrag = texture(currentScene, v_texCoord);
vec4 oldFrag = texture(frozenScene, v_texCoord);
fragColor = mix(newFrag, oldFrag, alpha);
void main()
{
float transV = texture2D(transMap, v_texCoord).r;
float cTransV = clamp(transV, prog, prog+vague);
lowp float alpha = (cTransV - prog) / vague;
vec4 newFrag = texture2D(currentScene, v_texCoord);
vec4 oldFrag = texture2D(frozenScene, v_texCoord);
gl_FragColor = mix(newFrag, oldFrag, alpha);
}

View file

@ -5,13 +5,12 @@ uniform sampler2D frozenScene;
uniform sampler2D currentScene;
uniform float prog;
in vec2 v_texCoord;
varying vec2 v_texCoord;
out vec4 fragColor;
void main()
{
vec4 newPixel = texture2D(currentScene, v_texCoord);
vec4 oldPixel = texture2D(frozenScene, v_texCoord);
void main() {
vec4 newPixel = texture(currentScene, v_texCoord);
vec4 oldPixel = texture(frozenScene, v_texCoord);
fragColor = mix(oldPixel, newPixel, prog);
gl_FragColor = mix(oldPixel, newPixel, prog);
}

View file

@ -29,11 +29,6 @@
struct Config {
int rgssVersion;
struct {
char major;
char minor;
} glVersion;
bool debugMode;
bool printFPS;

View file

@ -170,14 +170,6 @@ void Config::read(int argc, char *argv[]) {
fillStringVec(opts[@"rubyLoadpath"], rubyLoadpaths);
rgssVersion = clamp(rgssVersion, 0, 3);
SE.sourceCount = clamp(SE.sourceCount, 1, 64);
if ([opts[@"openGL4"] boolValue]) {
glVersion.major = 4;
glVersion.minor = 1;
} else {
glVersion.major = 3;
glVersion.minor = 3;
}
}
static void setupScreenSize(Config &conf) {

View file

@ -448,13 +448,6 @@ static SDL_GLContext initGL(SDL_Window *win, Config &conf,
if (conf.debugMode)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
// Core profile enables OpenGL4 on macOS
// Using OpenGL 4.1 requires a GPU with max texture size of 16384 or better
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, conf.glVersion.major);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, conf.glVersion.minor);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
glCtx = SDL_GL_CreateContext(win);
if (!glCtx) {

View file

@ -115,20 +115,20 @@ void Shader::unbind()
static void setupShaderSource(GLuint shader, GLenum type,
const unsigned char *body, int bodySize)
{
//static const char glesDefine[] = "#define GLSLES\n";
static const char fragDefine[] = "";//#define FRAGMENT_SHADER\n";
static const char glesDefine[] = "#define GLSLES\n";
static const char fragDefine[] = "#define FRAGMENT_SHADER\n";
const GLchar *shaderSrc[4];
GLint shaderSrcSize[4];
size_t i = 0;
/*
if (gl.glsles)
{
shaderSrc[i] = glesDefine;
shaderSrcSize[i] = sizeof(glesDefine)-1;
++i;
}
*/
if (type == GL_FRAGMENT_SHADER)
{
shaderSrc[i] = fragDefine;