Merge pull request #3987 from heuripedes/shader-things

(shader_glsl.c) Don't allocate/clear more than needed in gl_glsl_set_coords()
This commit is contained in:
Twinaphex 2016-11-13 02:20:28 +01:00 committed by GitHub
commit 4e901457a2

View File

@ -1354,17 +1354,26 @@ static bool gl_glsl_set_coords(void *handle_data, void *shader_data, const struc
if (!glsl || !glsl->shader->modern || !coords)
goto fallback;
attr = attribs;
uni = &glsl->uniforms[glsl->active_idx];
buffer = short_buffer;
if (coords->vertices > 4)
buffer = (GLfloat*)calloc(coords->vertices *
(2 + 2 + 4 + 2), sizeof(*buffer));
{
size_t elems = 0;
elems += (uni->color >= 0) * 4;
elems += (uni->tex_coord >= 0) * 2;
elems += (uni->vertex_coord >= 0) * 2;
elems += (uni->lut_tex_coord >= 0) * 2;
elems *= coords->vertices * sizeof(GLfloat);
buffer = (GLfloat*)malloc(elems);
}
if (!buffer)
goto fallback;
attr = attribs;
uni = &glsl->uniforms[glsl->active_idx];
if (uni->tex_coord >= 0)
gl_glsl_set_coord_array(attr, uni->tex_coord, coords->tex_coord, coords, size, 2);