diff options
Diffstat (limited to 'src/graphics/engine')
-rw-r--r-- | src/graphics/engine/engine.cpp | 33 | ||||
-rw-r--r-- | src/graphics/engine/engine.h | 6 |
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 ¶ms); + Texture CreateTexture(const std::string &texName, const TextureCreateParams ¶ms, CImage* image = nullptr); //! Tests whether the given object is visible bool IsVisible(int objRank); |