From d242638e28fe899406068e11681b002256708d46 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 25 May 2016 21:25:09 -0700 Subject: [PATCH] OpenGL: Add texSize uniform --- CHANGES | 1 + res/shaders/agb001.shader/agb001.fs | 5 +++-- res/shaders/ags001.shader/ags001.fs | 5 +++-- res/shaders/xbr.shader/xbr.fs | 4 ++-- res/shaders/xbr.shader/xbr.vs | 4 +++- src/platform/opengl/gles2.c | 2 ++ src/platform/opengl/gles2.h | 1 + 7 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index 2c048bc92..c257ce6a6 100644 --- a/CHANGES +++ b/CHANGES @@ -43,6 +43,7 @@ Misc: - ARM7: Support forcing Thumb mode via MSR - ARM7: Flush prefetch cache when loading CPSR via MSR - Qt: Canonicalize file paths when loading games + - OpenGL: Add texSize uniform 0.4.0: (2016-02-02) Features: diff --git a/res/shaders/agb001.shader/agb001.fs b/res/shaders/agb001.shader/agb001.fs index cb3964598..79a036ff7 100644 --- a/res/shaders/agb001.shader/agb001.fs +++ b/res/shaders/agb001.shader/agb001.fs @@ -1,5 +1,6 @@ varying vec2 texCoord; uniform sampler2D tex; +uniform vec2 texSize; void main() { vec4 color = texture2D(tex, texCoord); @@ -14,8 +15,8 @@ void main() { arrayY[2] = vec3(1.0, 1.0, 1.0); arrayY[3] = vec3(0.8, 0.8, 0.8); color.rgb = pow(color.rgb * vec3(0.8, 0.8, 0.8), vec3(1.8, 1.8, 1.8)) + vec3(0.16, 0.16, 0.16); - color.rgb *= arrayX[int(mod(texCoord.s * 960.0, 4.0))]; - color.rgb *= arrayY[int(mod(texCoord.t * 640.0, 4.0))]; + color.rgb *= arrayX[int(mod(texCoord.s * texSize.x * 4.0, 4.0))]; + color.rgb *= arrayY[int(mod(texCoord.t * texSize.y * 4.0, 4.0))]; color.a = 0.5; gl_FragColor = color; } diff --git a/res/shaders/ags001.shader/ags001.fs b/res/shaders/ags001.shader/ags001.fs index 96d0544d0..8b7265bd3 100644 --- a/res/shaders/ags001.shader/ags001.fs +++ b/res/shaders/ags001.shader/ags001.fs @@ -1,5 +1,6 @@ varying vec2 texCoord; uniform sampler2D tex; +uniform vec2 texSize; void main() { vec4 color = texture2D(tex, texCoord); @@ -14,8 +15,8 @@ void main() { arrayY[2] = vec3(1.0, 1.0, 1.0); arrayY[3] = vec3(0.9, 0.9, 0.9); color.rgb = pow(color.rgb, vec3(1.6, 1.6, 1.6)); - color.rgb *= arrayX[int(mod(texCoord.s * 960.0, 4.0))]; - color.rgb *= arrayY[int(mod(texCoord.t * 640.0, 4.0))]; + color.rgb *= arrayX[int(mod(texCoord.s * texSize.x * 4.0, 4.0))]; + color.rgb *= arrayY[int(mod(texCoord.t * texSize.y * 4.0, 4.0))]; color.a = 0.8; gl_FragColor = color; } diff --git a/res/shaders/xbr.shader/xbr.fs b/res/shaders/xbr.shader/xbr.fs index 69c0faaad..8fec26bc7 100644 --- a/res/shaders/xbr.shader/xbr.fs +++ b/res/shaders/xbr.shader/xbr.fs @@ -98,7 +98,7 @@ varying vec4 TEX5; varying vec4 TEX6; varying vec4 TEX7; -const vec2 TextureSize = vec2(240.0, 160.0); +uniform vec2 texSize; void main() { @@ -110,7 +110,7 @@ void main() vec3 res1, res2, pix1, pix2; float blend1, blend2; - vec2 fp = fract(texCoord * TextureSize); + vec2 fp = fract(texCoord * texSize); vec3 A1 = COMPAT_TEXTURE(tex, TEX1.xw).rgb; vec3 B1 = COMPAT_TEXTURE(tex, TEX1.yw).rgb; diff --git a/res/shaders/xbr.shader/xbr.vs b/res/shaders/xbr.shader/xbr.vs index d59a970ef..0d7b0d25e 100644 --- a/res/shaders/xbr.shader/xbr.vs +++ b/res/shaders/xbr.shader/xbr.vs @@ -34,12 +34,14 @@ varying vec4 TEX6; varying vec4 TEX7; attribute vec4 position; +uniform vec2 texSize; + /* VERTEX_SHADER */ void main() { gl_Position = position; - vec2 ps = vec2(1.0/240.0, 1.0/160.0); + vec2 ps = vec2(1.0) / texSize; float dx = ps.x; float dy = ps.y; diff --git a/src/platform/opengl/gles2.c b/src/platform/opengl/gles2.c index 88f6079dd..604384055 100644 --- a/src/platform/opengl/gles2.c +++ b/src/platform/opengl/gles2.c @@ -230,6 +230,7 @@ void _drawShader(struct mGLES2Context* context, struct mGLES2Shader* shader) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, shader->filter ? GL_LINEAR : GL_NEAREST); glUseProgram(shader->program); glUniform1i(shader->texLocation, 0); + glUniform2f(shader->texSizeLocation, context->d.width, context->d.height); glVertexAttribPointer(shader->positionLocation, 2, GL_FLOAT, GL_FALSE, 0, _vertices); glEnableVertexAttribArray(shader->positionLocation); size_t u; @@ -399,6 +400,7 @@ void mGLES2ShaderInit(struct mGLES2Shader* shader, const char* vs, const char* f } shader->texLocation = glGetUniformLocation(shader->program, "tex"); + shader->texSizeLocation = glGetUniformLocation(shader->program, "texSize"); shader->positionLocation = glGetAttribLocation(shader->program, "position"); size_t i; for (i = 0; i < shader->nUniforms; ++i) { diff --git a/src/platform/opengl/gles2.h b/src/platform/opengl/gles2.h index 510580861..fabdebc14 100644 --- a/src/platform/opengl/gles2.h +++ b/src/platform/opengl/gles2.h @@ -62,6 +62,7 @@ struct mGLES2Shader { GLuint vertexShader; GLuint program; GLuint texLocation; + GLuint texSizeLocation; GLuint positionLocation; struct mGLES2Uniform* uniforms;