1
0
Fork 0

Use a GArray for the texture vertices in cogl_texture_polygon

Previously it was a dynamic array that was manually reallocated.
This commit is contained in:
Neil Roberts 2008-11-27 16:44:39 +00:00
parent dfa730909c
commit 93ea1681bb
3 changed files with 17 additions and 29 deletions

View file

@ -57,9 +57,9 @@ cogl_create_context ()
_context->path_nodes_size = 0;
_context->texture_handles = NULL;
_context->texture_vertices_size = 0;
_context->texture_vertices = NULL;
_context->texture_vertices = g_array_new (FALSE, FALSE,
sizeof (CoglTextureGLVertex));
_context->fbo_handles = NULL;
_context->draw_buffer = COGL_WINDOW_BUFFER;
@ -140,7 +140,10 @@ cogl_destroy_context ()
g_array_free (_context->shader_handles, TRUE);
if (_context->program_handles)
g_array_free (_context->program_handles, TRUE);
if (_context->texture_vertices)
g_array_free (_context->texture_vertices, TRUE);
g_free (_context);
}

View file

@ -64,8 +64,7 @@ typedef struct
/* Textures */
GArray *texture_handles;
CoglTextureGLVertex *texture_vertices;
gulong texture_vertices_size;
GArray *texture_vertices;
/* Framebuffer objects */
GArray *fbo_handles;

View file

@ -2252,23 +2252,9 @@ cogl_texture_polygon (CoglHandle handle,
/* Make sure there is enough space in the global texture vertex
array. This is used so we can render the polygon with a single
call to OpenGL but still support any number of vertices */
if (ctx->texture_vertices_size < n_vertices)
{
guint nsize = ctx->texture_vertices_size;
if (nsize == 0)
nsize = 1;
do
nsize *= 2;
while (nsize < n_vertices);
ctx->texture_vertices_size = nsize;
g_array_set_size (ctx->texture_vertices, n_vertices);
p = (CoglTextureGLVertex *) ctx->texture_vertices->data;
ctx->texture_vertices = g_realloc (ctx->texture_vertices,
nsize
* sizeof (CoglTextureGLVertex));
}
/* Prepare GL state */
enable_flags = (COGL_ENABLE_TEXTURE_2D
| COGL_ENABLE_VERTEX_ARRAY
@ -2282,14 +2268,12 @@ cogl_texture_polygon (CoglHandle handle,
if (use_color)
{
enable_flags |= COGL_ENABLE_COLOR_ARRAY;
GE( glColorPointer (4, GL_UNSIGNED_BYTE, sizeof (CoglTextureGLVertex),
ctx->texture_vertices[0].c) );
GE( glColorPointer (4, GL_UNSIGNED_BYTE,
sizeof (CoglTextureGLVertex), p->c) );
}
GE( glVertexPointer (3, GL_FLOAT, sizeof (CoglTextureGLVertex),
ctx->texture_vertices[0].v) );
GE( glTexCoordPointer (2, GL_FLOAT, sizeof (CoglTextureGLVertex),
ctx->texture_vertices[0].t) );
GE( glVertexPointer (3, GL_FLOAT, sizeof (CoglTextureGLVertex), p->v ) );
GE( glTexCoordPointer (2, GL_FLOAT, sizeof (CoglTextureGLVertex), p->t ) );
cogl_enable (enable_flags);
@ -2320,9 +2304,11 @@ cogl_texture_polygon (CoglHandle handle,
gl_handle = g_array_index (tex->slice_gl_handles, GLuint, tex_num++);
p = (CoglTextureGLVertex *) ctx->texture_vertices->data;
/* Convert the vertices into an array of GLfloats ready to pass to
OpenGL */
for (i = 0, p = ctx->texture_vertices; i < n_vertices; i++, p++)
for (i = 0; i < n_vertices; i++, p++)
{
#define CFX_F COGL_FIXED_TO_FLOAT