Texture format detection; minor fixes

- detection of texture format
- fixed depth mask bug
- minor refactoring
dev-ui
Piotr Dziwinski 2012-09-09 12:56:09 +02:00
parent c2c1294ec9
commit c6673b9aee
5 changed files with 77 additions and 25 deletions

View File

@ -43,7 +43,7 @@ Gfx::CCloud::CCloud(CInstanceManager* iMan, Gfx::CEngine* engine)
m_level = 0.0f; m_level = 0.0f;
m_wind = Math::Vector(0.0f, 0.0f, 0.0f); m_wind = Math::Vector(0.0f, 0.0f, 0.0f);
m_subdiv = 8; m_subdiv = 8;
m_enable = true; m_enabled = true;
m_lines.reserve(CLOUD_LINE_PREALLOCATE_COUNT); m_lines.reserve(CLOUD_LINE_PREALLOCATE_COUNT);
} }
@ -96,7 +96,7 @@ void Gfx::CCloud::AdjustLevel(Math::Vector &pos, Math::Vector &eye, float deep,
void Gfx::CCloud::Draw() void Gfx::CCloud::Draw()
{ {
if (! m_enable) return; if (! m_enabled) return;
if (m_level == 0.0f) return; if (m_level == 0.0f) return;
if (m_lines.empty()) 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, void Gfx::CCloud::Create(const std::string& fileName,
Gfx::Color diffuse, Gfx::Color ambient, const Gfx::Color& diffuse, const Gfx::Color& ambient,
float level) float level)
{ {
m_diffuse = diffuse; m_diffuse = diffuse;
@ -258,12 +258,12 @@ float Gfx::CCloud::GetLevel()
return m_level; 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;
} }

View File

@ -83,18 +83,21 @@ public:
//! Removes all the clouds //! Removes all the clouds
void Flush(); void Flush();
//! Creates all areas of cloud //! 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 //! Draw the clouds
void Draw(); void Draw();
//! Modifies the cloud level //! Management of cloud level
//@{
void SetLevel(float level); void SetLevel(float level);
//! Returns the current level of clouds
float GetLevel(); float GetLevel();
//@}
//! Activate management of clouds //! Management of clouds
void SetEnable(bool enable); //@{
bool GetEnable(); void SetEnabled(bool enable);
bool GetEnabled();
//@}
protected: protected:
//! Makes the clouds evolve //! Makes the clouds evolve
@ -110,9 +113,11 @@ protected:
Gfx::CEngine* m_engine; Gfx::CEngine* m_engine;
Gfx::CTerrain* m_terrain; Gfx::CTerrain* m_terrain;
std::string m_fileName; bool m_enabled;
//! Overall level //! Overall level
float m_level; float m_level;
//! Texture
std::string m_fileName;
//! Feedrate (wind) //! Feedrate (wind)
Math::Point m_speed; Math::Point m_speed;
//! Diffuse color //! Diffuse color
@ -131,8 +136,6 @@ protected:
float m_brickSize; float m_brickSize;
std::vector<Gfx::CloudLine> m_lines; std::vector<Gfx::CloudLine> m_lines;
bool m_enable;
}; };

View File

@ -208,7 +208,7 @@ Gfx::CEngine::CEngine(CInstanceManager *iMan, CApplication *app)
m_mouseVisible = false; m_mouseVisible = false;
m_texPath = "textures/"; m_texPath = "textures/";
m_defaultTexParams.format = Gfx::TEX_IMG_RGB; m_defaultTexParams.format = Gfx::TEX_IMG_AUTO;
m_defaultTexParams.mipmap = true; m_defaultTexParams.mipmap = true;
m_defaultTexParams.minFilter = Gfx::TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR; m_defaultTexParams.minFilter = Gfx::TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR;
m_defaultTexParams.magFilter = Gfx::TEX_MAG_FILTER_LINEAR; m_defaultTexParams.magFilter = Gfx::TEX_MAG_FILTER_LINEAR;
@ -2101,6 +2101,7 @@ void Gfx::CEngine::SetViewParams(const Math::Vector& eyePt, const Math::Vector&
if (m_sound == nullptr) if (m_sound == nullptr)
m_sound = static_cast<CSoundInterface*>( m_iMan->SearchInstance(CLASS_SOUND) ); m_sound = static_cast<CSoundInterface*>( m_iMan->SearchInstance(CLASS_SOUND) );
if (m_sound != nullptr)
m_sound->SetListener(eyePt, lookatPt); m_sound->SetListener(eyePt, lookatPt);
} }

View File

@ -148,8 +148,6 @@ bool Gfx::CLightManager::DeleteLight(int lightRank)
return true; return true;
} }
// Specifies a light.
bool Gfx::CLightManager::SetLight(int lightRank, const Gfx::Light &light) bool Gfx::CLightManager::SetLight(int lightRank, const Gfx::Light &light)
{ {
if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) )

View File

@ -187,6 +187,7 @@ void Gfx::CGLDevice::EndScene()
void Gfx::CGLDevice::Clear() void Gfx::CGLDevice::Clear()
{ {
glDepthMask(GL_TRUE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 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; sourceFormat = GL_BGRA;
result.alpha = true; 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 else
assert(false); assert(false);