From c6673b9aee483cfa64b49395c5c96b023bb09549 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 9 Sep 2012 12:56:09 +0200 Subject: Texture format detection; minor fixes - detection of texture format - fixed depth mask bug - minor refactoring --- src/graphics/engine/cloud.cpp | 18 +++++++-------- src/graphics/engine/cloud.h | 27 ++++++++++++---------- src/graphics/engine/engine.cpp | 5 ++-- src/graphics/engine/lightman.cpp | 2 -- src/graphics/opengl/gldevice.cpp | 50 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/graphics/engine/cloud.cpp b/src/graphics/engine/cloud.cpp index 4c1d179..26a75ab 100644 --- a/src/graphics/engine/cloud.cpp +++ b/src/graphics/engine/cloud.cpp @@ -43,7 +43,7 @@ Gfx::CCloud::CCloud(CInstanceManager* iMan, Gfx::CEngine* engine) m_level = 0.0f; m_wind = Math::Vector(0.0f, 0.0f, 0.0f); m_subdiv = 8; - m_enable = true; + m_enabled = true; m_lines.reserve(CLOUD_LINE_PREALLOCATE_COUNT); } @@ -78,8 +78,8 @@ bool Gfx::CCloud::EventFrame(const Event &event) return true; } -void Gfx::CCloud::AdjustLevel(Math::Vector &pos, Math::Vector &eye, float deep, - Math::Point &uv1, Math::Point &uv2) +void Gfx::CCloud::AdjustLevel(Math::Vector& pos, Math::Vector& eye, float deep, + Math::Point& uv1, Math::Point& uv2) { uv1.x = (pos.x+20000.0f)/1280.0f; uv1.y = (pos.z+20000.0f)/1280.0f; @@ -96,7 +96,7 @@ void Gfx::CCloud::AdjustLevel(Math::Vector &pos, Math::Vector &eye, float deep, void Gfx::CCloud::Draw() { - if (! m_enable) return; + if (! m_enabled) return; if (m_level == 0.0f) return; if (m_lines.empty()) return; @@ -206,7 +206,7 @@ void Gfx::CCloud::CreateLine(int x, int y, int len) } void Gfx::CCloud::Create(const std::string& fileName, - Gfx::Color diffuse, Gfx::Color ambient, + const Gfx::Color& diffuse, const Gfx::Color& ambient, float level) { m_diffuse = diffuse; @@ -258,12 +258,12 @@ float Gfx::CCloud::GetLevel() return m_level; } -void Gfx::CCloud::SetEnable(bool enable) +void Gfx::CCloud::SetEnabled(bool enabled) { - m_enable = enable; + m_enabled = enabled; } -bool Gfx::CCloud::GetEnable() +bool Gfx::CCloud::GetEnabled() { - return m_enable; + return m_enabled; } diff --git a/src/graphics/engine/cloud.h b/src/graphics/engine/cloud.h index 9822c24..a9109fa 100644 --- a/src/graphics/engine/cloud.h +++ b/src/graphics/engine/cloud.h @@ -79,29 +79,32 @@ public: CCloud(CInstanceManager* iMan, CEngine* engine); ~CCloud(); - bool EventProcess(const Event &event); + bool EventProcess(const Event& event); //! Removes all the clouds void Flush(); //! Creates all areas of cloud - void Create(const std::string& fileName, Gfx::Color diffuse, Gfx::Color ambient, float level); + void Create(const std::string& fileName, const Gfx::Color& diffuse, const Gfx::Color& ambient, float level); //! Draw the clouds void Draw(); - //! Modifies the cloud level + //! Management of cloud level + //@{ void SetLevel(float level); - //! Returns the current level of clouds float GetLevel(); + //@} - //! Activate management of clouds - void SetEnable(bool enable); - bool GetEnable(); + //! Management of clouds + //@{ + void SetEnabled(bool enable); + bool GetEnabled(); + //@} protected: //! Makes the clouds evolve bool EventFrame(const Event &event); //! Adjusts the position to normal, to imitate the clouds at movement - void AdjustLevel(Math::Vector &pos, Math::Vector &eye, float deep, - Math::Point &uv1, Math::Point &uv2); + void AdjustLevel(Math::Vector& pos, Math::Vector& eye, float deep, + Math::Point& uv1, Math::Point& uv2); //! Updates the positions, relative to the ground void CreateLine(int x, int y, int len); @@ -110,9 +113,11 @@ protected: Gfx::CEngine* m_engine; Gfx::CTerrain* m_terrain; - std::string m_fileName; + bool m_enabled; //! Overall level float m_level; + //! Texture + std::string m_fileName; //! Feedrate (wind) Math::Point m_speed; //! Diffuse color @@ -131,8 +136,6 @@ protected: float m_brickSize; std::vector m_lines; - - bool m_enable; }; diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index ed7b9c7..068687a 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -208,7 +208,7 @@ Gfx::CEngine::CEngine(CInstanceManager *iMan, CApplication *app) m_mouseVisible = false; m_texPath = "textures/"; - m_defaultTexParams.format = Gfx::TEX_IMG_RGB; + m_defaultTexParams.format = Gfx::TEX_IMG_AUTO; m_defaultTexParams.mipmap = true; m_defaultTexParams.minFilter = Gfx::TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR; m_defaultTexParams.magFilter = Gfx::TEX_MAG_FILTER_LINEAR; @@ -2101,7 +2101,8 @@ void Gfx::CEngine::SetViewParams(const Math::Vector& eyePt, const Math::Vector& if (m_sound == nullptr) m_sound = static_cast( m_iMan->SearchInstance(CLASS_SOUND) ); - m_sound->SetListener(eyePt, lookatPt); + if (m_sound != nullptr) + m_sound->SetListener(eyePt, lookatPt); } Gfx::Texture Gfx::CEngine::CreateTexture(const std::string& texName, const Gfx::TextureCreateParams& params) diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp index b9796d2..46000d7 100644 --- a/src/graphics/engine/lightman.cpp +++ b/src/graphics/engine/lightman.cpp @@ -148,8 +148,6 @@ bool Gfx::CLightManager::DeleteLight(int lightRank) return true; } -// Specifies a light. - bool Gfx::CLightManager::SetLight(int lightRank, const Gfx::Light &light) { if ( (lightRank < 0) || (lightRank >= static_cast( m_dynLights.size() )) ) diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 7221421..a779a5f 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -187,6 +187,7 @@ void Gfx::CGLDevice::EndScene() void Gfx::CGLDevice::Clear() { + glDepthMask(GL_TRUE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } @@ -454,6 +455,55 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(ImageData *data, const Gfx::TextureCr sourceFormat = GL_BGRA; result.alpha = true; } + else if (params.format == Gfx::TEX_IMG_AUTO) + { + if (data->surface->format->Amask != 0) + { + if ((data->surface->format->Rmask == 0xFF000000) && + (data->surface->format->Gmask == 0x00FF0000) && + (data->surface->format->Bmask == 0x0000FF00) && + (data->surface->format->Amask == 0x000000FF)) + { + sourceFormat = GL_BGRA; + result.alpha = true; + } + else if ((data->surface->format->Bmask == 0xFF000000) && + (data->surface->format->Gmask == 0x00FF0000) && + (data->surface->format->Rmask == 0x0000FF00) && + (data->surface->format->Amask == 0x000000FF)) + { + sourceFormat = GL_RGBA; + result.alpha = true; + } + else + { + GetLogger()->Error("Auto texture format failed\n"); + return Gfx::Texture(); // other format? + } + } + else + { + if ((data->surface->format->Rmask == 0xFF0000) && + (data->surface->format->Gmask == 0x00FF00) && + (data->surface->format->Bmask == 0x0000FF)) + { + sourceFormat = GL_BGR; + result.alpha = false; + } + else if ((data->surface->format->Bmask == 0xFF0000) && + (data->surface->format->Gmask == 0x00FF00) && + (data->surface->format->Rmask == 0x0000FF)) + { + sourceFormat = GL_RGB; + result.alpha = false; + } + else + { + GetLogger()->Error("Auto texture format failed\n"); + return Gfx::Texture(); // other format? + } + } + } else assert(false); -- cgit v1.2.3-1-g7c22