Small work on gui renderer
This commit is contained in:
parent
c7c7fd9856
commit
02b1aab8f3
@ -5,9 +5,9 @@ connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=
|
||||
eclipse.preferences.version=1
|
||||
gradle.user.home=
|
||||
java.home=
|
||||
java.home=C\:/Program Files/Eclipse Adoptium/jdk-21.0.1.12-hotspot
|
||||
jvm.arguments=
|
||||
offline.mode=false
|
||||
override.workspace.settings=false
|
||||
override.workspace.settings=true
|
||||
show.console.view=false
|
||||
show.executions.view=false
|
||||
|
@ -14,6 +14,7 @@ import speiger.src.coreengine.rendering.models.DrawCall;
|
||||
import speiger.src.coreengine.rendering.tesselation.buffer.VertexBuilder;
|
||||
import speiger.src.coreengine.rendering.tesselation.format.VertexFormat;
|
||||
import speiger.src.coreengine.rendering.tesselation.format.VertexTypes;
|
||||
import speiger.src.coreengine.rendering.utils.ScissorsManager;
|
||||
import speiger.src.coreengine.rendering.utils.values.GLMode;
|
||||
|
||||
public class SimpleUIRenderer implements IUIRenderer, AutoCloseable {
|
||||
@ -23,8 +24,8 @@ public class SimpleUIRenderer implements IUIRenderer, AutoCloseable {
|
||||
int currentMatrix = 0;
|
||||
int lastTexture = 0;
|
||||
List<UIDrawCall> drawCalls = new ObjectArrayList<>();
|
||||
|
||||
VertexBuilder builder = new VertexBuilder(Short.MAX_VALUE);
|
||||
ScissorsManager manager = new ScissorsManager(32);
|
||||
|
||||
|
||||
@Override
|
||||
@ -34,17 +35,19 @@ public class SimpleUIRenderer implements IUIRenderer, AutoCloseable {
|
||||
|
||||
@Override
|
||||
public boolean isInScissors(IGuiBox box) {
|
||||
return false;
|
||||
return manager.contains(box);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushScissors(IGuiBox box) {
|
||||
|
||||
float minX = box.getMinX();
|
||||
float minY = box.getMinY();
|
||||
manager.push((int)minX, (int)minY, (int)(box.getMaxX() - minX), (int)(box.getMaxY() - minY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void popScissors() {
|
||||
|
||||
manager.pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,6 +55,7 @@ public class SimpleUIRenderer implements IUIRenderer, AutoCloseable {
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
pushDrawcall();
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,27 @@
|
||||
package speiger.src.coreengine.rendering.gui.renderer;
|
||||
|
||||
import speiger.src.coreengine.assets.AssetLocation;
|
||||
import speiger.src.coreengine.assets.base.IAssetProvider;
|
||||
import speiger.src.coreengine.math.vector.floats.Vec4f;
|
||||
import speiger.src.coreengine.math.vector.matrix.Matrix4f;
|
||||
import speiger.src.coreengine.rendering.shader.SimpleShader;
|
||||
import speiger.src.coreengine.rendering.shader.uniform.base.BufferUniform;
|
||||
import speiger.src.coreengine.rendering.shader.uniform.base.FloatUniform;
|
||||
import speiger.src.coreengine.rendering.shader.uniform.base.TextureUniform;
|
||||
import speiger.src.coreengine.rendering.shader.uniform.vec.Matrix4fUniform;
|
||||
import speiger.src.coreengine.rendering.shader.uniform.vec.Vec4fUniform;
|
||||
|
||||
public class SimpleUIShader extends SimpleShader {
|
||||
public BufferUniform camera = uniforms.addBuffer("cameraTransform", 0);
|
||||
public Matrix4fUniform modelMatrix = uniforms.addMat("modelMatrix", new Matrix4f());
|
||||
public TextureUniform texture = uniforms.addTexture("texture", 0);
|
||||
public FloatUniform useTexture = uniforms.addFloat("use_texture", 0);
|
||||
public Vec4fUniform bounds = uniforms.addVec4("bounds", Vec4f.ZERO);
|
||||
public FloatUniform roundness = uniforms.addFloat("roundness", 0);
|
||||
|
||||
|
||||
public SimpleUIShader(IAssetProvider provider) {
|
||||
super(provider, "gui_simple", AssetLocation.of("shader/gui/simple/vertex.vs"), AssetLocation.of("shader/gui/simple/fragment.vs"), "in_position", "in_tex", "in_color");
|
||||
}
|
||||
|
||||
}
|
@ -1071,7 +1071,7 @@ public abstract class GuiComponent extends FlagHolder
|
||||
int bottom = y + height;
|
||||
Window window = owner.getWindow();
|
||||
Vec2d vec = owner.getUIManager().res.getScaleVec();
|
||||
GLStateTracker.instance().scissors.enableScissors((int)(x * vec.x()), (int)(window.getHeight() - bottom * vec.y()), (int)(width * vec.x()), (int)(height * vec.y()));
|
||||
GLStateTracker.instance().scissors.push((int)(x * vec.x()), (int)(window.getHeight() - bottom * vec.y()), (int)(width * vec.x()), (int)(height * vec.y()));
|
||||
}
|
||||
|
||||
protected final boolean isInScissors(Plane box)
|
||||
@ -1094,13 +1094,13 @@ public abstract class GuiComponent extends FlagHolder
|
||||
int bottom = y + height;
|
||||
Window window = owner.getWindow();
|
||||
Vec2d vec = owner.getUIManager().res.getScaleVec();
|
||||
return GLStateTracker.instance().scissors.isInScissors((int)(x * vec.x()), (int)(window.getHeight() - bottom * vec.y()), (int)(width * vec.x()), (int)(height * vec.y()));
|
||||
return GLStateTracker.instance().scissors.contains((int)(x * vec.x()), (int)(window.getHeight() - bottom * vec.y()), (int)(width * vec.x()), (int)(height * vec.y()));
|
||||
}
|
||||
|
||||
public final void disableScissors()
|
||||
{
|
||||
getRenderer().flush();
|
||||
GLStateTracker.instance().scissors.disableScissors();
|
||||
GLStateTracker.instance().scissors.pop();
|
||||
}
|
||||
|
||||
class KeyBindAction implements IKeyComponent
|
||||
|
@ -3,6 +3,7 @@ package speiger.src.coreengine.rendering.shader.uniform;
|
||||
import speiger.src.coreengine.rendering.shader.ShaderProgram;
|
||||
|
||||
public interface IUniform {
|
||||
public String name();
|
||||
public void registerShader(ShaderProgram program);
|
||||
public void removeShader(ShaderProgram program);
|
||||
}
|
||||
|
@ -17,6 +17,10 @@ public abstract class Uniform implements IUniform {
|
||||
positions.setDefaultReturnValue(-1);
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
protected boolean contains(int shaderId) {
|
||||
return positions.containsKey(shaderId);
|
||||
}
|
||||
|
@ -81,6 +81,15 @@ public class UniformManager {
|
||||
return uniform;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends IUniform> T getUniform(String name) {
|
||||
for(int i = 0,m=uniforms.size();i<m;i++) {
|
||||
IUniform uni = uniforms.get(i);
|
||||
if(uni.name().equals(name)) return (T)uni;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void validate() {
|
||||
for(int i = 0,m=uniforms.size();i<m;i++) {
|
||||
uniforms.get(i).registerShader(owner);
|
||||
|
@ -3,6 +3,7 @@ package speiger.src.coreengine.rendering.utils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import speiger.src.coreengine.math.collision2d.Plane;
|
||||
import speiger.src.coreengine.rendering.guiOld.helper.box.IGuiBox;
|
||||
import speiger.src.coreengine.utils.io.GameLog;
|
||||
|
||||
public class ScissorsManager
|
||||
@ -17,7 +18,7 @@ public class ScissorsManager
|
||||
}
|
||||
}
|
||||
|
||||
public void enableScissors(int x, int y, int width, int height) {
|
||||
public void push(int x, int y, int width, int height) {
|
||||
if(inUse + 1 >= instances.length) {
|
||||
GameLog.warn("Scissors test would go out of Bounds!");
|
||||
return;
|
||||
@ -34,11 +35,15 @@ public class ScissorsManager
|
||||
GL11.glScissor(box.getMinX(), box.getMinY(), box.getWidth(), box.getHeight());
|
||||
}
|
||||
|
||||
public boolean isInScissors(int x, int y, int width, int height) {
|
||||
public boolean contains(IGuiBox box) {
|
||||
return inUse == -1 || instances[inUse].isIntersecting((int)box.getMinX(), (int)box.getMinY(), (int)box.getMaxX(), (int)box.getMaxY());
|
||||
}
|
||||
|
||||
public boolean contains(int x, int y, int width, int height) {
|
||||
return inUse == -1 || instances[inUse].isIntersecting(x, y, x + width, y + height);
|
||||
}
|
||||
|
||||
public void disableScissors() {
|
||||
public void pop() {
|
||||
if(inUse < 0) {
|
||||
GameLog.warn("Scissors test would go into negative");
|
||||
return;
|
||||
|
@ -0,0 +1,35 @@
|
||||
#version 330
|
||||
|
||||
in vec4 pass_color;
|
||||
in vec2 pass_tex;
|
||||
in vec2 pass_pos;
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform float use_texture;
|
||||
uniform vec4 bounds;
|
||||
uniform float roundness;
|
||||
|
||||
const vec4 no_texture = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
const float cornerSmoothFactor = 0.55;
|
||||
|
||||
float square(float val) {
|
||||
return val * val;
|
||||
}
|
||||
|
||||
float distanceSquared(vec2 p1, vec2 p2) {
|
||||
vec2 vector = p2 - p1;
|
||||
return dot(vector, vector);
|
||||
}
|
||||
|
||||
float calcRoundedCorners() {
|
||||
if (roundness <= 0.0) return 1.0;
|
||||
return smoothstep(square(roundness + cornerSmoothFactor), square(roundness - cornerSmoothFactor), distanceSquared(pass_pos, clamp(pass_pos, vec2(bounds.x + roundness, bounds.y + roundness), vec2(bounds.z - roundness, bounds.w - roundness))));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
frag_color = pass_color * mix(no_texture, texture2D(texture, pass_tex), use_texture);
|
||||
frag_color.a *= calcRoundedCorners();
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
#version 330
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
layout(location = 1) in vec2 in_tex;
|
||||
layout(location = 2) in vec4 in_color;
|
||||
|
||||
out vec4 pass_color;
|
||||
out vec2 pass_tex;
|
||||
out vec2 pass_pos;
|
||||
|
||||
layout (std140, column_major) uniform cameraTransform {
|
||||
mat4 proMatrix;
|
||||
};
|
||||
uniform mat4 modelMatrix;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = proMatrix * modelMatrix * vec4(in_position, 1.0);
|
||||
pass_color = in_color;
|
||||
pass_tex = in_tex;
|
||||
pass_pos = in_position.xy;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user