Add support for bottom-left origin in libretro GL.

This commit is contained in:
Themaister 2013-06-30 22:24:07 +02:00
parent feebb78f75
commit 6df083fc0f
5 changed files with 26 additions and 28 deletions

View File

@ -240,9 +240,6 @@ static void calculate_font_coords(gl_t *gl,
font_tex_coords[7] = hy;
}
extern const GLfloat vertexes_flipped[];
extern const GLfloat white_color[];
static void setup_font(void *data, const char *msg, GLfloat scale, GLfloat pos_x, GLfloat pos_y)
{
gl_t *gl = (gl_t*)data;
@ -297,9 +294,9 @@ static void setup_font(void *data, const char *msg, GLfloat scale, GLfloat pos_x
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
// Post - Go back to old rendering path.
gl->coords.vertex = vertexes_flipped;
gl->coords.vertex = gl->vertex_ptr;
gl->coords.tex_coord = gl->tex_coords;
gl->coords.color = white_color;
gl->coords.color = gl->white_color_ptr;
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
glDisable(GL_BLEND);

View File

@ -55,7 +55,7 @@
#endif
// Used for the last pass when rendering to the back buffer.
const GLfloat vertexes_flipped[] = {
static const GLfloat vertexes_flipped[] = {
0, 1,
1, 1,
0, 0,
@ -78,6 +78,13 @@ static const GLfloat tex_coords[] = {
1, 1
};
static const GLfloat white_color[] = {
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
};
// Workaround broken Apple headers.
typedef const GLubyte* (*gl_get_stringi_proc)(GLenum name, GLuint index);
static inline bool gl_query_extension(gl_t *gl, const char *ext)
@ -131,16 +138,6 @@ static inline void set_texture_coords(GLfloat *coords, GLfloat xamt, GLfloat yam
coords[7] = yamt;
}
const GLfloat white_color[] = {
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
};
const GLfloat *vertex_ptr = vertexes_flipped;
const GLfloat *default_vertex_ptr = vertexes_flipped;
#undef LOAD_GL_SYM
#define LOAD_GL_SYM(SYM) if (!pgl##SYM) { \
gfx_ctx_proc_t sym = gl->ctx_driver->get_proc_address("gl" #SYM); \
@ -1064,7 +1061,7 @@ static void gl_frame_fbo(void *data, const struct gl_tex_info *tex_info)
gl->vp.width, gl->vp.height, g_extern.frame_count,
tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt);
gl->coords.vertex = vertex_ptr;
gl->coords.vertex = gl->vertex_ptr;
gl_shader_set_coords(gl, &gl->coords, &gl->mvp);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
@ -1442,7 +1439,7 @@ static inline void gl_draw_texture(void *data)
glDisable(GL_BLEND);
gl->coords.tex_coord = gl->tex_coords;
gl->coords.color = white_color;
gl->coords.color = gl->white_color_ptr;
}
#endif
@ -2021,13 +2018,16 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo
gl->tex_filter = video->smooth ? GL_LINEAR : GL_NEAREST;
#ifdef HAVE_FBO
struct retro_hw_render_callback *hw_render = &g_extern.system.hw_render_callback;
gl->vertex_ptr = hw_render->bottom_left_origin ? vertexes : vertexes_flipped;
#ifdef HAVE_OPENGLES2
gl->hw_render_use = g_extern.system.hw_render_callback.context_type == RETRO_HW_CONTEXT_OPENGLES2;
gl->hw_render_use = hw_render->context_type == RETRO_HW_CONTEXT_OPENGLES2;
#else
gl->hw_render_use = g_extern.system.hw_render_callback.context_type == RETRO_HW_CONTEXT_OPENGL ||
gl->hw_render_use = hw_render->context_type == RETRO_HW_CONTEXT_OPENGL ||
g_extern.system.hw_render_callback.context_type == RETRO_HW_CONTEXT_OPENGL_CORE;
#endif
#endif
gl->white_color_ptr = white_color;
gl_set_texture_fmts(gl, video->rgb32);
@ -2041,9 +2041,9 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo
glDisable(GL_DITHER);
memcpy(gl->tex_coords, tex_coords, sizeof(tex_coords));
gl->coords.vertex = vertex_ptr;
gl->coords.vertex = gl->vertex_ptr;
gl->coords.tex_coord = gl->tex_coords;
gl->coords.color = white_color;
gl->coords.color = gl->white_color_ptr;
gl->coords.lut_tex_coord = tex_coords;
// Empty buffer that we use to clear out the texture with on res change.
@ -2439,9 +2439,9 @@ static void gl_render_overlay(void *data)
glDisable(GL_BLEND);
gl->coords.vertex = vertex_ptr;
gl->coords.vertex = gl->vertex_ptr;
gl->coords.tex_coord = gl->tex_coords;
gl->coords.color = white_color;
gl->coords.color = gl->white_color_ptr;
}
static const video_overlay_interface_t gl_overlay_interface = {

View File

@ -219,6 +219,8 @@ typedef struct gl
math_matrix mvp, mvp_no_rot;
struct gl_coords coords;
const GLfloat *vertex_ptr;
const GLfloat *white_color_ptr;
GLuint pbo;
@ -341,9 +343,6 @@ extern PFNGLACTIVETEXTUREPROC pglActiveTexture;
#undef GL_UNPACK_ROW_LENGTH
#endif
extern const GLfloat vertexes_flipped[];
extern const GLfloat white_color[];
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_shader_set_coords(void *data, const struct gl_coords *coords, const math_matrix *mat);

View File

@ -344,7 +344,7 @@ void retro_run(void)
static unsigned frame_count;
frame_count++;
float angle = frame_count / 100.0;
float angle = frame_count / 10.0;
float cos_angle = cos(angle);
float sin_angle = sin(angle);
@ -413,6 +413,7 @@ bool retro_load_game(const struct retro_game_info *info)
hw_render.context_reset = context_reset;
hw_render.depth = true;
hw_render.stencil = true;
hw_render.bottom_left_origin = true;
if (!environ_cb(RETRO_ENVIRONMENT_SET_HW_RENDER, &hw_render))
return false;

View File

@ -523,6 +523,7 @@ struct retro_hw_render_callback
bool depth; // Set if render buffers should have depth component attached.
bool stencil; // Set if stencil buffers should be attached.
// If depth and stencil are true, a packed 24/8 buffer will be added. Only attaching stencil is invalid and will be ignored.
bool bottom_left_origin; // Use conventional bottom-left origin convention. Is false, standard libretro top-left origin semantics are used.
unsigned version_major; // Major version number for core GL context.
unsigned version_minor; // Minor version number for core GL context.
};