Add image manipulator for srgb texture
This commit is contained in:
parent
f3497a9b3b
commit
b90d4b2d8a
@ -31,6 +31,7 @@
|
||||
#include "graphics/central_settings.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/particle_kind_manager.hpp"
|
||||
#include "graphics/sp/sp_base.hpp"
|
||||
#include "graphics/stk_tex_manager.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
@ -362,10 +363,28 @@ Material::Material(const XMLNode *node, bool deprecated)
|
||||
//-----------------------------------------------------------------------------
|
||||
video::ITexture* Material::getTexture(bool srgb, bool premul_alpha)
|
||||
{
|
||||
if (!m_installed)
|
||||
std::function<void(video::IImage*)> image_mani;
|
||||
#ifndef SERVER_ONLY
|
||||
if (srgb)
|
||||
{
|
||||
install(srgb, premul_alpha);
|
||||
image_mani = [](video::IImage* img)->void
|
||||
{
|
||||
if (!CVS->isDeferredEnabled() || !CVS->isGLSL())
|
||||
return;
|
||||
uint8_t* data = (uint8_t*)img->lock();
|
||||
for (unsigned int i = 0; i < img->getDimension().Width *
|
||||
img->getDimension().Height; i++)
|
||||
{
|
||||
data[i * 4] = SP::srgb255ToLinear(data[i * 4]);
|
||||
data[i * 4 + 1] = SP::srgb255ToLinear(data[i * 4 + 1]);
|
||||
data[i * 4 + 2] = SP::srgb255ToLinear(data[i * 4 + 2]);
|
||||
}
|
||||
img->unlock();
|
||||
};
|
||||
}
|
||||
#endif
|
||||
if (!m_installed)
|
||||
install(image_mani);
|
||||
return m_texture;
|
||||
} // getTexture
|
||||
|
||||
@ -482,7 +501,7 @@ void Material::init()
|
||||
} // init
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Material::install(bool srgb, bool premul_alpha)
|
||||
void Material::install(std::function<void(video::IImage*)> image_mani)
|
||||
{
|
||||
// Don't load a texture that are not supposed to be loaded automatically
|
||||
if (m_installed) return;
|
||||
@ -500,7 +519,8 @@ void Material::install(bool srgb, bool premul_alpha)
|
||||
}
|
||||
else
|
||||
{
|
||||
m_texture = STKTexManager::getInstance()->getTexture(m_sampler_path[0]);
|
||||
m_texture = STKTexManager::getInstance()->getTexture(m_sampler_path[0],
|
||||
image_mani);
|
||||
}
|
||||
|
||||
if (m_texture == NULL) return;
|
||||
|
@ -25,13 +25,14 @@
|
||||
|
||||
#include <array>
|
||||
#include <assert.h>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace video { class ITexture; class SMaterial; }
|
||||
namespace video { class ITexture; class IImage; class SMaterial; }
|
||||
namespace scene { class ISceneNode; class IMeshBuffer; }
|
||||
}
|
||||
using namespace irr;
|
||||
@ -201,7 +202,7 @@ private:
|
||||
std::string m_colorization_mask;
|
||||
|
||||
void init ();
|
||||
void install (bool srgb = false, bool premul_alpha = false);
|
||||
void install (std::function<void(video::IImage*)> image_mani = nullptr);
|
||||
void initCustomSFX(const XMLNode *sfx);
|
||||
void initParticlesEffect(const XMLNode *node);
|
||||
|
||||
|
@ -62,7 +62,8 @@ video::ITexture* STKTexManager::findTextureInFileSystem(const std::string& filen
|
||||
} // findTextureInFileSystem
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
video::ITexture* STKTexManager::getTexture(const std::string& path)
|
||||
video::ITexture* STKTexManager::getTexture(const std::string& path,
|
||||
std::function<void(video::IImage*)> image_mani)
|
||||
{
|
||||
if (path.empty())
|
||||
{
|
||||
@ -97,7 +98,8 @@ video::ITexture* STKTexManager::getTexture(const std::string& path)
|
||||
else
|
||||
{
|
||||
new_texture =
|
||||
GE::createTexture(full_path.empty() ? path : full_path);
|
||||
GE::createTexture(full_path.empty() ? path : full_path,
|
||||
image_mani);
|
||||
}
|
||||
if (new_texture->getTextureHandler() == 0)
|
||||
{
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "ITexture.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
@ -74,7 +75,8 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
~STKTexManager();
|
||||
// ------------------------------------------------------------------------
|
||||
irr::video::ITexture* getTexture(const std::string& path);
|
||||
irr::video::ITexture* getTexture(const std::string& path,
|
||||
std::function<void(irr::video::IImage*)> image_mani = nullptr);
|
||||
// ------------------------------------------------------------------------
|
||||
irr::video::ITexture* addTexture(irr::video::ITexture* texture);
|
||||
// ------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user