From cfcc86dd8b92f5a269a06e3357e67eb8e6a45938 Mon Sep 17 00:00:00 2001 From: shadowislord Date: Tue, 3 Jun 2014 23:16:34 -0400 Subject: [PATCH] * When creating display pixel format, do not use withSRGB as it could cause display creation to fail (when gamma correction is enabled). Based on online research, it seems that it is not necessary, and simply enabling SRGB writes on the main framebuffer is enough. * Added additional checks when enabling SRGB writes to ensure the default framebuffer actually supports it, and print a warning if it doesn't. --- .../jme3/renderer/lwjgl/LwjglRenderer.java | 19 +++++++++++++++---- .../com/jme3/system/lwjgl/LwjglCanvas.java | 3 +-- .../com/jme3/system/lwjgl/LwjglDisplay.java | 3 +-- .../system/lwjgl/LwjglOffscreenBuffer.java | 3 +-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglRenderer.java b/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglRenderer.java index bcfd1acc5..b43cea719 100644 --- a/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglRenderer.java +++ b/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglRenderer.java @@ -2565,14 +2565,25 @@ public class LwjglRenderer implements Renderer { return; } + setFrameBuffer(null); + if (enableSrgb) { if (!glGetBoolean(GL30.GL_FRAMEBUFFER_SRGB_CAPABLE)) { - logger.warning("Driver claims that default framebuffer " + - "is not sRGB capable. Enabling anyway."); + logger.warning("Driver claims that default framebuffer " + + "is not sRGB capable. Enabling anyway."); } - + + int encoding = GL30.glGetFramebufferAttachmentParameteri(GL30.GL_DRAW_FRAMEBUFFER, + GL_FRONT_LEFT, + GL30.GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING); + + if (encoding != GL21.GL_SRGB) { + logger.warning("Driver claims that default framebuffer " + + "is not using sRGB color encoding. Enabling anyway."); + } + glEnable(GL30.GL_FRAMEBUFFER_SRGB); - + logger.log(Level.FINER, "SRGB FrameBuffer enabled (Gamma Correction)"); } else { glDisable(GL30.GL_FRAMEBUFFER_SRGB); diff --git a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglCanvas.java b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglCanvas.java index e7d9756fe..43b46740e 100644 --- a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglCanvas.java +++ b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglCanvas.java @@ -323,8 +323,7 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex 0, 0, 0, - settings.useStereo3D()) - .withSRGB(settings.getGammaCorrection()); + settings.useStereo3D()); } return canvasFormat; } diff --git a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglDisplay.java b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglDisplay.java index cce6c0c06..1974e5137 100644 --- a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglDisplay.java +++ b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglDisplay.java @@ -91,8 +91,7 @@ public class LwjglDisplay extends LwjglAbstractDisplay { 0, 0, 0, - settings.useStereo3D()) - .withSRGB(settings.getGammaCorrection()); + settings.useStereo3D()); frameRate = settings.getFrameRate(); logger.log(Level.FINE, "Selected display mode: {0}", displayMode); diff --git a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglOffscreenBuffer.java b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglOffscreenBuffer.java index 6d5da4563..27af9317f 100644 --- a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglOffscreenBuffer.java +++ b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglOffscreenBuffer.java @@ -65,8 +65,7 @@ public class LwjglOffscreenBuffer extends LwjglContext implements Runnable { 0, settings.getDepthBits(), settings.getStencilBits(), - samples) - .withSRGB(settings.getGammaCorrection()); + samples); width = settings.getWidth(); height = settings.getHeight();