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