zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Video_GL_Shader.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 
32 #ifndef ZENI_VIDEO_GL_SHADER_H
33 #define ZENI_VIDEO_GL_SHADER_H
34 
35 #include <Zeni/Timer.h>
36 #include <Zeni/Video.h>
37 
38 #ifndef DISABLE_GL
39 
40 #if defined(REQUIRE_GL_ES)
41 #include <GLES/gl.h>
42 #define GL_ARRAY_BUFFER_ARB GL_ARRAY_BUFFER
43 #define GL_STATIC_DRAW_ARB GL_STATIC_DRAW
44 #define glBindFramebufferEXT glBindFramebuffer
45 #define glBindRenderbufferEXT glBindRenderbuffer
46 #define glFogi glFogx
47 #define glFramebufferRenderbufferEXT glFramebufferRenderbuffer
48 #define glFramebufferTexture2DEXT glFramebufferTexture2D
49 #define glGenFramebuffersEXT glGenFramebuffers
50 #define glGenRenderbuffersEXT glGenRenderbuffers
51 #define glRenderbufferStorageEXT glRenderbufferStorage
52 #else
53 #include <GL/glew.h>
54 #ifdef _LINUX
55 namespace GLXEW {
56 struct _XDisplay;
57 typedef _XDisplay Display;
58 typedef long unsigned int XID;
59 typedef XID GLXDrawable;
60 typedef void ( * PFNGLXSWAPINTERVALEXTPROC) (Display* dpy, GLXDrawable drawable, int interval);
61 typedef int ( * PFNGLXSWAPINTERVALSGIPROC) (int interval);
62 }
63 #endif
64 #endif
65 
66 namespace Zeni {
67 
68  class Texture_GL;
69 
70  class ZENI_GRAPHICS_DLL Video_GL_Shader : public Video {
71  friend class Video;
72  friend ZENI_GRAPHICS_DLL Video & get_Video();
73 
75  ~Video_GL_Shader();
76 
77  // Undefined
79  Video_GL_Shader & operator=(const Video_GL_Shader &);
80 
81  public:
82  // Rendering functions
83  bool begin_prerender();
84  bool begin_render();
85  void end_render();
86  void render(const Renderable &renderable);
87  void clear_depth_buffer();
88 
89  // Accessors
90  int get_maximum_anisotropy() const;
91  bool has_vertex_buffers() const;
92 
93  // Modifiers
94  void set_2d_view(const std::pair<Point2f, Point2f> & /*camera2d*/,
95  const std::pair<Point2i, Point2i> & /*viewport*/ = std::make_pair(Point2i(), get_Video().get_render_target_size()),
96  const bool &fix_aspect_ratio = false);
97  void set_3d_view(const Camera & /*camera*/,
98  const std::pair<Point2i, Point2i> & /*viewport*/ = std::make_pair(Point2i(), get_Video().get_render_target_size()));
99  void set_backface_culling(const bool &on);
100  void set_vertical_sync(const bool &on);
101  void set_zwrite(const bool &enabled);
102  void set_ztest(const bool &enabled);
103  void set_alpha_test(const bool &enabled, const TEST &test, const float &value);
104 
105  // Color and Texturing
106  void set_Color(const Color &color);
107  void set_clear_Color(const Color &color);
108  inline void apply_Texture(const String &name) {return Video::apply_Texture(name);}
109  void apply_Texture(const unsigned long &id);
110  void apply_Texture(const Texture &texture);
111  void unapply_Texture();
112 
113  // Lighting and Materials
114  void set_lighting(const bool &on = true);
115  void set_ambient_lighting(const Color &color);
116  void set_Light(const int &number, const Light &light);
117  void unset_Light(const int &number);
118  void set_Material(const Material &material);
119  void unset_Material(const Material &material);
120 
121  // Fog
122  void set_Fog(const Fog &fog);
123  void unset_Fog();
124 
125  // Shaders
126  void set_program(Program &program);
127  void unset_program();
128 
129  // Render-to-texture
130  void set_render_target(Texture &texture);
131  void unset_render_target();
132  void clear_render_target(const Color &color = Color(0.0f, 0.0f, 0.0f, 0.0f));
133  const Point2i & get_render_target_size() const;
134 
135  // Model/World Transformation Stack Functions
136  void select_world_matrix();
137  void push_world_stack();
138  void pop_world_stack();
139  void translate_scene(const Vector3f &direction);
140  void rotate_scene(const Vector3f &about, const float &radians);
141  void scale_scene(const Vector3f &factor);
142  void transform_scene(const Matrix4f &transformation);
143 
144  // View+Projection Matrix Functions
145  Point2f get_pixel_offset() const;
146  void set_view_matrix(const Matrix4f &view);
147  void set_projection_matrix(const Matrix4f &projection);
148  void set_viewport(const std::pair<Point2i, Point2i> &viewport =
149  std::make_pair(Point2i(), get_Video().get_render_target_size()));
150 
151  // Creation Functions
152  Texture * load_Texture(const String &filename, const bool &repeat, const bool &lazy_loading = false);
153  Texture * create_Texture(const Image &image);
154  Texture * create_Texture(const Point2i &size, const bool &repeat);
155  Font * create_Font(const String &filename,
156  const float &glyph_height, const float &virtual_screen_height);
157  Vertex_Buffer_Renderer * create_Vertex_Buffer_Renderer(Vertex_Buffer &vertex_buffer);
158  Shader * create_Vertex_Shader(const String &filename);
159  Shader * create_Fragment_Shader(const String &filename);
160  Program * create_Program();
161 
162 #if SDL_VERSION_ATLEAST(1,3,0)
163  virtual void alert_window_destroyed();
164 #endif
165 
166  protected:
167  void init();
168  void uninit();
169 
170  private:
171 #if SDL_VERSION_ATLEAST(1,3,0)
172  SDL_GLContext m_context;
173 #endif
174 
175 #if !defined(REQUIRE_GL_ES) && defined(_LINUX)
176  GLXEW::PFNGLXSWAPINTERVALEXTPROC m_pglSwapIntervalEXT;
177  GLXEW::PFNGLXSWAPINTERVALSGIPROC m_pglSwapIntervalSGI;
178 #endif
179 
180  int m_maximum_anisotropy;
181  bool m_zwrite;
182 
183  Texture_GL * m_render_target;
184 
185 #ifdef MANUAL_GL_VSYNC_DELAY
186  Zeni::Time m_buffer_swap_end_time;
187  float m_time_taken;
188  float m_weight_new;
189 #endif
190  };
191 
192 }
193 
194 #endif
195 
196 #endif
An Abstraction of a Light.
Definition: Light.h:57
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
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1824
GLuint color
Definition: glew.h:7185
Camera / Point of View.
Definition: Camera.h:49
The Video Rendering Singleton.
Definition: Video.h:71
GLclampf f
Definition: glew.h:3390
GLenum GLsizei const GLuint GLboolean enabled
Definition: glew.h:2538
void apply_Texture(const String &name)
Apply a texture by name.
static void init(struct bs2b *bs2b)
Definition: bs2b.c:46
static void render(const Vertex_Buffer_Macrorenderer &macrorenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
An Abstraction of a Material.
Definition: Material.h:56
void * SDL_GLContext
An opaque handle to an OpenGL context.
Definition: SDL_video.h:161
EGLImageKHR EGLint * name
Definition: eglext.h:284
A Renderable Interface.
Definition: Renderable.h:47
Image.
Definition: Image.h:52
EGLImageKHR image
Definition: eglext.h:88
void apply_Texture(const String &name)
Apply a texture by name.
Definition: Video.hxx:118
An Abstraction of a Texture.
Definition: Texture.h:61
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
int
Definition: SDL_systhread.c:37
An Abstraction of Fog.
Definition: Fog.h:47
XID GLXDrawable
Definition: glxew_head.h:58
The OpenGL Rendering System.
Font Abstraction.
Definition: Font.h:70
GLbitfield GLuint program
Definition: gl2ext.h:1203
void(* PFNGLXSWAPINTERVALEXTPROC)(Display *dpy, GLXDrawable drawable, int interval)
Definition: glxew.h:676
int(* PFNGLXSWAPINTERVALSGIPROC)(int interval)
Definition: glxew.h:1360
A Vertex_Buffer that accepts Triangle and Quadrilaterals.
Definition: Vertex_Buffer.h:85
GLenum GLenum GLuint texture
Definition: gl2ext.h:850
EGLSurface EGLint void ** value
Definition: eglext.h:301
A base class for Vertex_Shader and Fragment_Shader.
Definition: Shader.h:97
Video & get_Video()
Get access to the singleton.
Definition: Video.cpp:149
A Featureful 4-Space Matrix Class.
Definition: Matrix4f.h:47
A 2D Point represented with floats.
Definition: Coordinate.h:98
Color.
Definition: Color.h:41
Display * dpy
A Snapshot of the Timer.
Definition: Timer.h:63
GLsizei size
Definition: gl2ext.h:1467
A 2D Point represented with integers.
Definition: Coordinate.h:85