diff --git a/src/main/java/dev/hilligans/ourcraft/ClientMain.java b/src/main/java/dev/hilligans/ourcraft/ClientMain.java index 2d57a502..1ada1230 100644 --- a/src/main/java/dev/hilligans/ourcraft/ClientMain.java +++ b/src/main/java/dev/hilligans/ourcraft/ClientMain.java @@ -29,6 +29,7 @@ public static Client getClient() { public static void main(String[] args) throws IOException { startTime = System.currentTimeMillis(); argumentContainer = new ArgumentContainer(args); + System.out.println(STR."Starting client with PID \{ProcessHandle.current().pid()}"); gameInstance.handleArgs(args); gameInstance.side = Side.CLIENT; gameInstance.loadContent(); diff --git a/src/main/java/dev/hilligans/ourcraft/block/blocktypes/PlantBlock.java b/src/main/java/dev/hilligans/ourcraft/block/blocktypes/PlantBlock.java index 54864b81..98362742 100644 --- a/src/main/java/dev/hilligans/ourcraft/block/blocktypes/PlantBlock.java +++ b/src/main/java/dev/hilligans/ourcraft/block/blocktypes/PlantBlock.java @@ -16,6 +16,6 @@ public PlantBlock(String name, BlockProperties blockProperties) { @Override public void renderItem(MatrixStack matrixStack, int x, int y, int size, ItemStack itemStack) { - Renderer.renderItem(matrixStack,x,y,size,blockProperties.blockTextureManager); + Renderer.renderItem(matrixStack,x,y,size); } } diff --git a/src/main/java/dev/hilligans/ourcraft/client/Client.java b/src/main/java/dev/hilligans/ourcraft/client/Client.java index 79a7970c..35d964bc 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/Client.java +++ b/src/main/java/dev/hilligans/ourcraft/client/Client.java @@ -107,6 +107,7 @@ public Client(GameInstance gameInstance, ArgumentContainer argumentContainer) { public Client setGraphicsEngine(IGraphicsEngine graphicsEngine) { if(graphicsEngine != null) { + this.graphicsEngine = graphicsEngine; if(graphicsEngine instanceof VulkanEngine engine) { engine.client = this; diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/Renderer.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/Renderer.java index 35952fd6..5e062f30 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/Renderer.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/Renderer.java @@ -5,7 +5,6 @@ import dev.hilligans.ourcraft.client.rendering.graphics.RenderWindow; import dev.hilligans.ourcraft.client.rendering.newrenderer.TextAtlas; import dev.hilligans.ourcraft.item.ItemStack; -import dev.hilligans.ourcraft.client.rendering.world.managers.TextureManager; import dev.hilligans.ourcraft.client.rendering.world.managers.VAOManager; import dev.hilligans.ourcraft.Ourcraft; import dev.hilligans.ourcraft.util.Settings; @@ -46,13 +45,14 @@ public static void renderBlockItem(MatrixStack matrixStack, int x, int y, int si */ } - public static void renderItem(MatrixStack matrixStack, int x, int y, int size, TextureManager textureManager) { + public static void renderItem(MatrixStack matrixStack, int x, int y, int size) { size *= 2; size -= Settings.guiSize * 2; x += Settings.guiSize; y += Settings.guiSize; //matrixStack.applyTransformation(ClientMain.getClient().shaderManager.shaderProgram); //glUseProgram(ClientMain.getClient().shaderManager.shaderProgram); + /* glDisable(GL_DEPTH_TEST); int id = textureManager.getTextureId(); float minX = TextAtlas.getMinX(id); @@ -67,9 +67,12 @@ public static void renderItem(MatrixStack matrixStack, int x, int y, int size, T glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_INT,0); VAOManager.destroyBuffer(vao); glEnable(GL_DEPTH_TEST); + + */ } - public static void renderItem(RenderWindow window, MatrixStack matrixStack, int x, int y, int size, TextureManager textureManager) { + public static void renderItem(RenderWindow window, MatrixStack matrixStack, int x, int y, int size) { + /* size *= 2; size -= Settings.guiSize * 2; x += Settings.guiSize; @@ -85,5 +88,6 @@ public static void renderItem(RenderWindow window, MatrixStack matrixStack, int VertexMesh mesh = new VertexMesh(Ourcraft.position_color_texture); mesh.addData(indices, vertices); //window.getGraphicsEngine().getDefaultImpl().drawAndDestroyMesh(window, null, matrixStack, mesh, textureManager.getTextureId(), 0); + */ } } diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/VertexMesh.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/VertexMesh.java index cf89e860..4f4f6096 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/VertexMesh.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/VertexMesh.java @@ -22,6 +22,7 @@ public class VertexMesh implements IAllocator { public IntBuffer indices; public FloatBuffer vertices; + public int elementSize = 4; public IAllocator allocator; diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderPipeline.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderPipeline.java index 77597c1f..37b0d3e2 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderPipeline.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderPipeline.java @@ -3,6 +3,7 @@ import dev.hilligans.ourcraft.client.Client; import dev.hilligans.ourcraft.client.MatrixStack; import dev.hilligans.ourcraft.client.rendering.graphics.api.GraphicsContext; +import dev.hilligans.ourcraft.client.rendering.graphics.api.IGraphicsElement; import dev.hilligans.ourcraft.client.rendering.graphics.api.IGraphicsEngine; import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.mod.handler.content.ModContent; @@ -10,7 +11,7 @@ import java.util.ArrayList; -public class RenderPipeline implements IRegistryElement { +public class RenderPipeline implements IRegistryElement, IGraphicsElement { public String name; public ModContent modContent; @@ -107,4 +108,18 @@ public String toString() { ", renderTasks=" + renderTasks + '}'; } + + @Override + public void load(GameInstance gameInstance, IGraphicsEngine graphicsEngine, GraphicsContext graphicsContext) { + for(RenderTask renderTask : renderTasks) { + renderTask.load(gameInstance, graphicsEngine, graphicsContext); + } + } + + @Override + public void cleanup(GameInstance gameInstance, IGraphicsEngine graphicsEngine, GraphicsContext graphicsContext) { + for(RenderTask renderTask : renderTasks) { + renderTask.cleanup(gameInstance, graphicsEngine, graphicsContext); + } + } } diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderTask.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderTask.java index 5cfbf494..830bfa97 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderTask.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderTask.java @@ -1,11 +1,13 @@ package dev.hilligans.ourcraft.client.rendering.graphics; +import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.client.Client; import dev.hilligans.ourcraft.client.MatrixStack; import dev.hilligans.ourcraft.client.rendering.graphics.api.GraphicsContext; +import dev.hilligans.ourcraft.client.rendering.graphics.api.IGraphicsElement; import dev.hilligans.ourcraft.client.rendering.graphics.api.IGraphicsEngine; -public abstract class RenderTask { +public abstract class RenderTask implements IGraphicsElement { protected String identifierName; @@ -30,4 +32,10 @@ public RenderTask setNameIdentifierName(String name) { public String getIdentifierName() { return identifierName; } + + @Override + public void load(GameInstance gameInstance, IGraphicsEngine graphicsEngine, GraphicsContext graphicsContext) {} + + @Override + public void cleanup(GameInstance gameInstance, IGraphicsEngine graphicsEngine, GraphicsContext graphicsContext) {} } diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderWindow.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderWindow.java index b4e27783..a202b893 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderWindow.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderWindow.java @@ -83,7 +83,7 @@ public void queueRenderPipeline(String name) { public abstract boolean shouldClose(); - public void swapBuffers() { + public void swapBuffers(GraphicsContext graphicsContext) { if(queuedPipeline != null) { setRenderPipeline(queuedPipeline); queuedPipeline = null; diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/api/IDefaultEngineImpl.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/api/IDefaultEngineImpl.java index d184b94d..5547c36a 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/api/IDefaultEngineImpl.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/api/IDefaultEngineImpl.java @@ -62,6 +62,8 @@ default long createTexture(Q graphicsContext, Image image) { void clearFBO(Q graphicsContext, Vector4f clearColor); + void setScissor(Q graphicsContext, int x, int y, int width, int height); + default void drawMesh(Object graphicsContext, MatrixStack matrixStack, long meshID, long indicesIndex, int length) { drawMesh((Q) graphicsContext, matrixStack, meshID, indicesIndex, length); } @@ -150,4 +152,12 @@ default long getBoundProgram(Object graphicsContext) { default void clearFBO(Object graphicsContext, Vector4f clearColor) { clearFBO((Q)graphicsContext, clearColor); } + + default void setScissor(Object graphicsContext, int x, int y, int width, int height) { + setScissor((Q)graphicsContext, x, y, width, height); + } + + default void defaultScissor(Object graphicsContext, RenderWindow renderWindow) { + setScissor(graphicsContext, 0, 0, renderWindow.getWindowWidth(), renderWindow.getWindowHeight()); + } } diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/api/IGraphicsEngine.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/api/IGraphicsEngine.java index 79ad6574..99dedd2d 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/api/IGraphicsEngine.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/api/IGraphicsEngine.java @@ -49,7 +49,7 @@ default Runnable createRenderLoop(GameInstance gameInstance, RenderWindow window render(window, graphicsContext); } try (var $2 = section.startSection("swapBuffers")) { - window.swapBuffers(); + window.swapBuffers(graphicsContext); } } } diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/fixedfunctiongl/FixedFunctionGLDefaultImpl.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/fixedfunctiongl/FixedFunctionGLDefaultImpl.java index fc6d85af..1e1a7ca9 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/fixedfunctiongl/FixedFunctionGLDefaultImpl.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/fixedfunctiongl/FixedFunctionGLDefaultImpl.java @@ -201,6 +201,11 @@ public void clearFBO(GraphicsContext graphicsContext, Vector4f clearColor) { } + @Override + public void setScissor(GraphicsContext graphicsContext, int x, int y, int width, int height) { + + } + private int getGLPrimitive(int type) { return type + 0x1400; } diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/fixedfunctiongl/FixedFunctionGLWindow.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/fixedfunctiongl/FixedFunctionGLWindow.java index 0ad27e5e..67a57301 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/fixedfunctiongl/FixedFunctionGLWindow.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/fixedfunctiongl/FixedFunctionGLWindow.java @@ -1,6 +1,7 @@ package dev.hilligans.ourcraft.client.rendering.graphics.fixedfunctiongl; import dev.hilligans.ourcraft.client.Client; +import dev.hilligans.ourcraft.client.rendering.graphics.api.GraphicsContext; import dev.hilligans.ourcraft.client.rendering.graphics.implementations.FreeCamera; import dev.hilligans.ourcraft.client.rendering.graphics.RenderWindow; @@ -46,7 +47,7 @@ public boolean shouldClose() { } @Override - public void swapBuffers() { + public void swapBuffers(GraphicsContext graphicsContext) { glfwSwapBuffers(window); client.rendering = false; glfwPollEvents(); diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/implementations/splitwindows/FloatingWindow.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/implementations/splitwindows/FloatingWindow.java index 784904a4..3eb486aa 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/implementations/splitwindows/FloatingWindow.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/implementations/splitwindows/FloatingWindow.java @@ -1,6 +1,7 @@ package dev.hilligans.ourcraft.client.rendering.graphics.implementations.splitwindows; import dev.hilligans.ourcraft.client.Client; +import dev.hilligans.ourcraft.client.rendering.graphics.api.GraphicsContext; import dev.hilligans.ourcraft.client.rendering.graphics.api.IGraphicsEngine; import dev.hilligans.ourcraft.client.rendering.graphics.RenderWindow; @@ -35,7 +36,7 @@ public boolean shouldClose() { } @Override - public void swapBuffers() { + public void swapBuffers(GraphicsContext graphicsContext) { } diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/implementations/splitwindows/SplitWindow.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/implementations/splitwindows/SplitWindow.java index b00caec2..d4f5e7ea 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/implementations/splitwindows/SplitWindow.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/implementations/splitwindows/SplitWindow.java @@ -43,9 +43,9 @@ public boolean shouldClose() { } @Override - public void swapBuffers() { - super.swapBuffers(); - baseWindow.swapBuffers(); + public void swapBuffers(GraphicsContext graphicsContext) { + super.swapBuffers(graphicsContext); + baseWindow.swapBuffers(graphicsContext); } @Override diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/implementations/splitwindows/SubWindow.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/implementations/splitwindows/SubWindow.java index fe4d935f..a9ec4638 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/implementations/splitwindows/SubWindow.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/implementations/splitwindows/SubWindow.java @@ -31,8 +31,8 @@ public long getTexture() { } @Override - public void swapBuffers() { - super.swapBuffers(); + public void swapBuffers(GraphicsContext graphicsContext) { + super.swapBuffers(graphicsContext); long t = fbo1; fbo1 = fbo2; fbo2 = t; diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/nuklear/NuklearLayout.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/nuklear/NuklearLayout.java index f88e4f2d..d5567007 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/nuklear/NuklearLayout.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/nuklear/NuklearLayout.java @@ -17,6 +17,7 @@ import java.nio.IntBuffer; import static org.lwjgl.nuklear.Nuklear.*; +import static org.lwjgl.opengl.GL11.glScissor; import static org.lwjgl.system.MemoryStack.stackPush; import static org.lwjgl.system.MemoryUtil.*; @@ -42,8 +43,6 @@ protected NuklearLayout setup() { nk_init(ctx, ALLOCATOR, null); nk_buffer_init(cmds, ALLOCATOR, 1024); nk_style_set_font(ctx, engine.default_font); - - layout(ctx, width, height); return this; } @@ -51,7 +50,8 @@ protected NuklearLayout setup() { public void drawLayout(RenderWindow renderWindow, GraphicsContext graphicsContext, IGraphicsEngine engine, MatrixStack matrixStack, Client client) { int AA = NK_ANTI_ALIASING_ON; - IDefaultEngineImpl impl = engine.getDefaultImpl(); + IDefaultEngineImpl impl = engine.getDefaultImpl(); + layout(ctx, width, height); ByteBuffer vertices; ByteBuffer elements; @@ -70,8 +70,8 @@ public void drawLayout(RenderWindow renderWindow, GraphicsContext graphicsContex .line_AA(AA); // setup buffers to load vertices and elements - NkBuffer vbuf = NkBuffer.malloc(stack); - NkBuffer ebuf = NkBuffer.malloc(stack); + NkBuffer vbuf = NkBuffer.calloc(stack); + NkBuffer ebuf = NkBuffer.calloc(stack); nk_buffer_init(vbuf, ALLOCATOR, 1024); nk_buffer_init(ebuf, ALLOCATOR, 1024); @@ -93,39 +93,42 @@ public void drawLayout(RenderWindow renderWindow, GraphicsContext graphicsContex } catch (Exception e) { throw new RuntimeException("Failed to render nk layout", e); } - if(vertices == null) { + if (vertices == null) { throw new NullPointerException("vertex buffer is null"); } - if(elements == null) { + if (elements == null) { throw new NullPointerException("index buffer is null"); } //glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); //glUnmapBuffer(GL_ARRAY_BUFFER); VertexMesh vertexMesh = new VertexMesh(this.engine.vertexFormat).addData(elements, vertices); + vertexMesh.elementSize = 2; long mesh = impl.createMesh(graphicsContext, vertexMesh); // iterate over and execute each draw command - //float fb_scale_x = (float) display_width / (float) width; - //float fb_scale_y = (float) display_height / (float) height; + float fb_scale_x = (float) renderWindow.getWindowWidth() / (float) width; + float fb_scale_y = (float) renderWindow.getWindowHeight() / (float) height; long offset = NULL; for (NkDrawCommand cmd = nk__draw_begin(ctx, cmds); cmd != null; cmd = nk__draw_next(cmd, cmds, ctx)) { if (cmd.elem_count() == 0) { continue; } + //System.out.println(cmd.elem_count()); impl.bindTexture(graphicsContext, cmd.texture().id()); + //glBindTexture(GL_TEXTURE_2D, cmd.texture().id()); + NkRect rect = cmd.clip_rect(); + int x = (int) (rect.x() * fb_scale_x); + int y = (int) ((height - (int) (rect.y() + rect.h())) * fb_scale_y); + int width = (int) (rect.w() * fb_scale_x); + int height = (int) (rect.h() * fb_scale_y); + impl.setScissor(graphicsContext, x, y, width, height); impl.drawMesh(graphicsContext, matrixStack, mesh, offset, cmd.elem_count()); - //glBindTexture(GL_TEXTURE_2D, cmd.texture().id()); - //glScissor( - // (int) (cmd.clip_rect().x() * fb_scale_x), - // (int) ((height - (int) (cmd.clip_rect().y() + cmd.clip_rect().h())) * fb_scale_y), - // (int) (cmd.clip_rect().w() * fb_scale_x), - // (int) (cmd.clip_rect().h() * fb_scale_y) - //); //glDrawElements(GL_TRIANGLES, cmd.elem_count(), GL_UNSIGNED_SHORT, offset); - offset += cmd.elem_count() * 2; + offset += cmd.elem_count() * 2L; } + impl.defaultScissor(graphicsContext, renderWindow); nk_clear(ctx); nk_buffer_clear(cmds); } @@ -139,10 +142,9 @@ void layout(NkContext ctx, int x, int y) { "Demo", nk_rect(x, y, 230, 250, rect), NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE | NK_WINDOW_MINIMIZABLE | NK_WINDOW_TITLE)) { - nk_label(ctx, "some rando text", NK_LEFT); - } + // nk_label(ctx, "some rando text", NK_LEFT); + - /*{ nk_layout_row_static(ctx, 30, 80, 1); if (nk_button_label(ctx, "button")) { System.out.println("button pressed"); @@ -175,7 +177,6 @@ void layout(NkContext ctx, int x, int y) { } } - */ nk_end(ctx); } } diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenGLEngine.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenGLEngine.java index 5fed705f..368e384e 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenGLEngine.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenGLEngine.java @@ -8,7 +8,9 @@ import dev.hilligans.ourcraft.client.rendering.screens.JoinScreen; import dev.hilligans.ourcraft.data.primitives.Tuple; import dev.hilligans.ourcraft.util.Logger; +import dev.hilligans.ourcraft.util.sections.ISection; import dev.hilligans.ourcraft.util.sections.ProfiledSection; +import dev.hilligans.ourcraft.util.sections.SteppingSection; import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GL43; import org.lwjgl.opengl.GLDebugMessageCallback; @@ -142,7 +144,7 @@ public GraphicsContext getGraphicsContext() { if(profiling) { return new GraphicsContext().setSection(new ProfiledSection().setMonitorName("loop")); } - return new GraphicsContext(); + return new GraphicsContext().setSection(ISection.getSection(client.argumentContainer.getString("--clientSection", "empty"))); } @Override diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenGLWindow.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenGLWindow.java index 38ad3b0e..0ec1b259 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenGLWindow.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenGLWindow.java @@ -2,6 +2,7 @@ import dev.hilligans.ourcraft.client.Client; import dev.hilligans.ourcraft.client.input.key.MouseHandler; +import dev.hilligans.ourcraft.client.rendering.graphics.api.GraphicsContext; import dev.hilligans.ourcraft.client.rendering.graphics.implementations.FreeCamera; import dev.hilligans.ourcraft.client.rendering.graphics.RenderWindow; import dev.hilligans.ourcraft.client.ScreenShot; @@ -56,10 +57,12 @@ public boolean shouldClose() { } @Override - public void swapBuffers() { - super.swapBuffers(); - glfwSwapInterval(0); - glfwSwapBuffers(window); + public void swapBuffers(GraphicsContext graphicsContext) { + super.swapBuffers(graphicsContext); + try(var $ = graphicsContext.getSection().startSection("glfw_swap_buffers")) { + glfwSwapInterval(0); + glfwSwapBuffers(window); + } client.rendering = false; client.soundEngine.tick(); if(client.screenShot) { diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenglDefaultImpl.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenglDefaultImpl.java index 46576166..fee49d97 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenglDefaultImpl.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenglDefaultImpl.java @@ -87,7 +87,7 @@ public long createMesh(GraphicsContext graphicsContext, VertexMesh mesh) { mesh.destroy(); meshReferences.put(VAO, mesh); - meshData.put(VAO, new Tuple<>(GL_TRIANGLES, GL_UNSIGNED_INT)); + meshData.put(VAO, new Tuple<>(GL_TRIANGLES, mesh.elementSize == 4 ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT)); vertexArrayObjects.put(VAO, ((long)VBO << 32) | (long)EBO); return VAO; } @@ -314,6 +314,11 @@ public void clearFBO(GraphicsContext graphicsContext, Vector4f clearColor) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } + @Override + public void setScissor(GraphicsContext graphicsContext, int x, int y, int width, int height) { + glScissor(x, y, width, height); + } + @Override public void close() { for(int texture : textureTypes.keySet()) { diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/tasks/SplitWindowRenderTask.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/tasks/SplitWindowRenderTask.java index 28159911..5daddd11 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/tasks/SplitWindowRenderTask.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/tasks/SplitWindowRenderTask.java @@ -57,7 +57,7 @@ public void draw(RenderWindow window, GraphicsContext graphicsContext, IGraphics engine.getDefaultImpl().bindPipeline(graphicsContext, shaderSource.program); engine.getDefaultImpl().bindTexture(graphicsContext, subWindow.getTexture()); engine.getDefaultImpl().drawAndDestroyMesh(graphicsContext, screenStack, mesh); - subWindow.swapBuffers(); + subWindow.swapBuffers(graphicsContext); } } }; diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/tasks/WorldRenderTask.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/tasks/WorldRenderTask.java index 9572c478..aa1a6f30 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/tasks/WorldRenderTask.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/tasks/WorldRenderTask.java @@ -42,7 +42,6 @@ public WorldRenderTask() { @Override public RenderTask getDefaultTask() { - IThreeDContainer meshes = new EmptyContainer<>(); return new RenderTask() { @@ -50,7 +49,6 @@ public RenderTask getDefaultTask() { public void draw(RenderWindow window, GraphicsContext graphicsContext, IGraphicsEngine engine, Client client, MatrixStack worldStack, MatrixStack screenStack, float delta) { int a = 0; - IWorld world = client.newClientWorld; //engine.getDefaultImpl().setState(window, graphicsContext, new PipelineState().setDepth(true)); Vector3d pos = window.camera.getSavedPosition(); diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/vulkan/VulkanDefaultImpl.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/vulkan/VulkanDefaultImpl.java index 71d2fbec..d4f7d548 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/vulkan/VulkanDefaultImpl.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/vulkan/VulkanDefaultImpl.java @@ -249,6 +249,11 @@ public void clearFBO(VulkanBaseGraphicsContext graphicsContext, Vector4f clearCo } + @Override + public void setScissor(VulkanBaseGraphicsContext graphicsContext, int x, int y, int width, int height) { + //vkCmdSetScissor(); + } + public void submitShader(String path, String modID, LogicalDevice device, int bit) { synchronized (shaderCache) { if(!shaderCache.containsKey(path)) { diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/vulkan/VulkanWindow.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/vulkan/VulkanWindow.java index 454766da..9b17a5e7 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/vulkan/VulkanWindow.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/vulkan/VulkanWindow.java @@ -2,6 +2,7 @@ import dev.hilligans.ourcraft.client.Client; import dev.hilligans.ourcraft.client.input.InputHandler; +import dev.hilligans.ourcraft.client.rendering.graphics.api.GraphicsContext; import dev.hilligans.ourcraft.client.rendering.graphics.api.IGraphicsEngine; import dev.hilligans.ourcraft.client.rendering.graphics.implementations.FreeCamera; import dev.hilligans.ourcraft.client.rendering.graphics.RenderWindow; @@ -199,7 +200,7 @@ public boolean shouldClose() { } @Override - public void swapBuffers() { + public void swapBuffers(GraphicsContext graphicsContext) { windowRenderer.present(context.bufferIndex); glfwPollEvents(); //startDrawing(); diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/newrenderer/BlockModel.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/newrenderer/BlockModel.java index 39d49988..b2d98526 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/newrenderer/BlockModel.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/newrenderer/BlockModel.java @@ -2,7 +2,6 @@ import dev.hilligans.ourcraft.block.Block; import dev.hilligans.ourcraft.client.rendering.world.managers.BlockTextureManager; -import dev.hilligans.ourcraft.client.rendering.world.managers.TextureManager; import dev.hilligans.ourcraft.Ourcraft; import dev.hilligans.ourcraft.save.WorldLoader; import org.joml.Vector3f; @@ -118,16 +117,16 @@ private void modifyData(float[] data, int swapMode, boolean negateX, boolean neg } @Override - public void addData(PrimitiveBuilder primitiveBuilder, TextureManager textureManager, int side, float size, Vector3f offset, int rotX, int rotY) { + public void addData(PrimitiveBuilder primitiveBuilder, BlockTextureManager textureManager, int side, float size, Vector3f offset, int rotX, int rotY) { rotX = 0; rotY = 0; float[] vertices = getVertices(side,rotX,rotY); int[] indices = this.indices[side]; if(vertices != null) { - if(textureManager instanceof BlockTextureManager) { + if(textureManager != null) { float color = getSideColor(side, rotX, rotY); //float[] vals = new float[vertices.length]; - int id = ((BlockTextureManager) textureManager).textures[side]; + int id = textureManager.textures[side]; float startX = TextAtlas.getMinX(id); float startY = TextAtlas.getMinY(id); diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/newrenderer/IModel.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/newrenderer/IModel.java index af633c80..50ecdae0 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/newrenderer/IModel.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/newrenderer/IModel.java @@ -1,6 +1,6 @@ package dev.hilligans.ourcraft.client.rendering.newrenderer; -import dev.hilligans.ourcraft.client.rendering.world.managers.TextureManager; +import dev.hilligans.ourcraft.client.rendering.world.managers.BlockTextureManager; import org.joml.Vector3f; public interface IModel { @@ -14,7 +14,7 @@ default float[] getVertices(int side, int rotX, int rotY) { default int[] getIndices(int side, int rotX, int rotY) { return getIndices(side); } - void addData(PrimitiveBuilder primitiveBuilder, TextureManager textureManager, int side, float size, Vector3f offset, int rotX, int rotY); + void addData(PrimitiveBuilder primitiveBuilder, BlockTextureManager textureManager, int side, float size, Vector3f offset, int rotX, int rotY); String getModel(); String getPath(); diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/newrenderer/ItemModel.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/newrenderer/ItemModel.java index 427b21b7..c12e650e 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/newrenderer/ItemModel.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/newrenderer/ItemModel.java @@ -1,6 +1,6 @@ package dev.hilligans.ourcraft.client.rendering.newrenderer; -import dev.hilligans.ourcraft.client.rendering.world.managers.TextureManager; +import dev.hilligans.ourcraft.client.rendering.world.managers.BlockTextureManager; import dev.hilligans.ourcraft.util.Settings; import org.joml.Vector3f; @@ -31,8 +31,8 @@ public int[] getIndices(int side) { } @Override - public void addData(PrimitiveBuilder primitiveBuilder, TextureManager textureManager, int side, float size, Vector3f offset, int rotX, int rotY) { - int id = textureManager.getTextureId(); + public void addData(PrimitiveBuilder primitiveBuilder, BlockTextureManager textureManager, int side, float size, Vector3f offset, int rotX, int rotY) { + //int id = textureManager.getTextureId(); /* BufferedImage bufferedImage = TextAtlas.instance.register(new ImageLocation("Items/" + path,"purcraft")); float minX = TextAtlas.getMinX(id); float minY = TextAtlas.getMinY(id); diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/world/managers/BlockTextureManager.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/world/managers/BlockTextureManager.java index f026aff1..7c5069ce 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/world/managers/BlockTextureManager.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/world/managers/BlockTextureManager.java @@ -2,10 +2,9 @@ import dev.hilligans.ourcraft.client.rendering.newrenderer.TextAtlas; -import dev.hilligans.ourcraft.ClientMain; import dev.hilligans.ourcraft.Ourcraft; -public class BlockTextureManager implements TextureManager { +public class BlockTextureManager { public int[] textures = new int[6]; @@ -75,14 +74,4 @@ public String[] getTextures() { return new String[]{location}; } } - - @Override - public int getTextureId() { - return textures[0]; - } - - @Override - public int getTextureMap() { - return ClientMain.getClient().texture; - } } diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/world/managers/ItemTextureManager.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/world/managers/ItemTextureManager.java index 37f41156..b1fd4d33 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/world/managers/ItemTextureManager.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/world/managers/ItemTextureManager.java @@ -5,7 +5,7 @@ import static org.lwjgl.opengl.GL11.GL_TRIANGLES; -public class ItemTextureManager implements TextureManager { +public class ItemTextureManager { public int id; public String path; @@ -19,14 +19,4 @@ public void generate() { id = TextAtlas.instance.loadTextureId("Items/" + path,"Items/" + path.substring(0,path.length() - 4),""); // PrimitiveBuilder primitiveBuilder = new PrimitiveBuilder(GL_TRIANGLES, ShaderManager.worldShader); } - - @Override - public int getTextureId() { - return id; - } - - @Override - public int getTextureMap() { - return 0; - } } diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/world/managers/TextureManager.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/world/managers/TextureManager.java deleted file mode 100644 index c3ddc7d0..00000000 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/world/managers/TextureManager.java +++ /dev/null @@ -1,9 +0,0 @@ -package dev.hilligans.ourcraft.client.rendering.world.managers; - -public interface TextureManager { - - int getTextureId(); - - int getTextureMap(); - -} diff --git a/src/main/java/dev/hilligans/ourcraft/item/Item.java b/src/main/java/dev/hilligans/ourcraft/item/Item.java index 0dcfd118..14b58564 100644 --- a/src/main/java/dev/hilligans/ourcraft/item/Item.java +++ b/src/main/java/dev/hilligans/ourcraft/item/Item.java @@ -119,7 +119,7 @@ public void renderHolding(RenderWindow window, MatrixStack matrixStack, int size } public void addData(PrimitiveBuilder primitiveBuilder, float size) { - itemProperties.itemModel.addData(primitiveBuilder,itemProperties.itemTextureManager,0,size,null,0,0); + //itemProperties.itemModel.addData(primitiveBuilder,itemProperties.itemTextureManager,0,size,null,0,0); } public boolean onActivate(World world, PlayerEntity playerEntity) { diff --git a/src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java b/src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java index a6ea330e..41f21695 100644 --- a/src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java +++ b/src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java @@ -45,7 +45,7 @@ public void startServer(String port) { executorService.scheduleAtFixedRate(server, 0, 40, TimeUnit.MILLISECONDS); ScheduledExecutorService executorService1 = Executors.newScheduledThreadPool(1, new NamedThreadFactory("server_player_handler")); executorService1.scheduleAtFixedRate(new PlayerHandler(this), 0, 10, TimeUnit.MILLISECONDS); - ConsoleReader consoleReader = new ConsoleReader(this::executeCommand); + // ConsoleReader consoleReader = new ConsoleReader(this::executeCommand); serverNetwork = new ServerNetwork(gameInstance.PROTOCOLS.get("Play"), this).debug(ServerMain.argumentContainer.getBoolean("--packetTrace", false)); try { diff --git a/src/main/java/dev/hilligans/ourcraft/util/ConsoleReader.java b/src/main/java/dev/hilligans/ourcraft/util/ConsoleReader.java index fcca5a6c..d230fcb8 100644 --- a/src/main/java/dev/hilligans/ourcraft/util/ConsoleReader.java +++ b/src/main/java/dev/hilligans/ourcraft/util/ConsoleReader.java @@ -16,7 +16,7 @@ public ConsoleReader(Consumer consoleEvent) { public void run() { Scanner scan = new Scanner(System.in); String line; - while(!(line = scan.nextLine()).equals(""+((char) 3))) { + while(!(line = scan.next()).equals(""+((char) 3))) { consoleEvent.accept(line); } } diff --git a/src/main/java/dev/hilligans/ourcraft/util/sections/ISection.java b/src/main/java/dev/hilligans/ourcraft/util/sections/ISection.java index d5c37480..d53713e8 100644 --- a/src/main/java/dev/hilligans/ourcraft/util/sections/ISection.java +++ b/src/main/java/dev/hilligans/ourcraft/util/sections/ISection.java @@ -6,4 +6,12 @@ public interface ISection { void stopSection(String name); + static ISection getSection(String name) { + if("stepping".equals(name)) { + return new SteppingSection(); + } else if ("profiled".equals(name)) { + return new ProfiledSection(); + } + return new EmptySection(); + } } diff --git a/src/main/java/dev/hilligans/ourcraft/util/sections/SteppingSection.java b/src/main/java/dev/hilligans/ourcraft/util/sections/SteppingSection.java new file mode 100644 index 00000000..dab7f5fb --- /dev/null +++ b/src/main/java/dev/hilligans/ourcraft/util/sections/SteppingSection.java @@ -0,0 +1,31 @@ +package dev.hilligans.ourcraft.util.sections; + +import dev.hilligans.ourcraft.util.ConsoleReader; + +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; + +public class SteppingSection implements ISection { + + public ConsoleReader consoleReader; + public AtomicInteger step = new AtomicInteger(); + + public SteppingSection() { + consoleReader = new ConsoleReader(s -> { + if(s.equals("n")) {step.incrementAndGet(); } + }); + } + + @Override + public SectionView startSection(String name) { + System.out.println(STR."Waiting on section:\{name}"); + while(step.get() == 0) {} + step.decrementAndGet(); + return new SectionView(name, this); + } + + @Override + public void stopSection(String name) { + + } +}