Added support for hardware srgb output (gamma correction).

It can be toggled at render time.
Works with lwjgl
Couldn't test with Jogl and might be not working
Not supported by mobile renderers
experimental
Nehon 11 years ago
parent a23038430c
commit 77a4002c3d
  1. 4
      jme3-android/src/main/java/com/jme3/renderer/android/OGLESShaderRenderer.java
  2. 22
      jme3-core/src/main/java/com/jme3/renderer/Renderer.java
  3. 3
      jme3-core/src/main/java/com/jme3/system/NullRenderer.java
  4. 4
      jme3-ios/src/main/java/com/jme3/renderer/ios/IGLESShaderRenderer.java
  5. 3
      jme3-jogl/src/main/java/com/jme3/renderer/jogl/JoglGL1Renderer.java
  6. 11
      jme3-jogl/src/main/java/com/jme3/renderer/jogl/JoglRenderer.java
  7. 2
      jme3-jogl/src/main/java/com/jme3/system/jogl/JoglAbstractDisplay.java
  8. 2
      jme3-jogl/src/main/java/com/jme3/system/jogl/JoglNewtAbstractDisplay.java
  9. 4
      jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java
  10. 12
      jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglRenderer.java
  11. 6
      jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglCanvas.java
  12. 1
      jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java
  13. 3
      jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglDisplay.java
  14. 3
      jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglOffscreenBuffer.java

@ -2532,4 +2532,8 @@ public class OGLESShaderRenderer implements Renderer {
boundShader = null; boundShader = null;
lastFb = null; lastFb = null;
} }
public void setMainFrameBufferSrgb(boolean srgb) {
//TODO once opglES3.0 is supported maybe....
}
} }

@ -313,4 +313,26 @@ public interface Renderer {
* </p> * </p>
*/ */
public void setAlphaToCoverage(boolean value); public void setAlphaToCoverage(boolean value);
/**
* If enabled, color values rendered to the main framebuffer undergo
* linear -> sRGB conversion.
*
* This is identical to {@link FrameBuffer#setSrgb(boolean)} except it is toggled
* for the main framebuffer instead of an offscreen buffer.
*
* This should be set together with {@link Renderer#setLinearizeSrgbImages(boolean)}
*
* As a shorthand, the user can set {@link AppSettings#setSrgbPipeline(boolean)} to true
* to toggle both {@link Renderer#setLinearizeSrgbImages(boolean)} and
* {@link Renderer#setMainFrameBufferSrgb(boolean)} if the
* {@link Caps#} is supported by the GPU.
*
* @throws RendererException If the GPU hardware does not support sRGB.
*
* @seealso FrameBuffer#setSrgb(boolean)
*
* @seealso Caps#Srgb
*/
public void setMainFrameBufferSrgb(boolean srgb);
} }

@ -152,4 +152,7 @@ public class NullRenderer implements Renderer {
public void setAlphaToCoverage(boolean value) { public void setAlphaToCoverage(boolean value) {
} }
public void setMainFrameBufferSrgb(boolean srgb) {
}
} }

@ -2572,4 +2572,8 @@ public class IGLESShaderRenderer implements Renderer {
throw new UnsupportedOperationException("Unrecognized test function: " + testFunc); throw new UnsupportedOperationException("Unrecognized test function: " + testFunc);
} }
} }
public void setMainFrameBufferSrgb(boolean srgb) {
}
} }

@ -1258,4 +1258,7 @@ public class JoglGL1Renderer implements GL1Renderer {
public void deleteBuffer(VertexBuffer vb) { public void deleteBuffer(VertexBuffer vb) {
} }
public void setMainFrameBufferSrgb(boolean srgb) {
}
} }

@ -2589,4 +2589,15 @@ public class JoglRenderer implements Renderer {
renderMeshDefault(mesh, lod, count); renderMeshDefault(mesh, lod, count);
// } // }
} }
public void setMainFrameBufferSrgb(boolean srgb) {
//Gamma correction
if(srgb && GLContext.getCurrent().isExtensionAvailable("GL_ARB_framebuffer_sRGB")){
GLContext.getCurrentGL().glEnable(GL3.GL_FRAMEBUFFER_SRGB);
logger.log(Level.FINER, "SRGB FrameBuffer enabled (Gamma Correction)");
}else{
GLContext.getCurrentGL().glDisable(GL3.GL_FRAMEBUFFER_SRGB);
}
}
} }

@ -164,6 +164,8 @@ public abstract class JoglAbstractDisplay extends JoglContext implements GLEvent
} }
renderer = new JoglRenderer(); renderer = new JoglRenderer();
renderer.setMainFrameBufferSrgb(settings.getGammaCorrection());
} }
protected void startGLCanvas() { protected void startGLCanvas() {

@ -144,6 +144,8 @@ public abstract class JoglNewtAbstractDisplay extends JoglContext implements GLE
} }
renderer = new JoglRenderer(); renderer = new JoglRenderer();
renderer.setMainFrameBufferSrgb(settings.getGammaCorrection());
} }
protected void startGLCanvas() { protected void startGLCanvas() {

@ -1198,4 +1198,8 @@ public class LwjglGL1Renderer implements GL1Renderer {
public void deleteBuffer(VertexBuffer vb) { public void deleteBuffer(VertexBuffer vb) {
} }
public void setMainFrameBufferSrgb(boolean srgb) {
}
} }

@ -55,9 +55,7 @@ import com.jme3.texture.Texture;
import com.jme3.texture.Texture.WrapAxis; import com.jme3.texture.Texture.WrapAxis;
import com.jme3.util.BufferUtils; import com.jme3.util.BufferUtils;
import com.jme3.util.ListMap; import com.jme3.util.ListMap;
import com.jme3.util.NativeObject;
import com.jme3.util.NativeObjectManager; import com.jme3.util.NativeObjectManager;
import com.jme3.util.SafeArrayList;
import java.nio.*; import java.nio.*;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
@ -2488,4 +2486,14 @@ public class LwjglRenderer implements Renderer {
renderMeshDefault(mesh, lod, count); renderMeshDefault(mesh, lod, count);
// } // }
} }
public void setMainFrameBufferSrgb(boolean srgb) {
//Gamma correction
if(srgb && GLContext.getCapabilities().GL_ARB_framebuffer_sRGB){
glEnable(GL30.GL_FRAMEBUFFER_SRGB);
logger.log(Level.FINER, "SRGB FrameBuffer enabled (Gamma Correction)");
}else{
glDisable(GL30.GL_FRAMEBUFFER_SRGB);
}
}
} }

@ -308,7 +308,8 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
0, 0,
0, 0,
0, 0,
settings.useStereo3D()); settings.useStereo3D())
.withSRGB(settings.getGammaCorrection());
} }
return pbufferFormat; return pbufferFormat;
}else{ }else{
@ -322,7 +323,8 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
0, 0,
0, 0,
0, 0,
settings.useStereo3D()); settings.useStereo3D())
.withSRGB(settings.getGammaCorrection());
} }
return canvasFormat; return canvasFormat;
} }

@ -237,6 +237,7 @@ public abstract class LwjglContext implements JmeContext {
}else{ }else{
assert false; assert false;
} }
renderer.setMainFrameBufferSrgb(settings.getGammaCorrection());
// Init input // Init input
if (keyInput != null) { if (keyInput != null) {

@ -91,7 +91,8 @@ public class LwjglDisplay extends LwjglAbstractDisplay {
0, 0,
0, 0,
0, 0,
settings.useStereo3D()); settings.useStereo3D())
.withSRGB(settings.getGammaCorrection());
frameRate = settings.getFrameRate(); frameRate = settings.getFrameRate();
logger.log(Level.FINE, "Selected display mode: {0}", displayMode); logger.log(Level.FINE, "Selected display mode: {0}", displayMode);

@ -65,7 +65,8 @@ public class LwjglOffscreenBuffer extends LwjglContext implements Runnable {
0, 0,
settings.getDepthBits(), settings.getDepthBits(),
settings.getStencilBits(), settings.getStencilBits(),
samples); samples)
.withSRGB(settings.getGammaCorrection());
width = settings.getWidth(); width = settings.getWidth();
height = settings.getHeight(); height = settings.getHeight();

Loading…
Cancel
Save