|
11 | 11 | import imgui.flag.ImGuiConfigFlags;
|
12 | 12 | import imgui.flag.ImGuiViewportFlags;
|
13 | 13 | import imgui.type.ImInt;
|
| 14 | +import org.lwjgl.opengl.GL; |
| 15 | +import org.lwjgl.opengl.GLCapabilities; |
14 | 16 |
|
15 | 17 | import java.nio.ByteBuffer;
|
16 | 18 | import java.util.regex.Matcher;
|
@@ -157,6 +159,7 @@ protected static class Data {
|
157 | 159 | // protected boolean glProfileIsES3;
|
158 | 160 | protected boolean glProfileIsCompat;
|
159 | 161 | protected int glProfileMask;
|
| 162 | + protected GLCapabilities glCapabilities = null; |
160 | 163 | protected String glslVersion = "";
|
161 | 164 | protected int fontTexture = 0;
|
162 | 165 | protected int shaderHandle = 0;
|
@@ -273,6 +276,15 @@ public boolean init(final String glslVersion) {
|
273 | 276 | data.glVersion = major * 100 + minor * 10;
|
274 | 277 | data.glProfileMask = glGetInteger(GL_CONTEXT_PROFILE_MASK);
|
275 | 278 | data.glProfileIsCompat = (data.glProfileMask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0;
|
| 279 | + if (data.glVersion < 330) { // Ignore in higher GL versions since they support sampler objects anyway |
| 280 | + try { |
| 281 | + data.glCapabilities = GL.getCapabilities(); |
| 282 | + } catch (IllegalStateException ignored) { |
| 283 | + // IllegalStateException – if setCapabilities has never been called in the current thread or was last called with a null value |
| 284 | + // This exception can be safely ignored as it does not impact the initialization process. |
| 285 | + // GL_ARB_sampler_objects will be unavailable (and therefore not supported) if the GL version is less than 3.3. |
| 286 | + } |
| 287 | + } |
276 | 288 | }
|
277 | 289 |
|
278 | 290 | // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
@@ -381,7 +393,7 @@ protected void setupRenderState(final ImDrawData drawData, final int fbWidth, fi
|
381 | 393 | glUniform1i(data.attribLocationTex, 0);
|
382 | 394 | glUniformMatrix4fv(data.attribLocationProjMtx, false, props.orthoProjMatrix);
|
383 | 395 |
|
384 |
| - if (data.glVersion >= 330) { |
| 396 | + if (data.glVersion >= 330 || (data.glCapabilities != null && data.glCapabilities.GL_ARB_sampler_objects)) { |
385 | 397 | glBindSampler(0, 0);
|
386 | 398 | }
|
387 | 399 |
|
@@ -421,7 +433,7 @@ public void renderDrawData(final ImDrawData drawData) {
|
421 | 433 | glActiveTexture(GL_TEXTURE0);
|
422 | 434 | glGetIntegerv(GL_CURRENT_PROGRAM, props.lastProgram);
|
423 | 435 | glGetIntegerv(GL_TEXTURE_BINDING_2D, props.lastTexture);
|
424 |
| - if (data.glVersion >= 330) { |
| 436 | + if (data.glVersion >= 330 || (data.glCapabilities != null && data.glCapabilities.GL_ARB_sampler_objects)) { |
425 | 437 | glGetIntegerv(GL_SAMPLER_BINDING, props.lastSampler);
|
426 | 438 | }
|
427 | 439 | glGetIntegerv(GL_ARRAY_BUFFER_BINDING, props.lastArrayBuffer);
|
@@ -525,7 +537,7 @@ public void renderDrawData(final ImDrawData drawData) {
|
525 | 537 | glUseProgram(props.lastProgram[0]);
|
526 | 538 | }
|
527 | 539 | glBindTexture(GL_TEXTURE_2D, props.lastTexture[0]);
|
528 |
| - if (data.glVersion >= 330) { |
| 540 | + if (data.glVersion >= 330 || (data.glCapabilities != null && data.glCapabilities.GL_ARB_sampler_objects)) { |
529 | 541 | glBindSampler(0, props.lastSampler[0]);
|
530 | 542 | }
|
531 | 543 | glActiveTexture(props.lastActiveTexture[0]);
|
|
0 commit comments