mirror of
https://github.com/brl/mutter.git
synced 2025-02-08 17:44:09 +00:00
cogl-path: Use the vertex array API instead of CoglVertexBuffer
The new vertex array is now implemented in terms of the CoglVertexBuffer anyway so it should be slightly faster to use a vertex array directly.
This commit is contained in:
parent
0c8eb904c0
commit
db86a5a486
@ -66,24 +66,26 @@ struct _CoglPath
|
|||||||
CoglPathData *data;
|
CoglPathData *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define COGL_PATH_N_ATTRIBUTES 2
|
||||||
|
|
||||||
struct _CoglPathData
|
struct _CoglPathData
|
||||||
{
|
{
|
||||||
unsigned int ref_count;
|
unsigned int ref_count;
|
||||||
|
|
||||||
CoglPathFillRule fill_rule;
|
CoglPathFillRule fill_rule;
|
||||||
|
|
||||||
GArray *path_nodes;
|
GArray *path_nodes;
|
||||||
|
|
||||||
floatVec2 path_start;
|
floatVec2 path_start;
|
||||||
floatVec2 path_pen;
|
floatVec2 path_pen;
|
||||||
unsigned int last_path;
|
unsigned int last_path;
|
||||||
floatVec2 path_nodes_min;
|
floatVec2 path_nodes_min;
|
||||||
floatVec2 path_nodes_max;
|
floatVec2 path_nodes_max;
|
||||||
|
|
||||||
CoglHandle vbo;
|
CoglVertexArray *vbo;
|
||||||
unsigned int vbo_n_vertices;
|
CoglIndices *vbo_indices;
|
||||||
CoglHandle vbo_indices;
|
unsigned int vbo_n_indices;
|
||||||
unsigned int vbo_n_indices;
|
CoglVertexAttribute *vbo_attributes[COGL_PATH_N_ATTRIBUTES + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This is an internal version of cogl_path_new that doesn't affect
|
/* This is an internal version of cogl_path_new that doesn't affect
|
||||||
|
@ -61,8 +61,13 @@ _cogl_path_data_unref (CoglPathData *data)
|
|||||||
|
|
||||||
if (data->vbo)
|
if (data->vbo)
|
||||||
{
|
{
|
||||||
cogl_handle_unref (data->vbo);
|
int i;
|
||||||
cogl_handle_unref (data->vbo_indices);
|
|
||||||
|
cogl_object_unref (data->vbo);
|
||||||
|
cogl_object_unref (data->vbo_indices);
|
||||||
|
|
||||||
|
for (i = 0; i < COGL_PATH_N_ATTRIBUTES; i++)
|
||||||
|
cogl_object_unref (data->vbo_attributes[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_slice_free (CoglPathData, data);
|
g_slice_free (CoglPathData, data);
|
||||||
@ -89,7 +94,6 @@ _cogl_path_modify (CoglPath *path)
|
|||||||
old_data->path_nodes->len);
|
old_data->path_nodes->len);
|
||||||
|
|
||||||
path->data->vbo = COGL_INVALID_HANDLE;
|
path->data->vbo = COGL_INVALID_HANDLE;
|
||||||
path->data->vbo_indices = COGL_INVALID_HANDLE;
|
|
||||||
path->data->ref_count = 1;
|
path->data->ref_count = 1;
|
||||||
|
|
||||||
_cogl_path_data_unref (old_data);
|
_cogl_path_data_unref (old_data);
|
||||||
@ -97,10 +101,14 @@ _cogl_path_modify (CoglPath *path)
|
|||||||
/* The path is altered so the vbo will now be invalid */
|
/* The path is altered so the vbo will now be invalid */
|
||||||
else if (path->data->vbo)
|
else if (path->data->vbo)
|
||||||
{
|
{
|
||||||
cogl_handle_unref (path->data->vbo);
|
int i;
|
||||||
cogl_handle_unref (path->data->vbo_indices);
|
|
||||||
|
cogl_object_unref (path->data->vbo);
|
||||||
|
cogl_object_unref (path->data->vbo_indices);
|
||||||
|
for (i = 0; i < COGL_PATH_N_ATTRIBUTES; i++)
|
||||||
|
cogl_object_unref (path->data->vbo_attributes[i]);
|
||||||
|
|
||||||
path->data->vbo = COGL_INVALID_HANDLE;
|
path->data->vbo = COGL_INVALID_HANDLE;
|
||||||
path->data->vbo_indices = COGL_INVALID_HANDLE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,11 +342,11 @@ _cogl_path_fill_nodes (CoglPath *path)
|
|||||||
|
|
||||||
_cogl_path_build_vbo (path);
|
_cogl_path_build_vbo (path);
|
||||||
|
|
||||||
cogl_vertex_buffer_draw_elements (path->data->vbo,
|
cogl_draw_indexed_vertex_attributes_array (COGL_VERTICES_MODE_TRIANGLES,
|
||||||
COGL_VERTICES_MODE_TRIANGLES,
|
0, /* first_vertex */
|
||||||
path->data->vbo_indices,
|
path->data->vbo_n_indices,
|
||||||
0, path->data->vbo_n_vertices - 1,
|
path->data->vbo_indices,
|
||||||
0, path->data->vbo_n_indices);
|
path->data->vbo_attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -972,7 +980,6 @@ _cogl_path_new (void)
|
|||||||
data->path_nodes = g_array_new (FALSE, FALSE, sizeof (CoglPathNode));
|
data->path_nodes = g_array_new (FALSE, FALSE, sizeof (CoglPathNode));
|
||||||
data->last_path = 0;
|
data->last_path = 0;
|
||||||
data->vbo = COGL_INVALID_HANDLE;
|
data->vbo = COGL_INVALID_HANDLE;
|
||||||
data->vbo_indices = COGL_INVALID_HANDLE;
|
|
||||||
|
|
||||||
return _cogl_path_object_new (path);
|
return _cogl_path_object_new (path);
|
||||||
}
|
}
|
||||||
@ -1469,31 +1476,35 @@ _cogl_path_build_vbo (CoglPath *path)
|
|||||||
|
|
||||||
gluDeleteTess (tess.glu_tess);
|
gluDeleteTess (tess.glu_tess);
|
||||||
|
|
||||||
data->vbo = cogl_vertex_buffer_new (tess.vertices->len);
|
data->vbo = cogl_vertex_array_new (sizeof (CoglPathTesselatorVertex) *
|
||||||
cogl_vertex_buffer_add (data->vbo,
|
tess.vertices->len);
|
||||||
"gl_Vertex",
|
data->vbo_attributes[0] =
|
||||||
2, COGL_ATTRIBUTE_TYPE_FLOAT,
|
cogl_vertex_attribute_new (data->vbo,
|
||||||
FALSE,
|
"cogl_position_in",
|
||||||
sizeof (CoglPathTesselatorVertex),
|
sizeof (CoglPathTesselatorVertex),
|
||||||
&g_array_index (tess.vertices,
|
G_STRUCT_OFFSET (CoglPathTesselatorVertex, x),
|
||||||
CoglPathTesselatorVertex,
|
2, /* n_components */
|
||||||
0).x);
|
COGL_VERTEX_ATTRIBUTE_TYPE_FLOAT);
|
||||||
cogl_vertex_buffer_add (data->vbo,
|
data->vbo_attributes[1] =
|
||||||
"gl_MultiTexCoord0",
|
cogl_vertex_attribute_new (data->vbo,
|
||||||
2, COGL_ATTRIBUTE_TYPE_FLOAT,
|
"cogl_tex_coord0_in",
|
||||||
FALSE,
|
sizeof (CoglPathTesselatorVertex),
|
||||||
sizeof (CoglPathTesselatorVertex),
|
G_STRUCT_OFFSET (CoglPathTesselatorVertex, s),
|
||||||
&g_array_index (tess.vertices,
|
2, /* n_components */
|
||||||
CoglPathTesselatorVertex,
|
COGL_VERTEX_ATTRIBUTE_TYPE_FLOAT);
|
||||||
0).s);
|
/* NULL terminator */
|
||||||
cogl_vertex_buffer_submit (data->vbo);
|
data->vbo_attributes[2] = NULL;
|
||||||
data->vbo_n_vertices = tess.vertices->len;
|
|
||||||
data->vbo_indices =
|
data->vbo_indices = cogl_indices_new (tess.indices_type,
|
||||||
cogl_vertex_buffer_indices_new (tess.indices_type,
|
tess.indices->data,
|
||||||
tess.indices->data,
|
tess.indices->len);
|
||||||
tess.indices->len);
|
|
||||||
data->vbo_n_indices = tess.indices->len;
|
data->vbo_n_indices = tess.indices->len;
|
||||||
|
|
||||||
|
cogl_buffer_set_data (COGL_BUFFER (data->vbo),
|
||||||
|
0, /* offset */
|
||||||
|
tess.vertices->data,
|
||||||
|
sizeof (CoglPathTesselatorVertex) * tess.vertices->len);
|
||||||
|
|
||||||
g_array_free (tess.vertices, TRUE);
|
g_array_free (tess.vertices, TRUE);
|
||||||
g_array_free (tess.indices, TRUE);
|
g_array_free (tess.indices, TRUE);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user