Skip to content

Commit

Permalink
fix sRGB | windows
Browse files Browse the repository at this point in the history
  • Loading branch information
wil authored and SWinxy committed Dec 22, 2024
1 parent 3de01d6 commit 7043714
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
22 changes: 13 additions & 9 deletions src/org/lwjgl/opengl/awt/GLData.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ public class GLData {
* New fields not in SWT's GLData
*/

public static enum Profile {
CORE, COMPATIBILITY;
}
public enum Profile {
CORE, COMPATIBILITY
}

public static enum API {
GL, GLES;
}
public enum API {
GL, GLES
}

public static enum ReleaseBehavior {
NONE, FLUSH;
}
public enum ReleaseBehavior {
NONE, FLUSH
}

/**
* The major GL context version to use. It defaults to 0 for "not specified".
Expand Down Expand Up @@ -120,6 +120,10 @@ public static enum ReleaseBehavior {
* Whether to use sRGB color space.
*/
public boolean sRGB;
/**
* Used to determine the sRGB extension to use
*/
boolean extBuffer_sRGB = true;
/**
* Whether to use a floating point pixel format.
*/
Expand Down
13 changes: 9 additions & 4 deletions src/org/lwjgl/opengl/awt/PlatformWin32GLCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import static org.lwjgl.opengl.WGLARBCreateContext.*;
import static org.lwjgl.opengl.WGLARBCreateContextProfile.*;
import static org.lwjgl.opengl.WGLARBCreateContextRobustness.*;
import static org.lwjgl.opengl.WGLARBFramebufferSRGB.*;
import static org.lwjgl.opengl.WGLARBMultisample.WGL_SAMPLES_ARB;
import static org.lwjgl.opengl.WGLARBMultisample.WGL_SAMPLE_BUFFERS_ARB;
import static org.lwjgl.opengl.WGLARBPixelFormat.*;
Expand Down Expand Up @@ -110,7 +111,7 @@ private static void encodePixelFormatAttribs(IntBuffer ib, GLData attribs) {
if (attribs.accumRedSize > 0 || attribs.accumGreenSize > 0 || attribs.accumBlueSize > 0 || attribs.accumAlphaSize > 0)
ib.put(WGL_ACCUM_BITS_ARB).put(attribs.accumRedSize + attribs.accumGreenSize + attribs.accumBlueSize + attribs.accumAlphaSize);
if (attribs.sRGB)
ib.put(WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT).put(1);
ib.put(attribs.extBuffer_sRGB ? WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT : WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB).put(1);
if (attribs.samples > 0) {
ib.put(WGL_SAMPLE_BUFFERS_ARB).put(1);
ib.put(WGL_SAMPLES_ARB).put(attribs.samples);
Expand Down Expand Up @@ -426,14 +427,18 @@ private static long create(MemoryStack stack, long windowHandle, long dummyWindo
}
}
if (attribs.sRGB) {
// Check for WGL_EXT_framebuffer_sRGB
boolean has_WGL_EXT_framebuffer_sRGB = wglExtensionsList.contains("WGL_EXT_framebuffer_sRGB");
if (!has_WGL_EXT_framebuffer_sRGB) {
// Check for WGL_EXT_framebuffer_sRGB | WGL_ARB_framebuffer_sRGB
boolean has_WGL_EXT_framebuffer_sRGB = wglExtensionsList.contains("WGL_EXT_framebuffer_sRGB"),
has_WGL_ARB_framebuffer_sRGB = wglExtensionsList.contains("WGL_ARB_framebuffer_sRGB");

if (! (has_WGL_EXT_framebuffer_sRGB || has_WGL_ARB_framebuffer_sRGB) ) {
ReleaseDC(windowHandle, hDC);
wglDeleteContext(null, dummyContext);
wglMakeCurrent(null, currentDc, currentContext);
throw new AWTException("sRGB color space requested but WGL_EXT_framebuffer_sRGB is unavailable");
}

attribs.extBuffer_sRGB = has_WGL_EXT_framebuffer_sRGB;
}
if (attribs.pixelFormatFloat) {
// Check for WGL_ARB_pixel_format_float
Expand Down

0 comments on commit 7043714

Please sign in to comment.