[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
|
||||
* 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
|
||||
* 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);
|
||||
#endif
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -1408,7 +1408,7 @@ get_gl_type_from_attribute_flags (CoglVertexBufferAttribFlags flags)
|
||||
}
|
||||
|
||||
static void
|
||||
enable_state_for_drawing_attributes_buffer (CoglVertexBuffer *buffer)
|
||||
enable_state_for_drawing_buffer (CoglVertexBuffer *buffer)
|
||||
{
|
||||
GList *tmp;
|
||||
GLenum gl_type;
|
||||
@ -1442,8 +1442,8 @@ enable_state_for_drawing_attributes_buffer (CoglVertexBuffer *buffer)
|
||||
switch (type)
|
||||
{
|
||||
case COGL_VERTEX_BUFFER_ATTRIB_FLAG_COLOR_ARRAY:
|
||||
/* FIXME: go through cogl cache to enable color array */
|
||||
GE (glEnableClientState (GL_COLOR_ARRAY));
|
||||
enable_flags |= COGL_ENABLE_COLOR_ARRAY | COGL_ENABLE_BLEND;
|
||||
/* GE (glEnableClientState (GL_COLOR_ARRAY)); */
|
||||
GE (glColorPointer (attribute->n_components,
|
||||
gl_type,
|
||||
attribute->stride,
|
||||
@ -1532,8 +1532,6 @@ enable_state_for_drawing_attributes_buffer (CoglVertexBuffer *buffer)
|
||||
*/
|
||||
fallback_mask |= (1 << i);
|
||||
}
|
||||
else if (!(disable_mask & (1 << i)))
|
||||
fallback_mask |= (1 << i);
|
||||
}
|
||||
|
||||
cogl_material_flush_gl_state (ctx->source_material,
|
||||
@ -1581,8 +1579,7 @@ disable_state_for_drawing_buffer (CoglVertexBuffer *buffer)
|
||||
switch (type)
|
||||
{
|
||||
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;
|
||||
case COGL_VERTEX_BUFFER_ATTRIB_FLAG_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);
|
||||
|
||||
enable_state_for_drawing_attributes_buffer (buffer);
|
||||
enable_state_for_drawing_buffer (buffer);
|
||||
|
||||
/* FIXME: flush cogl cache */
|
||||
GE (glDrawArrays (mode, first, count));
|
||||
@ -1648,7 +1645,7 @@ cogl_vertex_buffer_draw_elements (CoglHandle 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 */
|
||||
GE (glDrawRangeElements (mode, min_index, max_index,
|
||||
|
@ -18,6 +18,8 @@
|
||||
typedef struct _TestState
|
||||
{
|
||||
CoglHandle buffer;
|
||||
CoglHandle texture;
|
||||
CoglHandle material;
|
||||
ClutterGeometry stage_geom;
|
||||
guint frame;
|
||||
} TestState;
|
||||
@ -74,9 +76,9 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
cogl_vertex_buffer_enable (state->buffer, "gl_Color::blue");
|
||||
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
|
||||
cogl_vertex_buffer_draw (state->buffer,
|
||||
GL_TRIANGLE_STRIP, /* mode */
|
||||
0, /* first */
|
||||
3); /* count */
|
||||
GL_TRIANGLE_STRIP, /* mode */
|
||||
0, /* first */
|
||||
3); /* count */
|
||||
|
||||
/* Draw a red triangle */
|
||||
/* Here we are testing that the disable attribute works; if it doesn't
|
||||
@ -100,6 +102,15 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
0, /* first */
|
||||
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
|
||||
* glReadPixels there is some kind of race, so we delay our test for a
|
||||
* 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);
|
||||
|
||||
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] =
|
||||
{
|
||||
@ -163,6 +183,12 @@ test_vertex_buffer_contiguous (TestConformSimpleFixture *fixture,
|
||||
{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 */);
|
||||
cogl_vertex_buffer_add (state.buffer,
|
||||
"gl_Vertex",
|
||||
@ -178,6 +204,14 @@ test_vertex_buffer_contiguous (TestConformSimpleFixture *fixture,
|
||||
FALSE, /* normalized */
|
||||
0, /* stride */
|
||||
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);
|
||||
}
|
||||
|
||||
@ -186,6 +220,8 @@ test_vertex_buffer_contiguous (TestConformSimpleFixture *fixture,
|
||||
clutter_main ();
|
||||
|
||||
cogl_vertex_buffer_unref (state.buffer);
|
||||
cogl_material_unref (state.material);
|
||||
cogl_texture_unref (state.texture);
|
||||
|
||||
g_source_remove (idle_source);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user