X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Fimage.hh;h=89a7faa1518dfeeb8245ae31ba8e9446e662a396;hp=97572708379ba76210422f5adc708c8c8175b65e;hb=HEAD;hpb=831f04d4bc19a390415ac0bbac4331c7a65509bc diff --git a/src/moof/image.hh b/src/moof/image.hh index 9757270..89a7faa 100644 --- a/src/moof/image.hh +++ b/src/moof/image.hh @@ -1,74 +1,122 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #ifndef _MOOF_IMAGE_HH_ #define _MOOF_IMAGE_HH_ +#include + +#include +#include +#include + + /** * \file image.hh * Defines classes for loading and manipulating images. */ -#include - -#include -#include - - namespace moof { -class image; -typedef boost::shared_ptr 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 width_; + } + + int height() const { - return image_ptr(new image(name)); + return height_; } - explicit image(const std::string& name); + int depth() const + { + return depth_; + } - bool is_valid() const; + int pitch() const + { + return pitch_; + } - int width() const; - int height() const; + int channels() const + { + return channels_; + } - unsigned depth() const; - unsigned pitch() const; - GLuint mode() const; + const char* pixels() const + { + return pixels_; + } - std::string comment() const; + void set_as_icon() const; - const char* pixels() const; - char* pixels(); + /** + * 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 fix_uv(std::vector& p) const; + + void bind() const; + static void reset_binding(); - void flip(); +private: - void set_as_icon() const; + void postprocess(); + void upload_to_gl() const; + void unload_from_gl() const; + void context_recreated(); + void set_properties() const; - static bool find_path(std::string& name); + char* pixels_; + mutable unsigned object_; + static unsigned global_object_; -private: + int width_; + int height_; + int depth_; + int pitch_; + int channels_; - static FILE* open_file(std::string& name); + unsigned min_filter_; + unsigned mag_filter_; + int tile_s_; + int tile_t_; + unsigned wrap_s_; + unsigned wrap_t_; - class impl; - boost::shared_ptr impl_; + //mutable dispatcher::handle new_context_; }; +typedef resource_handle image_handle; + } // namespace moof