From 5fd1ff4904b778a4703c1665d777236de9d317c2 Mon Sep 17 00:00:00 2001 From: Speiger Date: Wed, 7 Aug 2024 20:23:26 +0200 Subject: [PATCH] Uploading latest changes --- TESTS_TO_DO.md | 3 +- build.gradle | 4 ++ gradle.properties | 2 +- .../speiger/src/coreengine/NewInputTest.java | 30 +++++---- .../coreengine/rendering/gui/font/Font.java | 14 ++-- .../rendering/gui/font/FontManager.java | 2 +- .../rendering/gui/font/FontTexture.java | 67 +++++++++---------- .../rendering/gui/font/glyth/Glyth.java | 4 +- .../gui/font/glyth/IGlythSheetInfo.java | 2 +- .../gui/font/glyth/MissingGlyth.java | 6 +- .../gui/font/providers/FreeTypeProvider.java | 23 +++++++ .../font/providers/STBTrueTypeProvider.java | 6 +- .../shader/uniform/base/TextureUniform.java | 25 ++----- .../tesselation/buffer/VertexBuilder.java | 5 ++ .../rendering/textures/base/BaseTexture.java | 3 +- .../textures/base/TextureMetadata.java | 10 +-- .../rendering/textures/custom/Drawable.java | 10 ++- .../textures/custom/DynamicTexture.java | 11 ++- .../textures/simple/DirectTexture.java | 4 +- .../textures/simple/SimpleTexture.java | 6 +- .../rendering/utils/GLFunctions.java | 45 +++++++------ .../rendering/utils/states/TextureState.java | 4 ++ .../values/textures/GLTextureFormat.java | 22 +++--- .../assets/base/font/roboto/font.json | 3 +- .../assets/base/shader/testGui/vertex.vs | 1 + .../assets/base/shader/testing/fragment.fs | 4 +- .../assets/base/shader/testing/vertex.vs | 2 +- 27 files changed, 171 insertions(+), 147 deletions(-) create mode 100644 src/main/java/speiger/src/coreengine/rendering/gui/font/providers/FreeTypeProvider.java diff --git a/TESTS_TO_DO.md b/TESTS_TO_DO.md index 15d3ce6..1c6a7f9 100644 --- a/TESTS_TO_DO.md +++ b/TESTS_TO_DO.md @@ -1,3 +1,4 @@ # Tests that should be done. -- Test starting animations with delays of each other to see if they act properly. \ No newline at end of file +- Test starting animations with delays of each other to see if they act properly. +- Reafactor the GL_TEXTURE_FORMAT because it's in desperate need of an refactor. \ No newline at end of file diff --git a/build.gradle b/build.gradle index 732fa41..a4ab7b5 100644 --- a/build.gradle +++ b/build.gradle @@ -62,6 +62,7 @@ dependencies { implementation "org.lwjgl:lwjgl-opengl" implementation "org.lwjgl:lwjgl-stb" implementation "org.lwjgl:lwjgl-nfd" + implementation "org.lwjgl:lwjgl-freetype" implementation "org.lwjgl:lwjgl-nanovg" implementation "org.lwjgl:lwjgl::$lwjglNatives" implementation "org.lwjgl:lwjgl-glfw::$lwjglNatives" @@ -70,8 +71,11 @@ dependencies { implementation "org.lwjgl:lwjgl-opengl::$lwjglNatives" implementation "org.lwjgl:lwjgl-stb::$lwjglNatives" implementation "org.lwjgl:lwjgl-nfd::$lwjglNatives" + implementation "org.lwjgl:lwjgl-freetype::$lwjglNatives" implementation "org.lwjgl:lwjgl-nanovg::$lwjglNatives" + + //Gson implementation 'com.google.code.gson:gson:2.8.6' diff --git a/gradle.properties b/gradle.properties index bb2f0a5..9b30e24 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ org.gradle.jvmargs=-Xmx2G -lwjglVersion = 3.3.3 +lwjglVersion = 3.3.4 lwjglNatives = natives-windows \ No newline at end of file diff --git a/src/main/java/speiger/src/coreengine/NewInputTest.java b/src/main/java/speiger/src/coreengine/NewInputTest.java index 96ac1b7..90bbdc0 100644 --- a/src/main/java/speiger/src/coreengine/NewInputTest.java +++ b/src/main/java/speiger/src/coreengine/NewInputTest.java @@ -69,7 +69,7 @@ public class NewInputTest { Joystick.INSTANCE.init(manager, bus); FileDrop.INSTANCE.init(bus); manager.addDevices(Mouse.INSTANCE, Keyboard.INSTANCE, Joystick.INSTANCE, FileDrop.INSTANCE); - Window window = manager.builder().title("Testing Engine").build(); + Window window = manager.builder().title("Testing Engine").antialis(16).build(); shaderTest.register(); guiShader.register(); assets.addListener(GLStateTracker.instance().shaders); @@ -82,6 +82,7 @@ public class NewInputTest { IFontProvider provider = STBTrueTypeProvider.create(AssetLocation.of("font/roboto/font.json"), assets); guiShader.get().proView.set(new Matrix4f().ortho(0, 0, window.width(), window.height(), 1000, -1000)); + guiShader.get().model.set(new Matrix4f().scale(1.1F)); int size = 512; int half = size >> 1; @@ -101,7 +102,7 @@ public class NewInputTest { // texture.bind(); Drawable drawable = new Drawable(GLTextureFormat.RGBA, half, half); drawable.fill(0, 0, half, half, 255, 255, 0, 255); - drawable.upload(base * 3, base * 3, base, base, base * 2, base * 2); + drawable.upload(texture.id(), base * 3, base * 3, base, base, base * 2, base * 2); drawable.close(); } else if(T.key() == GLFW.GLFW_KEY_Z) { @@ -114,7 +115,7 @@ public class NewInputTest { public Glyth bake(IGlythSheetInfo info) { int width = info.width(); int height = info.height(); - info.upload(half - (width >> 1), half - (height >> 1)); + info.upload(texture.id(), half - (width >> 1), half - (height >> 1)); System.out.println("Test2: "+width+", "+height); return null; } @@ -127,7 +128,7 @@ public class NewInputTest { public Glyth bake(IGlythSheetInfo info) { int width = info.width(); int height = info.height(); - info.upload(half - (width >> 1), half - (height >> 1)); + info.upload(texture.id(), half - (width >> 1), half - (height >> 1)); System.out.println("Test3: "+width+", "+height); return null; } @@ -144,7 +145,7 @@ public class NewInputTest { builder.pos(-0.5F, 0.5F, 0).tex(0F, 0F).rgba(-1).endVertex(); builder.pos(-0.5F, -0.5F, 0).tex(0F, 1F).rgba(-1).endVertex(); - Font font = fonts.createFont(18.5F); + Font font = fonts.createFont(18F, 4F); TestModel model = new TestModel(builder.getBytes()); TestModel[] guiModel = new TestModel[1]; List draws = new ObjectArrayList<>(); @@ -154,25 +155,24 @@ public class NewInputTest { System.out.println("Testing: "+V.length+" bytes, "+K.size()); })); + GLStateTracker tracker = GLStateTracker.instance(); GL11.glClearColor(0.2F, 0.55F, 0.66F, 1F); while(!window.shouldClose()) { GLFW.glfwPollEvents(); window.beginFrame(); - GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); - shaderTest.bind(); - shaderTest.get().texture.set(texture); - model.bindArray(); - GLStateTracker.drawArrays(GLMode.TRIANGLES.glValue(), 6); - model.unbindArray(); + GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); +// texture.bind(); +// shaderTest.bind(); +// model.bindArray(); +// GLStateTracker.drawArrays(GLMode.TRIANGLES.glValue(), 6); +// model.unbindArray(); guiModel[0].bindArray(); guiShader.bind(); for(GLDraw draw : draws) { -// System.out.println("Draw: "+draw.texture()+", "+draw.startVertex()+", "+draw.vertexCount()); - guiShader.get().texture.set(draw.texture()); + tracker.textures.bind(draw.texture()); GLStateTracker.drawArrays(GLMode.TRIANGLES.glValue(), draw.startVertex(), draw.vertexCount()); } guiModel[0].unbindArray(); - window.handleInput(); window.finishFrame(); try { Thread.sleep(100); } @@ -216,6 +216,7 @@ public class NewInputTest { int count = builder.size() - lastVertex; draws.add(new GLDraw(previousId, lastVertex, count)); callbacks.accept(draws, builder.getBytes()); + builder.close(); } } @@ -227,6 +228,7 @@ public class NewInputTest { public static class GuiShader extends SimpleShader { public TextureUniform texture = uniforms.addTexture("texture", 0); public Matrix4fUniform proView = uniforms.addMat("proViewMatrix", new Matrix4f()); + public Matrix4fUniform model = uniforms.addMat("modelmatrix", new Matrix4f()); public GuiShader(IAssetProvider provider) { super(provider, "gui_shader", AssetLocation.of("shader/testGui/vertex.vs"), AssetLocation.of("shader/testGui/fragment.fs"), "in_position", "in_tex", "in_color"); diff --git a/src/main/java/speiger/src/coreengine/rendering/gui/font/Font.java b/src/main/java/speiger/src/coreengine/rendering/gui/font/Font.java index 5390da4..62496de 100644 --- a/src/main/java/speiger/src/coreengine/rendering/gui/font/Font.java +++ b/src/main/java/speiger/src/coreengine/rendering/gui/font/Font.java @@ -63,13 +63,15 @@ public class Font { float maxX = glyth.right() + x; float maxY = glyth.bottom() + y; +// System.out.println("Test: MinX="+minX+", MinY="+minY+", MaxX="+maxX+", MaxY="+maxY+", MinU="+glyth.minU()+", MinV="+glyth.minV()+", MaxU="+glyth.maxU()+", MaxV="+glyth.maxV()); + IVertexBuilder builder = buffer.builderForTexture(glyth.texture()); - builder.pos(minX, minY, 0F).tex(glyth.minU(), glyth.maxV()).rgba(-1).endVertex(); - builder.pos(maxX, minY, 0F).tex(glyth.maxU(), glyth.maxV()).rgba(-1).endVertex(); - builder.pos(maxX, maxY, 0F).tex(glyth.maxU(), glyth.minV()).rgba(-1).endVertex(); - builder.pos(maxX, maxY, 0F).tex(glyth.maxU(), glyth.minV()).rgba(-1).endVertex(); - builder.pos(minX, maxY, 0F).tex(glyth.minU(), glyth.minV()).rgba(-1).endVertex(); - builder.pos(minX, minY, 0F).tex(glyth.minU(), glyth.maxV()).rgba(-1).endVertex(); + builder.pos(minX, minY, 0F).tex(glyth.minU(), glyth.minV()).rgba(-1).endVertex(); + builder.pos(maxX, minY, 0F).tex(glyth.maxU(), glyth.minV()).rgba(-1).endVertex(); + builder.pos(maxX, maxY, 0F).tex(glyth.maxU(), glyth.maxV()).rgba(-1).endVertex(); + builder.pos(maxX, maxY, 0F).tex(glyth.maxU(), glyth.maxV()).rgba(-1).endVertex(); + builder.pos(minX, maxY, 0F).tex(glyth.minU(), glyth.maxV()).rgba(-1).endVertex(); + builder.pos(minX, minY, 0F).tex(glyth.minU(), glyth.minV()).rgba(-1).endVertex(); } x += data.advance(); i += Character.charCount(codepoint); diff --git a/src/main/java/speiger/src/coreengine/rendering/gui/font/FontManager.java b/src/main/java/speiger/src/coreengine/rendering/gui/font/FontManager.java index 68bad1e..64a247a 100644 --- a/src/main/java/speiger/src/coreengine/rendering/gui/font/FontManager.java +++ b/src/main/java/speiger/src/coreengine/rendering/gui/font/FontManager.java @@ -23,7 +23,7 @@ import speiger.src.coreengine.rendering.gui.font.providers.STBTrueTypeProvider; import speiger.src.coreengine.utils.helpers.JsonUtil; public class FontManager extends SteppedReloadableAsset>> { - private static final int TEXTURE_SIZE = 2048; + private static final int TEXTURE_SIZE = 512; private static final AssetFilter FILTER = AssetFilter.json("font"); Map fonts = Object2ObjectMap.builder().linkedMap(); Map> fontParsers = Object2ObjectMap.builder().map(); diff --git a/src/main/java/speiger/src/coreengine/rendering/gui/font/FontTexture.java b/src/main/java/speiger/src/coreengine/rendering/gui/font/FontTexture.java index 8609c2b..00ab193 100644 --- a/src/main/java/speiger/src/coreengine/rendering/gui/font/FontTexture.java +++ b/src/main/java/speiger/src/coreengine/rendering/gui/font/FontTexture.java @@ -1,8 +1,10 @@ package speiger.src.coreengine.rendering.gui.font; -import org.lwjgl.system.MemoryUtil; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL45; import speiger.src.coreengine.assets.base.IAssetProvider; +import speiger.src.coreengine.math.MathUtils; import speiger.src.coreengine.rendering.gui.font.glyth.Glyth; import speiger.src.coreengine.rendering.gui.font.glyth.IGlythSheetInfo; import speiger.src.coreengine.rendering.textures.base.BaseTexture; @@ -16,10 +18,10 @@ import speiger.src.coreengine.rendering.utils.values.textures.GLTextureValue; public class FontTexture extends BaseTexture { private static final TextureMetadata COLOR = TextureMetadata.builder() - .externalFormat(GLTextureFormat.RGBA).internalFormat(GLTextureFormat.RGBA).dataFormat(GLDataType.UNSIGNED_BYTE).mipmapping(false) + .externalFormat(GLTextureFormat.RGBA).internalFormat(GLTextureFormat.RGBAI).dataFormat(GLDataType.UNSIGNED_BYTE).mipmapping(false) .arguement(GLTextureParameter.MIN_FILTER, GLTextureValue.NEAREST).arguement(GLTextureParameter.MAG_FILTER, GLTextureValue.NEAREST) .arguement(GLTextureParameter.WRAP_S, GLTextureValue.CLAMP_TO_EDGE).arguement(GLTextureParameter.WRAP_T, GLTextureValue.CLAMP_TO_EDGE).build(); - private static final TextureMetadata NO_COLOR = COLOR.copy().internalFormat(GLTextureFormat.LUMINANCE).externalFormat(GLTextureFormat.LUMINANCE).arguement(GLTextureParameter.SWIZZLE_RGBA, GLTextureValue.RED).build(); + private static final TextureMetadata NO_COLOR = COLOR.copy().internalFormat(GLTextureFormat.LUMINANCE).externalFormat(GLTextureFormat.R).specialarguments(FontTexture::swizzle).build(); boolean color; int bounds; @@ -33,36 +35,36 @@ public class FontTexture extends BaseTexture { } public static ITextureComponentFormat formatByColor(boolean colored) { - return colored ? GLTextureFormat.RGBA : GLTextureFormat.LUMINANCE; + return colored ? GLTextureFormat.RGBA : GLTextureFormat.R; } public static TextureMetadata metadataByColor(boolean colored) { return colored ? COLOR : NO_COLOR; } + private static void swizzle(int texture) { + GL45.glTextureParameterIiv(texture, GLTextureParameter.SWIZZLE_RGBA.glValue(), new int[]{GL11.GL_RED, GL11.GL_RED, GL11.GL_RED, GL11.GL_RED}); + } + @Override public void load(IAssetProvider provider) { createTexture(); TextureMetadata metadata = metadataByColor(color); - metadata.applyArguments(textureType()); - long allocate = MemoryUtil.nmemAlloc(bounds * bounds * formatByColor(color).components()); - ITextureComponentFormat format = formatByColor(color); - GLFunctions.upload2DImage(textureType(), 0, format, bounds, bounds, 0, format, GLDataType.UNSIGNED_BYTE, allocate); -// GLFunctions.upload2DImage(textureType(), 0, metadata, bounds, bounds, 0, allocate); - MemoryUtil.nmemFree(allocate); + metadata.applyArguments(id()); + GLFunctions.prepare2DImage(id(), 1, metadata, bounds, bounds); } public Glyth build(IGlythSheetInfo info) { if(color != info.isColored()) return null; Slot result = slot.insert(info); if(result != null) { - bind(); - info.upload(result.x, result.y); - float minU = (slot.x + 0.01F) / bounds; - float maxU = (slot.x - 0.01F + info.width()) / bounds; - float minV = (slot.y + 0.01F) / bounds; - float maxV = (slot.y - 0.01F + info.height()) / bounds; - return new Glyth(id(), minU, minV, maxU, maxV); + info.upload(id(), result.x, result.y); + float minU = (float)(result.x) / (float)bounds; + float maxU = (float)((result.x) + info.width()) / (float)bounds; + float minV = (float)(result.y) / (float)bounds; + float maxV = (float)((result.y) + info.height()) / (float)bounds; + System.out.println("Baking: MinU="+minU+", MinV="+minV+", MaxU="+maxU+", MaxV="+maxV+", "+result.x+", "+result.y); + return new Glyth(id(), minU, minV, maxU, maxV, info.left(), info.right(), info.top(), info.bottom()); } return null; } @@ -100,9 +102,17 @@ public class FontTexture extends BaseTexture { } int dw = width - iw; int dh = height - ih; - children = new Slot[dw > 0 && dh > 0 ? 3 : 2]; - children[0] = new Slot(x, y, iw, ih); - expandSlot(iw, ih, dw, dh); + children = new Slot[2]; + if(dw > dh) { + int offset = MathUtils.ceil(iw / 50F); + children[0] = new Slot(x, y, iw, height); + children[1] = new Slot(x + iw + offset, y, dw - offset, height); + } + else { + int offset = MathUtils.ceil(ih / 50F); + children[0] = new Slot(x, y, width, ih); + children[1] = new Slot(x, y + ih + offset, width, dh - offset); + } return children[0].insert(info); } for(int i = 0,m=children.length;i 0 && dh > 0) { - if(dw >= dh) { - children[1] = new Slot(x + rw, y, dw, rh); - children[2] = new Slot(x, y + rh, width, dh); - } - else { - children[1] = new Slot(x, y + rh, rw, dh); - children[2] = new Slot(x + rw, y, dw, height); - } - } - else if(dw == 0) children[1] = new Slot(x, y + rh, rw, dh); - else if(dh == 0) children[1] = new Slot(x + rw, y, dw, rh); - } - + @Override public String toString() { return "Slot[x="+x+", y="+y+", w="+width+", h="+height+"]"; diff --git a/src/main/java/speiger/src/coreengine/rendering/gui/font/glyth/Glyth.java b/src/main/java/speiger/src/coreengine/rendering/gui/font/glyth/Glyth.java index f5e09c3..e8d55fe 100644 --- a/src/main/java/speiger/src/coreengine/rendering/gui/font/glyth/Glyth.java +++ b/src/main/java/speiger/src/coreengine/rendering/gui/font/glyth/Glyth.java @@ -1,10 +1,10 @@ package speiger.src.coreengine.rendering.gui.font.glyth; -public record Glyth(int texture, float minU, float minV, float maxU, float maxV, int left, int right, int top, int bottom) { +public record Glyth(int texture, float minU, float minV, float maxU, float maxV, float left, float right, float top, float bottom) { public static final Glyth EMPTY = new Glyth(); private Glyth() { - this(-1, 0F, 0F, 0F, 0F, 0, 0, 0, 0); + this(-1, 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F); } public Glyth(int texture, float minU, float minV, float maxU, float maxV) { diff --git a/src/main/java/speiger/src/coreengine/rendering/gui/font/glyth/IGlythSheetInfo.java b/src/main/java/speiger/src/coreengine/rendering/gui/font/glyth/IGlythSheetInfo.java index 981e4fc..42a0fe1 100644 --- a/src/main/java/speiger/src/coreengine/rendering/gui/font/glyth/IGlythSheetInfo.java +++ b/src/main/java/speiger/src/coreengine/rendering/gui/font/glyth/IGlythSheetInfo.java @@ -7,7 +7,7 @@ public interface IGlythSheetInfo { public default float yOffset() { return 3F; } public float oversample(); public boolean isColored(); - public void upload(int x, int y); + public void upload(int texture, int x, int y); public default float left() { return xOffset(); } public default float right() { return xOffset() + width() / oversample(); } diff --git a/src/main/java/speiger/src/coreengine/rendering/gui/font/glyth/MissingGlyth.java b/src/main/java/speiger/src/coreengine/rendering/gui/font/glyth/MissingGlyth.java index 5340cb3..f13c104 100644 --- a/src/main/java/speiger/src/coreengine/rendering/gui/font/glyth/MissingGlyth.java +++ b/src/main/java/speiger/src/coreengine/rendering/gui/font/glyth/MissingGlyth.java @@ -41,10 +41,10 @@ public class MissingGlyth implements GlythData { @Override public int height() { return height; } @Override - public void upload(int x, int y) { + public void upload(int texture, int x, int y) { Drawable drawable = new Drawable(FontTexture.formatByColor(false), width, height); draw(drawable); - drawable.upload(x, y, 0, 0, width, height); + drawable.upload(texture, x, y, 0, 0, width, height); drawable.close(); } @Override @@ -58,7 +58,7 @@ public class MissingGlyth implements GlythData { private void draw(Drawable texture) { texture.fill(0, 0, width, height, 255); - int offset = MathUtils.ceil(width / 7.5F); + int offset = MathUtils.ceil(width / 5F); texture.fill(offset, offset, width - offset * 2, height - offset * 2, 0); } } diff --git a/src/main/java/speiger/src/coreengine/rendering/gui/font/providers/FreeTypeProvider.java b/src/main/java/speiger/src/coreengine/rendering/gui/font/providers/FreeTypeProvider.java new file mode 100644 index 0000000..70611f1 --- /dev/null +++ b/src/main/java/speiger/src/coreengine/rendering/gui/font/providers/FreeTypeProvider.java @@ -0,0 +1,23 @@ +package speiger.src.coreengine.rendering.gui.font.providers; + +import org.lwjgl.util.freetype.FreeType; + +import speiger.src.coreengine.rendering.gui.font.glyth.GlythData; + +public class FreeTypeProvider implements IFontProvider { + + public void test() { + + } + + @Override + public GlythData glythData(int codepoint, int style, float size, float oversample) { + return null; + } + + @Override + public void close() { + + } + +} diff --git a/src/main/java/speiger/src/coreengine/rendering/gui/font/providers/STBTrueTypeProvider.java b/src/main/java/speiger/src/coreengine/rendering/gui/font/providers/STBTrueTypeProvider.java index 89c759a..5684deb 100644 --- a/src/main/java/speiger/src/coreengine/rendering/gui/font/providers/STBTrueTypeProvider.java +++ b/src/main/java/speiger/src/coreengine/rendering/gui/font/providers/STBTrueTypeProvider.java @@ -22,7 +22,6 @@ import speiger.src.coreengine.rendering.gui.font.glyth.GlythData; import speiger.src.coreengine.rendering.gui.font.glyth.GlythData.EmptyGlythData; import speiger.src.coreengine.rendering.gui.font.glyth.IGlythSheetInfo; import speiger.src.coreengine.rendering.textures.custom.Drawable; -import speiger.src.coreengine.rendering.utils.GLStateTracker; import speiger.src.coreengine.utils.helpers.JsonUtil; public class STBTrueTypeProvider implements IFontProvider { @@ -203,11 +202,10 @@ public class STBTrueTypeProvider implements IFontProvider { @Override public boolean isColored() { return false; } @Override - public void upload(int x, int y) { - System.out.println("Testing: "+GLStateTracker.instance().textures.getTextureId(0)); + public void upload(int texture, int x, int y) { Drawable drawable = new Drawable(FontTexture.formatByColor(false), width, height); drawable.drawFont(owner.info, glyth, owner.xOff, owner.yOff, 0, 0, width, height, scale, scale); - drawable.upload(x, y, 0, 0, width, height); + drawable.upload(texture, x, y, 0, 0, width, height); drawable.close(); } }); diff --git a/src/main/java/speiger/src/coreengine/rendering/shader/uniform/base/TextureUniform.java b/src/main/java/speiger/src/coreengine/rendering/shader/uniform/base/TextureUniform.java index 624e770..11d00e0 100644 --- a/src/main/java/speiger/src/coreengine/rendering/shader/uniform/base/TextureUniform.java +++ b/src/main/java/speiger/src/coreengine/rendering/shader/uniform/base/TextureUniform.java @@ -2,28 +2,20 @@ package speiger.src.coreengine.rendering.shader.uniform.base; import org.lwjgl.opengl.GL41; -import speiger.src.coreengine.rendering.shader.uniform.IAutoUniform; import speiger.src.coreengine.rendering.shader.uniform.Uniform; -import speiger.src.coreengine.rendering.textures.base.ITexture; import speiger.src.coreengine.rendering.utils.AllocationTracker; -import speiger.src.coreengine.rendering.utils.GLStateTracker; -public class TextureUniform extends Uniform implements IAutoUniform { - final int unit; - int value; +public class TextureUniform extends Uniform { + int unit; public TextureUniform(String name, int unit) { super(name); this.unit = unit; } - public TextureUniform set(ITexture texture) { - return set(texture.id()); - } - - public TextureUniform set(int id) { - if(this.value != id) { - this.value = id; + public TextureUniform set(int unit) { + if(this.unit != unit) { + this.unit = unit; update(); } return this; @@ -31,12 +23,7 @@ public class TextureUniform extends Uniform implements IAutoUniform { @Override protected void processChanges(int programId, int location) { - GL41.glProgramUniform1i(programId, location, value); + GL41.glProgramUniform1i(programId, location, unit); AllocationTracker.INSTANCE.addGPUBytes(4L); } - - @Override - public void bind(int programId) { - GLStateTracker.instance().textures.bind(unit, value); - } } diff --git a/src/main/java/speiger/src/coreengine/rendering/tesselation/buffer/VertexBuilder.java b/src/main/java/speiger/src/coreengine/rendering/tesselation/buffer/VertexBuilder.java index f3e8db1..e6da496 100644 --- a/src/main/java/speiger/src/coreengine/rendering/tesselation/buffer/VertexBuilder.java +++ b/src/main/java/speiger/src/coreengine/rendering/tesselation/buffer/VertexBuilder.java @@ -26,6 +26,11 @@ public class VertexBuilder implements IVertexBuilder { this.buffer = buffer; } + public void close() { + MemoryUtil.memFree(buffer); + buffer = null; + } + public VertexBuilder start(GLMode mode, VertexFormat format) { this.mode = mode; this.format = format; diff --git a/src/main/java/speiger/src/coreengine/rendering/textures/base/BaseTexture.java b/src/main/java/speiger/src/coreengine/rendering/textures/base/BaseTexture.java index cb8da6d..0224277 100644 --- a/src/main/java/speiger/src/coreengine/rendering/textures/base/BaseTexture.java +++ b/src/main/java/speiger/src/coreengine/rendering/textures/base/BaseTexture.java @@ -16,8 +16,7 @@ public abstract class BaseTexture implements ITexture { } protected void createTexture() { - this.id = GLFunctions.createTexture(); - bind(); + this.id = GLFunctions.createTexture(textureType()); } protected IGLValue textureType() { diff --git a/src/main/java/speiger/src/coreengine/rendering/textures/base/TextureMetadata.java b/src/main/java/speiger/src/coreengine/rendering/textures/base/TextureMetadata.java index e6eae97..c922e81 100644 --- a/src/main/java/speiger/src/coreengine/rendering/textures/base/TextureMetadata.java +++ b/src/main/java/speiger/src/coreengine/rendering/textures/base/TextureMetadata.java @@ -15,20 +15,20 @@ public class TextureMetadata { int internalFormat; int externalFormat; int dataFormat; - boolean isSTBData = true; - boolean mipmapping = true; + boolean isSTBData = false; + boolean mipmapping = false; LongList arguments = new LongArrayList(); IntConsumer specialarguments; private TextureMetadata() {} - public void applyArguments(IGLValue textureType) { + public void applyArguments(int texture) { for(int i = 0,m=arguments.size();i 1; - case GL11.GL_LUMINANCE_ALPHA -> 2; + case GL30.GL_R8, GL11.GL_RED -> 1; + case GL11.GL_LUMINANCE8_ALPHA8, GL30.GL_RG -> 2; case GL11.GL_RGB -> 3; case GL11.GL_RGBA -> 4; default -> 0; diff --git a/src/main/resources/assets/base/font/roboto/font.json b/src/main/resources/assets/base/font/roboto/font.json index 42b96e6..a212135 100644 --- a/src/main/resources/assets/base/font/roboto/font.json +++ b/src/main/resources/assets/base/font/roboto/font.json @@ -2,8 +2,7 @@ "type": "stb-ttf", "regular": { "file": "font/roboto/Roboto-Medium.ttf", - "size": 18.5, - "oversample": 3, + "oversample": 1, "shadowOffset": 1, "skip": "", "offset": { "x": 0, "y": 0 } diff --git a/src/main/resources/assets/base/shader/testGui/vertex.vs b/src/main/resources/assets/base/shader/testGui/vertex.vs index 743718a..d6f9acd 100644 --- a/src/main/resources/assets/base/shader/testGui/vertex.vs +++ b/src/main/resources/assets/base/shader/testGui/vertex.vs @@ -8,6 +8,7 @@ out vec4 pass_color; out vec2 pass_tex; uniform mat4 proViewMatrix; +uniform mat4 modelmatrix; void main() { diff --git a/src/main/resources/assets/base/shader/testing/fragment.fs b/src/main/resources/assets/base/shader/testing/fragment.fs index 70eb167..a7b79e4 100644 --- a/src/main/resources/assets/base/shader/testing/fragment.fs +++ b/src/main/resources/assets/base/shader/testing/fragment.fs @@ -1,11 +1,11 @@ -#version 330 +#version 420 in vec4 pass_color; in vec2 pass_tex; out vec4 frag_color; -uniform sampler2D texture; +layout(binding = 0) uniform sampler2D texture; void main() { diff --git a/src/main/resources/assets/base/shader/testing/vertex.vs b/src/main/resources/assets/base/shader/testing/vertex.vs index 392ba50..20e3cf4 100644 --- a/src/main/resources/assets/base/shader/testing/vertex.vs +++ b/src/main/resources/assets/base/shader/testing/vertex.vs @@ -1,4 +1,4 @@ -#version 330 +#version 420 layout(location = 0) in vec3 in_position; layout(location = 1) in vec2 in_tex;