]> git.lizzy.rs Git - minetest.git/blobdiff - src/tile.cpp
Fix android build using hardcoded path for data instead of using the one fetched...
[minetest.git] / src / tile.cpp
index 366e03ce2af43838597c536c547519e100b57b22..ebef77fb9cbe148010b2688a3ff98a04c5023e38 100644 (file)
@@ -18,19 +18,21 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 
 #include "tile.h"
+
+#include <ICameraSceneNode.h>
+#include "util/string.h"
+#include "util/container.h"
+#include "util/thread.h"
+#include "util/numeric.h"
 #include "irrlichttypes_extrabloated.h"
 #include "debug.h"
 #include "main.h" // for g_settings
 #include "filesys.h"
 #include "settings.h"
 #include "mesh.h"
-#include <ICameraSceneNode.h>
 #include "log.h"
 #include "gamedef.h"
-#include "util/string.h"
-#include "util/container.h"
-#include "util/thread.h"
-#include "util/numeric.h"
+#include "strfnd.h"
 
 #ifdef __ANDROID__
 #include <GLES/gl.h>
@@ -537,6 +539,10 @@ static void blit_with_alpha(video::IImage *src, video::IImage *dst,
 static void blit_with_alpha_overlay(video::IImage *src, video::IImage *dst,
                v2s32 src_pos, v2s32 dst_pos, v2u32 size);
 
+// Apply a mask to an image
+static void apply_mask(video::IImage *mask, video::IImage *dst,
+               v2s32 mask_pos, v2s32 dst_pos, v2u32 size);
+
 // Draw or overlay a crack
 static void draw_crack(video::IImage *crack, video::IImage *dst,
                bool use_overlay, s32 frame_count, s32 progression,
@@ -894,7 +900,9 @@ video::ITexture* TextureSource::generateTextureFromMesh(
                        params.light_radius);
 
        // Render scene
+       driver->beginScene(true, true, video::SColor(0,0,0,0));
        smgr->drawAll();
+       driver->endScene();
 
        // Drop scene manager
        smgr->drop();
@@ -974,7 +982,7 @@ video::IImage* TextureSource::generateImage(const std::string &name)
 
        std::string last_part_of_name = name.substr(last_separator_pos + 1);
 
-       /*
+       /* 
                If this name is enclosed in parentheses, generate it
                and blit it onto the base image
        */
@@ -1555,6 +1563,31 @@ bool TextureSource::generateImagePart(std::string part_of_name,
                        baseimg->drop();
                        baseimg = img;
                }
+               /*
+                       [mask:filename
+                       Applies a mask to an image
+               */
+               else if(part_of_name.substr(0,6) == "[mask:")
+               {
+                       if (baseimg == NULL) {
+                               errorstream << "generateImage(): baseimg == NULL "
+                                               << "for part_of_name=\"" << part_of_name
+                                               << "\", cancelling." << std::endl;
+                               return false;
+                       }
+                       Strfnd sf(part_of_name);
+                       sf.next(":");
+                       std::string filename = sf.next(":");
+
+                       video::IImage *img = m_sourcecache.getOrLoad(filename, m_device);
+                       if (img) {
+                               apply_mask(img, baseimg, v2s32(0, 0), v2s32(0, 0),
+                                               img->getDimension());
+                       } else {
+                               errorstream << "generateImage(): Failed to load \""
+                                               << filename << "\".";
+                       }
+               }
                else
                {
                        errorstream<<"generateImagePart(): Invalid "
@@ -1613,6 +1646,26 @@ static void blit_with_alpha_overlay(video::IImage *src, video::IImage *dst,
        }
 }
 
+/*
+       Apply mask to destination
+*/
+static void apply_mask(video::IImage *mask, video::IImage *dst,
+               v2s32 mask_pos, v2s32 dst_pos, v2u32 size)
+{
+       for(u32 y0 = 0; y0 < size.Y; y0++) {
+               for(u32 x0 = 0; x0 < size.X; x0++) {
+                       s32 mask_x = x0 + mask_pos.X;
+                       s32 mask_y = y0 + mask_pos.Y;
+                       s32 dst_x = x0 + dst_pos.X;
+                       s32 dst_y = y0 + dst_pos.Y;
+                       video::SColor mask_c = mask->getPixel(mask_x, mask_y);
+                       video::SColor dst_c = dst->getPixel(dst_x, dst_y);
+                       dst_c.color &= mask_c.color;
+                       dst->setPixel(dst_x, dst_y, dst_c);
+               }
+       }
+}
+
 static void draw_crack(video::IImage *crack, video::IImage *dst,
                bool use_overlay, s32 frame_count, s32 progression,
                video::IVideoDriver *driver)