]> Dogcows Code - chaz/yoink/blob - src/moof/image.hh
compression functions; fixed texture seams
[chaz/yoink] / src / moof / image.hh
1
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
4 *
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
7 *
8 *****************************************************************************/
9
10 #ifndef _MOOF_IMAGE_HH_
11 #define _MOOF_IMAGE_HH_
12
13 #include <boost/noncopyable.hpp>
14
15 #include <moof/dispatcher.hh>
16 #include <moof/math.hh>
17 #include <moof/resource.hh>
18
19
20 /**
21 * \file image.hh
22 * Defines classes for loading and manipulating images.
23 */
24
25 namespace moof {
26
27
28 class image : public boost::noncopyable
29 {
30 public:
31
32 static const int no_tile = -1;
33
34 explicit image(const std::string& path);
35 ~image();
36
37 int width() const
38 {
39 return width_;
40 }
41
42 int height() const
43 {
44 return height_;
45 }
46
47 int depth() const
48 {
49 return depth_;
50 }
51
52 int pitch() const
53 {
54 return pitch_;
55 }
56
57 int channels() const
58 {
59 return channels_;
60 }
61
62 const char* pixels() const
63 {
64 return pixels_;
65 }
66
67 void set_as_icon() const;
68
69 /**
70 * Calculate texture coordinates for a tile at a certain index. Tiles
71 * are indexed start with zero as the top-left tile and moving across,
72 * then down.
73 * \param index The tile index.
74 * \param coords An array of scalars where the texture coordinates
75 * will be stored after this call. The first coordinate (u,v) will be
76 * in the first two places and so on until all four coordinates are
77 * stored, therefore requiring enough room for an array of eight
78 * scalars. The winding of the coordinates is always
79 * counter-clockwise (the GL default).
80 * \return True if index is valid, false otherwise.
81 */
82 bool tile_coordinates(int index, scalar coords[8]) const;
83
84 void fix_uv(std::vector<vector2>& p) const;
85
86 void bind() const;
87 static void reset_binding();
88
89 private:
90
91 void postprocess();
92 void upload_to_gl() const;
93 void unload_from_gl() const;
94 void context_recreated();
95 void set_properties() const;
96
97 char* pixels_;
98
99 mutable unsigned object_;
100 static unsigned global_object_;
101
102 int width_;
103 int height_;
104 int depth_;
105 int pitch_;
106 int channels_;
107
108 unsigned min_filter_;
109 unsigned mag_filter_;
110 int tile_s_;
111 int tile_t_;
112 unsigned wrap_s_;
113 unsigned wrap_t_;
114
115 //mutable dispatcher::handle new_context_;
116 };
117
118 typedef resource_handle<image> image_handle;
119
120
121 } // namespace moof
122
123 #endif // _MOOF_IMAGE_HH_
124
This page took 0.032502 seconds and 4 git commands to generate.