-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
755e0d2
commit f926fc6
Showing
6 changed files
with
139 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.wispforest.owo.ui.util; | ||
|
||
|
||
import org.lwjgl.opengl.ARBDebugOutput; | ||
import org.lwjgl.opengl.GL; | ||
import org.lwjgl.opengl.KHRDebug; | ||
|
||
public final class GlDebugUtils { | ||
public static final boolean GL_KHR_debug = GL.getCapabilities().GL_KHR_debug; | ||
|
||
private GlDebugUtils() { | ||
|
||
} | ||
|
||
public static void labelObject(int type, int id, String name) { | ||
if (GL_KHR_debug) { | ||
KHRDebug.glObjectLabel(type, id, name); | ||
} | ||
} | ||
|
||
public static DebugGroup pushGroup(String name) { | ||
if (GL_KHR_debug) { | ||
KHRDebug.glPushDebugGroup(KHRDebug.GL_DEBUG_SOURCE_APPLICATION, 42, name); | ||
} | ||
|
||
return new DebugGroup(); | ||
} | ||
|
||
public static class DebugGroup implements AutoCloseable { | ||
private DebugGroup() { | ||
|
||
} | ||
|
||
@Override | ||
public void close() { | ||
if (GL_KHR_debug) { | ||
KHRDebug.glPopDebugGroup(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.wispforest.owo.ui.util; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import com.mojang.blaze3d.systems.VertexSorter; | ||
import org.joml.Matrix4f; | ||
import org.lwjgl.glfw.GLFW; | ||
|
||
public final class OwoGlUtil { | ||
private OwoGlUtil() { | ||
|
||
} | ||
|
||
public static ContextRestorer setContext(long handle) { | ||
long old = GLFW.glfwGetCurrentContext(); | ||
if (old == handle) return new ContextRestorer(-1); | ||
|
||
GLFW.glfwMakeContextCurrent(handle); | ||
|
||
return new ContextRestorer(old); | ||
} | ||
|
||
public static ProjectionRestorer setProjectionMatrix(Matrix4f projectionMatrix, VertexSorter sorter) { | ||
Matrix4f oldMatrix = RenderSystem.getProjectionMatrix(); | ||
VertexSorter oldSorter = RenderSystem.getVertexSorting(); | ||
|
||
RenderSystem.setProjectionMatrix(projectionMatrix, sorter); | ||
|
||
return new ProjectionRestorer(oldMatrix, oldSorter); | ||
} | ||
|
||
public static class ContextRestorer implements AutoCloseable { | ||
private final long oldContext; | ||
|
||
private ContextRestorer(long old) { | ||
this.oldContext = old; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
if (oldContext == -1) return; | ||
|
||
GLFW.glfwMakeContextCurrent(oldContext); | ||
} | ||
} | ||
|
||
public static class ProjectionRestorer implements AutoCloseable { | ||
private final Matrix4f matrix; | ||
private final VertexSorter sorter; | ||
|
||
private ProjectionRestorer(Matrix4f matrix, VertexSorter sorter) { | ||
this.matrix = matrix; | ||
this.sorter = sorter; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
RenderSystem.setProjectionMatrix(matrix, sorter); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.