This commit is contained in:
twinaphex 2017-03-07 12:49:52 +01:00
parent f4ac760178
commit 4118d0bbd2
1 changed files with 15 additions and 18 deletions

View File

@ -1385,37 +1385,34 @@ fallback:
return false; return false;
} }
#define gl_glsl_set_coord_array(attr, coord1, coord2, coords, size, multiplier) \ #define gl_glsl_set_coord_array(attribs, coord1, coord2, coords, size, multiplier) \
unsigned y; \ unsigned y; \
attr->loc = coord1; \ attribs[attribs_size].loc = coord1; \
attr->size = multiplier; \ attribs[attribs_size].size = multiplier; \
attr->offset = size * sizeof(GLfloat); \ attribs[attribs_size].offset = size * sizeof(GLfloat); \
attr++; \
for (y = 0; y < (multiplier * coords->vertices); y++) \ for (y = 0; y < (multiplier * coords->vertices); y++) \
buffer[y + size] = coord2[y]; \ buffer[y + size] = coord2[y]; \
size += multiplier * coords->vertices; \ size += multiplier * coords->vertices; \
static bool gl_glsl_set_coords(void *handle_data, void *shader_data, const struct video_coords *coords) static bool gl_glsl_set_coords(void *handle_data, void *shader_data,
const struct video_coords *coords)
{ {
/* Avoid hitting malloc on every single regular quad draw. */
GLfloat short_buffer[4 * (2 + 2 + 4 + 2)]; GLfloat short_buffer[4 * (2 + 2 + 4 + 2)];
struct glsl_attrib attribs[4]; struct glsl_attrib attribs[4];
size_t attribs_size = 0; size_t attribs_size = 0;
size_t size = 0; size_t size = 0;
GLfloat *buffer = NULL; GLfloat *buffer = short_buffer;
struct glsl_attrib *attr = NULL;
const struct shader_uniforms *uni = NULL;
glsl_shader_data_t *glsl = (glsl_shader_data_t*)shader_data; glsl_shader_data_t *glsl = (glsl_shader_data_t*)shader_data;
const struct shader_uniforms *uni = glsl
? &glsl->uniforms[glsl->active_idx] : NULL;
if (!glsl || !glsl->shader->modern || !coords) if (!glsl || !glsl->shader->modern || !coords)
goto fallback; goto fallback;
attr = attribs;
uni = &glsl->uniforms[glsl->active_idx];
buffer = short_buffer;
if (coords->vertices > 4) if (coords->vertices > 4)
{ {
/* Avoid hitting malloc on every single regular quad draw. */
size_t elems = 0; size_t elems = 0;
elems += (uni->color >= 0) * 4; elems += (uni->color >= 0) * 4;
elems += (uni->tex_coord >= 0) * 2; elems += (uni->tex_coord >= 0) * 2;
@ -1432,28 +1429,28 @@ static bool gl_glsl_set_coords(void *handle_data, void *shader_data, const struc
if (uni->tex_coord >= 0) if (uni->tex_coord >= 0)
{ {
gl_glsl_set_coord_array(attr, uni->tex_coord, gl_glsl_set_coord_array(attribs, uni->tex_coord,
coords->tex_coord, coords, size, 2); coords->tex_coord, coords, size, 2);
attribs_size++; attribs_size++;
} }
if (uni->vertex_coord >= 0) if (uni->vertex_coord >= 0)
{ {
gl_glsl_set_coord_array(attr, uni->vertex_coord, gl_glsl_set_coord_array(attribs, uni->vertex_coord,
coords->vertex, coords, size, 2); coords->vertex, coords, size, 2);
attribs_size++; attribs_size++;
} }
if (uni->color >= 0) if (uni->color >= 0)
{ {
gl_glsl_set_coord_array(attr, uni->color, gl_glsl_set_coord_array(attribs, uni->color,
coords->color, coords, size, 4); coords->color, coords, size, 4);
attribs_size++; attribs_size++;
} }
if (uni->lut_tex_coord >= 0) if (uni->lut_tex_coord >= 0)
{ {
gl_glsl_set_coord_array(attr, uni->lut_tex_coord, gl_glsl_set_coord_array(attribs, uni->lut_tex_coord,
coords->lut_tex_coord, coords, size, 2); coords->lut_tex_coord, coords, size, 2);
attribs_size++; attribs_size++;
} }