summaryrefslogtreecommitdiffstats
path: root/src/graphics/engine
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-09-30 00:23:26 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-09-30 00:23:26 +0200
commitb46dc3850f489dca68fabe4512a611aed32e7df5 (patch)
treea0b8c0f35c270ca7a207f2d3788d8c73cbf47707 /src/graphics/engine
parenta8554cfae3358af6b909c45ba9dc9bdfc020bdfb (diff)
downloadcolobot-b46dc3850f489dca68fabe4512a611aed32e7df5.tar.gz
colobot-b46dc3850f489dca68fabe4512a611aed32e7df5.tar.bz2
colobot-b46dc3850f489dca68fabe4512a611aed32e7df5.zip
Map texture painting
Diffstat (limited to 'src/graphics/engine')
-rw-r--r--src/graphics/engine/engine.cpp33
-rw-r--r--src/graphics/engine/engine.h6
2 files changed, 29 insertions, 10 deletions
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index b4ad962..7e00134 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -2074,7 +2074,7 @@ void CEngine::SetViewParams(const Math::Vector& eyePt, const Math::Vector& looka
m_sound->SetListener(eyePt, lookatPt);
}
-Texture CEngine::CreateTexture(const std::string& texName, const TextureCreateParams& params)
+Texture CEngine::CreateTexture(const std::string& texName, const TextureCreateParams& params, CImage* image)
{
if (texName.empty())
return Texture(); // invalid texture
@@ -2082,16 +2082,25 @@ Texture CEngine::CreateTexture(const std::string& texName, const TextureCreatePa
if (m_texBlacklist.find(texName) != m_texBlacklist.end())
return Texture(); // invalid texture
- CImage img;
- if (! img.Load(m_app->GetDataFilePath(DIR_TEXTURE, texName)))
+ Texture tex;
+
+ if (image == nullptr)
{
- std::string error = img.GetError();
- GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str());
- m_texBlacklist.insert(texName);
- return Texture(); // invalid texture
- }
+ CImage img;
+ if (! img.Load(m_app->GetDataFilePath(DIR_TEXTURE, texName)))
+ {
+ std::string error = img.GetError();
+ GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str());
+ m_texBlacklist.insert(texName);
+ return Texture(); // invalid texture
+ }
- Texture tex = m_device->CreateTexture(&img, params);
+ tex = m_device->CreateTexture(&img, params);
+ }
+ else
+ {
+ tex = m_device->CreateTexture(image, params);
+ }
if (! tex.Valid())
{
@@ -2111,6 +2120,12 @@ Texture CEngine::LoadTexture(const std::string& name)
return LoadTexture(name, m_defaultTexParams);
}
+Texture CEngine::LoadTexture(const std::string& name, CImage* image)
+{
+ Texture tex = CreateTexture(name, m_defaultTexParams, image);
+ return tex;
+}
+
Texture CEngine::LoadTexture(const std::string& name, const TextureCreateParams& params)
{
if (m_texBlacklist.find(name) != m_texBlacklist.end())
diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h
index cbe5d04..14a40db 100644
--- a/src/graphics/engine/engine.h
+++ b/src/graphics/engine/engine.h
@@ -48,6 +48,7 @@ class CApplication;
class CInstanceManager;
class CObject;
class CSoundInterface;
+class CImage;
// Graphics module namespace
@@ -891,11 +892,14 @@ public:
//! Loads texture, creating it if not already present
Texture LoadTexture(const std::string& name);
+ //! Loads texture from existing image
+ Texture LoadTexture(const std::string& name, CImage* image);
//! Loads texture, creating it with given params if not already present
Texture LoadTexture(const std::string& name, const TextureCreateParams& params);
//! Loads all necessary textures
bool LoadAllTextures();
+ //! Changes colors in a texture
bool ChangeTextureColor(const std::string& texName,
Color colorRef1, Color colorNew1,
Color colorRef2, Color colorNew2,
@@ -1196,7 +1200,7 @@ protected:
const Material& mat, int state);
//! Create texture and add it to cache
- Texture CreateTexture(const std::string &texName, const TextureCreateParams &params);
+ Texture CreateTexture(const std::string &texName, const TextureCreateParams &params, CImage* image = nullptr);
//! Tests whether the given object is visible
bool IsVisible(int objRank);