]> Dogcows Code - chaz/yoink/blob - src/Moof/Texture.hh
library class revamped as manager, goodbye tilemap
[chaz/yoink] / src / Moof / Texture.hh
1
2 /*******************************************************************************
3
4 Copyright (c) 2009, Charles McGarvey
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
10 * Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 *******************************************************************************/
28
29 #ifndef _MOOF_TEXTURE_HH_
30 #define _MOOF_TEXTURE_HH_
31
32 /**
33 * @file Texture.hh
34 * Image-loading and OpenGL texture loading.
35 */
36
37 #include <boost/shared_ptr.hpp>
38
39 #include <Moof/Image.hh>
40 #include <Moof/OpenGL.hh>
41
42
43 namespace Mf {
44
45
46 class Texture;
47 typedef boost::shared_ptr<Texture> TextureP;
48
49
50 class Texture : public Image
51 {
52 public:
53
54 /**
55 * Possible orientations for texture coordinates.
56 */
57
58 typedef unsigned TileIndex;
59 static const TileIndex NO_TILE = -1;
60
61 typedef enum
62 {
63 NORMAL = 0, ///< Normal orientation.
64 FLIP = 1, ///< Flip over a horizontal axis.
65 REVERSE = 2, ///< Flip over a vertical axis.
66 FLIP_AND_REVERSE = 3 ///< Flip over both.
67 } Orientation;
68
69
70 static TextureP alloc(const std::string& name)
71 {
72 return TextureP(new Texture(name));
73 }
74
75 explicit Texture(const std::string& name);
76
77 void bind() const;
78 GLuint getObject() const;
79
80 static void resetBind();
81
82 void setMinFilter(GLuint filter);
83 void setMagFilter(GLuint filter);
84 void setWrapS(GLuint wrap);
85 void setWrapT(GLuint wrap);
86
87
88 /**
89 * Calculate texture coordinates for a tile at a certain index. Tiles are
90 * indexed start with zero as the to-left tile and moving across, then down.
91 * @param index The tile index.
92 * @param coords An array of scalars where the texture coordinates will be
93 * stored after this call. The first coordinate (u,v) will be in the first
94 * two places and so on until all four coordinates are stored, therefore
95 * requiring enough room for an array of eight scalars. The winding of the
96 * coordinates is always counter-clockwise (the GL default).
97 * @return True if index is valid, false otherwise.
98 */
99
100 bool getTileCoords(TileIndex index, Scalar coords[8]) const;
101
102
103 /**
104 * This version let's you specify an orientation that will be reflected in
105 * the texture coordinates. This allows you to easily map a texture
106 * backwards or upside-down.
107 * @param what The orientation; can be flip, reverse, or flip_and_reverse.
108 * @return True if index is valid, false otherwise.
109 */
110
111 bool getTileCoords(TileIndex index, Scalar coords[8], Orientation what) const;
112
113
114 static std::string getPath(const std::string& name);
115
116 private:
117
118 class Impl;
119 boost::shared_ptr<Impl> mImpl;
120 };
121
122
123 } // namespace Mf
124
125 #endif // _MOOF_TEXTURE_HH_
126
127 /** vim: set ts=4 sw=4 tw=80: *************************************************/
128
This page took 0.034801 seconds and 4 git commands to generate.