Quellcode durchsuchen

Detect sRGB capability also on Direct3D9.
Detect sRGB sampling & writing capability separately.

Lasse Öörni vor 12 Jahren
Ursprung
Commit
a3c66ca360

+ 1 - 0
Docs/ScriptAPI.dox

@@ -2788,6 +2788,7 @@ Properties:<br>
 - bool deferredSupport (readonly)
 - bool deferredSupport (readonly)
 - bool hardwareShadowSupport (readonly)
 - bool hardwareShadowSupport (readonly)
 - bool sRGBSupport (readonly)
 - bool sRGBSupport (readonly)
+- bool sRGBWriteSupport (readonly)
 - bool forceSM2
 - bool forceSM2
 - IntVector2[]@ resolutions (readonly)
 - IntVector2[]@ resolutions (readonly)
 - int[]@ multiSampleLevels (readonly)
 - int[]@ multiSampleLevels (readonly)

+ 1 - 0
Engine/Engine/GraphicsAPI.cpp

@@ -1013,6 +1013,7 @@ static void RegisterGraphics(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Graphics", "bool get_deferredSupport() const", asMETHOD(Graphics, GetDeferredSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_deferredSupport() const", asMETHOD(Graphics, GetDeferredSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_hardwareShadowSupport() const", asMETHOD(Graphics, GetHardwareShadowSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_hardwareShadowSupport() const", asMETHOD(Graphics, GetHardwareShadowSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_sRGBSupport() const", asMETHOD(Graphics, GetSRGBSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_sRGBSupport() const", asMETHOD(Graphics, GetSRGBSupport), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Graphics", "bool get_sRGBWriteSupport() const", asMETHOD(Graphics, GetSRGBWriteSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "void set_forceSM2(bool)", asMETHOD(Graphics, SetForceSM2), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "void set_forceSM2(bool)", asMETHOD(Graphics, SetForceSM2), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_forceSM2() const", asMETHOD(Graphics, GetForceSM2), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_forceSM2() const", asMETHOD(Graphics, GetForceSM2), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "Array<IntVector2>@ get_resolutions() const", asFUNCTION(GraphicsGetResolutions), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Graphics", "Array<IntVector2>@ get_resolutions() const", asFUNCTION(GraphicsGetResolutions), asCALL_CDECL_OBJLAST);

+ 16 - 7
Engine/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -188,7 +188,8 @@ Graphics::Graphics(Context* context) :
     deferredSupport_(false),
     deferredSupport_(false),
     hardwareShadowSupport_(false),
     hardwareShadowSupport_(false),
     streamOffsetSupport_(false),
     streamOffsetSupport_(false),
-    sRGBSupport_(true),
+    sRGBSupport_(false),
+    sRGBWriteSupport_(false),
     hasSM3_(false),
     hasSM3_(false),
     forceSM2_(false),
     forceSM2_(false),
     numPrimitives_(0),
     numPrimitives_(0),
@@ -447,7 +448,7 @@ bool Graphics::SetMode(int width, int height)
 
 
 void Graphics::SetSRGB(bool enabled)
 void Graphics::SetSRGB(bool enabled)
 {
 {
-    sRGB_ = enabled;
+    sRGB_ = enabled && sRGBWriteSupport_;
 }
 }
 
 
 bool Graphics::ToggleFullscreen()
 bool Graphics::ToggleFullscreen()
@@ -1281,11 +1282,14 @@ void Graphics::SetTexture(unsigned index, Texture* texture)
                 impl_->borderColors_[index] = borderColor;
                 impl_->borderColors_[index] = borderColor;
             }
             }
         }
         }
-        bool sRGB = texture->GetSRGB();
-        if (sRGB != impl_->sRGBModes_[index])
+        if (sRGBSupport_)
         {
         {
-            impl_->device_->SetSamplerState(index, D3DSAMP_SRGBTEXTURE, sRGB ? TRUE : FALSE);
-            impl_->sRGBModes_[index] = sRGB;
+            bool sRGB = texture->GetSRGB();
+            if (sRGB != impl_->sRGBModes_[index])
+            {
+                impl_->device_->SetSamplerState(index, D3DSAMP_SRGBTEXTURE, sRGB ? TRUE : FALSE);
+                impl_->sRGBModes_[index] = sRGB;
+            }
         }
         }
     }
     }
 }
 }
@@ -1359,7 +1363,7 @@ void Graphics::SetRenderTarget(unsigned index, RenderSurface* renderTarget)
     }
     }
     
     
     // First rendertarget controls sRGB write mode
     // First rendertarget controls sRGB write mode
-    if (!index)
+    if (!index && sRGBWriteSupport_)
     {
     {
         bool sRGBWrite = renderTarget ? renderTarget->GetParentTexture()->GetSRGB() : sRGB_;
         bool sRGBWrite = renderTarget ? renderTarget->GetParentTexture()->GetSRGB() : sRGB_;
         if (sRGBWrite != impl_->sRGBWrite_)
         if (sRGBWrite != impl_->sRGBWrite_)
@@ -2248,6 +2252,11 @@ void Graphics::CheckFeatureSupport()
     if (impl_->deviceCaps_.DevCaps2 & D3DDEVCAPS2_STREAMOFFSET)
     if (impl_->deviceCaps_.DevCaps2 & D3DDEVCAPS2_STREAMOFFSET)
         streamOffsetSupport_ = true;
         streamOffsetSupport_ = true;
     
     
+    // Check for sRGB read & write
+    /// \todo Should be checked for each texture format separately
+    sRGBSupport_ = impl_->CheckFormatSupport(D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_SRGBREAD, D3DRTYPE_TEXTURE);
+    sRGBWriteSupport_ = impl_->CheckFormatSupport(D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_SRGBWRITE, D3DRTYPE_TEXTURE);
+    
     SendEvent(E_GRAPHICSFEATURES);
     SendEvent(E_GRAPHICSFEATURES);
 }
 }
 
 

+ 6 - 2
Engine/Graphics/Direct3D9/D3D9Graphics.h

@@ -246,8 +246,10 @@ public:
     bool GetHardwareShadowSupport() const { return hardwareShadowSupport_; }
     bool GetHardwareShadowSupport() const { return hardwareShadowSupport_; }
     /// Return whether stream offset is supported.
     /// Return whether stream offset is supported.
     bool GetStreamOffsetSupport() const { return streamOffsetSupport_; }
     bool GetStreamOffsetSupport() const { return streamOffsetSupport_; }
-    /// Return whether sRGB textures are supported.
+    /// Return whether sRGB conversion on texture sampling is supported.
     bool GetSRGBSupport() const { return sRGBSupport_; }
     bool GetSRGBSupport() const { return sRGBSupport_; }
+    /// Return whether sRGB conversion on rendertarget writing is supported.
+    bool GetSRGBWriteSupport() const { return sRGBWriteSupport_; }
     /// Return supported fullscreen resolutions.
     /// Return supported fullscreen resolutions.
     PODVector<IntVector2> GetResolutions() const;
     PODVector<IntVector2> GetResolutions() const;
     /// Return supported multisampling levels.
     /// Return supported multisampling levels.
@@ -425,8 +427,10 @@ private:
     bool hardwareShadowSupport_;
     bool hardwareShadowSupport_;
     /// Stream offset support flag.
     /// Stream offset support flag.
     bool streamOffsetSupport_;
     bool streamOffsetSupport_;
-    /// sRGB texture support flag.
+    /// sRGB conversion on read support flag.
     bool sRGBSupport_;
     bool sRGBSupport_;
+    /// sRGB conversion on write support flag.
+    bool sRGBWriteSupport_;
     /// Shader Model 3 flag.
     /// Shader Model 3 flag.
     bool hasSM3_;
     bool hasSM3_;
     /// Force Shader Model 2 flag.
     /// Force Shader Model 2 flag.

+ 3 - 0
Engine/Graphics/Direct3D9/D3D9Texture.cpp

@@ -103,6 +103,9 @@ void Texture::SetBorderColor(const Color& color)
 
 
 void Texture::SetSRGB(bool enable)
 void Texture::SetSRGB(bool enable)
 {
 {
+    if (graphics_)
+        enable &= graphics_->GetSRGBSupport();
+    
     sRGB_ = enable;
     sRGB_ = enable;
 }
 }
 
 

+ 24 - 15
Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -169,6 +169,7 @@ Graphics::Graphics(Context* context_) :
     etcTextureSupport_(false),
     etcTextureSupport_(false),
     pvrtcTextureSupport_(false),
     pvrtcTextureSupport_(false),
     sRGBSupport_(false),
     sRGBSupport_(false),
+    sRGBWriteSupport_(false),
     numPrimitives_(0),
     numPrimitives_(0),
     numBatches_(0),
     numBatches_(0),
     maxScratchBufferRequest_(0),
     maxScratchBufferRequest_(0),
@@ -382,6 +383,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool resizable, b
             dxtTextureSupport_ = GLEW_EXT_texture_compression_s3tc != 0;
             dxtTextureSupport_ = GLEW_EXT_texture_compression_s3tc != 0;
             anisotropySupport_ = GLEW_EXT_texture_filter_anisotropic != 0;
             anisotropySupport_ = GLEW_EXT_texture_filter_anisotropic != 0;
             sRGBSupport_ = GLEW_EXT_texture_sRGB != 0;
             sRGBSupport_ = GLEW_EXT_texture_sRGB != 0;
+            sRGBWriteSupport_ = GLEW_EXT_framebuffer_sRGB != 0;
             #else
             #else
             dxtTextureSupport_ = CheckExtension(extensions, "EXT_texture_compression_dxt1");
             dxtTextureSupport_ = CheckExtension(extensions, "EXT_texture_compression_dxt1");
             etcTextureSupport_ = CheckExtension(extensions, "OES_compressed_ETC1_RGB8_texture");
             etcTextureSupport_ = CheckExtension(extensions, "OES_compressed_ETC1_RGB8_texture");
@@ -444,7 +446,8 @@ bool Graphics::SetMode(int width, int height)
 
 
 void Graphics::SetSRGB(bool enabled)
 void Graphics::SetSRGB(bool enabled)
 {
 {
-    enabled &= sRGBSupport_;
+    enabled &= sRGBWriteSupport_;
+    
     if (enabled != sRGB_)
     if (enabled != sRGB_)
     {
     {
         sRGB_ = enabled;
         sRGB_ = enabled;
@@ -2276,14 +2279,17 @@ void Graphics::CommitFramebuffer()
         
         
         #ifndef GL_ES_VERSION_2_0
         #ifndef GL_ES_VERSION_2_0
         // Disable/enable sRGB write
         // Disable/enable sRGB write
-        bool sRGBWrite = sRGB_;
-        if (sRGBWrite != impl_->sRGBWrite_)
+        if (sRGBWriteSupport_)
         {
         {
-            if (sRGBWrite)
-                glEnable(GL_FRAMEBUFFER_SRGB_EXT);
-            else
-                glDisable(GL_FRAMEBUFFER_SRGB_EXT);
-            impl_->sRGBWrite_ = sRGBWrite;
+            bool sRGBWrite = sRGB_;
+            if (sRGBWrite != impl_->sRGBWrite_)
+            {
+                if (sRGBWrite)
+                    glEnable(GL_FRAMEBUFFER_SRGB_EXT);
+                else
+                    glDisable(GL_FRAMEBUFFER_SRGB_EXT);
+                impl_->sRGBWrite_ = sRGBWrite;
+            }
         }
         }
         #endif
         #endif
         
         
@@ -2448,14 +2454,17 @@ void Graphics::CommitFramebuffer()
     
     
     #ifndef GL_ES_VERSION_2_0
     #ifndef GL_ES_VERSION_2_0
     // Disable/enable sRGB write
     // Disable/enable sRGB write
-    bool sRGBWrite = renderTargets_[0] ? renderTargets_[0]->GetParentTexture()->GetSRGB() : sRGB_;
-    if (sRGBWrite != impl_->sRGBWrite_)
+    if (sRGBWriteSupport_)
     {
     {
-        if (sRGBWrite)
-            glEnable(GL_FRAMEBUFFER_SRGB_EXT);
-        else
-            glDisable(GL_FRAMEBUFFER_SRGB_EXT);
-        impl_->sRGBWrite_ = sRGBWrite;
+        bool sRGBWrite = renderTargets_[0] ? renderTargets_[0]->GetParentTexture()->GetSRGB() : sRGB_;
+        if (sRGBWrite != impl_->sRGBWrite_)
+        {
+            if (sRGBWrite)
+                glEnable(GL_FRAMEBUFFER_SRGB_EXT);
+            else
+                glDisable(GL_FRAMEBUFFER_SRGB_EXT);
+            impl_->sRGBWrite_ = sRGBWrite;
+        }
     }
     }
     #endif
     #endif
 }
 }

+ 6 - 2
Engine/Graphics/OpenGL/OGLGraphics.h

@@ -257,8 +257,10 @@ public:
     bool GetHardwareShadowSupport() const { return true; }
     bool GetHardwareShadowSupport() const { return true; }
     /// Return whether stream offset is supported. Always false on OpenGL.
     /// Return whether stream offset is supported. Always false on OpenGL.
     bool GetStreamOffsetSupport() const { return false; }
     bool GetStreamOffsetSupport() const { return false; }
-    /// Return whether sRGB textures are supported.
+    /// Return whether sRGB conversion on texture sampling is supported.
     bool GetSRGBSupport() const { return sRGBSupport_; }
     bool GetSRGBSupport() const { return sRGBSupport_; }
+    /// Return whether sRGB conversion on rendertarget writing is supported.
+    bool GetSRGBWriteSupport() const { return sRGBWriteSupport_; }
     /// Return supported fullscreen resolutions.
     /// Return supported fullscreen resolutions.
     PODVector<IntVector2> GetResolutions() const;
     PODVector<IntVector2> GetResolutions() const;
     /// Return supported multisampling levels.
     /// Return supported multisampling levels.
@@ -438,8 +440,10 @@ private:
     bool etcTextureSupport_;
     bool etcTextureSupport_;
     /// PVRTC formats support flag.
     /// PVRTC formats support flag.
     bool pvrtcTextureSupport_;
     bool pvrtcTextureSupport_;
-    /// sRGB texture support flag.
+    /// sRGB conversion on read support flag.
     bool sRGBSupport_;
     bool sRGBSupport_;
+    /// sRGB conversion on write support flag.
+    bool sRGBWriteSupport_;
     /// Number of primitives this frame.
     /// Number of primitives this frame.
     unsigned numPrimitives_;
     unsigned numPrimitives_;
     /// Number of batches this frame.
     /// Number of batches this frame.