]> Dogcows Code - chaz/yoink/blobdiff - src/moof/image.cc
pch support
[chaz/yoink] / src / moof / image.cc
index 09f797ca8f3fc3d9235fb7ccf4f1ad21f5f84eae..77b15c13903bead2a4bd05bc33e3a0081fbd2f91 100644 (file)
@@ -7,14 +7,16 @@
 *
 *****************************************************************************/
 
-#include <cstring>             // strncmp
 #include <fstream>
 #include <stdexcept>
-
 #include <png.h>
+
 #include <SDL/SDL.h>
 
+#include <stlplus/portability/file_system.hpp>
+
 #include "backend.hh"
+#include "debug.hh"
 #include "image.hh"
 #include "log.hh"
 #include "opengl.hh"
 namespace moof {
 
 
+MOOF_REGISTER_RESOURCE(image, bmp, textures);
 MOOF_REGISTER_RESOURCE(image, png, textures);
 
-//static int power_of_two(int input)
-//{
-       //int value = 1;
-
-       //while (value < input)
-       //{
-               //value <<= 1;
-       //}
-       //return value;
-//}
-
-unsigned image::global_object_ = 0;
 
+static int higher_power_of_two(int input)
+{
+       int value = 2;
+       while (value <= input) value <<= 1;
+       return value;
+}
 
-static void read_from_stream(png_structp context, png_bytep data, png_size_t length)
+static void read_from_stream(png_structp context,
+               png_bytep data, png_size_t length)
 {
        std::istream& stream(*(std::istream*)png_get_io_ptr(context));
        stream.read((char*)data, length);
 }
 
 
-image::image(const std::string& path) :
-       pixels_(0),
-       object_(0),
-       min_filter_(GL_NEAREST),
-       mag_filter_(GL_NEAREST),
-       tile_s_(1),
-       tile_t_(1),
-       wrap_s_(GL_CLAMP),
-       wrap_t_(GL_CLAMP)
+struct texture_attributes
+{
+       texture_attributes() :
+               min_filter(GL_NEAREST),
+               mag_filter(GL_NEAREST),
+               tile_s(1),
+               tile_t(1),
+               wrap_s(GL_CLAMP_TO_EDGE),
+               wrap_t(GL_CLAMP_TO_EDGE) {}
+
+       void init(const std::string& info)
+       {
+               script script;
+               log::import(script);
+
+               script::slot g = script.globals();
+#define EXPORT_CONSTANT(K) g.set_field(#K, GL_##K)
+               EXPORT_CONSTANT(CLAMP);
+               EXPORT_CONSTANT(CLAMP_TO_EDGE);
+               EXPORT_CONSTANT(REPEAT);
+               EXPORT_CONSTANT(LINEAR);
+               EXPORT_CONSTANT(NEAREST);
+               EXPORT_CONSTANT(LINEAR_MIPMAP_LINEAR);
+               EXPORT_CONSTANT(LINEAR_MIPMAP_NEAREST);
+               EXPORT_CONSTANT(NEAREST_MIPMAP_LINEAR);
+               EXPORT_CONSTANT(NEAREST_MIPMAP_NEAREST);
+#undef export_constant
+
+               if (script.do_string(info) != script::success)
+               {
+                       std::string str;
+                       script[-1].get(str);
+                       log_warning(str);
+               }
+               else
+               {
+                       log_info("loading texture information...");
+
+                       script::slot globals = script.globals();
+                       globals.get(min_filter, "min_filter");
+                       globals.get(mag_filter, "mag_filter");
+                       globals.get(tile_s, "tile_s");
+                       globals.get(tile_t, "tile_t");
+                       globals.get(wrap_s, "wrap_s");
+                       globals.get(wrap_t, "wrap_t");
+               }
+       }
+
+       GLuint  min_filter;
+       GLuint  mag_filter;
+       int     tile_s;
+       int     tile_t;
+       GLuint  wrap_s;
+       GLuint  wrap_t;
+};
+
+
+static SDL_Surface* load_png(const std::string& path, texture_attributes& attribs)
 {
        std::ifstream file(path.c_str(), std::ifstream::binary);
        if (!file.good())
This page took 0.020848 seconds and 4 git commands to generate.