cogl: cleanly separate primitives + paths code

The function prototypes for the primitives API were spread between
cogl-path.h and cogl-texture.h and should have been in a
cogl-primitives.h.

As well as shuffling the prototypes around into more sensible places
this commit splits the cogl-path API out from cogl-primitives.c into
a cogl-path.c
This commit is contained in:
Robert Bragg 2010-02-10 22:30:37 +00:00
parent 9f5a3e1445
commit 48660349db
8 changed files with 1312 additions and 1265 deletions

View File

@ -61,6 +61,7 @@ cogl_public_h = \
$(srcdir)/cogl-material.h \ $(srcdir)/cogl-material.h \
$(srcdir)/cogl-matrix.h \ $(srcdir)/cogl-matrix.h \
$(srcdir)/cogl-offscreen.h \ $(srcdir)/cogl-offscreen.h \
$(srcdir)/cogl-primitives.h \
$(srcdir)/cogl-path.h \ $(srcdir)/cogl-path.h \
$(srcdir)/cogl-pixel-buffer.h \ $(srcdir)/cogl-pixel-buffer.h \
$(srcdir)/cogl-shader.h \ $(srcdir)/cogl-shader.h \
@ -96,6 +97,8 @@ cogl_sources_c = \
$(srcdir)/cogl-bitmap-fallback.c \ $(srcdir)/cogl-bitmap-fallback.c \
$(srcdir)/cogl-primitives.h \ $(srcdir)/cogl-primitives.h \
$(srcdir)/cogl-primitives.c \ $(srcdir)/cogl-primitives.c \
$(srcdir)/cogl-path.h \
$(srcdir)/cogl-path.c \
$(srcdir)/cogl-bitmap-pixbuf.c \ $(srcdir)/cogl-bitmap-pixbuf.c \
$(srcdir)/cogl-clip-stack.h \ $(srcdir)/cogl-clip-stack.h \
$(srcdir)/cogl-clip-stack.c \ $(srcdir)/cogl-clip-stack.c \

View File

@ -27,6 +27,34 @@
#include "cogl.h" #include "cogl.h"
#include "cogl-matrix-stack.h" #include "cogl-matrix-stack.h"
typedef struct _floatVec2
{
float x;
float y;
} floatVec2;
typedef struct _CoglPathNode
{
float x;
float y;
unsigned int path_size;
} CoglPathNode;
typedef struct _CoglBezQuad
{
floatVec2 p1;
floatVec2 p2;
floatVec2 p3;
} CoglBezQuad;
typedef struct _CoglBezCubic
{
floatVec2 p1;
floatVec2 p2;
floatVec2 p3;
floatVec2 p4;
} CoglBezCubic;
typedef enum typedef enum
{ {
COGL_FRONT_WINDING_CLOCKWISE, COGL_FRONT_WINDING_CLOCKWISE,

File diff suppressed because it is too large Load Diff

View File

@ -33,17 +33,14 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/** /**
* SECTION:cogl-primitives * SECTION:cogl-paths
* @short_description: Functions that draw various primitive shapes and * @short_description: Functions for constructing and drawing 2D paths.
* allow for construction of more complex paths.
* *
* There are three levels on which drawing with cogl can be used. The * There are two levels on which drawing with cogl-paths can be used.
* highest level functions construct various simple primitive shapes * The highest level functions construct various simple primitive
* to be either filled or stroked. Using a lower-level set of functions * shapes to be either filled or stroked. Using a lower-level set of
* more complex and arbitrary paths can be constructed by concatenating * functions more complex and arbitrary paths can be constructed by
* straight line, bezier curve and arc segments. Additionally there * concatenating straight line, bezier curve and arc segments.
* are utility functions that draw the most common primitives - rectangles
* and trapezoids - in a maximaly optimized fashion.
* *
* When constructing arbitrary paths, the current pen location is * When constructing arbitrary paths, the current pen location is
* initialized using the move_to command. The subsequent path segments * initialized using the move_to command. The subsequent path segments
@ -54,21 +51,6 @@ G_BEGIN_DECLS
* rather then in the absolute coordinates. * rather then in the absolute coordinates.
*/ */
/**
* cogl_rectangle:
* @x_1: X coordinate of the top-left corner
* @y_1: Y coordinate of the top-left corner
* @x_2: X coordinate of the bottom-right corner
* @y_2: Y coordinate of the bottom-right corner
*
* Fills a rectangle at the given coordinates with the current source material
**/
void
cogl_rectangle (float x_1,
float y_1,
float x_2,
float y_2);
/** /**
* cogl_path_fill: * cogl_path_fill:
* *
@ -101,7 +83,6 @@ cogl_path_fill_preserve (void);
void void
cogl_path_stroke (void); cogl_path_stroke (void);
/** /**
* cogl_path_stroke_preserve: * cogl_path_stroke_preserve:
* *

File diff suppressed because it is too large Load Diff

View File

@ -24,37 +24,161 @@
#ifndef __COGL_PRIMITIVES_H #ifndef __COGL_PRIMITIVES_H
#define __COGL_PRIMITIVES_H #define __COGL_PRIMITIVES_H
typedef struct _floatVec2 floatVec2; /**
typedef struct _CoglBezQuad CoglBezQuad; * SECTION:cogl-primitives
typedef struct _CoglBezCubic CoglBezCubic; * @short_description: Functions that draw various primitive 3D shapes
typedef struct _CoglPathNode CoglPathNode; *
* The primitives API provides utilities for drawing some
* common 3D shapes in a more convenient way than the CoglVertexBuffer
* API provides.
*/
struct _floatVec2 /**
{ * cogl_rectangle:
float x; * @x_1: X coordinate of the top-left corner
float y; * @y_1: Y coordinate of the top-left corner
}; * @x_2: X coordinate of the bottom-right corner
* @y_2: Y coordinate of the bottom-right corner
*
* Fills a rectangle at the given coordinates with the current source material
**/
void
cogl_rectangle (float x_1,
float y_1,
float x_2,
float y_2);
struct _CoglPathNode /**
{ * cogl_rectangle_with_texture_coords:
float x; * @x1: x coordinate upper left on screen.
float y; * @y1: y coordinate upper left on screen.
unsigned int path_size; * @x2: x coordinate lower right on screen.
}; * @y2: y coordinate lower right on screen.
* @tx1: x part of texture coordinate to use for upper left pixel
* @ty1: y part of texture coordinate to use for upper left pixel
* @tx2: x part of texture coordinate to use for lower right pixel
* @ty2: y part of texture coordinate to use for left pixel
*
* Draw a rectangle using the current material and supply texture coordinates
* to be used for the first texture layer of the material. To draw the entire
* texture pass in @tx1=0.0 @ty1=0.0 @tx2=1.0 @ty2=1.0.
*
* Since: 1.0
*/
void
cogl_rectangle_with_texture_coords (float x1,
float y1,
float x2,
float y2,
float tx1,
float ty1,
float tx2,
float ty2);
struct _CoglBezQuad /**
{ * cogl_rectangle_with_multitexture_coords:
floatVec2 p1; * @x1: x coordinate upper left on screen.
floatVec2 p2; * @y1: y coordinate upper left on screen.
floatVec2 p3; * @x2: x coordinate lower right on screen.
}; * @y2: y coordinate lower right on screen.
* @tex_coords: (in) (array) (transfer none): An array containing groups of
* 4 float values: [tx1, ty1, tx2, ty2] that are interpreted as two texture
* coordinates; one for the upper left texel, and one for the lower right
* texel. Each value should be between 0.0 and 1.0, where the coordinate
* (0.0, 0.0) represents the top left of the texture, and (1.0, 1.0) the
* bottom right.
* @tex_coords_len: The length of the tex_coords array. (e.g. for one layer
* and one group of texture coordinates, this would be 4)
*
* This function draws a rectangle using the current source material to
* texture or fill with. As a material may contain multiple texture layers
* this interface lets you supply texture coordinates for each layer of the
* material.
*
* The first pair of coordinates are for the first layer (with the smallest
* layer index) and if you supply less texture coordinates than there are
* layers in the current source material then default texture coordinates
* (0.0, 0.0, 1.0, 1.0) are generated.
*
* Since: 1.0
*/
void
cogl_rectangle_with_multitexture_coords (float x1,
float y1,
float x2,
float y2,
const float *tex_coords,
int tex_coords_len);
struct _CoglBezCubic /**
{ * cogl_rectangles_with_texture_coords:
floatVec2 p1; * @verts: (in) (array) (transfer none): an array of vertices
floatVec2 p2; * @n_rects: number of rectangles to draw
floatVec2 p3; *
floatVec2 p4; * Draws a series of rectangles in the same way that
}; * cogl_rectangle_with_texture_coords() does. In some situations it can give a
* significant performance boost to use this function rather than
* calling cogl_rectangle_with_texture_coords() separately for each rectangle.
*
* @verts should point to an array of #float<!-- -->s with
* @n_rects * 8 elements. Each group of 8 values corresponds to the
* parameters x1, y1, x2, y2, tx1, ty1, tx2 and ty2 and have the same
* meaning as in cogl_rectangle_with_texture_coords().
*
* Since: 0.8.6
*/
void
cogl_rectangles_with_texture_coords (const float *verts,
unsigned int n_rects);
/**
* cogl_rectangles:
* @verts: (in) (array) (transfer none): an array of vertices
* @n_rects: number of rectangles to draw
*
* Draws a series of rectangles in the same way that
* cogl_rectangle() does. In some situations it can give a
* significant performance boost to use this function rather than
* calling cogl_rectangle() separately for each rectangle.
*
* @verts should point to an array of #float<!-- -->s with
* @n_rects * 4 elements. Each group of 4 values corresponds to the
* parameters x1, y1, x2, and y2, and have the same
* meaning as in cogl_rectangle().
*
* Since: 1.0
*/
void
cogl_rectangles (const float *verts,
unsigned int n_rects);
/**
* cogl_polygon:
* @vertices: An array of #CoglTextureVertex structs
* @n_vertices: The length of the vertices array
* @use_color: %TRUE if the color member of #CoglTextureVertex should be used
*
* Draws a convex polygon using the current source material to fill / texture
* with according to the texture coordinates passed.
*
* If @use_color is %TRUE then the color will be changed for each vertex using
* the value specified in the color member of #CoglTextureVertex. This can be
* used for example to make the texture fade out by setting the alpha value of
* the color.
*
* All of the texture coordinates must be in the range [0,1] and repeating the
* texture is not supported.
*
* Because of the way this function is implemented it will currently
* only work if either the texture is not sliced or the backend is not
* OpenGL ES and the minifying and magnifying functions are both set
* to COGL_MATERIAL_FILTER_NEAREST.
*
* Since: 1.0
*/
void
cogl_polygon (const CoglTextureVertex *vertices,
unsigned int n_vertices,
gboolean use_color);
#endif /* __COGL_PRIMITIVES_H */ #endif /* __COGL_PRIMITIVES_H */

View File

@ -448,139 +448,6 @@ cogl_texture_unref (CoglHandle handle);
#endif /* COGL_DISABLE_DEPRECATED */ #endif /* COGL_DISABLE_DEPRECATED */
/**
* cogl_rectangle_with_texture_coords:
* @x1: x coordinate upper left on screen.
* @y1: y coordinate upper left on screen.
* @x2: x coordinate lower right on screen.
* @y2: y coordinate lower right on screen.
* @tx1: x part of texture coordinate to use for upper left pixel
* @ty1: y part of texture coordinate to use for upper left pixel
* @tx2: x part of texture coordinate to use for lower right pixel
* @ty2: y part of texture coordinate to use for left pixel
*
* Draw a rectangle using the current material and supply texture coordinates
* to be used for the first texture layer of the material. To draw the entire
* texture pass in @tx1=0.0 @ty1=0.0 @tx2=1.0 @ty2=1.0.
*
* Since: 1.0
*/
void
cogl_rectangle_with_texture_coords (float x1,
float y1,
float x2,
float y2,
float tx1,
float ty1,
float tx2,
float ty2);
/**
* cogl_rectangle_with_multitexture_coords:
* @x1: x coordinate upper left on screen.
* @y1: y coordinate upper left on screen.
* @x2: x coordinate lower right on screen.
* @y2: y coordinate lower right on screen.
* @tex_coords: (in) (array) (transfer none): An array containing groups of
* 4 float values: [tx1, ty1, tx2, ty2] that are interpreted as two texture
* coordinates; one for the upper left texel, and one for the lower right
* texel. Each value should be between 0.0 and 1.0, where the coordinate
* (0.0, 0.0) represents the top left of the texture, and (1.0, 1.0) the
* bottom right.
* @tex_coords_len: The length of the tex_coords array. (e.g. for one layer
* and one group of texture coordinates, this would be 4)
*
* This function draws a rectangle using the current source material to
* texture or fill with. As a material may contain multiple texture layers
* this interface lets you supply texture coordinates for each layer of the
* material.
*
* The first pair of coordinates are for the first layer (with the smallest
* layer index) and if you supply less texture coordinates than there are
* layers in the current source material then default texture coordinates
* (0.0, 0.0, 1.0, 1.0) are generated.
*
* Since: 1.0
*/
void
cogl_rectangle_with_multitexture_coords (float x1,
float y1,
float x2,
float y2,
const float *tex_coords,
int tex_coords_len);
/**
* cogl_rectangles_with_texture_coords:
* @verts: (in) (array) (transfer none): an array of vertices
* @n_rects: number of rectangles to draw
*
* Draws a series of rectangles in the same way that
* cogl_rectangle_with_texture_coords() does. In some situations it can give a
* significant performance boost to use this function rather than
* calling cogl_rectangle_with_texture_coords() separately for each rectangle.
*
* @verts should point to an array of #float<!-- -->s with
* @n_rects * 8 elements. Each group of 8 values corresponds to the
* parameters x1, y1, x2, y2, tx1, ty1, tx2 and ty2 and have the same
* meaning as in cogl_rectangle_with_texture_coords().
*
* Since: 0.8.6
*/
void
cogl_rectangles_with_texture_coords (const float *verts,
unsigned int n_rects);
/**
* cogl_rectangles:
* @verts: (in) (array) (transfer none): an array of vertices
* @n_rects: number of rectangles to draw
*
* Draws a series of rectangles in the same way that
* cogl_rectangle() does. In some situations it can give a
* significant performance boost to use this function rather than
* calling cogl_rectangle() separately for each rectangle.
*
* @verts should point to an array of #float<!-- -->s with
* @n_rects * 4 elements. Each group of 4 values corresponds to the
* parameters x1, y1, x2, and y2, and have the same
* meaning as in cogl_rectangle().
*
* Since: 1.0
*/
void
cogl_rectangles (const float *verts,
unsigned int n_rects);
/**
* cogl_polygon:
* @vertices: An array of #CoglTextureVertex structs
* @n_vertices: The length of the vertices array
* @use_color: %TRUE if the color member of #CoglTextureVertex should be used
*
* Draws a convex polygon using the current source material to fill / texture
* with according to the texture coordinates passed.
*
* If @use_color is %TRUE then the color will be changed for each vertex using
* the value specified in the color member of #CoglTextureVertex. This can be
* used for example to make the texture fade out by setting the alpha value of
* the color.
*
* All of the texture coordinates must be in the range [0,1] and repeating the
* texture is not supported.
*
* Because of the way this function is implemented it will currently
* only work if either the texture is not sliced or the backend is not
* OpenGL ES and the minifying and magnifying functions are both set
* to COGL_MATERIAL_FILTER_NEAREST.
*
* Since: 1.0
*/
void
cogl_polygon (const CoglTextureVertex *vertices,
unsigned int n_vertices,
gboolean use_color);
G_END_DECLS G_END_DECLS
#endif /* __COGL_TEXTURE_H__ */ #endif /* __COGL_TEXTURE_H__ */

View File

@ -38,6 +38,7 @@
#include <cogl/cogl-material.h> #include <cogl/cogl-material.h>
#include <cogl/cogl-matrix.h> #include <cogl/cogl-matrix.h>
#include <cogl/cogl-offscreen.h> #include <cogl/cogl-offscreen.h>
#include <cogl/cogl-primitives.h>
#include <cogl/cogl-path.h> #include <cogl/cogl-path.h>
#include <cogl/cogl-shader.h> #include <cogl/cogl-shader.h>
#include <cogl/cogl-texture.h> #include <cogl/cogl-texture.h>