GPU: Fix Catmull-Rom weight calculation resulting in much sharper image, add XBR pixel art upscaling (MIT license implementation taken from libretro), add Mitchell bicubic option as a softer alternative to C-R
This commit is contained in:
@@ -220,6 +220,8 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
||||
private int uniBrightness;
|
||||
private int uniTex;
|
||||
private int uniTexSamplingMode;
|
||||
private int uniTexSourceDimensions;
|
||||
private int uniTexTargetDimensions;
|
||||
private int uniTextures;
|
||||
private int uniTextureOffsets;
|
||||
private int uniBlockSmall;
|
||||
@@ -501,10 +503,14 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
||||
glUiProgram = gl.glCreateProgram();
|
||||
glUiVertexShader = gl.glCreateShader(gl.GL_VERTEX_SHADER);
|
||||
glUiFragmentShader = gl.glCreateShader(gl.GL_FRAGMENT_SHADER);
|
||||
template = new Template(resourceLoader);
|
||||
vertSource = template.process(resourceLoader.apply("vertui.glsl"));
|
||||
template = new Template(resourceLoader);
|
||||
fragSource = template.process(resourceLoader.apply("fragui.glsl"));
|
||||
GLUtil.loadShaders(gl, glUiProgram, glUiVertexShader, -1, glUiFragmentShader,
|
||||
inputStreamToString(getClass().getResourceAsStream("vertui.glsl")),
|
||||
vertSource,
|
||||
null,
|
||||
inputStreamToString(getClass().getResourceAsStream("fragui.glsl")));
|
||||
fragSource);
|
||||
|
||||
initUniforms();
|
||||
}
|
||||
@@ -521,6 +527,8 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
||||
|
||||
uniTex = gl.glGetUniformLocation(glUiProgram, "tex");
|
||||
uniTexSamplingMode = gl.glGetUniformLocation(glUiProgram, "samplingMode");
|
||||
uniTexTargetDimensions = gl.glGetUniformLocation(glUiProgram, "targetDimensions");
|
||||
uniTexSourceDimensions = gl.glGetUniformLocation(glUiProgram, "sourceDimensions");
|
||||
uniTextures = gl.glGetUniformLocation(glProgram, "textures");
|
||||
uniTextureOffsets = gl.glGetUniformLocation(glProgram, "textureOffsets");
|
||||
|
||||
@@ -1156,20 +1164,24 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
||||
gl.glTexSubImage2D(gl.GL_TEXTURE_2D, 0, 0, 0, width, height, gl.GL_BGRA, gl.GL_UNSIGNED_INT_8_8_8_8_REV, interfaceBuffer);
|
||||
}
|
||||
|
||||
if (client.isStretchedEnabled())
|
||||
{
|
||||
Dimension dim = client.getStretchedDimensions();
|
||||
glDpiAwareViewport(0, 0, dim.width, dim.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDpiAwareViewport(0, 0, canvasWidth, canvasHeight);
|
||||
}
|
||||
|
||||
// Use the texture bound in the first pass
|
||||
gl.glUseProgram(glUiProgram);
|
||||
gl.glUniform1i(uniTex, 0);
|
||||
gl.glUniform1i(uniTexSamplingMode, config.uiScalingMode().getMode());
|
||||
gl.glUniform2i(uniTexSourceDimensions, canvasWidth, canvasHeight);
|
||||
|
||||
if (client.isStretchedEnabled())
|
||||
{
|
||||
Dimension dim = client.getStretchedDimensions();
|
||||
glDpiAwareViewport(0, 0, dim.width, dim.height);
|
||||
gl.glUniform2i(uniTexTargetDimensions, dim.width, dim.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDpiAwareViewport(0, 0, canvasWidth, canvasHeight);
|
||||
gl.glUniform2i(uniTexTargetDimensions, canvasWidth, canvasHeight);
|
||||
}
|
||||
|
||||
|
||||
// Set the sampling function used when stretching the UI.
|
||||
// This is probably better done with sampler objects instead of texture parameters, but this is easier and likely more portable.
|
||||
|
||||
@@ -33,7 +33,9 @@ public enum UIScalingMode
|
||||
{
|
||||
NEAREST("Nearest Neighbor", 0),
|
||||
LINEAR("Bilinear", 0),
|
||||
CATMULL_ROM("Bicubic (Catmull-Rom)", 1);
|
||||
MITCHELL("Bicubic (Mitchell)", 1),
|
||||
CATMULL_ROM("Bicubic (Catmull-Rom)", 2),
|
||||
XBR("XBR (use Integer Scaling)", 3);
|
||||
|
||||
private final String name;
|
||||
private final int mode;
|
||||
|
||||
Reference in New Issue
Block a user