Small Progress on the Renderer
This commit is contained in:
@@ -26,7 +26,7 @@ public interface IUIRenderer {
|
|||||||
void alignH(Align align);
|
void alignH(Align align);
|
||||||
|
|
||||||
void pushLayer(LayerType type);
|
void pushLayer(LayerType type);
|
||||||
void popLayer();
|
void popLayer(LayerType type);
|
||||||
|
|
||||||
|
|
||||||
void drawLine(float startX, float startY, float endX, float endY, float lineWidth, int color);
|
void drawLine(float startX, float startY, float endX, float endY, float lineWidth, int color);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package speiger.src.coreengine.ui.gui.renderer;
|
package speiger.src.coreengine.ui.gui.renderer;
|
||||||
|
|
||||||
public enum LayerType {
|
public enum LayerType {
|
||||||
COMPONENT,
|
|
||||||
COMPONENT_STACK,
|
COMPONENT_STACK,
|
||||||
WINDOW;
|
WINDOW;
|
||||||
}
|
}
|
||||||
@@ -2,12 +2,19 @@ package speiger.src.coreengine.ui.gui.renderer;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import speiger.src.collections.ints.collections.IntStack;
|
||||||
|
import speiger.src.collections.ints.lists.IntArrayList;
|
||||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||||
|
import speiger.src.collections.utils.Stack;
|
||||||
|
import speiger.src.coreengine.math.MathUtils;
|
||||||
|
import speiger.src.coreengine.math.bits.BitUtil;
|
||||||
import speiger.src.coreengine.math.vector.matrix.Matrix4fStack;
|
import speiger.src.coreengine.math.vector.matrix.Matrix4fStack;
|
||||||
import speiger.src.coreengine.math.vector.quaternion.Quaternion;
|
import speiger.src.coreengine.math.vector.quaternion.Quaternion;
|
||||||
import speiger.src.coreengine.platform.graphics.api.core.GraphicsDevice;
|
import speiger.src.coreengine.platform.graphics.api.core.GraphicsDevice;
|
||||||
import speiger.src.coreengine.platform.graphics.api.shader.ShaderPipeline;
|
import speiger.src.coreengine.platform.graphics.api.shader.ShaderPipeline;
|
||||||
import speiger.src.coreengine.platform.graphics.api.utils.SampledTexture;
|
import speiger.src.coreengine.platform.graphics.api.utils.SampledTexture;
|
||||||
|
import speiger.src.coreengine.platform.graphics.api.utils.ScissorsManager;
|
||||||
|
import speiger.src.coreengine.platform.graphics.api.utils.ScissorsManager.IScissorsHandler;
|
||||||
import speiger.src.coreengine.platform.graphics.api.vertex.builder.IVertexBuffer.BufferResult;
|
import speiger.src.coreengine.platform.graphics.api.vertex.builder.IVertexBuffer.BufferResult;
|
||||||
import speiger.src.coreengine.platform.graphics.api.vertex.builder.IVertexBuilder;
|
import speiger.src.coreengine.platform.graphics.api.vertex.builder.IVertexBuilder;
|
||||||
import speiger.src.coreengine.platform.graphics.api.vertex.builder.VertexBuilder;
|
import speiger.src.coreengine.platform.graphics.api.vertex.builder.VertexBuilder;
|
||||||
@@ -21,26 +28,30 @@ public class UIRenderer implements IUIRenderer {
|
|||||||
VertexBuilder builder = new VertexBuilder(100);
|
VertexBuilder builder = new VertexBuilder(100);
|
||||||
List<UIDraw> draws = new ObjectArrayList<>();
|
List<UIDraw> draws = new ObjectArrayList<>();
|
||||||
Align[] alignment = new Align[] { Align.CENTER, Align.CENTER };
|
Align[] alignment = new Align[] { Align.CENTER, Align.CENTER };
|
||||||
|
Stack<WindowLayer> layers = new ObjectArrayList<>();
|
||||||
|
int windowLayer = 1;
|
||||||
|
int currentComponent = 0;
|
||||||
ShaderPipeline currentPipeline;
|
ShaderPipeline currentPipeline;
|
||||||
SampledTexture currentTexture;
|
SampledTexture currentTexture;
|
||||||
|
ScissorsManager clippingManager = new ScissorsManager(64, ScissorsManager.NoOp.INSTANCE);
|
||||||
|
|
||||||
public UIRenderer(GraphicsDevice device) {
|
public UIRenderer(GraphicsDevice device) {
|
||||||
this.device = device;
|
this.device = device;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isClipping(IGuiBox box) {
|
public boolean isClipping(IGuiBox box) {
|
||||||
return false;
|
return clippingManager.contains(Math.round(box.getMinX()), Math.round(box.getMinY()), Math.round(box.getWidth()), Math.round(box.getHeight()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pushClip(IGuiBox box) {
|
public void pushClip(IGuiBox box) {
|
||||||
|
clippingManager.push(Math.round(box.getMinX()), Math.round(box.getMinY()), Math.round(box.getWidth()), Math.round(box.getHeight()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void popClip() {
|
public void popClip() {
|
||||||
|
clippingManager.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -83,12 +94,12 @@ public class UIRenderer implements IUIRenderer {
|
|||||||
alignment[0] = vertical;
|
alignment[0] = vertical;
|
||||||
alignment[1] = horizontal;
|
alignment[1] = horizontal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void alignV(Align align) {
|
public void alignV(Align align) {
|
||||||
alignment[0] = align;
|
alignment[0] = align;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void alignH(Align align) {
|
public void alignH(Align align) {
|
||||||
alignment[1] = align;
|
alignment[1] = align;
|
||||||
@@ -96,14 +107,44 @@ public class UIRenderer implements IUIRenderer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pushLayer(LayerType type) {
|
public void pushLayer(LayerType type) {
|
||||||
|
switch(type) {
|
||||||
|
case WINDOW:
|
||||||
|
layers.push(new WindowLayer(windowLayer++));
|
||||||
|
break;
|
||||||
|
case COMPONENT_STACK:
|
||||||
|
if(layers.isEmpty()) return;
|
||||||
|
layers.top().push();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void popLayer() {
|
public void popLayer(LayerType type) {
|
||||||
|
switch(type) {
|
||||||
|
case WINDOW:
|
||||||
|
layers.pop();
|
||||||
|
break;
|
||||||
|
case COMPONENT_STACK:
|
||||||
|
if(layers.isEmpty()) return;
|
||||||
|
layers.top().pop();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Idea:
|
||||||
|
* public class DrawObject {
|
||||||
|
* int windowLayer;
|
||||||
|
* int componentLayer;
|
||||||
|
* ShaderPipeline pipeline;
|
||||||
|
* Int2ObjectMap<SampledTexture> textures;
|
||||||
|
* vec4 scissors;
|
||||||
|
* byte[] vertexData;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* We pregenerate the draw call
|
||||||
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawLine(float startX, float startY, float endX, float endY, float lineWidth, int color) {
|
public void drawLine(float startX, float startY, float endX, float endY, float lineWidth, int color) {
|
||||||
ensureType(UIConstants.GUI, null);
|
ensureType(UIConstants.GUI, null);
|
||||||
@@ -173,7 +214,7 @@ public class UIRenderer implements IUIRenderer {
|
|||||||
float minX = box.getMinX();
|
float minX = box.getMinX();
|
||||||
float minY = box.getMinY();
|
float minY = box.getMinY();
|
||||||
float maxX = box.getMaxX();
|
float maxX = box.getMaxX();
|
||||||
float maxY = box.getMaxY();
|
float maxY = box.getMaxY();
|
||||||
pos(minX, maxY, 0F, xOff, yOff).tex(minU, maxV).rgba(color);
|
pos(minX, maxY, 0F, xOff, yOff).tex(minU, maxV).rgba(color);
|
||||||
pos(minX, minY, 0F, xOff, yOff).tex(minU, minV).rgba(color);
|
pos(minX, minY, 0F, xOff, yOff).tex(minU, minV).rgba(color);
|
||||||
pos(maxX, maxY, 0F, xOff, yOff).tex(maxU, maxV).rgba(color);
|
pos(maxX, maxY, 0F, xOff, yOff).tex(maxU, maxV).rgba(color);
|
||||||
@@ -212,4 +253,25 @@ public class UIRenderer implements IUIRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected record UIDraw(ShaderPipeline pipeline, SampledTexture texture, BufferResult result) {}
|
protected record UIDraw(ShaderPipeline pipeline, SampledTexture texture, BufferResult result) {}
|
||||||
|
|
||||||
|
private class WindowLayer {
|
||||||
|
final int layer;
|
||||||
|
IntStack stack = new IntArrayList();
|
||||||
|
int currentLayer = 1;
|
||||||
|
public WindowLayer(int layer) {
|
||||||
|
this.layer = layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void push() {
|
||||||
|
stack.push(currentLayer++);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pop() {
|
||||||
|
stack.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int currentLayer() {
|
||||||
|
return BitUtil.toInt(layer, stack.isEmpty() ? 0 : stack.top());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user