mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-04-21 21:52:04 +02:00
Use Core GL context, allow OpenGL3/4 on macOS
This commit is contained in:
parent
3ffad8c05f
commit
827e20db87
18 changed files with 166 additions and 176 deletions
|
@ -8,26 +8,27 @@ uniform vec4 subRect;
|
|||
|
||||
uniform lowp float opacity;
|
||||
|
||||
varying vec2 v_texCoord;
|
||||
in vec2 v_texCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 coor = v_texCoord;
|
||||
vec2 dstCoor = (coor - subRect.xy) * subRect.zw;
|
||||
out vec4 fragColor;
|
||||
|
||||
vec4 srcFrag = texture2D(source, coor);
|
||||
vec4 dstFrag = texture2D(destination, dstCoor);
|
||||
void main() {
|
||||
vec2 coor = v_texCoord;
|
||||
vec2 dstCoor = (coor - subRect.xy) * subRect.zw;
|
||||
|
||||
vec4 resFrag;
|
||||
vec4 srcFrag = texture(source, coor);
|
||||
vec4 dstFrag = texture(destination, dstCoor);
|
||||
|
||||
float co1 = srcFrag.a * opacity;
|
||||
float co2 = dstFrag.a * (1.0 - co1);
|
||||
resFrag.a = co1 + co2;
|
||||
vec4 resFrag;
|
||||
|
||||
if (resFrag.a == 0.0)
|
||||
resFrag.rgb = srcFrag.rgb;
|
||||
else
|
||||
resFrag.rgb = (co1*srcFrag.rgb + co2*dstFrag.rgb) / resFrag.a;
|
||||
float co1 = srcFrag.a * opacity;
|
||||
float co2 = dstFrag.a * (1.0 - co1);
|
||||
resFrag.a = co1 + co2;
|
||||
|
||||
gl_FragColor = resFrag;
|
||||
if (resFrag.a == 0.0)
|
||||
resFrag.rgb = srcFrag.rgb;
|
||||
else
|
||||
resFrag.rgb = (co1 * srcFrag.rgb + co2 * dstFrag.rgb) / resFrag.a;
|
||||
|
||||
fragColor = resFrag;
|
||||
}
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D v_texture;
|
||||
|
||||
varying vec2 v_texCoord;
|
||||
varying vec2 v_blurCoord[2];
|
||||
in vec2 v_texCoord;
|
||||
in vec2 v_blurCoord[2];
|
||||
|
||||
void main()
|
||||
{
|
||||
lowp vec4 frag = vec4(0, 0, 0, 0);
|
||||
out vec4 fragColor;
|
||||
|
||||
frag += texture2D(texture, v_texCoord);
|
||||
frag += texture2D(texture, v_blurCoord[0]);
|
||||
frag += texture2D(texture, v_blurCoord[1]);
|
||||
void main() {
|
||||
lowp vec4 frag = vec4(0, 0, 0, 0);
|
||||
|
||||
gl_FragColor = frag / 3.0;
|
||||
frag += texture(v_texture, v_texCoord);
|
||||
frag += texture(v_texture, v_blurCoord[0]);
|
||||
frag += texture(v_texture, v_blurCoord[1]);
|
||||
|
||||
fragColor = frag / 3.0;
|
||||
}
|
||||
|
|
|
@ -1,15 +1,8 @@
|
|||
#ifdef GLSLES
|
||||
|
||||
#ifdef FRAGMENT_SHADER
|
||||
/* Only the fragment shader has no default float precision */
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
#else
|
||||
#version 330
|
||||
#define attribute in
|
||||
#define varying out
|
||||
|
||||
/* Desktop GLSL doesn't know about these */
|
||||
#define highp
|
||||
#define mediump
|
||||
#define lowp
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
|
||||
uniform lowp float alpha;
|
||||
|
||||
varying lowp vec4 v_color;
|
||||
in lowp vec4 v_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = vec4(v_color.rgb * alpha, 1);
|
||||
}
|
||||
out vec4 fragColor;
|
||||
void main() { fragColor = vec4(v_color.rgb * alpha, 1); }
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
|
||||
uniform lowp vec4 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = color;
|
||||
}
|
||||
out vec4 fragColor;
|
||||
void main() { fragColor = color; }
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D v_texture;
|
||||
uniform lowp float gray;
|
||||
|
||||
varying vec2 v_texCoord;
|
||||
in vec2 v_texCoord;
|
||||
|
||||
const vec3 lumaF = vec3(.299, .587, .114);
|
||||
|
||||
void main()
|
||||
{
|
||||
/* Sample source color */
|
||||
vec4 frag = texture2D(texture, v_texCoord);
|
||||
out vec4 fragColor;
|
||||
void main() {
|
||||
/* Sample source color */
|
||||
vec4 frag = texture(v_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);
|
||||
|
||||
gl_FragColor = frag;
|
||||
fragColor = frag;
|
||||
}
|
||||
|
|
|
@ -1,40 +1,39 @@
|
|||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D v_texture;
|
||||
uniform mediump float hueAdjust;
|
||||
|
||||
varying vec2 v_texCoord;
|
||||
in vec2 v_texCoord;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
/* 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 = texture2D (texture, v_texCoord.xy);
|
||||
vec3 hsv = rgb2hsv(color.rgb);
|
||||
void main() {
|
||||
vec4 color = texture(v_texture, v_texCoord.xy);
|
||||
vec3 hsv = rgb2hsv(color.rgb);
|
||||
|
||||
hsv.x += hueAdjust;
|
||||
color.rgb = hsv2rgb(hsv);
|
||||
hsv.x += hueAdjust;
|
||||
color.rgb = hsv2rgb(hsv);
|
||||
|
||||
gl_FragColor = color;
|
||||
fragColor = color;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,4 @@
|
|||
uniform mat4 projMat;
|
||||
attribute vec2 position;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projMat * vec4(position, 0, 1);
|
||||
}
|
||||
void main() { gl_Position = projMat * vec4(position, 0, 1); }
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D v_texture;
|
||||
|
||||
uniform lowp vec4 tone;
|
||||
|
||||
|
@ -7,30 +7,31 @@ uniform lowp float opacity;
|
|||
uniform lowp vec4 color;
|
||||
uniform lowp vec4 flash;
|
||||
|
||||
varying vec2 v_texCoord;
|
||||
in vec2 v_texCoord;
|
||||
|
||||
const vec3 lumaF = vec3(.299, .587, .114);
|
||||
|
||||
void main()
|
||||
{
|
||||
/* Sample source color */
|
||||
vec4 frag = texture2D(texture, v_texCoord);
|
||||
out vec4 fragColor;
|
||||
|
||||
/* Apply gray */
|
||||
float luma = dot(frag.rgb, lumaF);
|
||||
frag.rgb = mix(frag.rgb, vec3(luma), tone.w);
|
||||
void main() {
|
||||
/* Sample source color */
|
||||
vec4 frag = texture(v_texture, v_texCoord);
|
||||
|
||||
/* Apply tone */
|
||||
frag.rgb += tone.rgb;
|
||||
/* Apply gray */
|
||||
float luma = dot(frag.rgb, lumaF);
|
||||
frag.rgb = mix(frag.rgb, vec3(luma), tone.w);
|
||||
|
||||
/* Apply opacity */
|
||||
frag.a *= opacity;
|
||||
/* Apply tone */
|
||||
frag.rgb += tone.rgb;
|
||||
|
||||
/* Apply color */
|
||||
frag.rgb = mix(frag.rgb, color.rgb, color.a);
|
||||
/* Apply opacity */
|
||||
frag.a *= opacity;
|
||||
|
||||
/* Apply flash */
|
||||
frag.rgb = mix(frag.rgb, flash.rgb, flash.a);
|
||||
/* Apply color */
|
||||
frag.rgb = mix(frag.rgb, color.rgb, color.a);
|
||||
|
||||
gl_FragColor = frag;
|
||||
/* Apply flash */
|
||||
frag.rgb = mix(frag.rgb, flash.rgb, flash.a);
|
||||
|
||||
fragColor = frag;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D v_texture;
|
||||
|
||||
varying vec2 v_texCoord;
|
||||
in vec2 v_texCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(texture, v_texCoord);
|
||||
}
|
||||
out vec4 fragColor;
|
||||
void main() { fragColor = texture(v_texture, v_texCoord); }
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D v_texture;
|
||||
|
||||
varying vec2 v_texCoord;
|
||||
varying lowp vec4 v_color;
|
||||
in vec2 v_texCoord;
|
||||
in lowp vec4 v_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(texture, v_texCoord);
|
||||
gl_FragColor.a *= v_color.a;
|
||||
out vec4 fragColor;
|
||||
void main() {
|
||||
fragColor = texture(v_texture, v_texCoord);
|
||||
fragColor.a *= v_color.a;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D v_texture;
|
||||
uniform lowp float alpha;
|
||||
|
||||
varying vec2 v_texCoord;
|
||||
in vec2 v_texCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(texture, v_texCoord);
|
||||
gl_FragColor.a *= alpha;
|
||||
void main() {
|
||||
fragColor = texture(v_texture, v_texCoord);
|
||||
fragColor.a *= alpha;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
|
||||
varying lowp vec4 v_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = v_color;
|
||||
}
|
||||
in lowp vec4 v_color;
|
||||
out vec4 fragColor;
|
||||
void main() { fragColor = v_color; }
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D v_texture;
|
||||
|
||||
uniform lowp vec4 tone;
|
||||
|
||||
|
@ -9,31 +9,32 @@ uniform lowp vec4 color;
|
|||
uniform float bushDepth;
|
||||
uniform lowp float bushOpacity;
|
||||
|
||||
varying vec2 v_texCoord;
|
||||
in vec2 v_texCoord;
|
||||
|
||||
const vec3 lumaF = vec3(.299, .587, .114);
|
||||
|
||||
void main()
|
||||
{
|
||||
/* Sample source color */
|
||||
vec4 frag = texture2D(texture, v_texCoord);
|
||||
out vec4 fragColor;
|
||||
|
||||
/* Apply gray */
|
||||
float luma = dot(frag.rgb, lumaF);
|
||||
frag.rgb = mix(frag.rgb, vec3(luma), tone.w);
|
||||
void main() {
|
||||
/* Sample source color */
|
||||
vec4 frag = texture(v_texture, v_texCoord);
|
||||
|
||||
/* Apply tone */
|
||||
frag.rgb += tone.rgb;
|
||||
/* Apply gray */
|
||||
float luma = dot(frag.rgb, lumaF);
|
||||
frag.rgb = mix(frag.rgb, vec3(luma), tone.w);
|
||||
|
||||
/* Apply opacity */
|
||||
frag.a *= opacity;
|
||||
/* Apply tone */
|
||||
frag.rgb += tone.rgb;
|
||||
|
||||
/* Apply color */
|
||||
frag.rgb = mix(frag.rgb, color.rgb, color.a);
|
||||
/* Apply opacity */
|
||||
frag.a *= opacity;
|
||||
|
||||
/* Apply bush alpha by mathematical if */
|
||||
lowp float underBush = float(v_texCoord.y < bushDepth);
|
||||
frag.a *= clamp(bushOpacity + underBush, 0.0, 1.0);
|
||||
/* Apply color */
|
||||
frag.rgb = mix(frag.rgb, color.rgb, color.a);
|
||||
|
||||
gl_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);
|
||||
|
||||
fragColor = frag;
|
||||
}
|
||||
|
|
|
@ -8,16 +8,17 @@ uniform float prog;
|
|||
/* Vague [0, 512] normalized */
|
||||
uniform float vague;
|
||||
|
||||
varying vec2 v_texCoord;
|
||||
in vec2 v_texCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
float transV = texture2D(transMap, v_texCoord).r;
|
||||
float cTransV = clamp(transV, prog, prog+vague);
|
||||
lowp float alpha = (cTransV - prog) / vague;
|
||||
out vec4 fragColor;
|
||||
|
||||
vec4 newFrag = texture2D(currentScene, v_texCoord);
|
||||
vec4 oldFrag = texture2D(frozenScene, v_texCoord);
|
||||
void main() {
|
||||
float transV = texture(transMap, v_texCoord).r;
|
||||
float cTransV = clamp(transV, prog, prog + vague);
|
||||
lowp float alpha = (cTransV - prog) / vague;
|
||||
|
||||
gl_FragColor = mix(newFrag, oldFrag, alpha);
|
||||
vec4 newFrag = texture(currentScene, v_texCoord);
|
||||
vec4 oldFrag = texture(frozenScene, v_texCoord);
|
||||
|
||||
fragColor = mix(newFrag, oldFrag, alpha);
|
||||
}
|
||||
|
|
|
@ -5,12 +5,13 @@ uniform sampler2D frozenScene;
|
|||
uniform sampler2D currentScene;
|
||||
uniform float prog;
|
||||
|
||||
varying vec2 v_texCoord;
|
||||
in vec2 v_texCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 newPixel = texture2D(currentScene, v_texCoord);
|
||||
vec4 oldPixel = texture2D(frozenScene, v_texCoord);
|
||||
out vec4 fragColor;
|
||||
|
||||
gl_FragColor = mix(oldPixel, newPixel, prog);
|
||||
void main() {
|
||||
vec4 newPixel = texture(currentScene, v_texCoord);
|
||||
vec4 oldPixel = texture(frozenScene, v_texCoord);
|
||||
|
||||
fragColor = mix(oldPixel, newPixel, prog);
|
||||
}
|
||||
|
|
|
@ -409,6 +409,11 @@ static SDL_GLContext initGL(SDL_Window *win, Config &conf,
|
|||
if (conf.debugMode)
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
|
||||
|
||||
// Enables OpenGL 3 and 4 on macOS
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
|
||||
glCtx = SDL_GL_CreateContext(win);
|
||||
|
||||
if (!glCtx) {
|
||||
|
|
|
@ -114,20 +114,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;
|
||||
|
|
Loading…
Add table
Reference in a new issue