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_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;
}

View File

@ -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<Gfx::CloudLine> m_lines;
bool m_enable;
};

View File

@ -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<CSoundInterface*>( 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)

View File

@ -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<int>( m_dynLights.size() )) )

View File

@ -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);