aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorRealBadAngel <maciej.kasatkin@o2.pl>2015-07-16 15:36:48 +0200
committerRealBadAngel <maciej.kasatkin@o2.pl>2015-07-16 15:36:48 +0200
commit655fc6010ffd4be7de315be261df2a61d5d4538a (patch)
treea61da651c2647f10f4bfcce3a341aba170ffa164 /src/client
parentb30e8d8ec689fbb65b1cee6fb6ff79322b204d0d (diff)
downloadminetest-655fc6010ffd4be7de315be261df2a61d5d4538a.tar.gz
minetest-655fc6010ffd4be7de315be261df2a61d5d4538a.tar.bz2
minetest-655fc6010ffd4be7de315be261df2a61d5d4538a.zip
Fix relief mapping issues
Diffstat (limited to 'src/client')
-rw-r--r--src/client/tile.cpp41
-rw-r--r--src/client/tile.h11
2 files changed, 44 insertions, 8 deletions
diff --git a/src/client/tile.cpp b/src/client/tile.cpp
index cf8061982..5ad564b65 100644
--- a/src/client/tile.cpp
+++ b/src/client/tile.cpp
@@ -35,6 +35,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/string.h" // for parseColorString()
#include "imagefilters.h"
#include "guiscalingfilter.h"
+#include "nodedef.h"
+
#ifdef __ANDROID__
#include <GLES/gl.h>
@@ -330,7 +332,7 @@ public:
*/
video::ITexture* getTexture(u32 id);
- video::ITexture* getTexture(const std::string &name, u32 *id);
+ video::ITexture* getTexture(const std::string &name, u32 *id = NULL);
/*
Get a texture specifically intended for mesh
@@ -383,6 +385,7 @@ public:
video::ITexture* getNormalTexture(const std::string &name);
video::SColor getTextureAverageColor(const std::string &name);
+ video::ITexture *getShaderFlagsTexture(TileDef *tiledef, TileSpec *tile);
private:
@@ -1992,9 +1995,8 @@ void imageTransform(u32 transform, video::IImage *src, video::IImage *dst)
video::ITexture* TextureSource::getNormalTexture(const std::string &name)
{
- u32 id;
if (isKnownSourceImage("override_normal.png"))
- return getTexture("override_normal.png", &id);
+ return getTexture("override_normal.png");
std::string fname_base = name;
std::string normal_ext = "_normal.png";
size_t pos = fname_base.find(".");
@@ -2006,7 +2008,7 @@ video::ITexture* TextureSource::getNormalTexture(const std::string &name)
fname_base.replace(i, 4, normal_ext);
i += normal_ext.length();
}
- return getTexture(fname_base, &id);
+ return getTexture(fname_base);
}
return NULL;
}
@@ -2015,8 +2017,7 @@ video::SColor TextureSource::getTextureAverageColor(const std::string &name)
{
video::IVideoDriver *driver = m_device->getVideoDriver();
video::SColor c(0, 0, 0, 0);
- u32 id;
- video::ITexture *texture = getTexture(name, &id);
+ video::ITexture *texture = getTexture(name);
video::IImage *image = driver->createImage(texture,
core::position2d<s32>(0, 0),
texture->getOriginalSize());
@@ -2048,3 +2049,31 @@ video::SColor TextureSource::getTextureAverageColor(const std::string &name)
c.setAlpha(255);
return c;
}
+
+video::ITexture *TextureSource::getShaderFlagsTexture(TileDef *tiledef, TileSpec *tile)
+{
+ std::string tname = "__shaderFlagsTexture";
+
+ bool normalmap_present = tile->normal_texture ? true : false;
+ tname += normalmap_present ? "1" : "0";
+ tname += tiledef->tileable_horizontal ? "1" : "0";
+ tname += tiledef->tileable_vertical ? "1" : "0";
+
+ if (isKnownSourceImage(tname)) {
+ return getTexture(tname);
+ } else {
+ video::IVideoDriver *driver = m_device->getVideoDriver();
+ video::IImage *flags_image = driver->createImage(
+ video::ECF_A8R8G8B8, core::dimension2d<u32>(1, 1));
+ sanity_check(flags_image != NULL);
+ video::SColor c(
+ 255,
+ normalmap_present ? 255 : 0,
+ tiledef->tileable_horizontal ? 255 : 0,
+ tiledef->tileable_vertical ? 255 : 0);
+ flags_image->setPixel(0, 0, c);
+ insertSourceImage(tname, flags_image);
+ flags_image->drop();
+ return getTexture(tname);
+ }
+}
diff --git a/src/client/tile.h b/src/client/tile.h
index 674da66f2..13f1a8b34 100644
--- a/src/client/tile.h
+++ b/src/client/tile.h
@@ -31,6 +31,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/numeric.h"
class IGameDef;
+struct TileSpec;
+struct TileDef;
/*
tile.{h,cpp}: Texture handling stuff.
@@ -111,6 +113,7 @@ public:
const TextureFromMeshParams &params)=0;
virtual video::ITexture* getNormalTexture(const std::string &name)=0;
virtual video::SColor getTextureAverageColor(const std::string &name)=0;
+ virtual video::ITexture *getShaderFlagsTexture(TileDef *tiledef, TileSpec *tile)=0;
};
class IWritableTextureSource : public ITextureSource
@@ -133,6 +136,7 @@ public:
virtual void rebuildImagesAndTextures()=0;
virtual video::ITexture* getNormalTexture(const std::string &name)=0;
virtual video::SColor getTextureAverageColor(const std::string &name)=0;
+ virtual video::ITexture *getShaderFlagsTexture(TileDef *tiledef, TileSpec *tile)=0;
};
IWritableTextureSource* createTextureSource(IrrlichtDevice *device);
@@ -172,12 +176,14 @@ struct FrameSpec
FrameSpec():
texture_id(0),
texture(NULL),
- normal_texture(NULL)
+ normal_texture(NULL),
+ flags_texture(NULL)
{
}
u32 texture_id;
video::ITexture *texture;
video::ITexture *normal_texture;
+ video::ITexture *flags_texture;
};
struct TileSpec
@@ -186,6 +192,7 @@ struct TileSpec
texture_id(0),
texture(NULL),
normal_texture(NULL),
+ flags_texture(NULL),
alpha(255),
material_type(TILE_MATERIAL_BASIC),
material_flags(
@@ -252,6 +259,7 @@ struct TileSpec
u32 texture_id;
video::ITexture *texture;
video::ITexture *normal_texture;
+ video::ITexture *flags_texture;
// Vertex alpha (when MATERIAL_ALPHA_VERTEX is used)
u8 alpha;
@@ -266,5 +274,4 @@ struct TileSpec
u8 rotation;
};
-
#endif