Add _primitive_draw to replace _framebuffer_draw_primitive

When splitting out the CoglPath api we saw that we would be left with
inconsistent drawing apis if the drawing apis in core Cogl were lumped
into the cogl_framebuffer_ api considering other Cogl sub-libraries or
that others will want to create higher level drawing apis outside of
Cogl but can't use the same namespace.

So that we can aim for a more consistent style this adds a
cogl_primitive_draw() api, comparable to cogl_path_fill() or
cogl_pango_show_layout() that's intended to replace
cogl_framebuffer_draw_primitive()

Note: the attribute and rectangle drawing apis are still in the
cogl_framebuffer_ namespace and this might potentially change but in
these cases there is no single object representing the thing being drawn
so it seems a more reasonable they they live in the framebuffer
namespace for now.

Note: the cogl_framebuffer_draw_primitive() api isn't removed by this
patch so it can more conveniently be cherry picked to the 1.16 branch so
we can mark it deprecated for a short while. Even though it's marked as
experimental api we know that there are people using the api so we'd
like to give them a chance to switch to the new api.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 418912b93ff81a47f9b38114d05335ab76277c48)

Conflicts:
	cogl-pango/cogl-pango-display-list.c
	cogl/Makefile.am
	cogl/cogl-framebuffer.c
	cogl/cogl-pipeline-layer-state.h
	cogl/cogl2-path.c
	cogl/driver/gl/cogl-clip-stack-gl.c
This commit is contained in:
Robert Bragg 2013-07-09 23:47:29 +01:00 committed by Neil Roberts
parent 5580baeffb
commit e9f721216e
30 changed files with 133 additions and 100 deletions

View File

@ -373,9 +373,9 @@ emit_vertex_buffer_geometry (CoglFramebuffer *fb,
cogl_object_unref (attributes[1]);
}
cogl_framebuffer_draw_primitive (fb,
pipeline,
node->d.texture.primitive);
cogl_primitive_draw (node->d.texture.primitive,
fb,
pipeline);
}
static void

View File

@ -28,6 +28,10 @@
#ifndef __COGL_BITMAP_H__
#define __COGL_BITMAP_H__
/* XXX: We forward declare CoglBitmap here to allow for circular
* dependencies between some headers */
typedef struct _CoglBitmap CoglBitmap;
#include <cogl/cogl-types.h>
#include <cogl/cogl-buffer.h>
#include <cogl/cogl-context.h>
@ -39,8 +43,6 @@
COGL_BEGIN_DECLS
typedef struct _CoglBitmap CoglBitmap;
/**
* SECTION:cogl-bitmap
* @short_description: Functions for loading images

View File

@ -3,6 +3,12 @@
#include "config.h"
#endif
/* We need to undefine this so that we will be sure to include
* cogl-path.h instead of cogl2-path.h when we include the framebuffer
* header. Otherwise it will include both headers and it won't
* compile. */
#undef COGL_ENABLE_EXPERIMENTAL_2_0_API
#include "cogl-enum-types.h"
/*** END file-header ***/

View File

@ -406,12 +406,6 @@ _cogl_framebuffer_restore_clip_stack (CoglFramebuffer *framebuffer);
void
_cogl_framebuffer_unref (CoglFramebuffer *framebuffer);
void
_cogl_framebuffer_draw_primitive (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
CoglPrimitive *primitive,
CoglDrawFlags flags);
/* This can be called directly by the CoglJournal to draw attributes
* skipping the implicit journal flush, the framebuffer flush and
* pipeline validation. */

View File

@ -2554,40 +2554,13 @@ cogl_framebuffer_vdraw_indexed_attributes (CoglFramebuffer *framebuffer,
COGL_DRAW_SKIP_LEGACY_STATE);
}
void
_cogl_framebuffer_draw_primitive (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
CoglPrimitive *primitive,
CoglDrawFlags flags)
{
if (primitive->indices)
_cogl_framebuffer_draw_indexed_attributes (framebuffer,
pipeline,
primitive->mode,
primitive->first_vertex,
primitive->n_vertices,
primitive->indices,
primitive->attributes,
primitive->n_attributes,
flags);
else
_cogl_framebuffer_draw_attributes (framebuffer,
pipeline,
primitive->mode,
primitive->first_vertex,
primitive->n_vertices,
primitive->attributes,
primitive->n_attributes,
flags);
}
void
cogl_framebuffer_draw_primitive (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
CoglPrimitive *primitive)
{
_cogl_framebuffer_draw_primitive (framebuffer, pipeline, primitive,
COGL_DRAW_SKIP_LEGACY_STATE);
_cogl_primitive_draw (primitive, framebuffer, pipeline,
COGL_DRAW_SKIP_LEGACY_STATE);
}
void

View File

@ -32,6 +32,11 @@
#include <windows.h>
#endif /* COGL_HAS_WIN32_SUPPORT */
/* We forward declare the CoglFramebuffer type here to avoid some circular
* dependency issues with the following headers.
*/
typedef struct _CoglFramebuffer CoglFramebuffer;
#ifdef COGL_ENABLE_EXPERIMENTAL_2_0_API
#include <cogl/cogl2-path.h>
#else
@ -87,8 +92,6 @@ COGL_BEGIN_DECLS
* configuration.
*/
typedef struct _CoglFramebuffer CoglFramebuffer;
#ifdef COGL_ENABLE_EXPERIMENTAL_API
#define COGL_FRAMEBUFFER(X) ((CoglFramebuffer *)(X))
@ -1387,9 +1390,8 @@ cogl_framebuffer_draw_rectangle (CoglFramebuffer *framebuffer,
* This is a high level drawing api that can handle any kind of
* #CoglMetaTexture texture such as #CoglTexture2DSliced textures
* which may internally be comprised of multiple low-level textures.
* This is unlike low-level drawing apis such as
* cogl_framebuffer_draw_primitive() or
* cogl_framebuffer_draw_attributes() which only support low level
* This is unlike low-level drawing apis such as cogl_primitive_draw()
* or cogl_framebuffer_draw_attributes() which only support low level
* texture types that are directly supported by GPUs such as
* #CoglTexture2D.
*
@ -1454,10 +1456,9 @@ cogl_framebuffer_draw_textured_rectangle (CoglFramebuffer *framebuffer,
* #CoglMetaTexture texture for the first layer such as
* #CoglTexture2DSliced textures which may internally be comprised of
* multiple low-level textures. This is unlike low-level drawing apis
* such as cogl_framebuffer_draw_primitive() or
* cogl_framebuffer_draw_attributes() which only support low level
* texture types that are directly supported by GPUs such as
* #CoglTexture2D.
* such as cogl_primitive_draw() or cogl_framebuffer_draw_attributes()
* which only support low level texture types that are directly
* supported by GPUs such as #CoglTexture2D.
*
* <note>This api can not currently handle multiple high-level meta
* texture layers. The first layer may be a high level meta texture
@ -1562,9 +1563,8 @@ cogl_framebuffer_draw_rectangles (CoglFramebuffer *framebuffer,
* This is a high level drawing api that can handle any kind of
* #CoglMetaTexture texture such as #CoglTexture2DSliced textures
* which may internally be comprised of multiple low-level textures.
* This is unlike low-level drawing apis such as
* cogl_framebuffer_draw_primitive() or
* cogl_framebuffer_draw_attributes() which only support low level
* This is unlike low-level drawing apis such as cogl_primitive_draw()
* or cogl_framebuffer_draw_attributes() which only support low level
* texture types that are directly supported by GPUs such as
* #CoglTexture2D.
*

View File

@ -32,6 +32,10 @@
#ifndef __COGL_PIXEL_BUFFER_H__
#define __COGL_PIXEL_BUFFER_H__
/* XXX: We forward declare CoglPixelBuffer here to allow for circular
* dependencies between some headers */
typedef struct _CoglPixelBuffer CoglPixelBuffer;
#include <cogl/cogl-types.h>
#include <cogl/cogl-context.h>
@ -39,8 +43,6 @@ COGL_BEGIN_DECLS
#define COGL_PIXEL_BUFFER(buffer) ((CoglPixelBuffer *)(buffer))
typedef struct _CoglPixelBuffer CoglPixelBuffer;
/**
* cogl_pixel_buffer_new:
* @context: A #CoglContext

View File

@ -31,6 +31,7 @@
#include "cogl-object-private.h"
#include "cogl-attribute-buffer-private.h"
#include "cogl-attribute-private.h"
#include "cogl-framebuffer.h"
struct _CoglPrimitive
{
@ -58,6 +59,8 @@ _cogl_primitive_immutable_unref (CoglPrimitive *primitive);
void
_cogl_primitive_draw (CoglPrimitive *primitive,
CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
CoglDrawFlags flags);
#endif /* __COGL_PRIMITIVE_PRIVATE_H */

View File

@ -34,6 +34,7 @@
#include "cogl-primitive.h"
#include "cogl-primitive-private.h"
#include "cogl-attribute-private.h"
#include "cogl-framebuffer-private.h"
#include <stdarg.h>
#include <string.h>
@ -599,3 +600,38 @@ cogl_primitive_foreach_attribute (CoglPrimitive *primitive,
if (!callback (primitive, primitive->attributes[i], user_data))
break;
}
void
_cogl_primitive_draw (CoglPrimitive *primitive,
CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
CoglDrawFlags flags)
{
if (primitive->indices)
_cogl_framebuffer_draw_indexed_attributes (framebuffer,
pipeline,
primitive->mode,
primitive->first_vertex,
primitive->n_vertices,
primitive->indices,
primitive->attributes,
primitive->n_attributes,
flags);
else
_cogl_framebuffer_draw_attributes (framebuffer,
pipeline,
primitive->mode,
primitive->first_vertex,
primitive->n_vertices,
primitive->attributes,
primitive->n_attributes,
flags);
}
void
cogl_primitive_draw (CoglPrimitive *primitive,
CoglFramebuffer *framebuffer,
CoglPipeline *pipeline)
{
_cogl_primitive_draw (primitive, framebuffer, pipeline, 0 /* flags */);
}

View File

@ -38,6 +38,7 @@ typedef struct _CoglPrimitive CoglPrimitive;
#include <cogl/cogl-vertex-buffer.h> /* for CoglVerticesMode */
#include <cogl/cogl-attribute.h>
#include <cogl/cogl-framebuffer.h>
COGL_BEGIN_DECLS
@ -860,6 +861,30 @@ cogl_primitive_foreach_attribute (CoglPrimitive *primitive,
CoglPrimitiveAttributeCallback callback,
void *user_data);
/**
* cogl_primitive_draw:
* @primitive: A #CoglPrimitive geometry object
* @framebuffer: A destination #CoglFramebuffer
* @pipeline: A #CoglPipeline state object
*
* Draws the given @primitive geometry to the specified destination
* @framebuffer using the graphics processing state described by @pipeline.
*
* This drawing api doesn't support high-level meta texture types such
* as #CoglTexture2DSliced so it is the user's responsibility to
* ensure that only low-level textures that can be directly sampled by
* a GPU such as #CoglTexture2D, #CoglTextureRectangle or #CoglTexture3D
* are associated with layers of the given @pipeline.
*
* Stability: unstable
* Since: 1.16
*/
void
cogl_primitive_draw (CoglPrimitive *primitive,
CoglFramebuffer *framebuffer,
CoglPipeline *pipeline);
COGL_END_DECLS
#endif /* __COGL_PRIMITIVE_H__ */

View File

@ -105,6 +105,7 @@
#include "cogl-pipeline-private.h"
#include "cogl-primitives.h"
#include "cogl-framebuffer-private.h"
#include "cogl-primitive-private.h"
#include "cogl-journal-private.h"
#include "cogl1-context.h"
@ -1627,10 +1628,10 @@ update_primitive_and_draw (CoglVertexBuffer *buffer,
* to enable it) */
cogl_push_source (pipeline_priv->real_source);
_cogl_framebuffer_draw_primitive (cogl_get_draw_framebuffer (),
pipeline_priv->real_source,
buffer->primitive,
0 /* no draw flags */);
_cogl_primitive_draw (buffer->primitive,
cogl_get_draw_framebuffer (),
pipeline_priv->real_source,
0 /* no draw flags */);
cogl_pop_source ();
}

View File

@ -228,7 +228,6 @@ cogl_framebuffer_clear
cogl_framebuffer_discard_buffers
cogl_framebuffer_draw_attributes
cogl_framebuffer_draw_indexed_attributes
cogl_framebuffer_draw_primitive
cogl_framebuffer_draw_rectangle
cogl_framebuffer_draw_rectangles
cogl_framebuffer_draw_textured_rectangle
@ -684,6 +683,7 @@ cogl_primitive_set_first_vertex
cogl_primitive_set_indices
cogl_primitive_set_mode
cogl_primitive_set_n_vertices
cogl_primitive_draw
cogl_primitive_texture_set_auto_mipmap

View File

@ -35,6 +35,7 @@
#include "cogl-pipeline-opengl-private.h"
#include "cogl-path-private.h"
#include "cogl-clip-stack-gl-private.h"
#include "cogl-primitive-private.h"
#ifndef GL_CLIP_PLANE0
#define GL_CLIP_PLANE0 0x3000
@ -400,13 +401,13 @@ paint_primitive_silhouette (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
void *user_data)
{
_cogl_framebuffer_draw_primitive (framebuffer,
pipeline,
user_data,
COGL_DRAW_SKIP_JOURNAL_FLUSH |
COGL_DRAW_SKIP_PIPELINE_VALIDATION |
COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH |
COGL_DRAW_SKIP_LEGACY_STATE);
_cogl_primitive_draw (user_data,
framebuffer,
pipeline,
COGL_DRAW_SKIP_JOURNAL_FLUSH |
COGL_DRAW_SKIP_PIPELINE_VALIDATION |
COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH |
COGL_DRAW_SKIP_LEGACY_STATE);
}
static void

View File

@ -298,6 +298,7 @@ cogl_primitive_set_indices
cogl_primitive_copy
CoglPrimitiveAttributeCallback
cogl_primitive_foreach_attribute
cogl_primitive_draw
</SECTION>
<SECTION>
@ -541,7 +542,6 @@ cogl_framebuffer_set_dither_enabled
cogl_framebuffer_get_dither_enabled
<SUBSECTION>
cogl_framebuffer_draw_primitive
cogl_framebuffer_draw_attributes
cogl_framebuffer_vdraw_attributes
cogl_framebuffer_draw_indexed_attributes

View File

@ -115,7 +115,7 @@ paint (Data *data)
cogl_framebuffer_rotate (fb, rotation, 0, 1, 0);
cogl_framebuffer_rotate (fb, rotation, 1, 0, 0);
cogl_framebuffer_draw_primitive (fb, data->crate_pipeline, data->prim);
cogl_primitive_draw (data->prim, fb, data->crate_pipeline);
cogl_framebuffer_pop_matrix (fb);

View File

@ -30,7 +30,7 @@ redraw (Data *data)
cogl_framebuffer_push_matrix (fb);
cogl_framebuffer_translate (fb, data->center_x, -data->center_y, 0.0f);
cogl_framebuffer_draw_primitive (fb, data->pipeline, data->triangle);
cogl_primitive_draw (data->triangle, fb, data->pipeline);
cogl_framebuffer_pop_matrix (fb);
cogl_onscreen_swap_buffers (COGL_ONSCREEN (fb));

View File

@ -46,7 +46,7 @@ paint_cb (void *user_data)
cogl_pop_gles2_context (data->ctx);
/* Draw scene with Cogl */
cogl_framebuffer_draw_primitive (data->fb, data->pipeline, data->triangle);
cogl_primitive_draw (data->triangle, data->fb, data->pipeline);
cogl_onscreen_swap_buffers (COGL_ONSCREEN (data->fb));

View File

@ -24,9 +24,9 @@ paint_cb (void *user_data)
data->draw_ready = FALSE;
cogl_framebuffer_clear4f (data->fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
cogl_framebuffer_draw_primitive (data->fb,
data->pipeline,
data->triangle);
cogl_primitive_draw (data->triangle,
data->fb,
data->pipeline);
cogl_onscreen_swap_buffers (COGL_ONSCREEN (data->fb));
return G_SOURCE_REMOVE;

View File

@ -92,10 +92,10 @@ main (int argc, char **argv)
cogl_framebuffer_push_matrix (fb);
cogl_framebuffer_scale (fb, 0.5, 1, 1);
cogl_framebuffer_translate (fb, -1, 0, 0);
cogl_framebuffer_draw_primitive (fb, pipeline, triangle);
cogl_primitive_draw (triangle, fb, pipeline);
cogl_framebuffer_pop_matrix (fb);
cogl_framebuffer_draw_primitive (fb, pipeline, triangle);
cogl_primitive_draw (triangle, fb, pipeline);
cogl_framebuffer_resolve_samples (offscreen_fb);
texture_pipeline = cogl_pipeline_new (ctx);

View File

@ -26,7 +26,7 @@ redraw (Data *data)
cogl_framebuffer_push_matrix (fb);
cogl_framebuffer_translate (fb, data->center_x, -data->center_y, 0.0f);
cogl_framebuffer_draw_primitive (fb, data->pipeline, data->triangle);
cogl_primitive_draw (data->triangle, fb, data->pipeline);
cogl_framebuffer_pop_matrix (fb);
cogl_onscreen_swap_buffers (COGL_ONSCREEN (fb));

View File

@ -26,7 +26,7 @@ redraw (Data *data)
cogl_framebuffer_push_matrix (fb);
cogl_framebuffer_translate (fb, data->center_x, -data->center_y, 0.0f);
cogl_framebuffer_draw_primitive (fb, data->pipeline, data->triangle);
cogl_primitive_draw (data->triangle, fb, data->pipeline);
cogl_framebuffer_pop_matrix (fb);
cogl_onscreen_swap_buffers (COGL_ONSCREEN (fb));

View File

@ -195,7 +195,7 @@ main (int argc, char **argv)
poll_fds, n_poll_fds);
cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
cogl_framebuffer_draw_primitive (fb, pipeline, triangle);
cogl_primitive_draw (triangle, fb, pipeline);
cogl_onscreen_swap_buffers (onscreen);
}

View File

@ -392,8 +392,8 @@ paint_cb (void *user_data)
cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
cogl_framebuffer_draw_primitive (fb, compositor->triangle_pipeline,
compositor->triangle);
cogl_primitive_draw (compositor->triangle,
fb, compositor->triangle_pipeline);
for (l2 = compositor->surfaces; l2; l2 = l2->next)
{

View File

@ -41,8 +41,8 @@ paint (void)
* primitive will be drawn with blending still disabled.
*/
cogl_framebuffer_draw_primitive (test_fb, pipeline, tri0);
cogl_framebuffer_draw_primitive (test_fb, pipeline, tri1);
cogl_primitive_draw (tri0, test_fb, pipeline);
cogl_primitive_draw (tri1, test_fb, pipeline);
test_utils_check_pixel_and_alpha (test_fb,
half_width + 5,

View File

@ -122,7 +122,7 @@ do_test (const char *attribute_name,
cogl_pipeline_set_per_vertex_point_size (pipeline, TRUE, NULL);
if (pipeline_setup_func)
pipeline_setup_func (pipeline);
cogl_framebuffer_draw_primitive (test_fb, pipeline, primitive);
cogl_primitive_draw (primitive, test_fb, pipeline);
cogl_object_unref (pipeline);
cogl_object_unref (primitive);

View File

@ -79,9 +79,7 @@ test_point_size (void)
cogl_pipeline_set_point_size (pipeline, point_size);
cogl_pipeline_set_color4ub (pipeline, 0, 255, 0, 255);
cogl_framebuffer_draw_primitive (test_fb,
pipeline,
prim);
cogl_primitive_draw (prim, test_fb, pipeline);
cogl_object_unref (prim);
cogl_object_unref (pipeline);

View File

@ -81,9 +81,7 @@ do_test (CoglBool check_orientation)
1, /* n_vertices */
&point);
cogl_framebuffer_draw_primitive (test_fb,
pipeline,
prim);
cogl_primitive_draw (prim, test_fb, pipeline);
/* Render the primitive again without point sprites to make sure
disabling it works */
@ -99,9 +97,7 @@ do_test (CoglBool check_orientation)
POINT_SIZE * 2, /* x */
0.0f, /* y */
0.0f /* z */);
cogl_framebuffer_draw_primitive (test_fb,
solid_pipeline,
prim);
cogl_primitive_draw (prim, test_fb, solid_pipeline);
cogl_framebuffer_pop_matrix (test_fb);
cogl_object_unref (prim);

View File

@ -81,9 +81,7 @@ test_primitive_and_journal (void)
cogl_framebuffer_push_rectangle_clip (test_fb,
0, 50, 300, 100);
cogl_framebuffer_draw_primitive (test_fb,
pipeline,
primitives[0]);
cogl_primitive_draw (primitives[0], test_fb, pipeline);
/* Draw a rectangle using the journal in-between the two primitives.
* This should test that the journal gets flushed correctly and that
@ -94,9 +92,7 @@ test_primitive_and_journal (void)
100, 0, /* x1/y1 */
300, 100 /* x2/y2 */);
cogl_framebuffer_draw_primitive (test_fb,
pipeline,
primitives[1]);
cogl_primitive_draw (primitives[1], test_fb, pipeline);
/* Check the three rectangles */
test_utils_check_region (test_fb,

View File

@ -195,7 +195,7 @@ test_paint (TestState *state)
cogl_framebuffer_push_matrix (test_fb);
cogl_framebuffer_translate (test_fb, i * 10, 0, 0);
cogl_framebuffer_draw_primitive (test_fb, pipeline, prim);
cogl_primitive_draw (prim, test_fb, pipeline);
cogl_framebuffer_pop_matrix (test_fb);
test_utils_check_pixel (test_fb, i * 10 + 2, 2, expected_color);

View File

@ -156,7 +156,7 @@ draw_frame (TestState *state)
TEX_DEPTH),
6 * TEX_DEPTH);
cogl_framebuffer_draw_primitive (test_fb, pipeline, primitive);
cogl_primitive_draw (primitive, test_fb, pipeline);
g_free (verts);