]> Dogcows Code - chaz/yoink/blobdiff - src/moof/image.hh
converted image management to resource handles
[chaz/yoink] / src / moof / image.hh
index 614e614459a0fd0c5279d02e87f1bc895945c850..82c8f557206392980cddb6ee066a68a458e58899 100644 (file)
  * Defines classes for loading and manipulating images.
  */
 
-#include <boost/shared_ptr.hpp>
+#include <boost/noncopyable.hpp>
 
-#include <moof/opengl.hh>
+#include <moof/dispatcher.hh>
+#include <moof/math.hh>
 #include <moof/resource.hh>
 
 
 namespace moof {
 
 
-class image;
-typedef boost::shared_ptr<image> image_ptr;
-
-class image : public resource
+class image : public boost::noncopyable
 {
 public:
 
-       static image_ptr alloc(const std::string& name)
+       static const int no_tile = -1;
+
+
+       explicit image(const std::string& path);
+
+       ~image();
+
+       int width() const
        {
-               return image_ptr(new image(name));
+               return width_;
        }
 
-       explicit image(const std::string& name);
+       int height() const
+       {
+               return height_;
+       }
 
-       bool is_valid() const;
+       int depth() const
+       {
+               return depth_;
+       }
 
-       int width() const;
-       int height() const;
+       int pitch() const
+       {
+               return pitch_;
+       }
 
-       unsigned depth() const;
-       unsigned pitch() const;
-       GLuint mode() const;
+       int channels() const
+       {
+               return channels_;
+       }
 
-       std::string comment() const;
 
-       const char* pixels() const;
-       char* pixels();
+       std::string comment() const
+       {
+               return comment_;
+       }
+
+       const char* pixels() const
+       {
+               return pixels_;
+       }
 
-       void flip();
 
        void set_as_icon() const;
 
 
+       /**
+        * Calculate texture coordinates for a tile at a certain index.  Tiles
+        * are indexed start with zero as the top-left tile and moving across,
+        * then down.
+        * \param index The tile index.
+        * \param coords An array of scalars where the texture coordinates will
+        * be stored after this call.  The first coordinate (u,v) will be in
+        * the first two places and so on until all four coordinates are
+        * stored, therefore requiring enough room for an array of eight
+        * scalars.  The winding of the coordinates is always counter-clockwise
+        * (the GL default).
+        * \return True if index is valid, false otherwise.
+        */
+       bool tile_coordinates(int index, scalar coords[8]) const;
+
+
+       void bind() const;
+       static void reset_binding();
+
+
 private:
 
-       static FILE* open_file(std::string& name);
+       void upload_to_gl() const;
+       void unload_from_gl() const;
+       void context_recreated();
+       void set_properties() const;
+       void set_texture_info(const std::string& info);
 
-       class impl;
-       boost::shared_ptr<impl> impl_;
+
+       char*                           pixels_;
+
+       mutable unsigned        object_;
+       static unsigned         global_object_;
+
+       int                                     width_;
+       int                                     height_;
+       int                                     depth_;
+       int                                     pitch_;
+       int                                     channels_;
+
+       std::string                     comment_;
+
+       unsigned                        min_filter_;
+       unsigned                        mag_filter_;
+       unsigned                        wrap_s_;
+       unsigned                        wrap_t_;
+       int                                     tile_width_;
+       int                                     tile_height_;
+
+       //mutable dispatcher::handle    new_context_;
 };
 
+typedef resource_handle<image> image_handle;
+
 
 } // namespace moof
 
This page took 0.021034 seconds and 4 git commands to generate.