zenilib: zenilib/jni/external/zenilib/zeni_graphics/Zeni/Texture.h Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Texture.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2 * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3 *
4 * zenilib is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * zenilib is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16 */
17
34 #ifndef ZENI_TEXTURE_H
35 #define ZENI_TEXTURE_H
36
37 #include <Zeni/Coordinate.h>
38 #include <Zeni/Core.h>
39 #include <Zeni/String.h>
40
41 #include <vector>
42
43 #ifndef DISABLE_GL
44 #if defined(REQUIRE_GL_ES)
45 #include <GLES/gl.h>
46 #else
47 #include <GL/glew.h>
48 #endif
49 #endif
50
51 struct IDirect3DTexture9;
52 struct ID3DXRenderToSurface;
53
54 namespace Zeni {
55
56 class Video;
57 class Video_GL_Fixed;
58 class Video_GL_Shader;
59 class Video_DX9;
60
61 class ZENI_GRAPHICS_DLL Texture {
62 Texture(const Texture &);
63 Texture & operator=(const Texture &);
64
65 public:
66 Texture(const bool &repeat_) : m_repeat(repeat_) {}
67 virtual ~Texture() {}
68
69 virtual void apply_Texture() const = 0;
70
71 virtual const Point2i & get_size() const = 0;
72
73 protected:
74 const bool m_repeat;
75 };
76
77 class ZENI_GRAPHICS_DLL Sprite : public Texture {
78 public:
79 Sprite();
80 Sprite(const Sprite &rhs);
81 Sprite & operator=(const Sprite &rhs);
82
83 void append_frame(const String &name);
84 void append_frame(const String &name, const unsigned long &id);
85 int find_frame(const String &name, const int &starting_point = 0) const;
86 void insert_frame(const String &name, const int &at_this_index);
87 void insert_frame(const String &name, const unsigned long &id, const int &at_this_index);
88 void remove_frame(const int &frame_number);
89
90 int get_num_frames() const;
91 int get_current_frame() const;
92 void set_current_frame(const int &frame_number);
93
94 virtual void apply_Texture() const;
95
96 inline const Point2i & get_size() const;
97
98 private:
99 #ifdef _WINDOWS
100 #pragma warning( push )
101 #pragma warning( disable : 4251 )
102 #endif
103 mutable std::vector<std::pair<String, unsigned long> > m_frames;
104 #ifdef _WINDOWS
105 #pragma warning( pop )
106 #endif
107 int m_frame;
108 };
109
110 #ifndef DISABLE_GL
111 class ZENI_GRAPHICS_DLL Texture_GL : public Texture {
112 Texture_GL(const Texture_GL &);
113 Texture_GL & operator=(const Texture_GL &);
114
115 friend class Video_GL_Fixed;
116 friend class Video_GL_Shader;
117
118 public:
119 Texture_GL(const String &filename, const bool &repeat /* otherwise clamp */,
120 const bool &lazy_loading = false);
121 Texture_GL(const Image &image);
122 Texture_GL(const Point2i &size, const bool &repeat /* otherwise clamp */);
123 virtual ~Texture_GL();
124
125 virtual void apply_Texture() const;
126
127 inline const Point2i & get_size() const;
128
129 private:
130 static GLuint build_from_Image(const Image &image);
131
132 mutable Point2i m_size;
133 mutable GLuint m_texture_id;
134 GLuint m_render_buffer;
135 GLuint m_frame_buffer_object;
136
137 void load(const String &filename, const bool &repeat) const;
138
139 const String m_filename;
140 };
141 #endif
142
143 #ifndef TEMP_DISABLE
144 #ifndef DISABLE_DX9
145 class ZENI_GRAPHICS_DLL Texture_DX9 : public Texture {
146 Texture_DX9(const Texture_DX9 &);
147 Texture_DX9 & operator=(const Texture_DX9 &);
148
149 friend class Video_DX9;
150
151 public:
152 Texture_DX9(const String &filename, const bool &repeat /* otherwise clamp */);
153 Texture_DX9(const Image &image);
154 Texture_DX9(const Point2i &size, const bool &repeat /* otherwise clamp */);
155 virtual ~Texture_DX9();
156
157 virtual void apply_Texture() const;
158
159 inline const Point2i & get_size() const;
160 inline ID3DXRenderToSurface * render_to_surface() const;
161
162 private:
163 static void set_sampler_states(const bool &disable_mipmapping = false);
164 static IDirect3DTexture9 * build_from_Image(const Image &image);
165
166 mutable Point2i m_size;
167 mutable IDirect3DTexture9 *m_texture;
168
169 ID3DXRenderToSurface *m_render_to_surface;
170
171 void load(const String &filename) const;
172 };
173 #endif
174 #endif
175
176 struct ZENI_GRAPHICS_DLL Texture_Init_Failure : public Error {
177 Texture_Init_Failure() : Error("Zeni Texture Failed to Initialize Correctly") {}
178 };
179
180 struct ZENI_GRAPHICS_DLL Frame_Out_of_Range : public Error {
181 Frame_Out_of_Range() : Error("Frame Choice is Out of Range") {}
182 };
183
184 struct ZENI_GRAPHICS_DLL Sprite_Containing_Sprite : public Error {
185 Sprite_Containing_Sprite() : Error("Sprite Found Containing Another Sprite; This is Not Allowed") {}
186 };
187
188 }
189
190 #endif
Zeni::Texture_Init_Failure::Texture_Init_Failure
Texture_Init_Failure()
Definition: Texture.h:177
Zeni::Texture_GL
Definition: Texture.h:111
Zeni::Video_DX9
The Direct3D9 Rendering System.
Definition: Video_DX9.h:62
Zeni::Frame_Out_of_Range
Definition: Texture.h:180
Zeni::Texture_DX9
Definition: Texture.h:145
name
EGLImageKHR EGLint * name
Definition: eglext.h:284
Zeni::Texture_Init_Failure
Definition: Texture.h:176
Zeni::Image
Image.
Definition: Image.h:52
image
EGLImageKHR image
Definition: eglext.h:88
Zeni::String
Definition: String.h:29
Coordinate.h
Zeni::Frame_Out_of_Range::Frame_Out_of_Range
Frame_Out_of_Range()
Definition: Texture.h:181
Zeni::Texture
An Abstraction of a Texture.
Definition: Texture.h:61
ID3DXRenderToSurface
interface ID3DXRenderToSurface ID3DXRenderToSurface
Definition: d3dx9core.h:471
Zeni::Video_GL_Fixed
The OpenGL Rendering System.
Definition: Video_GL_Fixed.h:70
sort_controllers.filename
string filename
Definition: sort_controllers.py:8
Zeni::Video_GL_Shader
The OpenGL Rendering System.
Definition: Video_GL_Shader.h:70
Zeni::Sprite_Containing_Sprite::Sprite_Containing_Sprite
Sprite_Containing_Sprite()
Definition: Texture.h:185
Zeni::Sprite
Definition: Texture.h:77
GLuint
unsigned int GLuint
Definition: gl2.h:32
Zeni::Sprite_Containing_Sprite
Definition: Texture.h:184
Zeni::Texture::~Texture
virtual ~Texture()
Definition: Texture.h:67
IDirect3DTexture9
interface IDirect3DTexture9 IDirect3DTexture9
Definition: d3d9.h:264
String.h
Zeni::Texture::m_repeat
const bool m_repeat
Definition: Texture.h:74
Zeni::Error
The Error Class.
Definition: Error.h:52
Core.h
Zeni::Texture::Texture
Texture(const bool &repeat_)
Definition: Texture.h:66
size
GLsizei size
Definition: gl2ext.h:1467
Zeni::Point2i
A 2D Point represented with integers.
Definition: Coordinate.h:85