zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Video_GL_Fixed.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_FIXED_H
33 #define ZENI_VIDEO_GL_FIXED_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_Fixed : public Video {
71  friend class Video;
72  friend ZENI_GRAPHICS_DLL Video & get_Video();
73 
75  ~Video_GL_Fixed();
76 
77  // Undefined
79  Video_GL_Fixed & operator=(const Video_GL_Fixed &);
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  // Vertex Buffer Functions
163  inline void pglBindBufferARB(const GLenum target, const GLuint buffer) const;
164  inline void pglDeleteBuffersARB(const GLsizei n, GLuint * const buffers) const;
165  inline void pglGenBuffersARB(const GLsizei n, GLuint * const buffers) const;
166  inline void pglBufferDataARB(const GLenum target, const int size, const GLvoid * const data,
167  const GLenum usage) const;
168 
169  PFNGLBINDBUFFERARBPROC get_pglBindBufferARB() const {return m_pglBindBufferARB;}
170  PFNGLDELETEBUFFERSARBPROC get_pglDeleteBuffersARB() const {return m_pglDeleteBuffersARB;}
171  PFNGLGENBUFFERSARBPROC get_pglGenBuffersARB() const {return m_pglGenBuffersARB;}
172  PFNGLBUFFERDATAARBPROC get_pglBufferDataARB() const {return m_pglBufferDataARB;}
173 
174 #if SDL_VERSION_ATLEAST(1,3,0)
175  virtual void alert_window_destroyed();
176 #endif
177 
178  protected:
179  void init();
180  void uninit();
181 
182  private:
183 #if SDL_VERSION_ATLEAST(1,3,0)
184  SDL_GLContext m_context;
185 #endif
186 
187 #ifndef REQUIRE_GL_ES
188 #ifdef _LINUX
189  GLXEW::PFNGLXSWAPINTERVALEXTPROC m_pglSwapIntervalEXT;
190  GLXEW::PFNGLXSWAPINTERVALSGIPROC m_pglSwapIntervalSGI;
191 #endif
192  PFNGLBINDBUFFERARBPROC m_pglBindBufferARB;
193  PFNGLDELETEBUFFERSARBPROC m_pglDeleteBuffersARB;
194  PFNGLGENBUFFERSARBPROC m_pglGenBuffersARB;
195  PFNGLBUFFERDATAARBPROC m_pglBufferDataARB;
196 #endif
197 
198  int m_maximum_anisotropy;
199  bool m_zwrite;
200 
201  Texture_GL * m_render_target;
202 
203 #ifdef MANUAL_GL_VSYNC_DELAY
204  Zeni::Time m_buffer_swap_end_time;
205  float m_time_taken;
206  float m_weight_new;
207 #endif
208  };
209 
210 }
211 
212 #endif
213 
214 #endif
An Abstraction of a Light.
Definition: Light.h:57
int GLsizei
Definition: gl2.h:29
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
unsigned int GLenum
Definition: gl2.h:23
Camera / Point of View.
Definition: Camera.h:49
The Video Rendering Singleton.
Definition: Video.h:71
PFNGLDELETEBUFFERSARBPROC get_pglDeleteBuffersARB() const
GLclampf f
Definition: glew.h:3390
GLenum GLsizei const GLuint GLboolean enabled
Definition: glew.h:2538
GLclampd n
Definition: glew.h:7287
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
PFNGLBUFFERDATAARBPROC get_pglBufferDataARB() const
const GLuint * buffers
Definition: glew.h:1669
PFNGLGENBUFFERSARBPROC get_pglGenBuffersARB() const
EGLContext EGLenum target
Definition: eglext.h:87
EGLContext EGLenum EGLClientBuffer buffer
Definition: eglext.h:87
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
The OpenGL Rendering System.
An Abstraction of Fog.
Definition: Fog.h:47
void apply_Texture(const String &name)
Apply a texture by name.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
XID GLXDrawable
Definition: glxew_head.h:58
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
unsigned int GLuint
Definition: gl2.h:32
PFNGLBINDBUFFERARBPROC get_pglBindBufferARB() const
Video & get_Video()
Get access to the singleton.
Definition: Video.cpp:149
void GLvoid
Definition: gl2.h:21
A Featureful 4-Space Matrix Class.
Definition: Matrix4f.h:47
A 2D Point represented with floats.
Definition: Coordinate.h:98
GLsizeiptr const GLvoid GLenum usage
Definition: glew.h:1667
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