Skip to content

Commit

Permalink
[OpenGL] Rewrite GL20C, GL30C, GL41C (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Jan 31, 2024
1 parent b36dbfa commit bc8e131
Show file tree
Hide file tree
Showing 11 changed files with 1,886 additions and 3,342 deletions.
1,808 changes: 643 additions & 1,165 deletions modules/overrungl.opengl/src/main/java/overrungl/opengl/GL20C.java

Large diffs are not rendered by default.

1,871 changes: 693 additions & 1,178 deletions modules/overrungl.opengl/src/main/java/overrungl/opengl/GL30C.java

Large diffs are not rendered by default.

1,508 changes: 537 additions & 971 deletions modules/overrungl.opengl/src/main/java/overrungl/opengl/GL41C.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,6 @@
*/
public final class GLCapabilities {
private static final Pattern VERSION_PATTERN = Pattern.compile("^(\\d+)\\.(\\d+).*$");
/**
* OpenGL 2.0 method handles
*/
public MethodHandle glAttachShader, glBindAttribLocation, glBlendEquationSeparate, glCompileShader, glCreateProgram, glCreateShader,
glDeleteProgram, glDeleteShader, glDetachShader, glDisableVertexAttribArray, glDrawBuffers, glEnableVertexAttribArray,
glGetActiveAttrib, glGetActiveUniform, glGetAttachedShaders, glGetAttribLocation, glGetProgramInfoLog, glGetProgramiv,
glGetShaderInfoLog, glGetShaderSource, glGetShaderiv, glGetUniformLocation, glGetUniformfv, glGetUniformiv,
glGetVertexAttribPointerv, glGetVertexAttribdv, glGetVertexAttribfv, glGetVertexAttribiv, glIsProgram, glIsShader,
glLinkProgram, glShaderSource, glStencilFuncSeparate, glStencilMaskSeparate, glStencilOpSeparate, glUniform1f,
glUniform1fv, glUniform1i, glUniform1iv, glUniform2f, glUniform2fv, glUniform2i, glUniform2iv, glUniform3f,
glUniform3fv, glUniform3i, glUniform3iv, glUniform4f, glUniform4fv, glUniform4i, glUniform4iv, glUniformMatrix2fv,
glUniformMatrix3fv, glUniformMatrix4fv, glUseProgram, glValidateProgram, glVertexAttrib1d, glVertexAttrib1dv,
glVertexAttrib1f, glVertexAttrib1fv, glVertexAttrib1s, glVertexAttrib1sv, glVertexAttrib2d, glVertexAttrib2dv,
glVertexAttrib2f, glVertexAttrib2fv, glVertexAttrib2s, glVertexAttrib2sv, glVertexAttrib3d, glVertexAttrib3dv,
glVertexAttrib3f, glVertexAttrib3fv, glVertexAttrib3s, glVertexAttrib3sv, glVertexAttrib4Nbv, glVertexAttrib4Niv,
glVertexAttrib4Nsv, glVertexAttrib4Nub, glVertexAttrib4Nubv, glVertexAttrib4Nuiv, glVertexAttrib4Nusv, glVertexAttrib4bv,
glVertexAttrib4d, glVertexAttrib4dv, glVertexAttrib4f, glVertexAttrib4fv, glVertexAttrib4iv, glVertexAttrib4s,
glVertexAttrib4sv, glVertexAttrib4ubv, glVertexAttrib4uiv, glVertexAttrib4usv, glVertexAttribPointer;
/**
* OpenGL 3.0 method handles
*/
Expand Down Expand Up @@ -149,9 +131,6 @@ public int load(GLLoadFunc load) {
final MethodHandle glGetString = load.invoke("glGetString", FunctionDescriptor.of(Unmarshal.STR_LAYOUT, ValueLayout.JAVA_INT));
if (glGetString == null) return 0;

GL20C.load(this, load);
GL30C.load(this, load);
GL41C.load(this, load);
GL45C.load(this, load);

int version = findCoreGL(glGetString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* {@snippet lang = java:
* // loads OpenGL forward-compatible profile
* import java.util.Objects;
* Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL");
* Objects.requireNonNull(GLLoader.load(glfw::getProcAddress), "Failed to load OpenGL");
* }
*
* @author squid233
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
* @since 0.1.0
*/
public final class GLLoader {
private static final boolean DEFAULT_COMPATIBLE = false;
private static final boolean DEFAULT_COMPATIBLE = true;
@Deprecated(since = "0.1.0")
private static final ThreadLocal<GLCapabilities> capabilitiesTLS = new ThreadLocal<>();

/**
Expand All @@ -57,6 +58,7 @@ public final class GLLoader {
* <p>This {@code GLCapabilities} instance will be used by any OpenGL call in the current thread, until {@code setCapabilities} is called again with a
* different value.</p>
*/
@Deprecated(since = "0.1.0")
public static void setCapabilities(@Nullable GLCapabilities caps) {
capabilitiesTLS.set(caps);
}
Expand All @@ -68,6 +70,7 @@ public static void setCapabilities(@Nullable GLCapabilities caps) {
*
* @see #getCapabilities()
*/
@Deprecated(since = "0.1.0")
public static GLCapabilities getCapabilitiesSafe() {
return capabilitiesTLS.get();
}
Expand All @@ -78,6 +81,7 @@ public static GLCapabilities getCapabilitiesSafe() {
* @throws IllegalStateException if {@link #setCapabilities} has never been called in the current thread or was last called with a {@code null} value
* @see #getCapabilitiesSafe()
*/
@Deprecated(since = "0.1.0")
public static GLCapabilities getCapabilities() {
return checkCapabilities(capabilitiesTLS.get());
}
Expand All @@ -92,10 +96,12 @@ public static GLCapabilities getCapabilities() {
*
* @throws IllegalStateException if {@link #setCapabilities} has never been called in the current thread or was last called with a {@code null} value
*/
@Deprecated(since = "0.1.0")
public static GLExtCaps getExtCapabilities() {
return getCapabilities().ext();
}

@Deprecated(since = "0.1.0")
private static GLCapabilities checkCapabilities(@Nullable GLCapabilities caps) {
if (RuntimeHelper.CHECKS)
CheckUtil.check(caps != null, """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void init(Arena arena) {
}

private void load() {
Objects.requireNonNull(GLLoader.load(glfw::getProcAddress, true), "Failed to load OpenGL");
Objects.requireNonNull(GLLoader.load(glfw::getProcAddress), "Failed to load OpenGL");

GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void init() {
}

private void load() {
Objects.requireNonNull(GLLoader.load(glfw::getProcAddress), "Failed to load OpenGL");
Objects.requireNonNull(GLLoader.load(glfw::getProcAddress, false), "Failed to load OpenGL");

GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void init() {
}

private void load(Arena arena) {
Objects.requireNonNull(GLLoader.load(glfw::getProcAddress), "Failed to load OpenGL");
Objects.requireNonNull(GLLoader.load(glfw::getProcAddress, false), "Failed to load OpenGL");

GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f);
GL.enable(GL.TEXTURE_2D);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void init() {
}

private void load(Arena arena) {
Objects.requireNonNull(GLLoader.load(glfw::getProcAddress, true), "Failed to load OpenGL");
Objects.requireNonNull(GLLoader.load(glfw::getProcAddress), "Failed to load OpenGL");

GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void init() {
}

private void load(Arena arena) {
Objects.requireNonNull(GLLoader.load(glfw::getProcAddress, true), "Failed to load OpenGL");
Objects.requireNonNull(GLLoader.load(glfw::getProcAddress), "Failed to load OpenGL");

debugProc = GLUtil.setupDebugMessageCallback();
GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f);
Expand Down

0 comments on commit bc8e131

Please sign in to comment.