]> Dogcows Code - chaz/yoink/blob - src/moof/image.hh
pch support
[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 std::string comment() const
63 {
64 return comment_;
65 }
66
67 const char* pixels() const
68 {
69 return pixels_;
70 }
71
72 void set_as_icon() const;
73
74 /**
75 * Calculate texture coordinates for a tile at a certain index. Tiles
76 * are indexed start with zero as the top-left tile and moving across,
77 * then down.
78 * \param index The tile index.
79 * \param coords An array of scalars where the texture coordinates will
80 * be stored after this call. The first coordinate (u,v) will be in
81 * the first two places and so on until all four coordinates are
82 * stored, therefore requiring enough room for an array of eight
83 * scalars. The winding of the coordinates is always counter-clockwise
84 * (the GL default).
85 * \return True if index is valid, false otherwise.
86 */
87 bool tile_coordinates(int index, scalar coords[8]) const;
88
89 void bind() const;
90 static void reset_binding();
91
92 private:
93
94 void upload_to_gl() const;
95 void unload_from_gl() const;
96 void context_recreated();
97 void set_properties() const;
98 void set_texture_info(const std::string& info);
99
100 char* pixels_;
101
102 mutable unsigned object_;
103 static unsigned global_object_;
104
105 int width_;
106 int height_;
107 int depth_;
108 int pitch_;
109 int channels_;
110
111 std::string comment_;
112
113 unsigned min_filter_;
114 unsigned mag_filter_;
115 int tile_s_;
116 int tile_t_;
117 unsigned wrap_s_;
118 unsigned wrap_t_;
119
120 //mutable dispatcher::handle new_context_;
121 };
122
123 typedef resource_handle<image> image_handle;
124
125
126 } // namespace moof
127
128 #endif // _MOOF_IMAGE_HH_
129
This page took 0.033898 seconds and 4 git commands to generate.