22 #if defined(REQUIRE_GL_ES)
49 #if defined(_DEBUG) && defined(_WINDOWS)
50 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
56 extern "C" GL_API
int GL_APIENTRY _dgles_load_library(
void *,
void *(*)(
void *,
const char *));
58 static void * proc_loader(
void *,
const char *
name) {
66 Video_GL_Fixed::Video_GL_Fixed()
72 m_pglSwapIntervalEXT(0),
75 m_pglBindBufferARB(0),
76 m_pglDeleteBuffersARB(0),
77 m_pglGenBuffersARB(0),
78 m_pglBufferDataARB(0),
80 m_maximum_anisotropy(-1),
83 #ifdef MANUAL_GL_VSYNC_DELAY
85 m_buffer_swap_end_time(0
u),
93 Video_GL_Fixed::~Video_GL_Fixed() {
97 bool Video_GL_Fixed::begin_prerender() {
112 bool Video_GL_Fixed::begin_render() {
117 if(!is_zwrite_enabled())
119 set_clear_Color(get_clear_Color());
121 if(!is_zwrite_enabled())
127 void Video_GL_Fixed::end_render() {
129 #ifdef MANUAL_GL_VSYNC_DELAY
132 if(get_vertical_sync()) {
135 const unsigned int time_allowed = 1000
u/60
u - 2
u;
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;
139 if(m_time_taken < time_allowed)
140 SDL_Delay(static_cast<unsigned int>(time_allowed - m_time_taken));
146 #if SDL_VERSION_ATLEAST(1,3,0)
149 SDL_GL_SwapBuffers();
153 #ifdef MANUAL_GL_VSYNC_DELAY
154 m_buffer_swap_end_time = tr.
get_time();
158 #if SDL_VERSION_ATLEAST(1,3,0)
159 void Video_GL_Fixed::alert_window_destroyed() {
165 class PrePostRenderActor {
166 PrePostRenderActor & operator=(
const PrePostRenderActor &) {
return *
this;}
169 PrePostRenderActor(
const Renderable &renderable_)
170 : renderable(renderable_)
175 ~PrePostRenderActor() {
185 void Video_GL_Fixed::clear_depth_buffer() {
186 if(!is_zwrite_enabled())
189 if(!is_zwrite_enabled())
193 int Video_GL_Fixed::get_maximum_anisotropy()
const {
194 return m_maximum_anisotropy;
197 bool Video_GL_Fixed::has_vertex_buffers()
const {
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);
204 if(m_render_target) {
205 select_world_matrix();
206 translate_scene(
Vector3f(0.0
f, camera2d.second.y, 0.0f));
208 translate_scene(
Vector3f(0.0
f, -camera2d.first.y, 0.0f));
210 if(get_backface_culling())
213 else if(get_backface_culling())
217 void Video_GL_Fixed::set_3d_view(
const Camera &camera,
const std::pair<Point2i, Point2i> &viewport) {
218 Video::set_3d_view(camera, viewport);
220 if(m_render_target) {
221 if(get_backface_culling())
224 else if(get_backface_culling())
228 void Video_GL_Fixed::set_backface_culling(
const bool &on) {
229 Video::set_backface_culling(on);
244 void Video_GL_Fixed::set_vertical_sync(
const bool &on_) {
245 Core::assert_no_error();
246 Video::set_vertical_sync(on_);
248 #ifdef MANUAL_GL_VSYNC_DELAY
249 const bool on =
false;
255 #if SDL_VERSION_ATLEAST(1,3,0)
257 #elif !defined(DISABLE_WGL)
263 if(strstr(extensions,
"WGL_EXT_swap_control")) {
264 wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress(
"wglSwapIntervalEXT");
266 if(wglSwapIntervalEXT)
269 #elif defined(_LINUX)
270 if(m_pglSwapIntervalSGI)
271 m_pglSwapIntervalSGI(on);
272 else if(m_pglSwapIntervalEXT)
273 m_pglSwapIntervalEXT(0, 0, on);
284 void Video_GL_Fixed::set_zwrite(
const bool &
enabled) {
285 Video::set_zwrite(enabled);
290 void Video_GL_Fixed::set_ztest(
const bool &
enabled) {
291 Video::set_ztest(enabled);
301 void Video_GL_Fixed::set_alpha_test(
const bool &
enabled,
305 Video::set_alpha_test(enabled, test, value);
310 case ZENI_NEVER: func =
GL_NEVER;
break;
311 case ZENI_LESS: func =
GL_LESS;
break;
312 case ZENI_EQUAL: func =
GL_EQUAL;
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;
332 Video::set_Color(color);
338 Video::set_clear_Color(color);
343 void Video_GL_Fixed::apply_Texture(
const unsigned long &
id) {
351 void Video_GL_Fixed::unapply_Texture() {
355 void Video_GL_Fixed::set_lighting(
const bool &on) {
356 Video::set_lighting(on);
364 void Video_GL_Fixed::set_ambient_lighting(
const Color &
color) {
365 Video::set_ambient_lighting(color);
370 void Video_GL_Fixed::set_Light(
const int &number,
const Light &
light) {
385 Video::set_Light(number, light);
387 light.
set(ln, *
this);
390 void Video_GL_Fixed::unset_Light(
const int &number) {
405 Video::unset_Light(number);
410 void Video_GL_Fixed::set_Material(
const Material &material) {
414 void Video_GL_Fixed::unset_Material(
const Material &material) {
415 material.
unset(*
this);
418 void Video_GL_Fixed::set_Fog(
const Fog &fog) {
425 void Video_GL_Fixed::unset_Fog() {
436 void Video_GL_Fixed::unset_program() {
440 void Video_GL_Fixed::set_render_target(
Texture &
441 #
if !defined(REQUIRE_GL_ES) || defined(GL_OES_VERSION_2_0)
446 #if defined(REQUIRE_GL_ES) && !defined(GL_OES_VERSION_2_0)
454 if(!tgl.m_frame_buffer_object) {
474 m_render_target = &tgl;
478 void Video_GL_Fixed::unset_render_target() {
479 #if defined(REQUIRE_GL_ES) && !defined(GL_OES_VERSION_2_0)
498 Textures::get_mipmapping() ?
500 (Textures::get_bilinear_filtering() ?
GL_LINEAR : GL_NEAREST));
508 void Video_GL_Fixed::clear_render_target(
const Color &
color) {
509 set_clear_Color(color);
513 inline const Point2i & Video_GL_Fixed::get_render_target_size()
const {
515 return m_render_target->get_size();
520 void Video_GL_Fixed::select_world_matrix() {
524 void Video_GL_Fixed::push_world_stack() {
529 void Video_GL_Fixed::pop_world_stack() {
534 void Video_GL_Fixed::translate_scene(
const Vector3f &direction) {
538 void Video_GL_Fixed::rotate_scene(
const Vector3f &about,
const float &radians) {
542 void Video_GL_Fixed::scale_scene(
const Vector3f &factor) {
546 void Video_GL_Fixed::transform_scene(
const Matrix4f &transformation) {
547 glMultMatrixf(reinterpret_cast<const GLfloat * const>(&transformation));
550 Point2f Video_GL_Fixed::get_pixel_offset()
const {
554 void Video_GL_Fixed::set_view_matrix(
const Matrix4f &view) {
555 Video::set_view_matrix(view);
558 glLoadMatrixf(reinterpret_cast<GLfloat *>(const_cast<Matrix4f *>(&view)));
561 void Video_GL_Fixed::set_projection_matrix(
const Matrix4f &projection) {
562 Video::set_projection_matrix(projection);
565 if(m_render_target && is_3d()) {
567 glLoadMatrixf(reinterpret_cast<GLfloat *>(const_cast<Matrix4f *>(&flipped)));
570 glLoadMatrixf(reinterpret_cast<GLfloat *>(const_cast<Matrix4f *>(&projection)));
573 void Video_GL_Fixed::set_viewport(
const std::pair<Point2i, Point2i> &viewport) {
574 Video::set_viewport(viewport);
577 glViewport(viewport.first.x, viewport.first.y, viewport.second.x - viewport.first.x, viewport.second.y - viewport.first.y);
579 glViewport(viewport.first.x,
get_Window().get_height() - viewport.second.y, viewport.second.x - viewport.first.x, viewport.second.y - viewport.first.y);
583 return new Texture_GL(filename, repeat, lazy_loading);
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);
603 return new Shader_GL_Fixed(compile_glsles_shader(filename, m_vertex_compiler), Shader::VERTEX);
607 return new Shader_GL_Fixed(compile_glsles_shader(filename, m_fragment_compiler), Shader::FRAGMENT);
615 Core::assert_no_error();
617 std::cerr <<
"Initializing OpenGL" << std::endl;
633 if(get_multisampling() > 1) {
640 int err = _dgles_load_library(0, proc_loader);
646 Core::assert_no_error();
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));
655 while(!contexts.empty()) {
663 std::cerr <<
"OpenGL context " << contexts.front().first <<
'.' << contexts.front().second <<
" failed." << std::endl;
665 contexts.pop_front();
674 Core::assert_no_error();
679 Core::assert_no_error();
681 #ifndef REQUIRE_GL_ES
692 Core::assert_no_error();
696 #ifndef REQUIRE_GL_ES
707 #ifndef REQUIRE_GL_ES
711 std::cerr <<
"Quality Warning: Your graphics card does not support separate specular lighting in OpenGL.\n";
719 Core::assert_no_error();
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))
731 if(
const Fog *
const fp = get_Fog())
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());
737 Core::assert_no_error();
739 #ifndef REQUIRE_GL_ES
746 PFNGLBINDBUFFERARBPROC pglBindBufferARB;
747 PFNGLDELETEBUFFERSARBPROC pglDeleteBuffersARB;
748 PFNGLGENBUFFERSARBPROC pglGenBuffersARB;
749 PFNGLBUFFERDATAARBPROC pglBufferDataARB;
756 m_pglSwapIntervalEXT = ptr.pglSwapIntervalEXT;
761 m_pglSwapIntervalSGI = ptr.pglSwapIntervalSGI;
766 m_pglBindBufferARB = ptr.pglBindBufferARB;
769 m_pglDeleteBuffersARB = ptr.pglDeleteBuffersARB;
772 m_pglGenBuffersARB = ptr.pglGenBuffersARB;
775 m_pglBufferDataARB = ptr.pglBufferDataARB;
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;
783 std::cerr <<
"Performance Warning: Your graphics card does not offer Vertex Buffer Objects (VBO) in OpenGL.\n";
787 std::cerr <<
"Performance Warning: Your graphics card does not offer Vertex Buffer Objects (VBO) in OpenGL.\n";
792 m_maximum_anisotropy = 0;
794 m_maximum_anisotropy = 0;
798 set_vertical_sync(get_vertical_sync());
820 Core::assert_no_error();
823 void Video_GL_Fixed::uninit() {
827 #if SDL_VERSION_ATLEAST(1,3,0)
838 void * this_pointer_is_also_dead_beef = (
void *)0xDEADBEEF;
An Abstraction of a Light.
#define GLEW_EXT_texture_filter_anisotropic
#define GL_LINEAR_MIPMAP_LINEAR
#define wglSwapIntervalEXT
DECLSPEC void *SDLCALL SDL_GL_GetProcAddress(const char *proc)
Get the address of an OpenGL function.
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
virtual void post_render() const
virtual void render_to(Video_GL_Fixed &screen) const =0
Overridden for OpenGL rendering.
DECLSPEC SDL_GLContext SDLCALL SDL_GL_CreateContext(SDL_Window *window)
Create an OpenGL context for use with an OpenGL window, and make it current.
GLenum GLsizei const GLuint GLboolean enabled
int MaxVertexUniformVectors
COMPILER_EXPORT ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec, ShShaderOutput output, const ShBuiltInResources *resources)
int MaxFragmentUniformVectors
static void init(struct bs2b *bs2b)
#define GL_DEPTH_COMPONENT16
static void render(const Vertex_Buffer_Macrorenderer ¯orenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
int MaxVertexTextureImageUnits
An Abstraction of a Material.
#define glBindFramebufferEXT
#define GL_FRONT_AND_BACK
EGLImageKHR EGLint * name
void set(const GLenum &number, Video_GL_Fixed &screen) const
Tick_Type get_ticks_since(const Time &time) const
Get the number of clock ticks passed between 'time' and this Time.
#define GL_DEPTH_ATTACHMENT_EXT
void set(Video_GL_Fixed &screen) const
#define SDL_VERSION_ATLEAST(X, Y, Z)
#define glFramebufferRenderbufferEXT
DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value)
Set an OpenGL window attribute before window creation.
#define GL_COLOR_BUFFER_BIT
An Abstraction of a Texture.
Timer & get_Timer()
Get access to the singleton.
A Featureful 3-Space Vector Class.
#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
#define GL_TEXTURE_MIN_FILTER
DECLSPEC int SDLCALL SDL_GL_SetSwapInterval(int interval)
Set the swap interval for the current OpenGL context.
void unset(Video_GL_Fixed &screen) const
#define GL_RENDERBUFFER_EXT
COMPILER_EXPORT void ShDestruct(ShHandle handle)
COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources *resources)
#define GL_LIGHT_MODEL_COLOR_CONTROL
DECLSPEC void SDLCALL SDL_GL_DeleteContext(SDL_GLContext context)
Delete an OpenGL context.
DECLSPEC void SDLCALL SDL_Delay(Uint32 ms)
Wait a specified number of milliseconds before returning.
Time get_time()
Get the current Time.
#define glUseProgramObjectARB
#define glGenerateMipmapEXT
GLbitfield GLuint program
void(* PFNGLXSWAPINTERVALEXTPROC)(Display *dpy, GLXDrawable drawable, int interval)
int(* PFNGLXSWAPINTERVALSGIPROC)(int interval)
A Vertex_Buffer that accepts Triangle and Quadrilaterals.
#define glGenFramebuffersEXT
void set(Video_GL_Fixed &screen) const
#define GL_FRAMEBUFFER_EXT
Textures & get_Textures()
Get access to the singleton.
const Point2i & get_size() const
Get the resolution of the Texture on the GPU.
Window & get_Window()
Get access to the singleton.
virtual void apply_Texture() const =0
Apply a Texture to upcoming polygons.
void apply_Texture(const String &name)
Apply a texture for upcoming polygons (Called by Video::apply_Texture)
#define GLEW_ARB_vertex_buffer_object
int MaxCombinedTextureImageUnits
#define GL_COLOR_ATTACHMENT0_EXT
GLenum GLenum GLuint texture
void unlose_resources()
If resources have been lost, then reload them.
#define GL_LIGHT_MODEL_LOCAL_VIEWER
EGLSurface EGLint void ** value
A base class for Vertex_Shader and Fragment_Shader.
DECLSPEC void SDLCALL SDL_ClearError(void)
#define glBindRenderbufferEXT
const GLubyte *GLEWAPIENTRY glewGetErrorString(GLenum error)
#define GL_LIGHT_MODEL_AMBIENT
#define GL_ONE_MINUS_SRC_ALPHA
#define GL_SEPARATE_SPECULAR_COLOR
static const Point2i & get_size()
Fonts & get_Fonts()
Get access to the singleton.
virtual void pre_render() const
A Featureful 4-Space Matrix Class.
#define GL_DEPTH_BUFFER_BIT
int OES_EGL_image_external
GLenum GLEWAPIENTRY glewInit(void)
#define GL_NEAREST_MIPMAP_NEAREST
A 2D Point represented with floats.
#define glGenRenderbuffersEXT
#define glRenderbufferStorageEXT
DECLSPEC void SDLCALL SDL_GL_SwapWindow(SDL_Window *window)
Swap the OpenGL buffers for a window, if double-buffering is supported.
int OES_standard_derivatives
#define glFramebufferTexture2DEXT
typedef BOOL(WINAPI *PFNWGLSETSTEREOEMITTERSTATE3DLPROC)(HDC hDC
A 2D Point represented with integers.