(GL) Less chance of segfaults if gl is NULL
This commit is contained in:
parent
b683feb389
commit
5b59b7e267
70
gfx/gl.c
70
gfx/gl.c
|
@ -49,10 +49,6 @@
|
||||||
#include "shader_glsl.h"
|
#include "shader_glsl.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LAKKA
|
|
||||||
#include "../frontend/menu/disp/lakka.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "shader_common.h"
|
#include "shader_common.h"
|
||||||
|
|
||||||
// Used for the last pass when rendering to the back buffer.
|
// Used for the last pass when rendering to the back buffer.
|
||||||
|
@ -159,8 +155,7 @@ static bool init_vao(gl_t *gl)
|
||||||
if (!gl->core_context && !gl_query_extension(gl, "ARB_vertex_array_object"))
|
if (!gl->core_context && !gl_query_extension(gl, "ARB_vertex_array_object"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool present = glGenVertexArrays && glBindVertexArray && glDeleteVertexArrays;
|
if (!(glGenVertexArrays && glBindVertexArray && glDeleteVertexArrays))
|
||||||
if (!present)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
glGenVertexArrays(1, &gl->vao);
|
glGenVertexArrays(1, &gl->vao);
|
||||||
|
@ -328,6 +323,9 @@ void gl_shader_set_coords(void *data, const struct gl_coords *coords, const math
|
||||||
{
|
{
|
||||||
gl_t *gl = (gl_t*)data;
|
gl_t *gl = (gl_t*)data;
|
||||||
|
|
||||||
|
if (!gl)
|
||||||
|
return;
|
||||||
|
|
||||||
bool ret_coords = false;
|
bool ret_coords = false;
|
||||||
bool ret_mvp = false;
|
bool ret_mvp = false;
|
||||||
|
|
||||||
|
@ -482,6 +480,9 @@ static void gl_create_fbo_textures(void *data)
|
||||||
int i;
|
int i;
|
||||||
gl_t *gl = (gl_t*)data;
|
gl_t *gl = (gl_t*)data;
|
||||||
|
|
||||||
|
if (!gl)
|
||||||
|
return;
|
||||||
|
|
||||||
glGenTextures(gl->fbo_pass, gl->fbo_texture);
|
glGenTextures(gl->fbo_pass, gl->fbo_texture);
|
||||||
|
|
||||||
GLuint base_filt = g_settings.video.smooth ? GL_LINEAR : GL_NEAREST;
|
GLuint base_filt = g_settings.video.smooth ? GL_LINEAR : GL_NEAREST;
|
||||||
|
@ -576,6 +577,9 @@ static bool gl_create_fbo_targets(void *data)
|
||||||
int i;
|
int i;
|
||||||
gl_t *gl = (gl_t*)data;
|
gl_t *gl = (gl_t*)data;
|
||||||
|
|
||||||
|
if (!gl)
|
||||||
|
return false;
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
glGenFramebuffers(gl->fbo_pass, gl->fbo);
|
glGenFramebuffers(gl->fbo_pass, gl->fbo);
|
||||||
for (i = 0; i < gl->fbo_pass; i++)
|
for (i = 0; i < gl->fbo_pass; i++)
|
||||||
|
@ -616,7 +620,7 @@ void gl_init_fbo(void *data, unsigned width, unsigned height)
|
||||||
int i;
|
int i;
|
||||||
gl_t *gl = (gl_t*)data;
|
gl_t *gl = (gl_t*)data;
|
||||||
|
|
||||||
if (gl_shader_num(gl) == 0)
|
if (!gl || gl_shader_num(gl) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct gfx_fbo_scale scale, scale_last;
|
struct gfx_fbo_scale scale, scale_last;
|
||||||
|
@ -682,6 +686,9 @@ void gl_init_fbo(void *data, unsigned width, unsigned height)
|
||||||
#ifndef HAVE_GCMGL
|
#ifndef HAVE_GCMGL
|
||||||
static void gl_deinit_hw_render(gl_t *gl)
|
static void gl_deinit_hw_render(gl_t *gl)
|
||||||
{
|
{
|
||||||
|
if (!gl)
|
||||||
|
return;
|
||||||
|
|
||||||
context_bind_hw_render(gl, true);
|
context_bind_hw_render(gl, true);
|
||||||
|
|
||||||
if (gl->hw_render_fbo_init)
|
if (gl->hw_render_fbo_init)
|
||||||
|
@ -782,6 +789,9 @@ void gl_set_projection(void *data, struct gl_ortho *ortho, bool allow_rotate)
|
||||||
{
|
{
|
||||||
gl_t *gl = (gl_t*)data;
|
gl_t *gl = (gl_t*)data;
|
||||||
|
|
||||||
|
if (!gl)
|
||||||
|
return;
|
||||||
|
|
||||||
// Calculate projection.
|
// Calculate projection.
|
||||||
matrix_ortho(&gl->mvp_no_rot, ortho->left, ortho->right,
|
matrix_ortho(&gl->mvp_no_rot, ortho->left, ortho->right,
|
||||||
ortho->bottom, ortho->top, ortho->znear, ortho->zfar);
|
ortho->bottom, ortho->top, ortho->znear, ortho->zfar);
|
||||||
|
@ -798,12 +808,17 @@ void gl_set_projection(void *data, struct gl_ortho *ortho, bool allow_rotate)
|
||||||
|
|
||||||
void gl_set_viewport(void *data, unsigned width, unsigned height, bool force_full, bool allow_rotate)
|
void gl_set_viewport(void *data, unsigned width, unsigned height, bool force_full, bool allow_rotate)
|
||||||
{
|
{
|
||||||
|
int x, y;
|
||||||
|
float device_aspect = 0.0f;
|
||||||
gl_t *gl = (gl_t*)data;
|
gl_t *gl = (gl_t*)data;
|
||||||
|
|
||||||
int x = 0, y = 0;
|
|
||||||
struct gl_ortho ortho = {0, 1, 0, 1, -1, 1};
|
struct gl_ortho ortho = {0, 1, 0, 1, -1, 1};
|
||||||
|
|
||||||
float device_aspect = 0.0f;
|
if (!gl)
|
||||||
|
return;
|
||||||
|
|
||||||
|
x = 0;
|
||||||
|
y = 0;
|
||||||
|
|
||||||
if (gl->ctx_driver->translate_aspect)
|
if (gl->ctx_driver->translate_aspect)
|
||||||
device_aspect = context_translate_aspect_func(gl, width, height);
|
device_aspect = context_translate_aspect_func(gl, width, height);
|
||||||
else
|
else
|
||||||
|
@ -890,13 +905,19 @@ static void gl_set_rotation(void *data, unsigned rotation)
|
||||||
gl_t *gl = (gl_t*)data;
|
gl_t *gl = (gl_t*)data;
|
||||||
struct gl_ortho ortho = {0, 1, 0, 1, -1, 1};
|
struct gl_ortho ortho = {0, 1, 0, 1, -1, 1};
|
||||||
|
|
||||||
gl->rotation = 90 * rotation;
|
if (gl)
|
||||||
gl_set_projection(gl, &ortho, true);
|
{
|
||||||
|
gl->rotation = 90 * rotation;
|
||||||
|
gl_set_projection(gl, &ortho, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_FBO
|
#ifdef HAVE_FBO
|
||||||
static inline void gl_start_frame_fbo(gl_t *gl)
|
static inline void gl_start_frame_fbo(gl_t *gl)
|
||||||
{
|
{
|
||||||
|
if (!gl)
|
||||||
|
return;
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
||||||
glBindFramebuffer(RARCH_GL_FRAMEBUFFER, gl->fbo[0]);
|
glBindFramebuffer(RARCH_GL_FRAMEBUFFER, gl->fbo[0]);
|
||||||
gl_set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true, false);
|
gl_set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true, false);
|
||||||
|
@ -917,6 +938,9 @@ static void gl_check_fbo_dimensions(void *data)
|
||||||
int i;
|
int i;
|
||||||
gl_t *gl = (gl_t*)data;
|
gl_t *gl = (gl_t*)data;
|
||||||
|
|
||||||
|
if (!gl)
|
||||||
|
return;
|
||||||
|
|
||||||
// Check if we have to recreate our FBO textures.
|
// Check if we have to recreate our FBO textures.
|
||||||
for (i = 0; i < gl->fbo_pass; i++)
|
for (i = 0; i < gl->fbo_pass; i++)
|
||||||
{
|
{
|
||||||
|
@ -955,6 +979,9 @@ static void gl_frame_fbo(void *data, const struct gl_tex_info *tex_info)
|
||||||
gl_t *gl = (gl_t*)data;
|
gl_t *gl = (gl_t*)data;
|
||||||
GLfloat fbo_tex_coords[8] = {0.0f};
|
GLfloat fbo_tex_coords[8] = {0.0f};
|
||||||
|
|
||||||
|
if (!gl)
|
||||||
|
return;
|
||||||
|
|
||||||
// Render the rest of our passes.
|
// Render the rest of our passes.
|
||||||
gl->coords.tex_coord = fbo_tex_coords;
|
gl->coords.tex_coord = fbo_tex_coords;
|
||||||
|
|
||||||
|
@ -1471,6 +1498,10 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei
|
||||||
RARCH_PERFORMANCE_START(frame_run);
|
RARCH_PERFORMANCE_START(frame_run);
|
||||||
|
|
||||||
gl_t *gl = (gl_t*)data;
|
gl_t *gl = (gl_t*)data;
|
||||||
|
|
||||||
|
if (!gl)
|
||||||
|
return true;
|
||||||
|
|
||||||
context_bind_hw_render(gl, false);
|
context_bind_hw_render(gl, false);
|
||||||
|
|
||||||
#ifndef HAVE_OPENGLES
|
#ifndef HAVE_OPENGLES
|
||||||
|
@ -1571,7 +1602,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gl->shader)
|
if (gl->shader && gl->shader->set_params)
|
||||||
gl->shader->set_params(gl, width, height,
|
gl->shader->set_params(gl, width, height,
|
||||||
gl->tex_w, gl->tex_h,
|
gl->tex_w, gl->tex_h,
|
||||||
gl->vp.width, gl->vp.height,
|
gl->vp.width, gl->vp.height,
|
||||||
|
@ -1681,6 +1712,9 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei
|
||||||
static void gl_free_overlay(gl_t *gl)
|
static void gl_free_overlay(gl_t *gl)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
if (!gl)
|
||||||
|
return;
|
||||||
|
|
||||||
for (i = 0; i < gl->overlays; i++)
|
for (i = 0; i < gl->overlays; i++)
|
||||||
if (gl->overlay[i].tex)
|
if (gl->overlay[i].tex)
|
||||||
glDeleteTextures(1, &gl->overlay[i].tex);
|
glDeleteTextures(1, &gl->overlay[i].tex);
|
||||||
|
@ -1774,9 +1808,13 @@ static void gl_set_nonblock_state(void *data, bool state)
|
||||||
RARCH_LOG("GL VSync => %s\n", state ? "off" : "on");
|
RARCH_LOG("GL VSync => %s\n", state ? "off" : "on");
|
||||||
|
|
||||||
gl_t *gl = (gl_t*)data;
|
gl_t *gl = (gl_t*)data;
|
||||||
context_bind_hw_render(gl, false);
|
|
||||||
context_swap_interval_func(gl, state ? 0 : g_settings.video.swap_interval);
|
if (gl)
|
||||||
context_bind_hw_render(gl, true);
|
{
|
||||||
|
context_bind_hw_render(gl, false);
|
||||||
|
context_swap_interval_func(gl, state ? 0 : g_settings.video.swap_interval);
|
||||||
|
context_bind_hw_render(gl, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool resolve_extensions(gl_t *gl)
|
static bool resolve_extensions(gl_t *gl)
|
||||||
|
|
Loading…
Reference in New Issue