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
This commit is contained in:
Nehon 2014-05-16 00:04:29 +02:00
parent a23038430c
commit 77a4002c3d
14 changed files with 78 additions and 10 deletions

View File

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

View File

@ -313,4 +313,26 @@ public interface Renderer {
* </p>
*/
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);
}

View File

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

View File

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

View File

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

View File

@ -2589,4 +2589,15 @@ public class JoglRenderer implements Renderer {
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);
}
}
}

View File

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

View File

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

View File

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

View File

@ -55,9 +55,7 @@ import com.jme3.texture.Texture;
import com.jme3.texture.Texture.WrapAxis;
import com.jme3.util.BufferUtils;
import com.jme3.util.ListMap;
import com.jme3.util.NativeObject;
import com.jme3.util.NativeObjectManager;
import com.jme3.util.SafeArrayList;
import java.nio.*;
import java.util.EnumSet;
import java.util.List;
@ -371,7 +369,7 @@ public class LwjglRenderer implements Renderer {
caps.add(Caps.FrameBufferMRT);
logger.log(Level.FINER, "FBO Max MRT renderbuffers: {0}", maxMRTFBOAttachs);
}
// if (ctxCaps.GL_ARB_draw_buffers) {
// caps.add(Caps.FrameBufferMRT);
// glGetInteger(ARBDrawBuffers.GL_MAX_DRAW_BUFFERS_ARB, intBuf16);
@ -2488,4 +2486,14 @@ public class LwjglRenderer implements Renderer {
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);
}
}
}

View File

@ -308,7 +308,8 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
0,
0,
0,
settings.useStereo3D());
settings.useStereo3D())
.withSRGB(settings.getGammaCorrection());
}
return pbufferFormat;
}else{
@ -322,7 +323,8 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
0,
0,
0,
settings.useStereo3D());
settings.useStereo3D())
.withSRGB(settings.getGammaCorrection());
}
return canvasFormat;
}
@ -467,7 +469,7 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
}else{
Display.create(acquirePixelFormat(false));
}
renderer.invalidateState();
}else{
// First create the pbuffer, if it is needed.

View File

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

View File

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

View File

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