Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions imgui-lwjgl3/src/main/java/imgui/gl3/ImGuiImplGl3.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import imgui.flag.ImGuiConfigFlags;
import imgui.flag.ImGuiViewportFlags;
import imgui.type.ImInt;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLCapabilities;

import java.nio.ByteBuffer;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -157,6 +159,7 @@ protected static class Data {
// protected boolean glProfileIsES3;
protected boolean glProfileIsCompat;
protected int glProfileMask;
protected GLCapabilities glCapabilities = null;
protected String glslVersion = "";
protected int fontTexture = 0;
protected int shaderHandle = 0;
Expand Down Expand Up @@ -273,6 +276,15 @@ public boolean init(final String glslVersion) {
data.glVersion = major * 100 + minor * 10;
data.glProfileMask = glGetInteger(GL_CONTEXT_PROFILE_MASK);
data.glProfileIsCompat = (data.glProfileMask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0;
if (data.glVersion < 330) { // Ignore in higher GL versions since they support sampler objects anyway
try {
data.glCapabilities = GL.getCapabilities();
} catch (IllegalStateException ignored) {
// IllegalStateException – if setCapabilities has never been called in the current thread or was last called with a null value
// This exception can be safely ignored as it does not impact the initialization process.
// GL_ARB_sampler_objects will be unavailable (and therefore not supported) if the GL version is less than 3.3.
}
}
}

// We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
Expand Down Expand Up @@ -381,7 +393,7 @@ protected void setupRenderState(final ImDrawData drawData, final int fbWidth, fi
glUniform1i(data.attribLocationTex, 0);
glUniformMatrix4fv(data.attribLocationProjMtx, false, props.orthoProjMatrix);

if (data.glVersion >= 330) {
if (data.glVersion >= 330 || (data.glCapabilities != null && data.glCapabilities.GL_ARB_sampler_objects)) {
glBindSampler(0, 0);
}

Expand Down Expand Up @@ -421,7 +433,7 @@ public void renderDrawData(final ImDrawData drawData) {
glActiveTexture(GL_TEXTURE0);
glGetIntegerv(GL_CURRENT_PROGRAM, props.lastProgram);
glGetIntegerv(GL_TEXTURE_BINDING_2D, props.lastTexture);
if (data.glVersion >= 330) {
if (data.glVersion >= 330 || (data.glCapabilities != null && data.glCapabilities.GL_ARB_sampler_objects)) {
glGetIntegerv(GL_SAMPLER_BINDING, props.lastSampler);
}
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, props.lastArrayBuffer);
Expand Down Expand Up @@ -525,7 +537,7 @@ public void renderDrawData(final ImDrawData drawData) {
glUseProgram(props.lastProgram[0]);
}
glBindTexture(GL_TEXTURE_2D, props.lastTexture[0]);
if (data.glVersion >= 330) {
if (data.glVersion >= 330 || (data.glCapabilities != null && data.glCapabilities.GL_ARB_sampler_objects)) {
glBindSampler(0, props.lastSampler[0]);
}
glActiveTexture(props.lastActiveTexture[0]);
Expand Down