Commit 92f1299c authored by hybrid's avatar hybrid

Add flag to enable sRGB correct color calculations (e.g. blend and lighting)....

Add flag to enable sRGB correct color calculations (e.g. blend and lighting). This allows for much better color calculations, but requires to change the explicitly defined colors in the code to be converted to linear color space.
Changed many init routines to use SIrrlichtCreationParameters struct instead of many single parameters.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3729 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 65120d77
...@@ -29,6 +29,7 @@ namespace irr ...@@ -29,6 +29,7 @@ namespace irr
Stencilbuffer(false), Stencilbuffer(false),
Vsync(false), Vsync(false),
AntiAlias(0), AntiAlias(0),
HandleSRGB(false),
WithAlphaChannel(false), WithAlphaChannel(false),
Doublebuffer(true), Doublebuffer(true),
IgnoreInput(false), IgnoreInput(false),
...@@ -62,6 +63,7 @@ namespace irr ...@@ -62,6 +63,7 @@ namespace irr
Stencilbuffer = other.Stencilbuffer; Stencilbuffer = other.Stencilbuffer;
Vsync = other.Vsync; Vsync = other.Vsync;
AntiAlias = other.AntiAlias; AntiAlias = other.AntiAlias;
HandleSRGB = other.HandleSRGB;
WithAlphaChannel = other.WithAlphaChannel; WithAlphaChannel = other.WithAlphaChannel;
Doublebuffer = other.Doublebuffer; Doublebuffer = other.Doublebuffer;
IgnoreInput = other.IgnoreInput; IgnoreInput = other.IgnoreInput;
...@@ -140,6 +142,21 @@ namespace irr ...@@ -140,6 +142,21 @@ namespace irr
Default value: 0 - disabled */ Default value: 0 - disabled */
u8 AntiAlias; u8 AntiAlias;
//! Flag to enable proper sRGB and linear color handling
/** In most situations, it is desireable to have the color handling in
non-linear sRGB color space, and only do the intermediate color
calculations in linear RGB space. If this flag is enabled, the device and
driver try to assure that all color input and output are color corrected
and only the internal color representation is linear. This means, that
the color output is properly gamma-adjusted to provide the brighter
colors for monitor display. And that blending and lighting give a more
natural look, due to proper conversion from non-linear colors into linear
color space for blend operations. If this flag is enabled, all texture colors
(which are usually in sRGB space) are correctly displayed. However vertex colors
and other explicitly set values have to be manually encoded in linear color space.
Default value: false. */
bool HandleSRGB;
//! Whether the main framebuffer uses an alpha channel. //! Whether the main framebuffer uses an alpha channel.
/** In some situations it might be desireable to get a color /** In some situations it might be desireable to get a color
buffer with an alpha channel, e.g. when rendering into a buffer with an alpha channel, e.g. when rendering into a
......
This diff is collapsed.
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#endif #endif
#include "CNullDriver.h" #include "CNullDriver.h"
#include "SIrrCreationParameters.h"
#include "IMaterialRendererServices.h" #include "IMaterialRendererServices.h"
#if defined(__BORLANDC__) || defined (__BCPLUSPLUS__) #if defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
#include "irrMath.h" // needed by borland for sqrtf define #include "irrMath.h" // needed by borland for sqrtf define
...@@ -50,8 +51,7 @@ namespace video ...@@ -50,8 +51,7 @@ namespace video
friend class CD3D9Texture; friend class CD3D9Texture;
//! constructor //! constructor
CD3D9Driver(const core::dimension2d<u32>& screenSize, HWND window, bool fullscreen, CD3D9Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io);
bool stencibuffer, io::IFileSystem* io, bool pureSoftware=false);
//! destructor //! destructor
virtual ~CD3D9Driver(); virtual ~CD3D9Driver();
...@@ -191,9 +191,7 @@ namespace video ...@@ -191,9 +191,7 @@ namespace video
const core::vector3df& end, SColor color = SColor(255,255,255,255)); const core::vector3df& end, SColor color = SColor(255,255,255,255));
//! initialises the Direct3D API //! initialises the Direct3D API
bool initDriver(const core::dimension2d<u32>& screenSize, HWND hwnd, bool initDriver(HWND hwnd, bool pureSoftware);
u32 bits, bool fullScreen, bool pureSoftware,
bool highPrecisionFPU, bool vsync, u8 antiAlias, u32 displayAdapter);
//! \return Returns the name of the video driver. Example: In case of the DIRECT3D8 //! \return Returns the name of the video driver. Example: In case of the DIRECT3D8
//! driver, it would return "Direct3D8.1". //! driver, it would return "Direct3D8.1".
...@@ -412,8 +410,6 @@ namespace video ...@@ -412,8 +410,6 @@ namespace video
SMaterial Material, LastMaterial; SMaterial Material, LastMaterial;
bool ResetRenderStates; // bool to make all renderstates be reseted if set. bool ResetRenderStates; // bool to make all renderstates be reseted if set.
bool Transformation3DChanged; bool Transformation3DChanged;
bool StencilBuffer;
u8 AntiAliasing;
const ITexture* CurrentTexture[MATERIAL_MAX_TEXTURES]; const ITexture* CurrentTexture[MATERIAL_MAX_TEXTURES];
bool LastTextureMipMapsAvailable[MATERIAL_MAX_TEXTURES]; bool LastTextureMipMapsAvailable[MATERIAL_MAX_TEXTURES];
core::matrix4 Matrices[ETS_COUNT]; // matrizes of the 3d mode we need to restore when we switch back from the 2d mode. core::matrix4 Matrices[ETS_COUNT]; // matrizes of the 3d mode we need to restore when we switch back from the 2d mode.
...@@ -424,13 +420,14 @@ namespace video ...@@ -424,13 +420,14 @@ namespace video
IDirect3DSurface9* PrevRenderTarget; IDirect3DSurface9* PrevRenderTarget;
core::dimension2d<u32> CurrentRendertargetSize; core::dimension2d<u32> CurrentRendertargetSize;
core::dimension2d<u32> CurrentDepthBufferSize;
HWND WindowId; HWND WindowId;
core::rect<s32>* SceneSourceRect; core::rect<s32>* SceneSourceRect;
D3DCAPS9 Caps; D3DCAPS9 Caps;
SIrrlichtCreationParameters Params;
E_VERTEX_TYPE LastVertexType; E_VERTEX_TYPE LastVertexType;
SColorf AmbientLight; SColorf AmbientLight;
...@@ -459,12 +456,9 @@ namespace video ...@@ -459,12 +456,9 @@ namespace video
ECOLOR_FORMAT ColorFormat; ECOLOR_FORMAT ColorFormat;
D3DFORMAT D3DColorFormat; D3DFORMAT D3DColorFormat;
bool DeviceLost; bool DeviceLost;
bool Fullscreen;
bool DriverWasReset; bool DriverWasReset;
bool OcclusionQuerySupport; bool OcclusionQuerySupport;
bool AlphaToCoverageSupport; bool AlphaToCoverageSupport;
u32 DisplayAdapter;
}; };
......
...@@ -312,9 +312,9 @@ bool CD3D9Texture::createTexture(u32 flags, IImage * image) ...@@ -312,9 +312,9 @@ bool CD3D9Texture::createTexture(u32 flags, IImage * image)
{ {
LPDIRECT3D9 intf = Driver->getExposedVideoData().D3D9.D3D9; LPDIRECT3D9 intf = Driver->getExposedVideoData().D3D9.D3D9;
D3DDISPLAYMODE d3ddm; D3DDISPLAYMODE d3ddm;
intf->GetAdapterDisplayMode(Driver->DisplayAdapter, &d3ddm); intf->GetAdapterDisplayMode(Driver->Params.DisplayAdapter, &d3ddm);
if (D3D_OK==intf->CheckDeviceFormat(Driver->DisplayAdapter,D3DDEVTYPE_HAL,d3ddm.Format,D3DUSAGE_AUTOGENMIPMAP,D3DRTYPE_TEXTURE,format)) if (D3D_OK==intf->CheckDeviceFormat(Driver->Params.DisplayAdapter,D3DDEVTYPE_HAL,d3ddm.Format,D3DUSAGE_AUTOGENMIPMAP,D3DRTYPE_TEXTURE,format))
{ {
usage = D3DUSAGE_AUTOGENMIPMAP; usage = D3DUSAGE_AUTOGENMIPMAP;
HardwareMipMaps = true; HardwareMipMaps = true;
......
...@@ -410,6 +410,11 @@ bool CIrrDeviceLinux::createWindow() ...@@ -410,6 +410,11 @@ bool CIrrDeviceLinux::createWindow()
#elif defined(GLX_SGIS_multisample) #elif defined(GLX_SGIS_multisample)
GLX_SAMPLE_BUFFERS_SGIS, 1, GLX_SAMPLE_BUFFERS_SGIS, 1,
GLX_SAMPLES_SGIS, CreationParams.AntiAlias, // 18,19 GLX_SAMPLES_SGIS, CreationParams.AntiAlias, // 18,19
#endif
#ifdef GL_ARB_framebuffer_sRGB
CreationParams.HandleSRGB?GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB:GLX_USE_GL,
#elif defined(GL_EXT_framebuffer_sRGB)
CreationParams.HandleSRGB?GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT:GLX_USE_GL,
#endif #endif
GLX_STEREO, CreationParams.Stereobuffer?True:False, GLX_STEREO, CreationParams.Stereobuffer?True:False,
None None
...@@ -545,7 +550,7 @@ bool CIrrDeviceLinux::createWindow() ...@@ -545,7 +550,7 @@ bool CIrrDeviceLinux::createWindow()
// attribute array for the draw buffer // attribute array for the draw buffer
int visualAttrBuffer[] = int visualAttrBuffer[] =
{ {
GLX_RGBA, GL_TRUE, GLX_RGBA, GLX_USE_GL,
GLX_RED_SIZE, 4, GLX_RED_SIZE, 4,
GLX_GREEN_SIZE, 4, GLX_GREEN_SIZE, 4,
GLX_BLUE_SIZE, 4, GLX_BLUE_SIZE, 4,
...@@ -557,6 +562,11 @@ bool CIrrDeviceLinux::createWindow() ...@@ -557,6 +562,11 @@ bool CIrrDeviceLinux::createWindow()
// GLX_USE_GL, which is silently ignored by glXChooseVisual // GLX_USE_GL, which is silently ignored by glXChooseVisual
CreationParams.Doublebuffer?GLX_DOUBLEBUFFER:GLX_USE_GL, // 14 CreationParams.Doublebuffer?GLX_DOUBLEBUFFER:GLX_USE_GL, // 14
CreationParams.Stereobuffer?GLX_STEREO:GLX_USE_GL, // 15 CreationParams.Stereobuffer?GLX_STEREO:GLX_USE_GL, // 15
#ifdef GL_ARB_framebuffer_sRGB
CreationParams.HandleSRGB?GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB:GLX_USE_GL,
#elif defined(GL_EXT_framebuffer_sRGB)
CreationParams.HandleSRGB?GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT:GLX_USE_GL,
#endif
None None
}; };
...@@ -613,7 +623,7 @@ bool CIrrDeviceLinux::createWindow() ...@@ -613,7 +623,7 @@ bool CIrrDeviceLinux::createWindow()
} }
#ifdef _DEBUG #ifdef _DEBUG
else else
os::Printer::log("Visual chosen: ", core::stringc(static_cast<u32>(visual->visualid)).c_str(), ELL_INFORMATION); os::Printer::log("Visual chosen: ", core::stringc(static_cast<u32>(visual->visualid)).c_str(), ELL_DEBUG);
#endif #endif
// create color map // create color map
......
This diff is collapsed.
...@@ -33,19 +33,20 @@ namespace video ...@@ -33,19 +33,20 @@ namespace video
class COpenGLDriver : public CNullDriver, public IMaterialRendererServices, public COpenGLExtensionHandler class COpenGLDriver : public CNullDriver, public IMaterialRendererServices, public COpenGLExtensionHandler
{ {
friend class COpenGLTexture;
public: public:
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ #ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceWin32* device); COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceWin32* device);
//! inits the windows specific parts of the open gl driver //! inits the windows specific parts of the open gl driver
bool initDriver(SIrrlichtCreationParameters params, CIrrDeviceWin32* device); bool initDriver(CIrrDeviceWin32* device);
bool changeRenderContext(const SExposedVideoData& videoData, CIrrDeviceWin32* device); bool changeRenderContext(const SExposedVideoData& videoData, CIrrDeviceWin32* device);
#endif #endif
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_ #ifdef _IRR_COMPILE_WITH_X11_DEVICE_
COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceLinux* device); COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceLinux* device);
//! inits the GLX specific parts of the open gl driver //! inits the GLX specific parts of the open gl driver
bool initDriver(SIrrlichtCreationParameters params, CIrrDeviceLinux* device); bool initDriver(CIrrDeviceLinux* device);
bool changeRenderContext(const SExposedVideoData& videoData, CIrrDeviceLinux* device); bool changeRenderContext(const SExposedVideoData& videoData, CIrrDeviceLinux* device);
#endif #endif
...@@ -392,7 +393,7 @@ namespace video ...@@ -392,7 +393,7 @@ namespace video
void uploadClipPlane(u32 index); void uploadClipPlane(u32 index);
//! inits the parts of the open gl driver used on all platforms //! inits the parts of the open gl driver used on all platforms
bool genericDriverInit(const core::dimension2d<u32>& screenSize, bool stencilBuffer); bool genericDriverInit();
//! returns a device dependent texture from a software surface (IImage) //! returns a device dependent texture from a software surface (IImage)
virtual video::ITexture* createDeviceDependentTexture(IImage* surface, const io::path& name, void* mipmapData); virtual video::ITexture* createDeviceDependentTexture(IImage* surface, const io::path& name, void* mipmapData);
...@@ -472,6 +473,7 @@ namespace video ...@@ -472,6 +473,7 @@ namespace video
//! Render target type for render operations //! Render target type for render operations
E_RENDER_TARGET CurrentTarget; E_RENDER_TARGET CurrentTarget;
SIrrlichtCreationParameters Params;
bool Doublebuffer; bool Doublebuffer;
bool Stereo; bool Stereo;
......
...@@ -135,26 +135,31 @@ GLint COpenGLTexture::getOpenGLFormatAndParametersFromColorFormat(ECOLOR_FORMAT ...@@ -135,26 +135,31 @@ GLint COpenGLTexture::getOpenGLFormatAndParametersFromColorFormat(ECOLOR_FORMAT
filtering = GL_LINEAR; filtering = GL_LINEAR;
colorformat = GL_RGBA; colorformat = GL_RGBA;
type = GL_UNSIGNED_BYTE; type = GL_UNSIGNED_BYTE;
GLenum internalformat = GL_RGBA;
switch(format) switch(format)
{ {
case ECF_A1R5G5B5: case ECF_A1R5G5B5:
colorformat=GL_BGRA_EXT; colorformat=GL_BGRA_EXT;
type=GL_UNSIGNED_SHORT_1_5_5_5_REV; type=GL_UNSIGNED_SHORT_1_5_5_5_REV;
return GL_RGBA; internalformat = GL_RGBA;
break;
case ECF_R5G6B5: case ECF_R5G6B5:
colorformat=GL_BGR; colorformat=GL_BGR;
type=GL_UNSIGNED_SHORT_5_6_5_REV; type=GL_UNSIGNED_SHORT_5_6_5_REV;
return GL_RGB; internalformat = GL_RGB;
break;
case ECF_R8G8B8: case ECF_R8G8B8:
colorformat=GL_BGR; colorformat=GL_BGR;
type=GL_UNSIGNED_BYTE; type=GL_UNSIGNED_BYTE;
return GL_RGB; internalformat = GL_RGB;
break;
case ECF_A8R8G8B8: case ECF_A8R8G8B8:
colorformat=GL_BGRA_EXT; colorformat=GL_BGRA_EXT;
if (Driver->Version > 101) if (Driver->Version > 101)
type=GL_UNSIGNED_INT_8_8_8_8_REV; type=GL_UNSIGNED_INT_8_8_8_8_REV;
return GL_RGBA; internalformat = GL_RGBA;
break;
// Floating Point texture formats. Thanks to Patryk "Nadro" Nadrowski. // Floating Point texture formats. Thanks to Patryk "Nadro" Nadrowski.
case ECF_R16F: case ECF_R16F:
{ {
...@@ -163,11 +168,12 @@ GLint COpenGLTexture::getOpenGLFormatAndParametersFromColorFormat(ECOLOR_FORMAT ...@@ -163,11 +168,12 @@ GLint COpenGLTexture::getOpenGLFormatAndParametersFromColorFormat(ECOLOR_FORMAT
colorformat = GL_RED; colorformat = GL_RED;
type = GL_FLOAT; type = GL_FLOAT;
return GL_R16F; internalformat = GL_R16F;
#else #else
return GL_RGB8; internalformat = GL_RGB8;
#endif #endif
} }
break;
case ECF_G16R16F: case ECF_G16R16F:
{ {
#ifdef GL_ARB_texture_rg #ifdef GL_ARB_texture_rg
...@@ -175,11 +181,12 @@ GLint COpenGLTexture::getOpenGLFormatAndParametersFromColorFormat(ECOLOR_FORMAT ...@@ -175,11 +181,12 @@ GLint COpenGLTexture::getOpenGLFormatAndParametersFromColorFormat(ECOLOR_FORMAT
colorformat = GL_RG; colorformat = GL_RG;
type = GL_FLOAT; type = GL_FLOAT;
return GL_RG16F; internalformat = GL_RG16F;
#else #else
return GL_RGB8; internalformat = GL_RGB8;
#endif #endif
} }
break;
case ECF_A16B16G16R16F: case ECF_A16B16G16R16F:
{ {
#ifdef GL_ARB_texture_rg #ifdef GL_ARB_texture_rg
...@@ -187,11 +194,12 @@ GLint COpenGLTexture::getOpenGLFormatAndParametersFromColorFormat(ECOLOR_FORMAT ...@@ -187,11 +194,12 @@ GLint COpenGLTexture::getOpenGLFormatAndParametersFromColorFormat(ECOLOR_FORMAT
colorformat = GL_RGBA; colorformat = GL_RGBA;
type = GL_FLOAT; type = GL_FLOAT;
return GL_RGBA16F_ARB; internalformat = GL_RGBA16F_ARB;
#else #else
return GL_RGBA8; internalformat = GL_RGBA8;
#endif #endif
} }
break;
case ECF_R32F: case ECF_R32F:
{ {
#ifdef GL_ARB_texture_rg #ifdef GL_ARB_texture_rg
...@@ -199,11 +207,12 @@ GLint COpenGLTexture::getOpenGLFormatAndParametersFromColorFormat(ECOLOR_FORMAT ...@@ -199,11 +207,12 @@ GLint COpenGLTexture::getOpenGLFormatAndParametersFromColorFormat(ECOLOR_FORMAT
colorformat = GL_RED; colorformat = GL_RED;
type = GL_FLOAT; type = GL_FLOAT;
return GL_R32F; internalformat = GL_R32F;
#else #else
return GL_RGB8; internalformat = GL_RGB8;
#endif #endif
} }
break;
case ECF_G32R32F: case ECF_G32R32F:
{ {
#ifdef GL_ARB_texture_rg #ifdef GL_ARB_texture_rg
...@@ -211,11 +220,12 @@ GLint COpenGLTexture::getOpenGLFormatAndParametersFromColorFormat(ECOLOR_FORMAT ...@@ -211,11 +220,12 @@ GLint COpenGLTexture::getOpenGLFormatAndParametersFromColorFormat(ECOLOR_FORMAT
colorformat = GL_RG; colorformat = GL_RG;
type = GL_FLOAT; type = GL_FLOAT;
return GL_RG32F; internalformat = GL_RG32F;
#else #else
return GL_RGB8; internalformat = GL_RGB8;
#endif #endif
} }
break;
case ECF_A32B32G32R32F: case ECF_A32B32G32R32F:
{ {
#ifdef GL_ARB_texture_float #ifdef GL_ARB_texture_float
...@@ -223,17 +233,28 @@ GLint COpenGLTexture::getOpenGLFormatAndParametersFromColorFormat(ECOLOR_FORMAT ...@@ -223,17 +233,28 @@ GLint COpenGLTexture::getOpenGLFormatAndParametersFromColorFormat(ECOLOR_FORMAT
colorformat = GL_RGBA; colorformat = GL_RGBA;
type = GL_FLOAT; type = GL_FLOAT;
return GL_RGBA32F_ARB; internalformat = GL_RGBA32F_ARB;
#else #else
return GL_RGBA8; internalformat = GL_RGBA8;
#endif #endif
} }
break;
default: default:
{ {
os::Printer::log("Unsupported texture format", ELL_ERROR); os::Printer::log("Unsupported texture format", ELL_ERROR);
return GL_RGBA8; internalformat = GL_RGBA8;
} }
} }
#if defined(GL_ARB_framebuffer_sRGB) || defined(GL_EXT_framebuffer_sRGB)
if (Driver->Params.HandleSRGB)
{
if (internalformat==GL_RGBA)
internalformat=GL_SRGB_ALPHA_EXT;
else if (internalformat==GL_RGB)
internalformat=GL_SRGB_EXT;
}
#endif
return internalformat;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment