zenilib: zenilib/jni/external/zenilib/zeni_graphics/Zeni/Video.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
Video.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
35 #ifndef ZENI_VIDEO_H
36 #define ZENI_VIDEO_H
37
38 #include <Zeni/Core.h>
39 #include <Zeni/Color.h>
40 #include <Zeni/Coordinate.h>
41 #include <Zeni/Matrix4f.h>
42 #include <Zeni/Singleton.h>
43 #include <Zeni/String.h>
44
45 #include <SDL/SDL.h>
46 #include <cmath>
47 #include <vector>
48
49 typedef void* ShHandle;
50
51 namespace Zeni {
52
53 class Camera;
54 struct Fog;
55 class Font;
56 struct Light;
57 class Material;
58 class Program;
59 class Renderable;
60 class Shader;
61 class Texture;
62 class Vertex_Buffer;
63 class Vertex_Buffer_Renderer;
64 class Video;
65 class XML_Document;
66
67 #ifdef _WINDOWS
68 ZENI_GRAPHICS_EXT template class ZENI_GRAPHICS_DLL Singleton<Video>;
69 #endif
70
71 class ZENI_GRAPHICS_DLL Video : public Singleton<Video> {
72 friend class Singleton<Video>;
73
74 static Video * create();
75
76 #ifdef _WINDOWS
77 #pragma warning( push )
78 #pragma warning( disable : 4251 )
79 #endif
80 static Uninit g_uninit;
81 static Reinit g_reinit;
82 #ifdef _WINDOWS
83 #pragma warning( pop )
84 #endif
85
86 protected:
87 Video();
88 virtual ~Video() = 0;
89
90 private:
91 // Undefined
92 Video(const Video &);
93 Video & operator=(const Video &);
94
95 public:
96 enum VIDEO_MODE {ZENI_VIDEO_ANY, ZENI_VIDEO_GL_FIXED, ZENI_VIDEO_DX9, ZENI_VIDEO_GL_SHADER};
97
98 enum TEST {ZENI_NEVER = 0,
99 ZENI_LESS = 1,
100 ZENI_EQUAL = 2,
101 ZENI_GREATER = 4,
102 ZENI_NOT_EQUAL = 8,
103 ZENI_LESS_OR_EQUAL = 3,
104 ZENI_GREATER_OR_EQUAL = 6,
105 ZENI_ALWAYS = 15};
106
107 // Rendering functions
108 virtual bool begin_prerender() = 0;
109 virtual bool begin_render() = 0;
110 virtual void end_render() = 0;
111 virtual void render(const Renderable &renderable) = 0;
112 virtual void clear_depth_buffer() = 0;
113
114 // Accessors
115 inline static VIDEO_MODE get_video_mode();
116 inline static bool get_backface_culling();
117 inline static bool get_lighting();
118 inline static const Color & get_ambient_lighting();
119 inline static bool get_normal_interpolation();
120 inline static bool get_vertical_sync();
121 inline static int get_multisampling();
122 virtual int get_maximum_anisotropy() const = 0;
123 virtual bool has_vertex_buffers() const = 0;
124 inline bool is_zwrite_enabled() const;
125 inline bool is_ztest_enabled() const;
126 inline bool is_alpha_test_enabled() const;
127 inline TEST get_alpha_test_function() const;
128 inline float get_alpha_test_value() const;
129 inline bool is_3d() const;
130 inline ShHandle get_vertex_shader_compiler() const;
131 inline ShHandle get_fragment_shader_compiler() const;
132
133 // Modifiers
134 inline void set_2d();
135 inline void set_2d(const std::pair<Point2f, Point2f> &camera2d,
136 const bool &fix_aspect_ratio = false);
137 inline void set_3d(const Camera &camera);
138 virtual void set_2d_view(const std::pair<Point2f, Point2f> &camera2d,
139 const std::pair<Point2i, Point2i> &viewport = std::make_pair(Point2i(), get().get_render_target_size()),
140 const bool &fix_aspect_ratio = false) = 0;
141 virtual void set_3d_view(const Camera &camera, const std::pair<Point2i, Point2i> &viewport =
142 std::make_pair(Point2i(), get().get_render_target_size())) = 0;
143 virtual void set_backface_culling(const bool &on) = 0;
144 virtual void set_vertical_sync(const bool &on) = 0;
145 virtual void set_zwrite(const bool &enabled) = 0;
146 virtual void set_ztest(const bool &enabled) = 0;
147 virtual void set_alpha_test(const bool &enabled, const TEST &test = ZENI_ALWAYS, const float &value = 0.0f) = 0;
148
149 // Color and Texturing
150 inline const Color & get_Color() const;
151 inline const Color & get_clear_Color() const;
152 virtual void set_Color(const Color &color) = 0;
153 virtual void set_clear_Color(const Color &color) = 0;
154 inline void apply_Texture(const String &name);
155 virtual void apply_Texture(const unsigned long &id) = 0;
156 virtual void apply_Texture(const Texture &texture) = 0;
157 virtual void unapply_Texture() = 0;
158
159 // Lighting and Materials
160 virtual void set_lighting(const bool &on = true) = 0;
161 virtual void set_ambient_lighting(const Color &color) = 0;
162 const Light * get_Light(const int &number) const;
163 virtual void set_Light(const int &number, const Light &light) = 0;
164 virtual void unset_Light(const int &number) = 0;
165 virtual void set_Material(const Material &material) = 0;
166 virtual void unset_Material(const Material &material) = 0;
167
168 // Fog
169 const Fog * get_Fog() const;
170 virtual void set_Fog(const Fog &fog) = 0;
171 virtual void unset_Fog() = 0;
172
173 // Shaders
174 virtual void set_program(Program &program) = 0;
175 virtual void unset_program() = 0;
176
177 // Render-to-texture
178 virtual void set_render_target(Texture &texture) = 0;
179 virtual void unset_render_target() = 0;
180 virtual void clear_render_target(const Color &color = Color(0.0f, 0.0f, 0.0f, 0.0f)) = 0;
181 virtual const Point2i & get_render_target_size() const = 0;
182
183 // Model/World Transformation Stack Functions
184 virtual void select_world_matrix() = 0;
185 virtual void push_world_stack() = 0;
186 virtual void pop_world_stack() = 0;
187 virtual void translate_scene(const Vector3f &direction) = 0;
188 virtual void rotate_scene(const Vector3f &about, const float &radians) = 0;
189 inline void rotate_scene(const Quaternion &rotation);
190 virtual void scale_scene(const Vector3f &factor) = 0;
191 virtual void transform_scene(const Matrix4f &transformation) = 0;
192
193 // View+Projection Matrix Functions
194 virtual Point2f get_pixel_offset() const = 0;
195 inline const Matrix4f & get_view_matrix() const;
196 inline const Matrix4f & get_projection_matrix() const;
197 inline const std::pair<Point2i, Point2i> & get_viewport() const;
198 virtual void set_view_matrix(const Matrix4f &view) = 0;
199 virtual void set_projection_matrix(const Matrix4f &projection) = 0;
200 virtual void set_viewport(const std::pair<Point2i, Point2i> &viewport =
201 std::make_pair(Point2i(), get().get_render_target_size())) = 0;
202 void set_viewport(const float &aspect_ratio,
203 const std::pair<Point2i, Point2i> &viewport =
204 std::make_pair(Point2i(), get().get_render_target_size()));
205 std::pair<Point2i, Point2i> calculate_viewport(const std::pair<Point2f, Point2f> &camera2d,
206 const std::pair<Point2i, Point2i> &viewport,
207 const bool &fix_aspect_ratio);
208 std::pair<Point2i, Point2i> calculate_viewport(const float &aspect_ratio,
209 const std::pair<Point2i, Point2i> &viewport =
210 std::make_pair(Point2i(), get().get_render_target_size())) const;
211
212 // Creation Functions
213 virtual Texture * load_Texture(const String &filename, const bool &repeat, const bool &lazy_loading = false) = 0;
214 virtual Texture * create_Texture(const Image &image) = 0;
215 virtual Texture * create_Texture(const Point2i &size, const bool &repeat) = 0;
216 virtual Font * create_Font(const String &filename,
217 const float &glyph_height, const float &virtual_screen_height) = 0;
218 virtual Vertex_Buffer_Renderer * create_Vertex_Buffer_Renderer(Vertex_Buffer &vertex_buffer) = 0;
219 virtual Shader * create_Vertex_Shader(const String &filename) = 0;
220 virtual Shader * create_Fragment_Shader(const String &filename) = 0;
221 virtual Program * create_Program() = 0;
222
223 // Call before any other Video functions; May throw Video_Initialized
224 static void preinit_video_mode(const VIDEO_MODE &vm = ZENI_VIDEO_ANY);
225 static void preinit_multisampling(const int &multisampling = 0);
226 static void preinit_vertical_sync(const bool &vertical_sync = false);
227 static void preinit_from_file(const String &filename);
228 static void preinit_from_file(const XML_Document &file);
229
230 // Re/uninitialize the Rendering Device
231 static void change_resolution(const Point2i &resolution);
232 #ifndef ANDROID
233 static void save(const bool &backup = true);
234 static bool revert();
235 static void set_failsafe_defaults();
236
237 static void print_errors();
238 #endif
239
240 protected:
241 String compile_glsles_shader(const String &filename, const ShHandle &compiler);
242
243 ShHandle m_vertex_compiler;
244 ShHandle m_fragment_compiler;
245
246 private:
247 static VIDEO_MODE g_video_mode;
248
249 static bool g_backface_culling;
250 static bool g_lighting;
251 static Color g_ambient_lighting;
252 #ifdef _WINDOWS
253 #pragma warning( push )
254 #pragma warning( disable : 4251 )
255 #endif
256 static Unordered_Map<int, Light> g_lights;
257 static Fog g_fog;
258 #ifdef _WINDOWS
259 #pragma warning( pop )
260 #endif
261 static bool g_fog_enabled;
262 static Color g_clear_color;
263 static bool g_normal_interp;
264 static bool g_vertical_sync;
265 static int g_multisampling;
266
267 Color m_color;
268
269 const Matrix4f m_preview;
270 Matrix4f m_view;
271 Matrix4f m_projection;
272 #ifdef _WINDOWS
273 #pragma warning( push )
274 #pragma warning( disable : 4251 )
275 #endif
276 std::pair<Point2i, Point2i> m_viewport;
277 #ifdef _WINDOWS
278 #pragma warning( pop )
279 #endif
280
281 static bool g_zwrite;
282 static bool g_ztest;
283
284 bool m_alpha_test;
285 TEST m_alpha_function;
286 float m_alpha_value;
287
288 bool m_3d;
289 };
290
291 ZENI_GRAPHICS_DLL Video & get_Video();
292
293 struct ZENI_GRAPHICS_DLL Video_Init_Failure : public Error {
294 Video_Init_Failure() : Error("Zeni Video Failed to Initialize Correctly") {}
295 };
296
297 struct ZENI_GRAPHICS_DLL Light_Out_of_Range : public Error {
298 Light_Out_of_Range() : Error("Light Set Out of Range [0,7]") {}
299 };
300
301 struct ZENI_GRAPHICS_DLL Video_Render_To_Texture_Error : public Error {
302 Video_Render_To_Texture_Error() : Error("Zeni Video Render To Texture Encountered An Error") {}
303 };
304
305 struct ZENI_GRAPHICS_DLL GLSL_ES_Shader_Compilation_Failure : public Error {
306 GLSL_ES_Shader_Compilation_Failure() : Error("GLSL ES Shader failed to compile") {}
307 };
308
309 }
310
311 #endif
Zeni::Light
An Abstraction of a Light.
Definition: Light.h:57
Zeni::Singleton< Video >
light
const GLubyte GLuint GLuint GLuint GLuint alpha GLboolean GLboolean GLboolean GLboolean alpha GLint GLint GLsizei GLsizei GLenum type GLenum GLint GLenum GLint GLint GLsizei GLsizei GLint border GLenum GLint GLint GLint GLint GLint GLsizei GLsizei height GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLenum GLint GLint GLint GLint j2 GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum light
Definition: SDL_glfuncs.h:144
color
GLuint color
Definition: glew.h:7185
Zeni::Video_Init_Failure
Definition: Video.h:293
Zeni::Camera
Camera / Point of View.
Definition: Camera.h:49
Zeni::Video
The Video Rendering Singleton.
Definition: Video.h:71
f
GLclampf f
Definition: glew.h:3390
ShHandle
void * ShHandle
Definition: ShaderLang.h:255
enabled
GLenum GLsizei const GLuint GLboolean enabled
Definition: glew.h:2538
Zeni::Program
Definition: Shader.h:108
Zeni::Light_Out_of_Range::Light_Out_of_Range
Light_Out_of_Range()
Definition: Video.h:298
Zeni::Video::VIDEO_MODE
VIDEO_MODE
Definition: Video.h:96
Zeni::render
static void render(const Vertex_Buffer_Macrorenderer &macrorenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
Definition: Vertex_Buffer.cpp:581
Zeni::Material
An Abstraction of a Material.
Definition: Material.h:56
file
FILE * file
Definition: visualinfo.c:88
name
EGLImageKHR EGLint * name
Definition: eglext.h:284
Zeni::Renderable
A Renderable Interface.
Definition: Renderable.h:47
Zeni::GLSL_ES_Shader_Compilation_Failure
Definition: Video.h:305
Zeni::Video::m_vertex_compiler
ShHandle m_vertex_compiler
Definition: Video.h:243
Zeni::Image
Image.
Definition: Image.h:52
image
EGLImageKHR image
Definition: eglext.h:88
Zeni::String
Definition: String.h:29
Zeni::Unordered_Map
Definition: Hash_Map.h:82
Coordinate.h
Zeni::Texture
An Abstraction of a Texture.
Definition: Texture.h:61
Zeni::Vector3f
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
Zeni::Light_Out_of_Range
Definition: Video.h:297
Zeni::Fog
An Abstraction of Fog.
Definition: Fog.h:47
Matrix4f.h
Zeni::Video_Render_To_Texture_Error
Definition: Video.h:301
sort_controllers.filename
string filename
Definition: sort_controllers.py:8
Zeni::Quaternion
A Featureful Quaternion Class.
Definition: Quaternion.h:44
Zeni::GLSL_ES_Shader_Compilation_Failure::GLSL_ES_Shader_Compilation_Failure
GLSL_ES_Shader_Compilation_Failure()
Definition: Video.h:306
Zeni::Video_Render_To_Texture_Error::Video_Render_To_Texture_Error
Video_Render_To_Texture_Error()
Definition: Video.h:302
Zeni::Font
Font Abstraction.
Definition: Font.h:70
Zeni::XML_Document
A class to open an XML file and manage the root node.
Definition: XML.h:111
program
GLbitfield GLuint program
Definition: gl2ext.h:1203
Zeni::Vertex_Buffer
A Vertex_Buffer that accepts Triangle and Quadrilaterals.
Definition: Vertex_Buffer.h:85
texture
GLenum GLenum GLuint texture
Definition: gl2ext.h:850
value
EGLSurface EGLint void ** value
Definition: eglext.h:301
Zeni::Shader
A base class for Vertex_Shader and Fragment_Shader.
Definition: Shader.h:97
Singleton.h
String.h
Color.h
Zeni::Video_Init_Failure::Video_Init_Failure
Video_Init_Failure()
Definition: Video.h:294
print_errors
static void print_errors()
Definition: main.cpp:158
Zeni::Video::TEST
TEST
Definition: Video.h:98
Zeni::get_Video
Video & get_Video()
Get access to the singleton.
Definition: Video.cpp:149
Zeni::Matrix4f
A Featureful 4-Space Matrix Class.
Definition: Matrix4f.h:47
Zeni::Error
The Error Class.
Definition: Error.h:52
Core.h
Zeni::Video::m_fragment_compiler
ShHandle m_fragment_compiler
Definition: Video.h:244
Zeni::Point2f
A 2D Point represented with floats.
Definition: Coordinate.h:98
Zeni::Vertex_Buffer_Renderer
Definition: Vertex_Buffer.h:71
Zeni::Color
Color.
Definition: Color.h:41
size
GLsizei size
Definition: gl2ext.h:1467
Zeni::Point2i
A 2D Point represented with integers.
Definition: Coordinate.h:85