zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Video_GL_Fixed.cpp
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 
18 #include <zeni_graphics.h>
19 
20 #ifndef DISABLE_GL
21 
22 #if defined(REQUIRE_GL_ES)
23 #include <GLES/gl.h>
24 #else
25 #include <GL/glew.h>
26 #endif
27 
28 #include <SDL/SDL.h>
29 #ifndef TEMP_DISABLE
30 #ifdef REQUIRE_GL_ES
31 #include <SDL/SDL_opengles.h>
32 #else
33 namespace SDLOPENGL {
34 #include <SDL/SDL_opengl.h>
35 }
36 #endif
37 #endif
38 
39 #ifdef _LINUX
40 namespace GLXEW {
41 #include <GL/glxew.h>
42 }
43 #endif
44 
45 #include <GLSLANG/ShaderLang.h>
46 
47 #include <iostream>
48 
49 #if defined(_DEBUG) && defined(_WINDOWS)
50 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
51 #define new DEBUG_NEW
52 #endif
53 
54 #ifndef TEMP_DISABLE
55 #ifdef REQUIRE_GL_ES
56 extern "C" GL_API int GL_APIENTRY _dgles_load_library(void *, void *(*)(void *, const char *));
57 
58 static void * proc_loader(void *, const char * name) {
59  return SDL_GL_GetProcAddress(name);
60 }
61 #endif
62 #endif
63 
64 namespace Zeni {
65 
66  Video_GL_Fixed::Video_GL_Fixed()
67  :
68 #if SDL_VERSION_ATLEAST(1,3,0)
69  m_context(0),
70 #endif
71 #ifdef _LINUX
72  m_pglSwapIntervalEXT(0),
73 #endif
74 #ifndef REQUIRE_GL_ES
75  m_pglBindBufferARB(0),
76  m_pglDeleteBuffersARB(0),
77  m_pglGenBuffersARB(0),
78  m_pglBufferDataARB(0),
79 #endif
80  m_maximum_anisotropy(-1),
81  m_zwrite(false),
82  m_render_target(0)
83 #ifdef MANUAL_GL_VSYNC_DELAY
84  ,
85  m_buffer_swap_end_time(0u),
86  m_time_taken(0.0f),
87  m_weight_new(0.2f)
88 #endif
89  {
90  init();
91  }
92 
93  Video_GL_Fixed::~Video_GL_Fixed() {
94  uninit();
95  }
96 
97  bool Video_GL_Fixed::begin_prerender() {
98  assert(!m_render_target);
99 
100 #ifdef _WINDOWS
101  glFlush();
102 #else
103  glFinish();
104 #endif
105 
108 
109  return true;
110  }
111 
112  bool Video_GL_Fixed::begin_render() {
113  assert(!m_render_target);
114 
115  glViewport(0, 0, get_Window().get_width(), get_Window().get_height());
116 
117  if(!is_zwrite_enabled())
119  set_clear_Color(get_clear_Color());
121  if(!is_zwrite_enabled())
123 
124  return true;
125  }
126 
127  void Video_GL_Fixed::end_render() {
128  /*** Begin CPU saver ***/
129 #ifdef MANUAL_GL_VSYNC_DELAY
130  Timer &tr = get_Timer();
131 
132  if(get_vertical_sync()) {
133  Time buffer_swap_start_time = tr.get_time();
134 
135  const unsigned int time_allowed = 1000u/60u - 2u;
136  const unsigned int new_time_taken = buffer_swap_start_time.get_ticks_since(m_buffer_swap_end_time);
137  m_time_taken = (1.0f - m_weight_new) * m_time_taken + m_weight_new * new_time_taken;
138 
139  if(m_time_taken < time_allowed)
140  SDL_Delay(static_cast<unsigned int>(time_allowed - m_time_taken));
141  }
142 #endif
143 
145 #ifndef TEMP_DISABLE
146 #if SDL_VERSION_ATLEAST(1,3,0)
147  SDL_GL_SwapWindow(get_Window().get_window());
148 #else
149  SDL_GL_SwapBuffers();
150 #endif
151 #endif
152 
153 #ifdef MANUAL_GL_VSYNC_DELAY
154  m_buffer_swap_end_time = tr.get_time();
155 #endif
156  }
157 
158 #if SDL_VERSION_ATLEAST(1,3,0)
159  void Video_GL_Fixed::alert_window_destroyed() {
160  m_context = 0;
161  }
162 #endif
163 
164  void Video_GL_Fixed::render(const Renderable &renderable) {
165  class PrePostRenderActor {
166  PrePostRenderActor & operator=(const PrePostRenderActor &) {return *this;}
167 
168  public:
169  PrePostRenderActor(const Renderable &renderable_)
170  : renderable(renderable_)
171  {
172  renderable.pre_render();
173  }
174 
175  ~PrePostRenderActor() {
176  renderable.post_render();
177  }
178  private:
179  const Renderable &renderable;
180  } ppra(renderable);
181 
182  renderable.render_to(*this);
183  }
184 
185  void Video_GL_Fixed::clear_depth_buffer() {
186  if(!is_zwrite_enabled())
189  if(!is_zwrite_enabled())
191  }
192 
193  int Video_GL_Fixed::get_maximum_anisotropy() const {
194  return m_maximum_anisotropy;
195  }
196 
197  bool Video_GL_Fixed::has_vertex_buffers() const {
198  return GLEW_ARB_vertex_buffer_object != 0;
199  }
200 
201  void Video_GL_Fixed::set_2d_view(const std::pair<Point2f, Point2f> &camera2d, const std::pair<Point2i, Point2i> &viewport, const bool &fix_aspect_ratio) {
202  Video::set_2d_view(camera2d, viewport, fix_aspect_ratio);
203 
204  if(m_render_target) {
205  select_world_matrix();
206  translate_scene(Vector3f(0.0f, camera2d.second.y, 0.0f));
207  scale_scene(Vector3f(1.0f, -1.0f, 1.0f));
208  translate_scene(Vector3f(0.0f, -camera2d.first.y, 0.0f));
209 
210  if(get_backface_culling())
212  }
213  else if(get_backface_culling())
215  }
216 
217  void Video_GL_Fixed::set_3d_view(const Camera &camera, const std::pair<Point2i, Point2i> &viewport) {
218  Video::set_3d_view(camera, viewport);
219 
220  if(m_render_target) {
221  if(get_backface_culling())
223  }
224  else if(get_backface_culling())
226  }
227 
228  void Video_GL_Fixed::set_backface_culling(const bool &on) {
229  Video::set_backface_culling(on);
230 
231  if(on) {
232  // Enable Backface Culling
234 
235  if(m_render_target)
237  else
239  }
240  else
242  }
243 
244  void Video_GL_Fixed::set_vertical_sync(const bool &on_) {
245  Core::assert_no_error();
246  Video::set_vertical_sync(on_);
247 
248 #ifdef MANUAL_GL_VSYNC_DELAY
249  const bool on = false;
250 #else
251  const bool on = on_;
252 #endif
253 
254 #ifndef TEMP_DISABLE
255 #if SDL_VERSION_ATLEAST(1,3,0)
257 #elif !defined(DISABLE_WGL)
258  typedef BOOL (APIENTRY *PFNWGLSWAPINTERVALFARPROC)(int);
259  PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = 0;
260 
261  const char *extensions = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
262 
263  if(strstr(extensions, "WGL_EXT_swap_control")) {
264  wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress("wglSwapIntervalEXT");
265 
266  if(wglSwapIntervalEXT)
267  wglSwapIntervalEXT(on);
268  }
269 #elif defined(_LINUX)
270  if(m_pglSwapIntervalSGI)
271  m_pglSwapIntervalSGI(on);
272  else if(m_pglSwapIntervalEXT)
273  m_pglSwapIntervalEXT(0, 0, on);
274  else
275  SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, on);
276 #else
277  SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, on);
278 #endif
279 #endif
280 
281  SDL_ClearError();
282  }
283 
284  void Video_GL_Fixed::set_zwrite(const bool &enabled) {
285  Video::set_zwrite(enabled);
286 
287  glDepthMask(GLboolean(enabled));
288  }
289 
290  void Video_GL_Fixed::set_ztest(const bool &enabled) {
291  Video::set_ztest(enabled);
292 
293  if(enabled) {
296  }
297  else
299  }
300 
301  void Video_GL_Fixed::set_alpha_test(const bool &enabled,
302  const TEST &test,
303  const float &value)
304  {
305  Video::set_alpha_test(enabled, test, value);
306 
307  GLenum func;
308 
309  switch(test) {
310  case ZENI_NEVER: func = GL_NEVER; break;
311  case ZENI_LESS: func = GL_LESS; break;
312  case ZENI_EQUAL: func = GL_EQUAL; break;
313  case ZENI_GREATER: func = GL_GREATER; break;
314  case ZENI_NOT_EQUAL: func = GL_NOTEQUAL; break;
315  case ZENI_LESS_OR_EQUAL: func = GL_LEQUAL; break;
316  case ZENI_GREATER_OR_EQUAL: func = GL_GEQUAL; break;
317  case ZENI_ALWAYS: func = GL_ALWAYS; break;
318  default:
319  assert(false);
320  return;
321  }
322 
323  if(enabled)
325  else
327 
328  glAlphaFunc(func, value);
329  }
330 
331  void Video_GL_Fixed::set_Color(const Color &color) {
332  Video::set_Color(color);
333 
334  glColor4f(color.r, color.g, color.b, color.a);
335  }
336 
337  void Video_GL_Fixed::set_clear_Color(const Color &color) {
338  Video::set_clear_Color(color);
339 
340  glClearColor(color.r, color.g, color.b, color.a);
341  }
342 
343  void Video_GL_Fixed::apply_Texture(const unsigned long &id) {
345  }
346 
347  void Video_GL_Fixed::apply_Texture(const Texture &texture) {
348  texture.apply_Texture();
349  }
350 
351  void Video_GL_Fixed::unapply_Texture() {
353  }
354 
355  void Video_GL_Fixed::set_lighting(const bool &on) {
356  Video::set_lighting(on);
357 
358  if(on)
360  else
362  }
363 
364  void Video_GL_Fixed::set_ambient_lighting(const Color &color) {
365  Video::set_ambient_lighting(color);
366 
367  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, reinterpret_cast<const GLfloat *>(&color));
368  }
369 
370  void Video_GL_Fixed::set_Light(const int &number, const Light &light) {
371  GLenum ln;
372  switch(number) {
373  case 0: ln = GL_LIGHT0; break;
374  case 1: ln = GL_LIGHT1; break;
375  case 2: ln = GL_LIGHT2; break;
376  case 3: ln = GL_LIGHT3; break;
377  case 4: ln = GL_LIGHT4; break;
378  case 5: ln = GL_LIGHT5; break;
379  case 6: ln = GL_LIGHT6; break;
380  case 7: ln = GL_LIGHT7; break;
381  default:
382  throw Light_Out_of_Range();
383  }
384 
385  Video::set_Light(number, light);
386 
387  light.set(ln, *this);
388  }
389 
390  void Video_GL_Fixed::unset_Light(const int &number) {
391  GLenum ln;
392  switch(number) {
393  case 0: ln = GL_LIGHT0; break;
394  case 1: ln = GL_LIGHT1; break;
395  case 2: ln = GL_LIGHT2; break;
396  case 3: ln = GL_LIGHT3; break;
397  case 4: ln = GL_LIGHT4; break;
398  case 5: ln = GL_LIGHT5; break;
399  case 6: ln = GL_LIGHT6; break;
400  case 7: ln = GL_LIGHT7; break;
401  default:
402  throw Light_Out_of_Range();
403  }
404 
405  Video::unset_Light(number);
406 
407  glDisable(ln);
408  }
409 
410  void Video_GL_Fixed::set_Material(const Material &material) {
411  material.set(*this);
412  }
413 
414  void Video_GL_Fixed::unset_Material(const Material &material) {
415  material.unset(*this);
416  }
417 
418  void Video_GL_Fixed::set_Fog(const Fog &fog) {
419  Video::set_Fog(fog);
420 
421  glEnable(GL_FOG);
422  fog.set(*this);
423  }
424 
425  void Video_GL_Fixed::unset_Fog() {
426  Video::unset_Fog();
427 
428  glDisable(GL_FOG);
429  }
430 
431  void Video_GL_Fixed::set_program(Program &program) {
432  program.link();
433  glUseProgramObjectARB(dynamic_cast<Program_GL_Fixed &>(program).get());
434  }
435 
436  void Video_GL_Fixed::unset_program() {
438  }
439 
440  void Video_GL_Fixed::set_render_target(Texture &
441 #if !defined(REQUIRE_GL_ES) || defined(GL_OES_VERSION_2_0)
442  texture
443 #endif
444  )
445  {
446 #if defined(REQUIRE_GL_ES) && !defined(GL_OES_VERSION_2_0)
448 #else
449  if(m_render_target)
451 
452  Texture_GL &tgl = dynamic_cast<Texture_GL &>(texture);
453 
454  if(!tgl.m_frame_buffer_object) {
455  const Point2i &tex_size = tgl.get_size();
456 
457  // Generate Depth Buffer
458  glGenRenderbuffersEXT(1, &tgl.m_render_buffer);
459  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, tgl.m_render_buffer);
462 
463  // Generate Framebuffer Object
464  glGenFramebuffersEXT(1, &tgl.m_frame_buffer_object);
465  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tgl.m_frame_buffer_object);
466 
467  // Bind Both to the Texture
470  }
471  else
472  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tgl.m_frame_buffer_object);
473 
474  m_render_target = &tgl;
475 #endif
476  }
477 
478  void Video_GL_Fixed::unset_render_target() {
479 #if defined(REQUIRE_GL_ES) && !defined(GL_OES_VERSION_2_0)
481 #else
482  if(!m_render_target)
484 
485  // Unbind all
487 
488  // Prepare to Generate Mipmap
489  glBindTexture(GL_TEXTURE_2D, m_render_target->m_texture_id);
492  Textures::get_bilinear_filtering() ? GL_LINEAR : GL_NEAREST);
493 
495 
496  // Cleanup after Mipmap Generation
498  Textures::get_mipmapping() ?
499  (Textures::get_bilinear_filtering() ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST) :
500  (Textures::get_bilinear_filtering() ? GL_LINEAR : GL_NEAREST));
503 
504  m_render_target = 0;
505 #endif
506  }
507 
508  void Video_GL_Fixed::clear_render_target(const Color &color) {
509  set_clear_Color(color);
511  }
512 
513  inline const Point2i & Video_GL_Fixed::get_render_target_size() const {
514  if(m_render_target)
515  return m_render_target->get_size();
516  else
517  return get_Window().get_size();
518  }
519 
520  void Video_GL_Fixed::select_world_matrix() {
522  }
523 
524  void Video_GL_Fixed::push_world_stack() {
526  glPushMatrix();
527  }
528 
529  void Video_GL_Fixed::pop_world_stack() {
531  glPopMatrix();
532  }
533 
534  void Video_GL_Fixed::translate_scene(const Vector3f &direction) {
535  glTranslatef(direction.i, direction.j, direction.k);
536  }
537 
538  void Video_GL_Fixed::rotate_scene(const Vector3f &about, const float &radians) {
539  glRotatef(radians * 180.0f / Global::pi, about.i, about.j, about.k);
540  }
541 
542  void Video_GL_Fixed::scale_scene(const Vector3f &factor) {
543  glScalef(factor.i, factor.j, factor.k);
544  }
545 
546  void Video_GL_Fixed::transform_scene(const Matrix4f &transformation) {
547  glMultMatrixf(reinterpret_cast<const GLfloat * const>(&transformation));
548  }
549 
550  Point2f Video_GL_Fixed::get_pixel_offset() const {
551  return Point2f(0.0f, 0.0f);
552  }
553 
554  void Video_GL_Fixed::set_view_matrix(const Matrix4f &view) {
555  Video::set_view_matrix(view);
556 
558  glLoadMatrixf(reinterpret_cast<GLfloat *>(const_cast<Matrix4f *>(&view)));
559  }
560 
561  void Video_GL_Fixed::set_projection_matrix(const Matrix4f &projection) {
562  Video::set_projection_matrix(projection);
563 
565  if(m_render_target && is_3d()) {
566  const Matrix4f flipped = Matrix4f::Scale(Vector3f(1.0f, -1.0f, 1.0f)) * projection;
567  glLoadMatrixf(reinterpret_cast<GLfloat *>(const_cast<Matrix4f *>(&flipped)));
568  }
569  else
570  glLoadMatrixf(reinterpret_cast<GLfloat *>(const_cast<Matrix4f *>(&projection)));
571  }
572 
573  void Video_GL_Fixed::set_viewport(const std::pair<Point2i, Point2i> &viewport) {
574  Video::set_viewport(viewport);
575 
576  if(m_render_target)
577  glViewport(viewport.first.x, viewport.first.y, viewport.second.x - viewport.first.x, viewport.second.y - viewport.first.y);
578  else
579  glViewport(viewport.first.x, get_Window().get_height() - viewport.second.y, viewport.second.x - viewport.first.x, viewport.second.y - viewport.first.y);
580  }
581 
582  Texture * Video_GL_Fixed::load_Texture(const String &filename, const bool &repeat, const bool &lazy_loading) {
583  return new Texture_GL(filename, repeat, lazy_loading);
584  }
585 
586  Texture * Video_GL_Fixed::create_Texture(const Image &image) {
587  return new Texture_GL(image);
588  }
589 
590  Texture * Video_GL_Fixed::create_Texture(const Point2i &size, const bool &repeat) {
591  return new Texture_GL(size, repeat);
592  }
593 
594  Font * Video_GL_Fixed::create_Font(const String &filename, const float &glyph_height, const float &virtual_screen_height) {
595  return new Font_FT(filename, glyph_height, virtual_screen_height);
596  }
597 
598  Vertex_Buffer_Renderer * Video_GL_Fixed::create_Vertex_Buffer_Renderer(Vertex_Buffer &vertex_buffer) {
599  return new Vertex_Buffer_Renderer_GL_Fixed(vertex_buffer);
600  }
601 
602  Shader * Video_GL_Fixed::create_Vertex_Shader(const String &filename) {
603  return new Shader_GL_Fixed(compile_glsles_shader(filename, m_vertex_compiler), Shader::VERTEX);
604  }
605 
606  Shader * Video_GL_Fixed::create_Fragment_Shader(const String &filename) {
607  return new Shader_GL_Fixed(compile_glsles_shader(filename, m_fragment_compiler), Shader::FRAGMENT);
608  }
609 
610  Program * Video_GL_Fixed::create_Program() {
611  return new Program_GL_Fixed();
612  }
613 
615  Core::assert_no_error();
616 
617  std::cerr << "Initializing OpenGL" << std::endl;
618 
619 #ifndef TEMP_DISABLE
620  //double buffer, no stencil, no accumulation buffer
632 
633  if(get_multisampling() > 1) {
634  SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, get_multisampling());
636  }
637 
638 #ifdef REQUIRE_GL_ES
639  {
640  int err = _dgles_load_library(0, proc_loader);
641  if(err)
642  throw Video_Init_Failure();
643  }
644 #endif
645 
646  Core::assert_no_error();
647 
648 #if SDL_VERSION_ATLEAST(2,0,0)
649  std::list<std::pair<int, int> > contexts;
650  contexts.push_back(std::make_pair(1, 4));
651  contexts.push_back(std::make_pair(1, 3));
652  contexts.push_back(std::make_pair(1, 2));
653  contexts.push_back(std::make_pair(1, 1));
654 
655  while(!contexts.empty()) {
656  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, contexts.front().first);
657  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, contexts.front().second);
658 
659  m_context = SDL_GL_CreateContext(get_Window().get_window());
660  if(m_context)
661  break;
662 
663  std::cerr << "OpenGL context " << contexts.front().first << '.' << contexts.front().second << " failed." << std::endl;
664  SDL_ClearError();
665  contexts.pop_front();
666  }
667 
668  if(!m_context)
669  throw Video_Init_Failure();
670 
671  /* This had to be before SDL_GL_CreateContext to work correctly on OS X some time ago.
672  * Now it causes an error to be before. Test.
673  */
674  Core::assert_no_error();
675  SDL_GL_SetSwapInterval(get_vertical_sync());
676  SDL_ClearError();
677 #endif
678 
679  Core::assert_no_error();
680 
681 #ifndef REQUIRE_GL_ES
682  {
683  const GLenum err = glewInit();
684  if(GLEW_OK != err) {
685  std::cerr << "GLEW Error: " << glewGetErrorString(err) << std::endl;
686  throw Video_Init_Failure();
687  }
688  }
689 #endif
690 #endif
691 
692  Core::assert_no_error();
693 
694  // Set Fill/Shade Mode
696 #ifndef REQUIRE_GL_ES
698 #endif
699  glEnable(GL_NORMALIZE); //GL_RESCALE_NORMALIZE);
700 
701  // Enable Alpha Blitting
704  //glBlendEquation(GL_FUNC_ADD); // default // would require ARB ext
705 
706  // Set lighting variables
707 #ifndef REQUIRE_GL_ES
710  if(glGetError() == GL_INVALID_ENUM)
711  std::cerr << "Quality Warning: Your graphics card does not support separate specular lighting in OpenGL.\n";
712 #endif
713 
714  // Initialize Assorted Variables
715  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
716  //glPointSize(static_cast<GLfloat>(sqrt(pow(double(get_screen_width()), 2.) * pow(double(get_screen_height()), 2.)) / 1000000));
717  //glLineWidth(static_cast<GLfloat>(sqrt(pow(double(get_screen_width()), 2.) * pow(double(get_screen_height()), 2.)) / 1000000));
718 
719  Core::assert_no_error();
720 
721  // Finish with a few function calls
722  set_2d();
723  set_Color(get_Color());
724  set_clear_Color(get_clear_Color());
725  set_backface_culling(get_backface_culling());
726  set_lighting(get_lighting());
727  set_ambient_lighting(get_ambient_lighting());
728  for(int i = 0; i != 8; ++i)
729  if(const Light * const lp = get_Light(i))
730  set_Light(i, *lp);
731  if(const Fog * const fp = get_Fog())
732  set_Fog(*fp);
733  set_alpha_test(is_alpha_test_enabled(), get_alpha_test_function(), get_alpha_test_value());
734  set_zwrite(is_zwrite_enabled());
735  set_ztest(is_ztest_enabled());
736 
737  Core::assert_no_error();
738 
739 #ifndef REQUIRE_GL_ES
740  union {
741  void * v;
742 #ifdef _LINUX
743  GLXEW::PFNGLXSWAPINTERVALEXTPROC pglSwapIntervalEXT;
744  GLXEW::PFNGLXSWAPINTERVALSGIPROC pglSwapIntervalSGI;
745 #endif
746  PFNGLBINDBUFFERARBPROC pglBindBufferARB;
747  PFNGLDELETEBUFFERSARBPROC pglDeleteBuffersARB;
748  PFNGLGENBUFFERSARBPROC pglGenBuffersARB;
749  PFNGLBUFFERDATAARBPROC pglBufferDataARB;
750  } ptr;
751 
752 #ifdef _LINUX
753  ptr.v = SDL_GL_GetProcAddress("glXSwapIntervalEXT");
754  if(!ptr.v)
755  ptr.v = SDL_GL_GetProcAddress("wglSwapIntervalEXT");
756  m_pglSwapIntervalEXT = ptr.pglSwapIntervalEXT;
757 
758  ptr.v = SDL_GL_GetProcAddress("glXSwapIntervalSGI");
759  if(!ptr.v)
760  ptr.v = SDL_GL_GetProcAddress("wglSwapIntervalSGI");
761  m_pglSwapIntervalSGI = ptr.pglSwapIntervalSGI;
762 #endif
763 
765  ptr.v = SDL_GL_GetProcAddress("glBindBufferARB");
766  m_pglBindBufferARB = ptr.pglBindBufferARB;
767 
768  ptr.v = SDL_GL_GetProcAddress("glDeleteBuffersARB");
769  m_pglDeleteBuffersARB = ptr.pglDeleteBuffersARB;
770 
771  ptr.v = SDL_GL_GetProcAddress("glGenBuffersARB");
772  m_pglGenBuffersARB = ptr.pglGenBuffersARB;
773 
774  ptr.v = SDL_GL_GetProcAddress("glBufferDataARB");
775  m_pglBufferDataARB = ptr.pglBufferDataARB;
776 
777  if(!(m_pglBindBufferARB && m_pglDeleteBuffersARB && m_pglGenBuffersARB && m_pglBufferDataARB)) {
778  m_pglBindBufferARB = 0;
779  m_pglDeleteBuffersARB = 0;
780  m_pglGenBuffersARB = 0;
781  m_pglBufferDataARB = 0;
782 
783  std::cerr << "Performance Warning: Your graphics card does not offer Vertex Buffer Objects (VBO) in OpenGL.\n";
784  }
785  }
786  else
787  std::cerr << "Performance Warning: Your graphics card does not offer Vertex Buffer Objects (VBO) in OpenGL.\n";
788 
790  glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, reinterpret_cast<GLint *>(&m_maximum_anisotropy));
791  else
792  m_maximum_anisotropy = 0;
793 #else
794  m_maximum_anisotropy = 0;
795 #endif
796 
797  // Has to be done after finding the function pointer
798  set_vertical_sync(get_vertical_sync());
799 
801 
802  ShBuiltInResources resources;
803  ShInitBuiltInResources(&resources);
804 
805  resources.MaxVertexAttribs = 8;
806  resources.MaxVertexUniformVectors = 128;
807  resources.MaxVaryingVectors = 8;
808  resources.MaxVertexTextureImageUnits = 0;
809  resources.MaxCombinedTextureImageUnits = 8;
810  resources.MaxTextureImageUnits = 8;
811  resources.MaxFragmentUniformVectors = 16;
812  resources.MaxDrawBuffers = 1;
813 
814  resources.OES_standard_derivatives = 0;
815  resources.OES_EGL_image_external = 0;
816 
817  m_vertex_compiler = ShConstructCompiler(SH_VERTEX_SHADER, SH_GLES2_SPEC, SH_GLSL_OUTPUT, &resources);
818  m_fragment_compiler = ShConstructCompiler(SH_FRAGMENT_SHADER, SH_GLES2_SPEC, SH_GLSL_OUTPUT, &resources);
819 
820  Core::assert_no_error();
821  }
822 
823  void Video_GL_Fixed::uninit() {
824  ShDestruct(m_vertex_compiler);
825  ShDestruct(m_fragment_compiler);
826 
827 #if SDL_VERSION_ATLEAST(1,3,0)
828  if(m_context)
829  SDL_GL_DeleteContext(m_context);
830 #endif
831  }
832 
833 }
834 
835 #else
836 
837 namespace Zeni {
838  void * this_pointer_is_also_dead_beef = (void *)0xDEADBEEF;
839 }
840 
841 #endif
#define glDisable
Definition: gl_mangle.h:393
#define glTexParameteri
Definition: gl_mangle.h:1763
#define GL_TRUE
Definition: gl2.h:51
#define GL_FOG
Definition: glew_head.h:360
static const double pi
Definition: e_atan2.c:47
virtual void link()=0
#define GL_FRONT
Definition: gl2.h:130
An Abstraction of a Light.
Definition: Light.h:57
#define GLEW_EXT_texture_filter_anisotropic
Definition: glew.h:10087
#define GL_LINEAR_MIPMAP_LINEAR
Definition: gl2.h:316
#define GL_FALSE
Definition: gl2.h:50
#define GL_BLEND
Definition: gl2.h:147
#define GL_CULL_FACE
Definition: gl2.h:146
#define wglSwapIntervalEXT
Definition: wglew.h:716
DECLSPEC void *SDLCALL SDL_GL_GetProcAddress(const char *proc)
Get the address of an OpenGL function.
Definition: SDL_video.c:2340
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
#define glLightModelfv
Definition: gl_mangle.h:990
GLuint color
Definition: glew.h:7185
unsigned int GLenum
Definition: gl2.h:23
Camera / Point of View.
Definition: Camera.h:49
virtual void post_render() const
Definition: Renderable.cpp:61
virtual void render_to(Video_GL_Fixed &screen) const =0
Overridden for OpenGL rendering.
#define glPolygonMode
Definition: gl_mangle.h:1295
#define GL_SRC_ALPHA
Definition: gl2.h:77
#define glCullFace
Definition: gl_mangle.h:332
GLclampf f
Definition: glew.h:3390
unsigned char GLboolean
Definition: gl2.h:24
DECLSPEC SDL_GLContext SDLCALL SDL_GL_CreateContext(SDL_Window *window)
Create an OpenGL context for use with an OpenGL window, and make it current.
Definition: SDL_video.c:2758
#define GL_LIGHT6
Definition: glew_head.h:674
#define GL_BACK
Definition: gl2.h:131
GLenum GLsizei const GLuint GLboolean enabled
Definition: glew.h:2538
#define GL_EQUAL
Definition: gl2.h:283
#define GL_TEXTURE_2D
Definition: gl2.h:145
#define GL_NORMALIZE
Definition: glew_head.h:383
COMPILER_EXPORT ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec, ShShaderOutput output, const ShBuiltInResources *resources)
Definition: ShaderLang.cpp:140
#define glGetIntegerv
Definition: gl_mangle.h:679
int MaxFragmentUniformVectors
Definition: ShaderLang.h:212
static void init(struct bs2b *bs2b)
Definition: bs2b.c:46
#define GL_DEPTH_COMPONENT16
Definition: gl2.h:433
static void render(const Vertex_Buffer_Macrorenderer &macrorenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
int MaxVertexTextureImageUnits
Definition: ShaderLang.h:209
An Abstraction of a Material.
Definition: Material.h:56
#define glBindFramebufferEXT
Definition: glew.h:8999
#define glTranslatef
Definition: gl_mangle.h:1802
#define GL_LIGHT4
Definition: glew_head.h:672
#define GL_FRONT_AND_BACK
Definition: gl2.h:132
EGLImageKHR EGLint * name
Definition: eglext.h:284
#define GL_LIGHT3
Definition: glew_head.h:671
void set(const GLenum &number, Video_GL_Fixed &screen) const
Definition: Light.cpp:52
Tick_Type get_ticks_since(const Time &time) const
Get the number of clock ticks passed between &#39;time&#39; and this Time.
Definition: Timer.hxx:40
#define assert(x)
Definition: SDL_malloc.c:1234
#define GL_LIGHTING
Definition: glew_head.h:352
A Renderable Interface.
Definition: Renderable.h:47
if(!yyg->yy_init)
GLenum func
Definition: SDL_opengl.h:5654
#define GL_DEPTH_ATTACHMENT_EXT
Definition: glew.h:8963
Image.
Definition: Image.h:52
EGLImageKHR image
Definition: eglext.h:88
void set(Video_GL_Fixed &screen) const
Definition: Fog.cpp:48
#define SDL_VERSION_ATLEAST(X, Y, Z)
Definition: SDL_version.h:106
#define glClear
Definition: gl_mangle.h:170
#define glFlush
Definition: gl_mangle.h:485
#define glFramebufferRenderbufferEXT
Definition: glew.h:9004
#define GL_LESS
Definition: gl2.h:282
DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value)
Set an OpenGL window attribute before window creation.
Definition: SDL_video.c:2469
#define glPushMatrix
Definition: gl_mangle.h:1476
#define GL_COLOR_BUFFER_BIT
Definition: gl2.h:47
An Abstraction of a Texture.
Definition: Texture.h:61
Timer & get_Timer()
Get access to the singleton.
Definition: Timer.cpp:73
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
#define glRotatef
Definition: gl_mangle.h:1555
#define glFinish
Definition: gl_mangle.h:482
ALuint u
Definition: alMain.h:58
#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
Definition: gl2ext.h:406
#define GL_TEXTURE_MIN_FILTER
Definition: gl2.h:320
DECLSPEC int SDLCALL SDL_GL_SetSwapInterval(int interval)
Set the swap interval for the current OpenGL context.
Definition: SDL_video.c:2843
const GLdouble * v
Definition: glew.h:1377
#define glScalef
Definition: gl_mangle.h:1572
#define APIENTRY
Definition: glew_head.h:150
void unset(Video_GL_Fixed &screen) const
Definition: Material.cpp:115
int
Definition: SDL_systhread.c:37
#define glViewport
Definition: gl_mangle.h:2242
A Timer Singleton.
Definition: Timer.h:97
An Abstraction of Fog.
Definition: Fog.h:47
#define GL_NEVER
Definition: gl2.h:281
float a
Definition: Color.h:69
#define GL_RENDERBUFFER_EXT
Definition: glew.h:8966
COMPILER_EXPORT void ShDestruct(ShHandle handle)
Definition: ShaderLang.cpp:158
COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources *resources)
Definition: ShaderLang.cpp:109
#define GL_ALPHA_TEST
Definition: glew_head.h:393
#define glShadeModel
Definition: gl_mangle.h:1626
#define glEnable
Definition: gl_mangle.h:441
#define GL_LIGHT_MODEL_COLOR_CONTROL
Definition: glew.h:1226
DECLSPEC void SDLCALL SDL_GL_DeleteContext(SDL_GLContext context)
Delete an OpenGL context.
Definition: SDL_video.c:2889
#define GLEW_OK
Definition: glew_tail.h:4
#define GL_MODELVIEW
Definition: glew_head.h:581
#define glLightModeli
Definition: gl_mangle.h:991
DECLSPEC void SDLCALL SDL_Delay(Uint32 ms)
Wait a specified number of milliseconds before returning.
Definition: SDL_systimer.c:70
Time get_time()
Get the current Time.
Definition: Timer.hxx:69
#define glUseProgramObjectARB
Definition: glew.h:5698
#define GL_LIGHT1
Definition: glew_head.h:669
Font Abstraction.
Definition: Font.h:70
#define glGenerateMipmapEXT
Definition: glew.h:9010
#define glColor4f
Definition: gl_mangle.h:202
#define GL_FILL
Definition: glew_head.h:601
#define glMultMatrixf
Definition: gl_mangle.h:1187
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
#define glGenFramebuffersEXT
Definition: glew.h:9008
#define glDepthFunc
Definition: gl_mangle.h:379
#define GL_LINEAR
Definition: gl2.h:308
void set(Video_GL_Fixed &screen) const
Definition: Material.cpp:83
#define GL_FRAMEBUFFER_EXT
Definition: glew.h:8965
Textures & get_Textures()
Get access to the singleton.
Definition: Textures.cpp:64
const Point2i & get_size() const
Get the resolution of the Texture on the GPU.
Definition: Texture.hxx:48
#define GL_INVALID_ENUM
Definition: gl2.h:158
#define glDepthMask
Definition: gl_mangle.h:380
Window & get_Window()
Get access to the singleton.
Definition: Window.cpp:392
virtual void apply_Texture() const =0
Apply a Texture to upcoming polygons.
float b
Definition: Color.h:68
void apply_Texture(const String &name)
Apply a texture for upcoming polygons (Called by Video::apply_Texture)
Definition: Textures.cpp:68
#define GLEW_ARB_vertex_buffer_object
Definition: glew.h:6922
int MaxCombinedTextureImageUnits
Definition: ShaderLang.h:210
#define GL_COLOR_ATTACHMENT0_EXT
Definition: gl2ext.h:578
GLenum GLenum GLuint texture
Definition: gl2ext.h:850
#define glClearColor
Definition: gl_mangle.h:164
#define glPopMatrix
Definition: gl_mangle.h:1301
void unlose_resources()
If resources have been lost, then reload them.
Definition: Database.hxx:415
#define glLoadMatrixf
Definition: gl_mangle.h:1005
#define GL_LIGHT_MODEL_LOCAL_VIEWER
Definition: glew_head.h:353
#define glGetError
Definition: gl_mangle.h:643
EGLSurface EGLint void ** value
Definition: eglext.h:301
A base class for Vertex_Shader and Fragment_Shader.
Definition: Shader.h:97
#define GL_EXTENSIONS
Definition: gl2.h:304
DECLSPEC void SDLCALL SDL_ClearError(void)
Definition: SDL_error.c:212
#define glBindRenderbufferEXT
Definition: glew.h:9000
#define GL_GEQUAL
Definition: gl2.h:287
#define GL_PROJECTION
Definition: glew_head.h:582
#define GL_SMOOTH
Definition: glew_head.h:606
#define GL_NOTEQUAL
Definition: gl2.h:286
#define glMatrixMode
Definition: gl_mangle.h:1053
const GLubyte *GLEWAPIENTRY glewGetErrorString(GLenum error)
Definition: glew_init_tail.c:3
#define GL_LIGHT_MODEL_AMBIENT
Definition: glew_head.h:355
#define GL_LIGHT7
Definition: glew_head.h:675
#define GL_ONE_MINUS_SRC_ALPHA
Definition: gl2.h:78
#define GL_SEPARATE_SPECULAR_COLOR
Definition: glew.h:1228
#define GL_GREATER
Definition: gl2.h:285
float g
Definition: Color.h:67
static const Point2i & get_size()
Definition: Window.hxx:29
#define GL_LIGHT2
Definition: glew_head.h:670
#define GL_APIENTRY
Definition: gl2platform.h:27
#define GL_ALWAYS
Definition: gl2.h:288
Fonts & get_Fonts()
Get access to the singleton.
Definition: Fonts.cpp:60
#define glBindTexture
Definition: gl_mangle.h:98
virtual void pre_render() const
Definition: Renderable.cpp:56
A Featureful 4-Space Matrix Class.
Definition: Matrix4f.h:47
float r
Definition: Color.h:66
int i
Definition: pngrutil.c:1377
#define GL_DEPTH_BUFFER_BIT
Definition: gl2.h:45
GLenum GLEWAPIENTRY glewInit(void)
#define GL_NEAREST_MIPMAP_NEAREST
Definition: gl2.h:313
A 2D Point represented with floats.
Definition: Coordinate.h:98
#define glGenRenderbuffersEXT
Definition: glew.h:9009
#define glAlphaFunc
Definition: gl_mangle.h:42
#define GL_LIGHT5
Definition: glew_head.h:673
#define GL_LEQUAL
Definition: gl2.h:284
#define glRenderbufferStorageEXT
Definition: glew.h:9015
#define false
Definition: ftrandom.c:50
#define GL_LIGHT0
Definition: glew_head.h:667
Color.
Definition: Color.h:41
DECLSPEC void SDLCALL SDL_GL_SwapWindow(SDL_Window *window)
Swap the OpenGL buffers for a window, if double-buffering is supported.
Definition: SDL_video.c:2871
#define glGetString
Definition: gl_mangle.h:824
int OES_standard_derivatives
Definition: ShaderLang.h:217
#define GL_NEAREST
Definition: gl2.h:307
#define glBlendFunc
Definition: gl_mangle.h:135
A Snapshot of the Timer.
Definition: Timer.h:63
#define glFramebufferTexture2DEXT
Definition: glew.h:9006
typedef BOOL(WINAPI *PFNWGLSETSTEREOEMITTERSTATE3DLPROC)(HDC hDC
#define GL_DEPTH_TEST
Definition: gl2.h:150
GLsizei size
Definition: gl2ext.h:1467
A 2D Point represented with integers.
Definition: Coordinate.h:85