Abstract all use of *Pointer() functions to one point.

This commit is contained in:
Themaister 2012-08-14 23:32:55 +02:00
parent d0c4fdbc23
commit 447412c6df
3 changed files with 65 additions and 24 deletions

View File

@ -241,7 +241,8 @@ void gl_render_msg(void *data, const char *msg)
GLfloat font_tex_coords[8];
glBindTexture(GL_TEXTURE_2D, gl->font_tex);
glTexCoordPointer(2, GL_FLOAT, 0, font_tex_coords);
gl->coords.tex_coord = font_tex_coords;
struct font_output_list out;
@ -264,17 +265,20 @@ void gl_render_msg(void *data, const char *msg)
}
calculate_font_coords(gl, font_vertex, font_vertex_dark, font_tex_coords);
glVertexPointer(2, GL_FLOAT, 0, font_vertex_dark);
glColorPointer(4, GL_FLOAT, 0, gl->font_color_dark);
gl->coords.vertex = font_vertex_dark;
gl->coords.color = gl->font_color_dark;
gl_set_coords(&gl->coords, 0);
glDrawArrays(GL_QUADS, 0, 4);
glVertexPointer(2, GL_FLOAT, 0, font_vertex);
glColorPointer(4, GL_FLOAT, 0, gl->font_color);
gl->coords.vertex = font_vertex;
gl->coords.color = gl->font_color;
gl_set_coords(&gl->coords, 0);
glDrawArrays(GL_QUADS, 0, 4);
// Post - Go back to old rendering path.
glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords);
glVertexPointer(2, GL_FLOAT, 0, vertexes_flipped);
glColorPointer(4, GL_FLOAT, 0, white_color);
gl->coords.vertex = vertexes_flipped;
gl->coords.tex_coord = gl->tex_coords;
gl->coords.color = white_color;
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
glDisable(GL_BLEND);

View File

@ -480,6 +480,31 @@ void gl_init_fbo(gl_t *gl, unsigned width, unsigned height)
////////////
void gl_set_coords(const struct gl_coords *coords, unsigned unit)
{
pglClientActiveTexture(GL_TEXTURE0 + unit);
if (coords->vertex)
{
glVertexPointer(2, GL_FLOAT, 0, coords->vertex);
glEnableClientState(GL_VERTEX_ARRAY);
}
if (coords->color)
{
glColorPointer(4, GL_FLOAT, 0, coords->color);
glEnableClientState(GL_COLOR_ARRAY);
}
if (coords->tex_coord)
{
glTexCoordPointer(2, GL_FLOAT, 0, coords->tex_coord);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
pglClientActiveTexture(GL_TEXTURE0);
}
void gl_set_projection(gl_t *gl, struct gl_ortho *ortho, bool allow_rotate)
{
#ifdef RARCH_CONSOLE
@ -567,10 +592,9 @@ static inline void set_lut_texture_coords(const GLfloat *coords)
{
#if defined(HAVE_XML) || defined(HAVE_CG)
// For texture images.
pglClientActiveTexture(GL_TEXTURE1);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, coords);
pglClientActiveTexture(GL_TEXTURE0);
struct gl_coords co = {0};
co.tex_coord = coords;
gl_set_coords(&co, 1);
#else
(void)coords;
#endif
@ -597,7 +621,7 @@ static inline void gl_start_frame_fbo(gl_t *gl)
// consistent texture coordinates.
// We will "flip" it in place on last pass.
if (gl->render_to_tex)
glVertexPointer(2, GL_FLOAT, 0, vertexes);
gl->coords.vertex = vertexes;
}
static void gl_check_fbo_dimensions(gl_t *gl)
@ -638,7 +662,7 @@ static void gl_frame_fbo(gl_t *gl, const struct gl_tex_info *tex_info)
GLfloat fbo_tex_coords[8] = {0.0f};
// Render the rest of our passes.
glTexCoordPointer(2, GL_FLOAT, 0, fbo_tex_coords);
gl->coords.tex_coord = fbo_tex_coords;
// It's kinda handy ... :)
const struct gl_fbo_rect *prev_rect;
@ -680,6 +704,7 @@ static void gl_frame_fbo(gl_t *gl, const struct gl_tex_info *tex_info)
gl->vp_width, gl->vp_height, gl->frame_count,
tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt);
gl_set_coords(&gl->coords, 0);
glDrawArrays(GL_QUADS, 0, 4);
fbo_tex_info_cnt++;
@ -706,10 +731,12 @@ static void gl_frame_fbo(gl_t *gl, const struct gl_tex_info *tex_info)
gl->vp_width, gl->vp_height, gl->frame_count,
tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt);
glVertexPointer(2, GL_FLOAT, 0, vertex_ptr);
gl->coords.vertex = vertex_ptr;
gl_set_coords(&gl->coords, 0);
glDrawArrays(GL_QUADS, 0, 4);
glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords);
gl->coords.tex_coord = gl->tex_coords;
}
#endif
@ -862,7 +889,9 @@ static void gl_render_menu(gl_t *gl)
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, gl->menu_texture_id);
glVertexPointer(2, GL_FLOAT, 0, default_vertex_ptr);
gl->coords.vertex = default_vertex_ptr;
gl_set_coords(&gl->coords, 0);
glDrawArrays(GL_QUADS, 0, 4);
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
}
@ -919,6 +948,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei
gl->frame_count,
&tex_info, gl->prev_info, NULL, 0);
gl_set_coords(&gl->coords, 0);
glDrawArrays(GL_QUADS, 0, 4);
#ifdef HAVE_FBO
@ -1102,14 +1132,11 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo
glDisable(GL_DITHER);
glClearColor(0, 0, 0, 1);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vertex_ptr);
memcpy(gl->tex_coords, tex_coords, sizeof(tex_coords));
glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords);
glColorPointer(4, GL_FLOAT, 0, white_color);
gl->coords.vertex = vertex_ptr;
gl->coords.tex_coord = gl->tex_coords;
gl->coords.color = white_color;
gl_set_coords(&gl->coords, 0);
set_lut_texture_coords(tex_coords);

View File

@ -125,6 +125,13 @@ struct gl_tex_info
GLfloat coord[8];
};
struct gl_coords
{
const GLfloat *vertex;
const GLfloat *color;
const GLfloat *tex_coord;
};
#define MAX_SHADERS 16
#if defined(HAVE_XML) || defined(HAVE_CG)
@ -182,6 +189,8 @@ typedef struct gl
GLfloat tex_coords[8];
math_matrix mvp;
struct gl_coords coords;
#ifdef __CELLOS_LV2__
GLuint pbo;
#endif
@ -225,6 +234,7 @@ extern PFNGLACTIVETEXTUREPROC pglActiveTexture;
void gl_shader_use(unsigned index);
void gl_set_projection(gl_t *gl, struct gl_ortho *ortho, bool allow_rotate);
void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate);
void gl_set_coords(const struct gl_coords *coords, unsigned unit);
void gl_init_fbo(gl_t *gl, unsigned width, unsigned height);
void gl_deinit_fbo(gl_t *gl);