|
From: Lasse Kärkkäi. <tr...@us...> - 2011-10-22 19:34:48
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Fri Jul 8 11:20:59 2011 +0300
Enable sRGB framebuffer and textures for proper gamma-correct blending (if sRGB is available), glColor values need to be made darker now. Using floating-point linear formats in FBOs.
---
game/fbo.hh | 4 ++--
game/surface.cc | 7 ++++---
game/video_driver.cc | 1 +
3 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/game/fbo.hh b/game/fbo.hh
index f3773bd..856695a 100644
--- a/game/fbo.hh
+++ b/game/fbo.hh
@@ -11,11 +11,11 @@ class FBO: boost::noncopyable {
FBO(unsigned w, unsigned h) {
{
UseTexture tex(m_texture);
- glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_FLOAT, NULL);
}
{
UseTexture tex(m_depth);
- glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_DEPTH_COMPONENT24, w, h, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
+ glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_DEPTH_COMPONENT, w, h, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
}
// Create FBO
glGenFramebuffersEXT(1, &m_fbo);
diff --git a/game/surface.cc b/game/surface.cc
index d24ca16..5b7078b 100644
--- a/game/surface.cc
+++ b/game/surface.cc
@@ -79,6 +79,7 @@ namespace {
if (it != pixFormats.m.end()) return it->second;
throw std::logic_error("Unknown pixel format");
}
+ GLint internalFormat() { return GL_EXT_framebuffer_sRGB ? GL_SRGB_ALPHA : GL_RGBA; }
}
void Texture::load(unsigned int width, unsigned int height, pix::Format format, unsigned char const* buffer, float ar) {
@@ -103,7 +104,7 @@ void Texture::load(unsigned int width, unsigned int height, pix::Format format,
glPixelStorei(GL_UNPACK_SWAP_BYTES, f.swap);
// Load the data into texture
if ((isPow2(width) && isPow2(height)) || GLEW_ARB_texture_non_power_of_two) { // Can directly load the texture
- glTexImage2D(type(), 0, GL_RGBA, width, height, 0, f.format, f.type, buffer);
+ glTexImage2D(type(), 0, internalFormat(), width, height, 0, f.format, f.type, buffer);
} else {
int newWidth = prevPow2(width);
int newHeight = prevPow2(height);
@@ -114,7 +115,7 @@ void Texture::load(unsigned int width, unsigned int height, pix::Format format,
// (1) no repeat => cannot texture
// (2) coordinates not normalized => would require special hackery elsewhere
// Just don't do it in Surface class, thanks. -Tronic
- glTexImage2D(type(), 0, GL_RGBA, newWidth, newHeight, 0, f.format, f.type, &outBuf[0]);
+ glTexImage2D(type(), 0, internalFormat(), newWidth, newHeight, 0, f.format, f.type, &outBuf[0]);
}
glGenerateMipmap(type());
}
@@ -129,7 +130,7 @@ void Surface::load(unsigned int width, unsigned int height, pix::Format format,
UseTexture texture(m_texture);
PixFmt const& f = getPixFmt(format);
glPixelStorei(GL_UNPACK_SWAP_BYTES, f.swap);
- glTexImage2D(m_texture.type(), 0, GL_RGBA, width, height, 0, f.format, f.type, buffer);
+ glTexImage2D(m_texture.type(), 0, internalFormat(), width, height, 0, f.format, f.type, buffer);
}
void Surface::draw() const {
diff --git a/game/video_driver.cc b/game/video_driver.cc
index 568e219..6a92ce1 100644
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -244,6 +244,7 @@ void Window::view(unsigned num) {
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
+ if (GL_EXT_framebuffer_sRGB) glEnable(GL_FRAMEBUFFER_SRGB);
shader("color").bind();
// Setup views
double vx = 0.5f * (screen->w - s_width);
|