mirror of
https://github.com/brl/mutter.git
synced 2025-02-17 05:44:08 +00:00
[cogl-vertex-buffer] Some fixes for texturing and color arrays
Fixes some blending issues when using color arrays since we were conflicting with the cogl_enable state + fixes a texture layer validation bug. Adds a basic textured triangle to test-vertex-buffer-contiguous.
This commit is contained in:
parent
4a110afe08
commit
d01e3cd802
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: We need to do a better job of minimizing when we call glVertexPointer
|
* TODO: We need to do a better job of minimizing when we call glVertexPointer
|
||||||
* and pals in enable_state_for_drawing_attributes_buffer
|
* and pals in enable_state_for_drawing_buffer
|
||||||
*
|
*
|
||||||
* We should have an internal 2-tuple cache of (VBO, offset) for each of them
|
* We should have an internal 2-tuple cache of (VBO, offset) for each of them
|
||||||
* so we can avoid some GL calls. We could have cogl wrappers for the
|
* so we can avoid some GL calls. We could have cogl wrappers for the
|
||||||
@ -394,7 +394,7 @@ get_gl_type_size (CoglVertexBufferAttribFlags flags)
|
|||||||
return sizeof (GLdouble);
|
return sizeof (GLdouble);
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
g_warning ("Mesh API: Unrecognised OpenGL type enum 0x%08x\n", gl_type);
|
g_warning ("Vertex Buffer API: Unrecognised OpenGL type enum 0x%08x\n", gl_type);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1408,7 +1408,7 @@ get_gl_type_from_attribute_flags (CoglVertexBufferAttribFlags flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
enable_state_for_drawing_attributes_buffer (CoglVertexBuffer *buffer)
|
enable_state_for_drawing_buffer (CoglVertexBuffer *buffer)
|
||||||
{
|
{
|
||||||
GList *tmp;
|
GList *tmp;
|
||||||
GLenum gl_type;
|
GLenum gl_type;
|
||||||
@ -1442,8 +1442,8 @@ enable_state_for_drawing_attributes_buffer (CoglVertexBuffer *buffer)
|
|||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case COGL_VERTEX_BUFFER_ATTRIB_FLAG_COLOR_ARRAY:
|
case COGL_VERTEX_BUFFER_ATTRIB_FLAG_COLOR_ARRAY:
|
||||||
/* FIXME: go through cogl cache to enable color array */
|
enable_flags |= COGL_ENABLE_COLOR_ARRAY | COGL_ENABLE_BLEND;
|
||||||
GE (glEnableClientState (GL_COLOR_ARRAY));
|
/* GE (glEnableClientState (GL_COLOR_ARRAY)); */
|
||||||
GE (glColorPointer (attribute->n_components,
|
GE (glColorPointer (attribute->n_components,
|
||||||
gl_type,
|
gl_type,
|
||||||
attribute->stride,
|
attribute->stride,
|
||||||
@ -1532,8 +1532,6 @@ enable_state_for_drawing_attributes_buffer (CoglVertexBuffer *buffer)
|
|||||||
*/
|
*/
|
||||||
fallback_mask |= (1 << i);
|
fallback_mask |= (1 << i);
|
||||||
}
|
}
|
||||||
else if (!(disable_mask & (1 << i)))
|
|
||||||
fallback_mask |= (1 << i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cogl_material_flush_gl_state (ctx->source_material,
|
cogl_material_flush_gl_state (ctx->source_material,
|
||||||
@ -1581,8 +1579,7 @@ disable_state_for_drawing_buffer (CoglVertexBuffer *buffer)
|
|||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case COGL_VERTEX_BUFFER_ATTRIB_FLAG_COLOR_ARRAY:
|
case COGL_VERTEX_BUFFER_ATTRIB_FLAG_COLOR_ARRAY:
|
||||||
/* FIXME: go through cogl cache to enable color array */
|
/* GE (glDisableClientState (GL_COLOR_ARRAY)); */
|
||||||
GE (glDisableClientState (GL_COLOR_ARRAY));
|
|
||||||
break;
|
break;
|
||||||
case COGL_VERTEX_BUFFER_ATTRIB_FLAG_NORMAL_ARRAY:
|
case COGL_VERTEX_BUFFER_ATTRIB_FLAG_NORMAL_ARRAY:
|
||||||
/* FIXME: go through cogl cache to enable normal array */
|
/* FIXME: go through cogl cache to enable normal array */
|
||||||
@ -1622,7 +1619,7 @@ cogl_vertex_buffer_draw (CoglHandle handle,
|
|||||||
|
|
||||||
buffer = _cogl_vertex_buffer_pointer_from_handle (handle);
|
buffer = _cogl_vertex_buffer_pointer_from_handle (handle);
|
||||||
|
|
||||||
enable_state_for_drawing_attributes_buffer (buffer);
|
enable_state_for_drawing_buffer (buffer);
|
||||||
|
|
||||||
/* FIXME: flush cogl cache */
|
/* FIXME: flush cogl cache */
|
||||||
GE (glDrawArrays (mode, first, count));
|
GE (glDrawArrays (mode, first, count));
|
||||||
@ -1648,7 +1645,7 @@ cogl_vertex_buffer_draw_elements (CoglHandle handle,
|
|||||||
|
|
||||||
buffer = _cogl_vertex_buffer_pointer_from_handle (handle);
|
buffer = _cogl_vertex_buffer_pointer_from_handle (handle);
|
||||||
|
|
||||||
enable_state_for_drawing_attributes_buffer (buffer);
|
enable_state_for_drawing_buffer (buffer);
|
||||||
|
|
||||||
/* FIXME: flush cogl cache */
|
/* FIXME: flush cogl cache */
|
||||||
GE (glDrawRangeElements (mode, min_index, max_index,
|
GE (glDrawRangeElements (mode, min_index, max_index,
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
typedef struct _TestState
|
typedef struct _TestState
|
||||||
{
|
{
|
||||||
CoglHandle buffer;
|
CoglHandle buffer;
|
||||||
|
CoglHandle texture;
|
||||||
|
CoglHandle material;
|
||||||
ClutterGeometry stage_geom;
|
ClutterGeometry stage_geom;
|
||||||
guint frame;
|
guint frame;
|
||||||
} TestState;
|
} TestState;
|
||||||
@ -100,6 +102,15 @@ on_paint (ClutterActor *actor, TestState *state)
|
|||||||
0, /* first */
|
0, /* first */
|
||||||
3); /* count */
|
3); /* count */
|
||||||
|
|
||||||
|
/* Draw a textured triangle */
|
||||||
|
cogl_translate (100, 0, 0);
|
||||||
|
cogl_vertex_buffer_disable (state->buffer, "gl_Color::blue");
|
||||||
|
cogl_set_source (state->material);
|
||||||
|
cogl_vertex_buffer_draw (state->buffer,
|
||||||
|
GL_TRIANGLE_STRIP, /* mode */
|
||||||
|
0, /* first */
|
||||||
|
3); /* count */
|
||||||
|
|
||||||
/* XXX: Experiments have shown that for some buggy drivers, when using
|
/* XXX: Experiments have shown that for some buggy drivers, when using
|
||||||
* glReadPixels there is some kind of race, so we delay our test for a
|
* glReadPixels there is some kind of race, so we delay our test for a
|
||||||
* few frames and a few seconds:
|
* few frames and a few seconds:
|
||||||
@ -150,6 +161,15 @@ test_vertex_buffer_contiguous (TestConformSimpleFixture *fixture,
|
|||||||
|
|
||||||
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
|
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
|
||||||
|
|
||||||
|
state.texture = cogl_texture_new_from_file ("redhand.png", 64,
|
||||||
|
COGL_TEXTURE_NONE,
|
||||||
|
COGL_PIXEL_FORMAT_ANY,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
state.material = cogl_material_new ();
|
||||||
|
cogl_material_set_color4ub (state.material, 0x00, 0xff, 0x00, 0xff);
|
||||||
|
cogl_material_set_layer (state.material, 0, state.texture);
|
||||||
|
|
||||||
{
|
{
|
||||||
GLfloat triangle_verts[3][2] =
|
GLfloat triangle_verts[3][2] =
|
||||||
{
|
{
|
||||||
@ -163,6 +183,12 @@ test_vertex_buffer_contiguous (TestConformSimpleFixture *fixture,
|
|||||||
{0x00, 0x00, 0xff, 0x00}, /* transparent blue */
|
{0x00, 0x00, 0xff, 0x00}, /* transparent blue */
|
||||||
{0x00, 0x00, 0xff, 0x00} /* transparent blue */
|
{0x00, 0x00, 0xff, 0x00} /* transparent blue */
|
||||||
};
|
};
|
||||||
|
GLfloat triangle_tex_coords[3][2] =
|
||||||
|
{
|
||||||
|
{0.0, 0.0},
|
||||||
|
{1.0, 1.0},
|
||||||
|
{0.0, 1.0}
|
||||||
|
};
|
||||||
state.buffer = cogl_vertex_buffer_new (3 /* n vertices */);
|
state.buffer = cogl_vertex_buffer_new (3 /* n vertices */);
|
||||||
cogl_vertex_buffer_add (state.buffer,
|
cogl_vertex_buffer_add (state.buffer,
|
||||||
"gl_Vertex",
|
"gl_Vertex",
|
||||||
@ -178,6 +204,14 @@ test_vertex_buffer_contiguous (TestConformSimpleFixture *fixture,
|
|||||||
FALSE, /* normalized */
|
FALSE, /* normalized */
|
||||||
0, /* stride */
|
0, /* stride */
|
||||||
triangle_colors);
|
triangle_colors);
|
||||||
|
cogl_vertex_buffer_add (state.buffer,
|
||||||
|
"gl_MultiTexCoord0",
|
||||||
|
2, /* n components */
|
||||||
|
GL_FLOAT,
|
||||||
|
FALSE, /* normalized */
|
||||||
|
0, /* stride */
|
||||||
|
triangle_tex_coords);
|
||||||
|
|
||||||
cogl_vertex_buffer_submit (state.buffer);
|
cogl_vertex_buffer_submit (state.buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,6 +220,8 @@ test_vertex_buffer_contiguous (TestConformSimpleFixture *fixture,
|
|||||||
clutter_main ();
|
clutter_main ();
|
||||||
|
|
||||||
cogl_vertex_buffer_unref (state.buffer);
|
cogl_vertex_buffer_unref (state.buffer);
|
||||||
|
cogl_material_unref (state.material);
|
||||||
|
cogl_texture_unref (state.texture);
|
||||||
|
|
||||||
g_source_remove (idle_source);
|
g_source_remove (idle_source);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user