Kaynağa Gözat

Added possibility to run OpenGL mode without hardware DXT support (for severely broken drivers.)

Lasse Öörni 13 yıl önce
ebeveyn
işleme
a5b035d886

+ 1 - 0
Engine/Engine/GraphicsAPI.cpp

@@ -781,6 +781,7 @@ static void RegisterGraphics(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Graphics", "bool get_hardwareDepthSupport() const", asMETHOD(Graphics, GetHardwareDepthSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_hardwareDepthSupport() const", asMETHOD(Graphics, GetHardwareDepthSupport), 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_hiresShadowSupport() const", asMETHOD(Graphics, GetHiresShadowSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_hiresShadowSupport() const", asMETHOD(Graphics, GetHiresShadowSupport), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Graphics", "bool get_compressedTextureSupport() const", asMETHOD(Graphics, GetCompressedTextureSupport), 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);

+ 5 - 3
Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -133,6 +133,7 @@ Graphics::Graphics(Context* context_) :
     lightPrepassSupport_(false),
     lightPrepassSupport_(false),
     deferredSupport_(false),
     deferredSupport_(false),
     hardwareDepthSupport_(false),
     hardwareDepthSupport_(false),
+    compressedTextureSupport_(false),
     numPrimitives_(0),
     numPrimitives_(0),
     numBatches_(0),
     numBatches_(0),
     defaultTextureFilterMode_(FILTER_BILINEAR),
     defaultTextureFilterMode_(FILTER_BILINEAR),
@@ -249,16 +250,17 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool vsync, bool
             return false;
             return false;
         }
         }
         
         
-        if (!_GLEE_EXT_framebuffer_object || !_GLEE_EXT_packed_depth_stencil || !_GLEE_EXT_texture_compression_s3tc ||
-            !_GLEE_EXT_texture_filter_anisotropic)
+        if (!_GLEE_EXT_framebuffer_object || !_GLEE_EXT_packed_depth_stencil || !_GLEE_EXT_texture_filter_anisotropic)
         {
         {
-            LOGERROR("EXT_framebuffer_object, EXT_packed_depth_stencil, EXT_texture_compression_s3tc and "
+            LOGERROR("EXT_framebuffer_object, EXT_packed_depth_stencil and "
                 "EXT_texture_filter_anisotropic OpenGL extensions are required");
                 "EXT_texture_filter_anisotropic OpenGL extensions are required");
             glfwCloseWindow(impl_->window_);
             glfwCloseWindow(impl_->window_);
             impl_->window_ = 0;
             impl_->window_ = 0;
             return false;
             return false;
         }
         }
         
         
+        compressedTextureSupport_ = _GLEE_EXT_texture_compression_s3tc != 0;
+        
         // Set window close callback
         // Set window close callback
         glfwSetWindowCloseCallback(CloseCallback);
         glfwSetWindowCloseCallback(CloseCallback);
         
         

+ 4 - 0
Engine/Graphics/OpenGL/OGLGraphics.h

@@ -247,6 +247,8 @@ public:
     bool GetHiresShadowSupport() const { return true; }
     bool GetHiresShadowSupport() 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 DXT texture compression is supported.
+    bool GetCompressedTextureSupport() const { return compressedTextureSupport_; }
     /// Return supported fullscreen resolutions.
     /// Return supported fullscreen resolutions.
     PODVector<IntVector2> GetResolutions() const;
     PODVector<IntVector2> GetResolutions() const;
     /// Return supported multisampling levels.
     /// Return supported multisampling levels.
@@ -394,6 +396,8 @@ private:
     bool deferredSupport_;
     bool deferredSupport_;
     /// Hardware depth support flag.
     /// Hardware depth support flag.
     bool hardwareDepthSupport_;
     bool hardwareDepthSupport_;
+    /// Compressed texture support flag.
+    bool compressedTextureSupport_;
     /// Number of primitives this frame.
     /// Number of primitives this frame.
     unsigned numPrimitives_;
     unsigned numPrimitives_;
     /// Number of batches this frame.
     /// Number of batches this frame.

+ 20 - 2
Engine/Graphics/OpenGL/OGLTexture2D.cpp

@@ -303,6 +303,13 @@ bool Texture2D::Load(SharedPtr<Image> image, bool useAlpha)
         int height = image->GetHeight();
         int height = image->GetHeight();
         unsigned levels = image->GetNumCompressedLevels();
         unsigned levels = image->GetNumCompressedLevels();
         unsigned format = GetDXTFormat(image->GetCompressedFormat());
         unsigned format = GetDXTFormat(image->GetCompressedFormat());
+        bool needDecompress = false;
+        
+        if (!graphics_->GetCompressedTextureSupport())
+        {
+            format = Graphics::GetRGBAFormat();
+            needDecompress = true;
+        }
         
         
         unsigned mipsToSkip = mipsToSkip_[quality];
         unsigned mipsToSkip = mipsToSkip_[quality];
         if (mipsToSkip >= levels)
         if (mipsToSkip >= levels)
@@ -318,8 +325,19 @@ bool Texture2D::Load(SharedPtr<Image> image, bool useAlpha)
         for (unsigned i = 0; i < levels_ && i < levels - mipsToSkip; ++i)
         for (unsigned i = 0; i < levels_ && i < levels - mipsToSkip; ++i)
         {
         {
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
-            SetData(i, 0, 0, level.width_, level.height_, level.data_);
-            memoryUse += level.rows_ * level.rowSize_;
+            if (!needDecompress)
+            {
+                SetData(i, 0, 0, level.width_, level.height_, level.data_);
+                memoryUse += level.rows_ * level.rowSize_;
+            }
+            else
+            {
+                unsigned char* rgbaData = new unsigned char[level.width_ * level.height_ * 4];
+                level.Decompress(rgbaData);
+                SetData(i, 0, 0, level.width_, level.height_, rgbaData);
+                memoryUse += level.width_ * level.height_ * 4;
+                delete[] rgbaData;
+            }
         }
         }
     }
     }
     
     

+ 20 - 2
Engine/Graphics/OpenGL/OGLTextureCube.cpp

@@ -389,6 +389,7 @@ bool TextureCube::Load(CubeMapFace face, SharedPtr<Image> image, bool useAlpha)
         int height = image->GetHeight();
         int height = image->GetHeight();
         unsigned levels = image->GetNumCompressedLevels();
         unsigned levels = image->GetNumCompressedLevels();
         unsigned format = GetDXTFormat(image->GetCompressedFormat());
         unsigned format = GetDXTFormat(image->GetCompressedFormat());
+        bool needDecompress = false;
         
         
         if (width != height)
         if (width != height)
         {
         {
@@ -396,6 +397,12 @@ bool TextureCube::Load(CubeMapFace face, SharedPtr<Image> image, bool useAlpha)
             return false;
             return false;
         }
         }
         
         
+        if (!graphics_->GetCompressedTextureSupport())
+        {
+            format = Graphics::GetRGBAFormat();
+            needDecompress = true;
+        }
+        
         unsigned mipsToSkip = mipsToSkip_[quality];
         unsigned mipsToSkip = mipsToSkip_[quality];
         if (mipsToSkip >= levels)
         if (mipsToSkip >= levels)
             mipsToSkip = levels - 1;
             mipsToSkip = levels - 1;
@@ -427,8 +434,19 @@ bool TextureCube::Load(CubeMapFace face, SharedPtr<Image> image, bool useAlpha)
         for (unsigned i = 0; i < levels_ && i < levels - mipsToSkip; ++i)
         for (unsigned i = 0; i < levels_ && i < levels - mipsToSkip; ++i)
         {
         {
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
             CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
-            SetData(face, i, 0, 0, level.width_, level.height_, level.data_);
-            memoryUse += level.rows_ * level.rowSize_;
+            if (!needDecompress)
+            {
+                SetData(face, i, 0, 0, level.width_, level.height_, level.data_);
+                memoryUse += level.rows_ * level.rowSize_;
+            }
+            else
+            {
+                unsigned char* rgbaData = new unsigned char[level.width_ * level.height_ * 4];
+                level.Decompress(rgbaData);
+                SetData(face, i, 0, 0, level.width_, level.height_, rgbaData);
+                memoryUse += level.width_ * level.height_ * 4;
+                delete[] rgbaData;
+            }
         }
         }
     }
     }