gpu: add UI bicubic & xBR rescaling

This commit is contained in:
ln
2020-02-23 21:49:04 +02:00
committed by GitHub
parent 91bfe7eb6d
commit 66fac018eb
9 changed files with 624 additions and 10 deletions

View File

@@ -76,6 +76,7 @@ import net.runelite.client.plugins.PluginInstantiationException;
import net.runelite.client.plugins.PluginManager;
import static net.runelite.client.plugins.gpu.GLUtil.*;
import net.runelite.client.plugins.gpu.config.AntiAliasingMode;
import net.runelite.client.plugins.gpu.config.UIScalingMode;
import net.runelite.client.plugins.gpu.template.Template;
import net.runelite.client.ui.DrawManager;
import net.runelite.client.util.OSType;
@@ -239,6 +240,9 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
private int uniProjectionMatrix;
private int uniBrightness;
private int uniTex;
private int uniTexSamplingMode;
private int uniTexSourceDimensions;
private int uniTexTargetDimensions;
private int uniTextures;
private int uniTextureOffsets;
private int uniBlockSmall;
@@ -476,6 +480,9 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
uniDrawDistance = gl.glGetUniformLocation(glProgram, "drawDistance");
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");
@@ -623,8 +630,8 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
{
interfaceTexture = glGenTexture(gl);
gl.glBindTexture(gl.GL_TEXTURE_2D, interfaceTexture);
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_REPEAT);
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_REPEAT);
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR);
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR);
gl.glBindTexture(gl.GL_TEXTURE_2D, 0);
@@ -1132,26 +1139,32 @@ 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);
}
// Use the texture bound in the first pass
final UIScalingMode uiScalingMode = config.uiScalingMode();
gl.glUseProgram(glUiProgram);
gl.glUniform1i(uniTex, 0);
gl.glUniform1i(uniTexSamplingMode, 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);
}
// Use the texture bound in the first pass
gl.glUseProgram(glUiProgram);
gl.glUniform1i(uniTex, 0);
// 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.
// See https://www.khronos.org/opengl/wiki/Sampler_Object for details.
if (client.isStretchedEnabled())
{
final int function = client.isStretchedFast() ? gl.GL_NEAREST : gl.GL_LINEAR;
// GL_NEAREST makes sampling for bicubic/xBR simpler, so it should be used whenever linear isn't
final int function = uiScalingMode == UIScalingMode.LINEAR ? gl.GL_LINEAR : gl.GL_NEAREST;
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, function);
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, function);
}

View File

@@ -31,6 +31,7 @@ import net.runelite.client.config.Range;
import static net.runelite.client.plugins.gpu.GpuPlugin.MAX_FOG_DEPTH;
import net.runelite.client.plugins.gpu.config.AntiAliasingMode;
import static net.runelite.client.plugins.gpu.GpuPlugin.MAX_DISTANCE;
import net.runelite.client.plugins.gpu.config.UIScalingMode;
@ConfigGroup("gpu")
public interface GpuPluginConfig extends Config
@@ -71,6 +72,17 @@ public interface GpuPluginConfig extends Config
return AntiAliasingMode.DISABLED;
}
@ConfigItem(
keyName = "uiScalingMode",
name = "UI scaling mode",
description = "Sampling function to use for the UI in stretched mode",
position = 4
)
default UIScalingMode uiScalingMode()
{
return UIScalingMode.LINEAR;
}
@Range(
max = MAX_FOG_DEPTH
)
@@ -78,7 +90,7 @@ public interface GpuPluginConfig extends Config
keyName = "fogDepth",
name = "Fog depth",
description = "Distance from the scene edge the fog starts",
position = 4
position = 5
)
default int fogDepth()
{

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 2019 logarrhytmic <https://github.com/logarrhythmic>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.gpu.config;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
public enum UIScalingMode
{
NEAREST("Nearest Neighbor", 0),
LINEAR("Bilinear", 0),
MITCHELL("Bicubic (Mitchell)", 1),
CATMULL_ROM("Bicubic (Catmull-Rom)", 2),
XBR("xBR", 3);
private final String name;
private final int mode;
@Override
public String toString()
{
return name;
}
}