]> Dogcows Code - chaz/yoink/blob - src/moof/texture.hh
a53dcd1bb0580dfa977a9625f80997f8b36e9319
[chaz/yoink] / src / moof / texture.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_TEXTURE_HH_
13 #define _MOOF_TEXTURE_HH_
14
15 /**
16 * \file texture.hh
17 * Image-loading and OpenGL texture loading.
18 */
19
20 #include <string>
21
22 #include <boost/shared_ptr.hpp>
23
24 #include <moof/image.hh>
25 #include <moof/opengl.hh>
26
27
28 namespace moof {
29
30
31 class texture;
32 typedef boost::shared_ptr<texture> texture_ptr;
33
34
35 class texture : public image
36 {
37 public:
38
39 static const int no_tile = -1;
40
41 /**
42 * Possible orientations for texture coordinates.
43 */
44 typedef enum
45 {
46 normal = 0, ///< Normal orientation.
47 flip = 1, ///< Flip over a horizontal axis.
48 reverse = 2, ///< Flip over a vertical axis.
49 flip_and_reverse = 3 ///< Flip over both.
50 } orientation;
51
52
53 static texture_ptr alloc(const std::string& name)
54 {
55 return texture_ptr(new texture(name));
56 }
57
58 explicit texture(const std::string& name);
59
60 void bind() const;
61 GLuint object() const;
62
63 static void reset_binding();
64
65 void min_filter(GLuint filter);
66 void mag_filter(GLuint filter);
67 void wrap_s(GLuint wrap);
68 void wrap_t(GLuint wrap);
69
70
71 /**
72 * Calculate texture coordinates for a tile at a certain index. Tiles
73 * are indexed start with zero as the to-left tile and moving across,
74 * then down.
75 * \param index The tile index.
76 * \param coords An array of scalars where the texture coordinates will
77 * be stored after this call. The first coordinate (u,v) will be in
78 * the first two places and so on until all four coordinates are
79 * stored, therefore requiring enough room for an array of eight
80 * scalars. The winding of the coordinates is always counter-clockwise
81 * (the GL default).
82 * \return True if index is valid, false otherwise.
83 */
84 bool tile_coordinates(int index, scalar coords[8]) const;
85
86 /**
87 * This version let's you specify an orientation that will be reflected
88 * in the texture coordinates. This allows you to easily map a texture
89 * backwards or upside-down.
90 * \param what The orientation; can be flip, reverse, or
91 * flip_and_reverse.
92 * \return True if index is valid, false otherwise.
93 */
94 bool tile_coordinates(int index, scalar coords[8], orientation what) const;
95
96
97 private:
98
99 class impl;
100 boost::shared_ptr<impl> impl_;
101 };
102
103
104 } // namespace moof
105
106 #endif // _MOOF_TEXTURE_HH_
107
This page took 0.032728 seconds and 3 git commands to generate.