Merge commit 'origin/master' into cogl-material

Conflicts:

	clutter/clutter-texture.c
	clutter/cogl/cogl-texture.h
	clutter/cogl/cogl.h.in
	clutter/cogl/common/Makefile.am
	clutter/cogl/gl/Makefile.am
	clutter/cogl/gles/Makefile.am
	clutter/cogl/gles/cogl-gles2-wrapper.c
	clutter/cogl/gles/cogl-gles2-wrapper.h
This commit is contained in:
Robert Bragg 2009-01-23 15:23:49 +00:00
commit 0c8c273980
36 changed files with 2143 additions and 2103 deletions

View File

@ -68,22 +68,22 @@ void cogl_color_set_from_4d (CoglColor *dest,
gdouble alpha); gdouble alpha);
/** /**
* cogl_color_set_from_4x: * cogl_color_set_from_4f:
* @dest: return location for a #CoglColor * @dest: return location for a #CoglColor
* @red: value of the red channel, between 0 and %COGL_FIXED_1 * @red: value of the red channel, between 0 and %1.0
* @green: value of the green channel, between 0 and %COGL_FIXED_1 * @green: value of the green channel, between 0 and %1.0
* @blue: value of the blue channel, between 0 and %COGL_FIXED_1 * @blue: value of the blue channel, between 0 and %1.0
* @alpha: value of the alpha channel, between 0 and %COGL_FIXED_1 * @alpha: value of the alpha channel, between 0 and %1.0
* *
* Sets the values of the passed channels into a #CoglColor * Sets the values of the passed channels into a #CoglColor
* *
* Since: 1.0 * Since: 1.0
*/ */
void cogl_color_set_from_4x (CoglColor *dest, void cogl_color_set_from_4f (CoglColor *dest,
CoglFixed red, float red,
CoglFixed green, float green,
CoglFixed blue, float blue,
CoglFixed alpha); float alpha);
/** /**
* cogl_color_get_red_byte: * cogl_color_get_red_byte:
@ -194,52 +194,52 @@ float cogl_color_get_alpha_float (const CoglColor *color);
* @color: a #CoglColor * @color: a #CoglColor
* *
* Retrieves the red channel of @color as a fixed point * Retrieves the red channel of @color as a fixed point
* value between 0 and %COGL_FIXED_1. * value between 0 and %1.0.
* *
* Return value: the red channel of the passed color * Return value: the red channel of the passed color
* *
* Since: 1.0 * Since: 1.0
*/ */
CoglFixed cogl_color_get_red (const CoglColor *color); float cogl_color_get_red (const CoglColor *color);
/** /**
* cogl_color_get_green: * cogl_color_get_green:
* @color: a #CoglColor * @color: a #CoglColor
* *
* Retrieves the green channel of @color as a fixed point * Retrieves the green channel of @color as a fixed point
* value between 0 and %COGL_FIXED_1. * value between 0 and %1.0.
* *
* Return value: the green channel of the passed color * Return value: the green channel of the passed color
* *
* Since: 1.0 * Since: 1.0
*/ */
CoglFixed cogl_color_get_green (const CoglColor *color); float cogl_color_get_green (const CoglColor *color);
/** /**
* cogl_color_get_blue: * cogl_color_get_blue:
* @color: a #CoglColor * @color: a #CoglColor
* *
* Retrieves the blue channel of @color as a fixed point * Retrieves the blue channel of @color as a fixed point
* value between 0 and %COGL_FIXED_1. * value between 0 and %1.0.
* *
* Return value: the blue channel of the passed color * Return value: the blue channel of the passed color
* *
* Since: 1.0 * Since: 1.0
*/ */
CoglFixed cogl_color_get_blue (const CoglColor *color); float cogl_color_get_blue (const CoglColor *color);
/** /**
* cogl_color_get_alpha: * cogl_color_get_alpha:
* @color: a #CoglColor * @color: a #CoglColor
* *
* Retrieves the alpha channel of @color as a fixed point * Retrieves the alpha channel of @color as a fixed point
* value between 0 and %COGL_FIXED_1. * value between 0 and %1.0.
* *
* Return value: the alpha channel of the passed color * Return value: the alpha channel of the passed color
* *
* Since: 1.0 * Since: 1.0
*/ */
CoglFixed cogl_color_get_alpha (const CoglColor *color); float cogl_color_get_alpha (const CoglColor *color);
/** /**
* cogl_set_source_color: * cogl_set_source_color:
@ -248,7 +248,7 @@ CoglFixed cogl_color_get_alpha (const CoglColor *color);
* Sets the source color using normalized values for each component. * Sets the source color using normalized values for each component.
* This color will be used for any subsequent drawing operation. * This color will be used for any subsequent drawing operation.
* *
* See also cogl_set_source_color4ub() and cogl_set_source_color4x() * See also cogl_set_source_color4ub() and cogl_set_source_color4f()
* if you already have the color components. * if you already have the color components.
* *
* Since: 1.0 * Since: 1.0
@ -276,25 +276,25 @@ void cogl_set_source_color4ub (guint8 red,
guint8 alpha); guint8 alpha);
/** /**
* cogl_set_source_color4x: * cogl_set_source_color4f:
* @red: value of the red channel, between 0 and %COGL_FIXED_1 * @red: value of the red channel, between 0 and %1.0
* @green: value of the green channel, between 0 and %COGL_FIXED_1 * @green: value of the green channel, between 0 and %1.0
* @blue: value of the blue channel, between 0 and %COGL_FIXED_1 * @blue: value of the blue channel, between 0 and %1.0
* @alpha: value of the alpha channel, between 0 and %COGL_FIXED_1 * @alpha: value of the alpha channel, between 0 and %1.0
* *
* Sets the source color using normalized values for each component. * Sets the source color using normalized values for each component.
* This color will be used for any subsequent drawing operation. * This color will be used for any subsequent drawing operation.
* *
* The value for each component is a fixed point number in the range * The value for each component is a fixed point number in the range
* between 0 and %COGL_FIXED_1. If the values passed in are outside that * between 0 and %1.0. If the values passed in are outside that
* range, they will be clamped. * range, they will be clamped.
* *
* Since: 1.0 * Since: 1.0
*/ */
void cogl_set_source_color4x (CoglFixed red, void cogl_set_source_color4f (float red,
CoglFixed green, float green,
CoglFixed blue, float blue,
CoglFixed alpha); float alpha);
G_END_DECLS G_END_DECLS

View File

@ -455,6 +455,18 @@ G_BEGIN_DECLS
*/ */
CoglFixed cogl_fixed_sin (CoglFixed angle); CoglFixed cogl_fixed_sin (CoglFixed angle);
/**
* cogl_fixed_tan:
* @angle: a #CoglFixed number
*
* Computes the tangent of @angle.
*
* Return value: the tangent of the passed angle, in fixed point notation
*
* Since: 1.0
*/
CoglFixed cogl_fixed_tan (CoglFixed angle);
/** /**
* cogl_fixed_cos: * cogl_fixed_cos:
* @angle: a #CoglFixed number * @angle: a #CoglFixed number

View File

@ -60,24 +60,10 @@ G_BEGIN_DECLS
* Fills a rectangle at the given coordinates with the current * Fills a rectangle at the given coordinates with the current
* drawing color in a highly optimizied fashion. * drawing color in a highly optimizied fashion.
**/ **/
void cogl_rectangle (gint x, void cogl_rectangle (float x,
gint y, float y,
guint width, float width,
guint height); float height);
/**
* cogl_rectanglex:
* @x: X coordinate of the top-left corner
* @y: Y coordinate of the top-left corner
* @width: Width of the rectangle
* @height: Height of the rectangle
*
* A fixed-point version of cogl_fast_fill_rectangle.
**/
void cogl_rectanglex (CoglFixed x,
CoglFixed y,
CoglFixed width,
CoglFixed height);
/** /**
* cogl_path_fill: * cogl_path_fill:
@ -136,8 +122,8 @@ void cogl_path_new (void);
* Moves the pen to the given location. If there is an existing path * Moves the pen to the given location. If there is an existing path
* this will start a new disjoint subpath. * this will start a new disjoint subpath.
**/ **/
void cogl_path_move_to (CoglFixed x, void cogl_path_move_to (float x,
CoglFixed y); float y);
/** /**
@ -149,8 +135,8 @@ void cogl_path_move_to (CoglFixed x,
* location. If there is an existing path this will start a new * location. If there is an existing path this will start a new
* disjoint subpath. * disjoint subpath.
**/ **/
void cogl_path_rel_move_to (CoglFixed x, void cogl_path_rel_move_to (float x,
CoglFixed y); float y);
/** /**
* cogl_path_line_to: * cogl_path_line_to:
@ -160,8 +146,8 @@ void cogl_path_rel_move_to (CoglFixed x,
* Adds a straight line segment to the current path that ends at the * Adds a straight line segment to the current path that ends at the
* given coordinates. * given coordinates.
**/ **/
void cogl_path_line_to (CoglFixed x, void cogl_path_line_to (float x,
CoglFixed y); float y);
/** /**
* cogl_path_rel_line_to: * cogl_path_rel_line_to:
@ -171,8 +157,8 @@ void cogl_path_line_to (CoglFixed x,
* Adds a straight line segment to the current path that ends at the * Adds a straight line segment to the current path that ends at the
* given coordinates relative to the current pen location. * given coordinates relative to the current pen location.
**/ **/
void cogl_path_rel_line_to (CoglFixed x, void cogl_path_rel_line_to (float x,
CoglFixed y); float y);
/** /**
@ -189,12 +175,12 @@ void cogl_path_rel_line_to (CoglFixed x,
* of the arc. If you perform a move_to to the arcs start just before * of the arc. If you perform a move_to to the arcs start just before
* drawing it you create a free standing arc. * drawing it you create a free standing arc.
**/ **/
void cogl_path_arc (CoglFixed center_x, void cogl_path_arc (float center_x,
CoglFixed center_y, float center_y,
CoglFixed radius_x, float radius_x,
CoglFixed radius_y, float radius_y,
CoglAngle angle_1, float angle_1,
CoglAngle angle_2); float angle_2);
@ -211,12 +197,12 @@ void cogl_path_arc (CoglFixed center_x,
* second, third and fourth control points and using current pen location * second, third and fourth control points and using current pen location
* as the first control point. * as the first control point.
**/ **/
void cogl_path_curve_to (CoglFixed x1, void cogl_path_curve_to (float x1,
CoglFixed y1, float y1,
CoglFixed x2, float x2,
CoglFixed y2, float y2,
CoglFixed x3, float x3,
CoglFixed y3); float y3);
/** /**
* cogl_path_rel_curve_to: * cogl_path_rel_curve_to:
@ -232,12 +218,12 @@ void cogl_path_curve_to (CoglFixed x1,
* as the first control point. The given coordinates are relative to the * as the first control point. The given coordinates are relative to the
* current pen location. * current pen location.
*/ */
void cogl_path_rel_curve_to (CoglFixed x1, void cogl_path_rel_curve_to (float x1,
CoglFixed y1, float y1,
CoglFixed x2, float x2,
CoglFixed y2, float y2,
CoglFixed x3, float x3,
CoglFixed y3); float y3);
/** /**
* cogl_path_close: * cogl_path_close:
@ -258,10 +244,10 @@ void cogl_path_close (void);
* coordinates. If there is an existing path this will start a new * coordinates. If there is an existing path this will start a new
* disjoint sub-path. * disjoint sub-path.
**/ **/
void cogl_path_line (CoglFixed x1, void cogl_path_line (float x1,
CoglFixed y1, float y1,
CoglFixed x2, float x2,
CoglFixed y2); float y2);
/** /**
* cogl_path_polyline: * cogl_path_polyline:
@ -281,7 +267,7 @@ void cogl_path_line (CoglFixed x1,
* fashion for the rest of the vertices. (num_points - 1) segments will * fashion for the rest of the vertices. (num_points - 1) segments will
* be constructed. * be constructed.
**/ **/
void cogl_path_polyline (CoglFixed *coords, void cogl_path_polyline (float *coords,
gint num_points); gint num_points);
@ -299,7 +285,7 @@ void cogl_path_polyline (CoglFixed *coords,
* represents the Y coordinate of the first vertex, continuing in the same * represents the Y coordinate of the first vertex, continuing in the same
* fashion for the rest of the vertices. * fashion for the rest of the vertices.
**/ **/
void cogl_path_polygon (CoglFixed *coords, void cogl_path_polygon (float *coords,
gint num_points); gint num_points);
@ -313,10 +299,10 @@ void cogl_path_polygon (CoglFixed *coords,
* Constructs a rectangular shape at the given coordinates. If there * Constructs a rectangular shape at the given coordinates. If there
* is an existing path this will start a new disjoint sub-path. * is an existing path this will start a new disjoint sub-path.
**/ **/
void cogl_path_rectangle (CoglFixed x, void cogl_path_rectangle (float x,
CoglFixed y, float y,
CoglFixed width, float width,
CoglFixed height); float height);
/** /**
* cogl_path_ellipse: * cogl_path_ellipse:
@ -328,10 +314,10 @@ void cogl_path_rectangle (CoglFixed x,
* Constructs an ellipse shape. If there is an existing path this will * Constructs an ellipse shape. If there is an existing path this will
* start a new disjoint sub-path. * start a new disjoint sub-path.
**/ **/
void cogl_path_ellipse (CoglFixed center_x, void cogl_path_ellipse (float center_x,
CoglFixed center_y, float center_y,
CoglFixed radius_x, float radius_x,
CoglFixed radius_y); float radius_y);
/** /**
* cogl_path_round_rectangle: * cogl_path_round_rectangle:
@ -346,12 +332,12 @@ void cogl_path_ellipse (CoglFixed center_x,
* Constructs a rectangular shape with rounded corners. If there is an * Constructs a rectangular shape with rounded corners. If there is an
* existing path this will start a new disjoint sub-path. * existing path this will start a new disjoint sub-path.
**/ **/
void cogl_path_round_rectangle (CoglFixed x, void cogl_path_round_rectangle (float x,
CoglFixed y, float y,
CoglFixed width, float width,
CoglFixed height, float height,
CoglFixed radius, float radius,
CoglAngle arc_step); float arc_step);
G_END_DECLS G_END_DECLS

View File

@ -41,73 +41,77 @@ G_BEGIN_DECLS
* cogl_texture_new_with_size: * cogl_texture_new_with_size:
* @width: width of texture in pixels. * @width: width of texture in pixels.
* @height: height of texture in pixels. * @height: height of texture in pixels.
* @max_waste: maximum extra horizontal and|or vertical margin pixels to make * @max_waste: maximum extra horizontal and|or vertical margin pixels
* texture fit GPU limitations. * to make the texture fit GPU limitations
* @auto_mipmap: enable or disable automatic generation of mipmap pyramid * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
* from the base level image whenever it is updated.
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the * @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture. * texture.
* *
* Create a new texture with specified dimensions and pixel format. * Creates a new COGL texture with the specified dimensions and pixel format.
* *
* Returns: a #CoglHandle to the newly created texture or COGL_INVALID_HANDLE * Return value: a #CoglHandle to the newly created texture or
* if texture creation failed. * %COGL_INVALID_HANDLE on failure
*
* Since: 0.8
*/ */
CoglHandle cogl_texture_new_with_size (guint width, CoglHandle cogl_texture_new_with_size (guint width,
guint height, guint height,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat internal_format); CoglPixelFormat internal_format);
/** /**
* cogl_texture_new_from_file: * cogl_texture_new_from_file:
* @filename: the file to load * @filename: the file to load
* @max_waste: maximum extra horizontal and|or vertical margin pixels to make * @max_waste: maximum extra horizontal and|or vertical margin pixels
* texture fit GPU limitations. * to make the texture fit GPU limitations
* @auto_mipmap: enable or disable automatic generation of mipmap pyramid * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
* from the base level image whenever it is updated.
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the * @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture. * texture
* @error: a #GError or NULL. * @error: return location for a #GError or %NULL
* *
* Load an image file from disk. * Creates a COGL texture from an image file.
* *
* Returns: a #CoglHandle to the newly created texture or COGL_INVALID_HANDLE * Return value: a #CoglHandle to the newly created texture or
* if creating the texture failed. * %COGL_INVALID_HANDLE on failure
*
* Since: 0.8
*/ */
CoglHandle cogl_texture_new_from_file (const gchar *filename, CoglHandle cogl_texture_new_from_file (const gchar *filename,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
GError **error); GError **error);
/** /**
* cogl_texture_new_from_data: * cogl_texture_new_from_data:
* @width: width of texture in pixels. * @width: width of texture in pixels
* @height: height of texture in pixels. * @height: height of texture in pixels
* @max_waste: maximum extra horizontal and|or vertical margin pixels to make * @max_waste: maximum extra horizontal and|or vertical margin pixels
* @auto_mipmap: enable or disable automatic generation of mipmap pyramid * to make the texture fit GPU limitations
* from the base level image whenever it is updated. * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
* @format: the #CoglPixelFormat the buffer is stored in in RAM * @format: the #CoglPixelFormat the buffer is stored in in RAM
* @internal_format: the #CoglPixelFormat that will be used for storing the * @internal_format: the #CoglPixelFormat that will be used for storing
* buffer on the GPU. * the buffer on the GPU
* @rowstride: the memory offset in bytes between the starts of scanlines in * @rowstride: the memory offset in bytes between the starts of
* @data. * scanlines in @data
* @data: pointer the memory region where the source buffer resides. * @data: pointer the memory region where the source buffer resides
* *
* Create a new cogl texture based on data residing in memory. * Creates a new COGL texture based on data residing in memory.
* *
* Returns: a #CoglHandle to the newly created texture or COGL_INVALID_HANDLE * Return value: a #CoglHandle to the newly created texture or
* if creating the texture failed. * %COGL_INVALID_HANDLE on failure
*
* Since: 0.8
*/ */
CoglHandle cogl_texture_new_from_data (guint width, CoglHandle cogl_texture_new_from_data (guint width,
guint height, guint height,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
guint rowstride, guint rowstride,
const guchar *data); const guchar *data);
/** /**
* cogl_texture_new_from_foreign: * cogl_texture_new_from_foreign:
@ -119,12 +123,14 @@ CoglHandle cogl_texture_new_from_data (guint width,
* @y_pot_waste: maximum vertical waste. * @y_pot_waste: maximum vertical waste.
* @format: format of the foreign texture. * @format: format of the foreign texture.
* *
* Create a cogl texture based on an existing OpenGL texture, the width, height * Creates a COGL texture based on an existing OpenGL texture; the
* and format are passed along since it is not possible to query this from a * width, height and format are passed along since it is not possible
* handle with GLES 1.0. * to query this from a handle with GLES 1.0.
* *
* Returns: a #CoglHandle to the newly created texture or COGL_INVALID_HANDLE * Return value: a #CoglHandle to the newly created texture or
* if creating the texture failed. * %COGL_INVALID_HANDLE on failure
*
* Since: 0.8
*/ */
CoglHandle cogl_texture_new_from_foreign (GLuint gl_handle, CoglHandle cogl_texture_new_from_foreign (GLuint gl_handle,
GLenum gl_target, GLenum gl_target,
@ -134,6 +140,27 @@ CoglHandle cogl_texture_new_from_foreign (GLuint gl_handle,
GLuint y_pot_waste, GLuint y_pot_waste,
CoglPixelFormat format); CoglPixelFormat format);
/**
* cogl_texture_new_from_bitmap:
* @bitmap: a #CoglBitmap
* @max_waste: maximum extra horizontal and|or vertical margin pixels
* to make the texture fit GPU limitations
* @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture
*
* Creates a COGL texture from a #CoglBitmap.
*
* Return value: a #CoglHandle to the newly created texture or
* %COGL_INVALID_HANDLE on failure
*
* Since: 1.0
*/
CoglHandle cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
gint max_waste,
CoglTextureFlags flags,
CoglPixelFormat internal_format);
/** /**
* cogl_is_texture: * cogl_is_texture:
* @handle: A CoglHandle * @handle: A CoglHandle
@ -348,14 +375,14 @@ void cogl_texture_unref (CoglHandle handle);
* texture pass in @tx1=0.0 @ty1=0.0 @tx2=1.0 @ty2=1.0. * texture pass in @tx1=0.0 @ty1=0.0 @tx2=1.0 @ty2=1.0.
*/ */
void cogl_texture_rectangle (CoglHandle handle, void cogl_texture_rectangle (CoglHandle handle,
CoglFixed x1, float x1,
CoglFixed y1, float y1,
CoglFixed x2, float x2,
CoglFixed y2, float y2,
CoglFixed tx1, float tx1,
CoglFixed ty1, float ty1,
CoglFixed tx2, float tx2,
CoglFixed ty2); float ty2);
/** /**
* cogl_texture_polygon: * cogl_texture_polygon:
@ -416,6 +443,45 @@ void cogl_material_rectangle (CoglFixed x1,
gint tex_coords_len, gint tex_coords_len,
const CoglFixed *tex_coords); const CoglFixed *tex_coords);
/**
* cogl_bitmap_new_from_file:
* @filename: the file to load.
* @error: a #GError or %NULL.
*
* Load an image file from disk. This function can be safely called from
* within a thread.
*
* Returns: A #CoglBitmap to the new loaded image data, or %NULL if loading
* the image failed.
*
* Since: 1.0
*/
CoglBitmap * cogl_bitmap_new_from_file (const gchar *filename,
GError **error);
/**
* cogl_bitmap_get_size_from_file:
* @filename: the file to check
* @width: return location for the bitmap width
* @height: return location for the bitmap height
*
* Parses an image file enough to extract the width and height
* of the bitmap.
*
* Since: 1.0
*/
gboolean cogl_bitmap_get_size_from_file (const gchar *filename,
gint *width,
gint *height);
/**
* cogl_bitmap_free:
* @bmp: a #CoglBitmap.
*
* Frees a #CoglBitmap.
*/
void cogl_bitmap_free (CoglBitmap *bmp);
/** /**
* cogl_texture_multiple_rectangles: * cogl_texture_multiple_rectangles:
* @handle: a @CoglHandle. * @handle: a @CoglHandle.
@ -427,16 +493,16 @@ void cogl_material_rectangle (CoglFixed x1,
* significant performance boost to use this function rather than * significant performance boost to use this function rather than
* calling cogl_texture_rectangle() separately for each rectangle. * calling cogl_texture_rectangle() separately for each rectangle.
* *
* @verts should point to an array of #CoglFixed<!-- -->s with * @verts should point to an array of #float<!-- -->s with
* @n_rects * 8 elements. Each group of 8 values corresponds to the * @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 * parameters x1, y1, x2, y2, tx1, ty1, tx2 and ty2 and have the same
* meaning as in cogl_texture_rectangle(). * meaning as in cogl_texture_rectangle().
* *
* Since: 1.0 * Since: 0.8.6
*/ */
void cogl_texture_multiple_rectangles void cogl_texture_multiple_rectangles
(CoglHandle handle, (CoglHandle handle,
const CoglFixed *verts, const float *verts,
guint n_rects); guint n_rects);
G_END_DECLS G_END_DECLS

View File

@ -28,6 +28,13 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/**
* CoglBitmap:
*
* Type used for storing image data.
*/
typedef struct _CoglBitmap CoglBitmap;
/** /**
* CoglHandle: * CoglHandle:
* *
@ -257,11 +264,26 @@ struct _CoglColor
*/ */
struct _CoglTextureVertex struct _CoglTextureVertex
{ {
CoglFixed x, y, z; float x, y, z;
CoglFixed tx, ty; float tx, ty;
CoglColor color; CoglColor color;
}; };
/**
* CoglTextureFlags:
* @COGL_TEXTURE_NONE: No flags specified
* @COGL_TEXTURE_AUTO_MIPMAP: Enables the automatic generation of the
* mipmap pyramid from the base level image whenever it is updated
*
* Flags to pass to the cogl_texture_new_* family of functions.
*
* Since: 1.0
*/
typedef enum {
COGL_TEXTURE_NONE = 0,
COGL_TEXTURE_AUTO_MIPMAP = 1 << 0
} CoglTextureFlags;
G_END_DECLS G_END_DECLS
#endif /* __COGL_TYPES_H__ */ #endif /* __COGL_TYPES_H__ */

View File

@ -1,9 +1,13 @@
/* cogl-mesh.h: Handle extensible arrays of vertex attributes /*
* This file is part of Clutter * Cogl.
*
* An OpenGL/GLES Abstraction/Utility Layer
*
* Vertex Buffer API: Handle extensible arrays of vertex attributes
* *
* Copyright (C) 2008 Intel Corporation. * Copyright (C) 2008 Intel Corporation.
* *
* Authored by: Robert Bragg <bob@o-hand.com> * Authored by: Robert Bragg <robert@linux.intel.com>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -23,8 +27,8 @@
#error "Only <cogl/cogl.h> can be included directly." #error "Only <cogl/cogl.h> can be included directly."
#endif #endif
#ifndef __COGL_MESH_H__ #ifndef __COGL_VERTEX_BUFFER_H__
#define __COGL_MESH_H__ #define __COGL_VERTEX_BUFFER_H__
#include <glib.h> #include <glib.h>
#include <cogl/cogl-types.h> #include <cogl/cogl-types.h>
@ -32,42 +36,42 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/** /**
* SECTION:cogl-mesh * SECTION:cogl-vertex-buffer
* @short_description: An API for submitting extensible arrays of vertex * @short_description: An API for submitting extensible arrays of vertex
* attributes to OpenGL in a way that aims to minimise * attributes to OpenGL in a way that aims to minimise
* copying or reformatting of the original data. * copying or reformatting of the original data.
* *
* The Mesh API is designed to be a fairly raw mechanism for developers * The Attributes Buffer API is designed to be a fairly raw mechanism for
* to be able to submit geometry to Cogl in a format that can be directly * developers to be able to submit geometry to Cogl in a format that can be
* consumed by an OpenGL driver and with awareness of the specific hardware * directly consumed by an OpenGL driver and with awareness of the specific
* being used then costly format conversion can also be avoided. * hardware being used then costly format conversion can also be avoided.
* *
* They are designed to work on top of buffer objects and developers should * They are designed to work on top of buffer objects and developers should
* understand that mesh objects are not cheap to create but once they * understand that attribute buffers are not that cheap to create but once they
* have been submitted they are stored in GPU addressable memory and can * have been submitted they can be stored in GPU addressable memory and can
* be quickly reused. * be quickly reused.
* *
* Although this API does allow you to modify mesh objects after they have * Although this API does allow you to modify attribute buffers after they have
* been submitted to the GPU you must note that modification is still * been submitted to the GPU you must note that modification is also not that
* not cheap, so if at all possible think of tricks that let you reuse * cheap, so if at all possible think of tricks that let you reuse a static
* a static buffer. To help with this, it is possible to enable and disable * buffer. To help with this, it is possible to enable and disable individual
* individual attributes cheaply. * attributes cheaply.
* *
* Take for example a mesh representing an elipse. If you were to submit * Take for example attributes representing an elipse. If you were to submit
* a mesh with color attributes, texture coordinates and normals, then * color attributes, texture coordinates and normals, then you would be able
* you would be able to draw an elipses in the following different ways * to draw an elipses in the following different ways without modifying
* without creating a new mesh: * the vertex buffer, only by changing your source material.
* <itemizedlist> * <itemizedlist>
* <listitem>Flat colored elipse</listitem> * <listitem>Flat colored elipse</listitem>
* <listitem>Textured elipse</listitem> * <listitem>Textured elipse</listitem>
* <listitem>Smoothly lit textured elipse blended with the color.</listitem> * <listitem>Smoothly lit textured elipse blended with the color.</listitem>
* </itemizedlist> * </itemizedlist>
*
* Another trick that can be used is submitting a highly detailed mesh
* and then using cogl_mesh_draw_range_elements to sample lower resolution
* geometry out from a fixed mesh.
* *
* The API doesn't currently give you any control over the actual buffer * Another trick that can be used is submitting highly detailed vertices and
* then using cogl_vertex_buffer_draw_range_elements to sample sub-sets of
* the geometry or lower resolution geometry out from a fixed buffer.
*
* The API doesn't currently give you any control over the actual OpenGL buffer
* objects that are created, but you can expect that when you first submit * objects that are created, but you can expect that when you first submit
* your attributes they start off in one or more GL_STATIC_DRAW buffers. * your attributes they start off in one or more GL_STATIC_DRAW buffers.
* If you then update some of your attributes; then these attributes will * If you then update some of your attributes; then these attributes will
@ -75,18 +79,18 @@ G_BEGIN_DECLS
*/ */
/** /**
* cogl_mesh_new: * cogl_vertex_buffer_new:
* @n_vertices: The number of vertices that will make up your mesh. * @n_vertices: The number of vertices that your attributes will correspond to.
* *
* This creates a Cogl handle for a new mesh that you can then start to add * This creates a Cogl handle for a new vertex buffer that you can then start
* attributes too. * to add attributes too.
*/ */
CoglHandle CoglHandle
cogl_mesh_new (guint n_vertices); cogl_vertex_buffer_new (guint n_vertices);
/** /**
* cogl_mesh_add_attribute: * cogl_vertex_buffer_add:
* @handle: A Cogl mesh handle * @handle: A vertex buffer handle
* @attribute_name: The name of your attribute. It should be a valid GLSL * @attribute_name: The name of your attribute. It should be a valid GLSL
* variable name and standard attribute types must use one * variable name and standard attribute types must use one
* of following built-in names: (Note: they correspond to the * of following built-in names: (Note: they correspond to the
@ -115,90 +119,106 @@ cogl_mesh_new (guint n_vertices);
* stride for both attributes is 6. The special value 0 means the * stride for both attributes is 6. The special value 0 means the
* values are stored sequentially in memory. * values are stored sequentially in memory.
* @pointer: This addresses the first attribute in the vertex array. (This * @pointer: This addresses the first attribute in the vertex array. (This
* must remain valid until you call cogl_mesh_submit) * must remain valid until you call cogl_vertex_buffer_submit)
* *
* This function lets you add an attribute to a mesh. You either use one * This function lets you add an attribute to a buffer. You either use one
* of the built-in names to add standard attributes, like positions, colors * of the built-in names to add standard attributes, like positions, colors
* and normals or you can add custom attributes for use in shaders. * and normals or you can add custom attributes for use in shaders.
* *
* Note: The number of vertices declared when creating the mesh is used to * Note: The number of vertices declared when first creating the vertex
* determine how many attribute values will be read from the supplied pointer. * buffer is used to determine how many attribute values will be read from the
* supplied pointer.
* *
* Note: the data supplied here isn't copied anywhere until you call * Note: the data supplied here isn't copied anywhere until you call
* cogl_mesh_submit, so the supplied pointer must remain valid until then. * cogl_vertex_buffer_submit, so the supplied pointer must remain valid
* (This is an important optimisation since we can't create a buffer * until then.
* object until we know about all the attributes, and repeatedly copying * (This is an important optimisation since we can't create the underlying
* large buffers of vertex data may be very costly) If you add attributes * OpenGL buffer object until we know about all the attributes, and repeatedly
* after submitting then you will need to re-call cogl_mesh_submit to * copying large buffers of vertex data may be very costly) If you add
* commit the changes to the GPU. (Be carefull to minimize the number of * attributes after submitting then you will need to re-call
* calls to cogl_mesh_submit though) * cogl_vertex_buffer_submit to commit the changes to the GPU. (Be carefull
* to minimize the number of calls to cogl_vertex_buffer_submit though)
* *
* Note: If you are interleving attributes it is assumed that that each * Note: If you are interleving attributes it is assumed that that each
* interleaved attribute starts no farther than +- stride bytes from * interleaved attribute starts no farther than +- stride bytes from the other
* the other attributes it is interleved with. I.e. this is ok: * attributes it is interleved with. I.e. this is ok:
* |-0-0-0-0-0-0-0-0-0-0| * |-0-0-0-0-0-0-0-0-0-0|
* This is not ok: * This is not ok:
* |- - - - -0-0-0-0-0-0 0 0 0 0| * |- - - - -0-0-0-0-0-0 0 0 0 0|
* (Though you can have multiple groups of interleved attributes) * (Though you can have multiple groups of interleved attributes)
*/ */
void void
cogl_mesh_add_attribute (CoglHandle handle, cogl_vertex_buffer_add (CoglHandle handle,
const char *attribute_name, const char *attribute_name,
guint8 n_components, guint8 n_components,
GLenum gl_type, GLenum gl_type,
gboolean normalized, gboolean normalized,
guint16 stride, guint16 stride,
const void *pointer); const void *pointer);
/** /**
* cogl_mesh_delete_attribute: * cogl_vertex_buffer_delete:
* @handle: A Cogl mesh handle * @handle: A vertex buffer handle
* @attribute_name: The name of a previously added attribute * @attribute_name: The name of a previously added attribute
* *
* This function deletes an attribute from a mesh. You will need to * This function deletes an attribute from a buffer. You will need to
* call cogl_mesh_submit to commit this change to the GPU. * call cogl_vertex_buffer_submit to commit this change to the GPU.
*/ */
void void
cogl_mesh_delete_attribute (CoglHandle handle, cogl_vertex_buffer_delete (CoglHandle handle,
const char *attribute_name); const char *attribute_name);
/** /**
* cogl_mesh_enable_attribute: * cogl_vertex_buffer_enable:
* @handle: A Cogl mesh handle * @handle: A vertex buffer handle
* @attribute_name: The name of the attribute you want to enable * @attribute_name: The name of the attribute you want to enable
* *
* This function enables a previosuly added attribute * This function enables a previosuly added attribute
* *
* Since it is costly to create new mesh objects, then to make individual mesh * Since it can be costly to add and remove new attributes to buffers; to make
* objects more reuseable it is possible to enable and disable attributes * individual buffers more reuseable it is possible to enable and disable
* before using a mesh for drawing. * attributes before using a buffer for drawing.
* *
* Note: You don't need to call cogl_mesh_submit after using this function * Note: You don't need to call cogl_vertex_buffer_submit after using this
* function
*/ */
void void
cogl_mesh_enable_attribute (CoglHandle handle, cogl_vertex_buffer_enable (CoglHandle handle,
const char *attribute_name); const char *attribute_name);
/** /**
* cogl_mesh_disable_attribute: * cogl_vertex_buffer_submit:
* @handle: A Cogl mesh handle * @handle: A vertex buffer handle
*
* This function copies all the user added attributes into buffer objects
* managed by the OpenGL driver.
*
* You should aim to minimize calls to this function.
*/
void
cogl_vertex_buffer_submit (CoglHandle handle);
/**
* cogl_vertex_buffer_disable:
* @handle: A vertex buffer handle
* @attribute_name: The name of the attribute you want to disable * @attribute_name: The name of the attribute you want to disable
* *
* This function disables a previosuly added attribute * This function disables a previosuly added attribute
* *
* Since it is costly to create new mesh objects, then to make individual mesh * Since it can be costly to add and remove new attributes to buffers; to make
* objects more reuseable it is possible to enable and disable attributes * individual buffers more reuseable it is possible to enable and disable
* before using a mesh for drawing. * attributes before using a buffer for drawing.
* *
* Note: You don't need to call cogl_mesh_submit after using this function * Note: You don't need to call cogl_vertex_buffer_submit after using this
* function
*/ */
void void
cogl_mesh_disable_attribute (CoglHandle handle, cogl_vertex_buffer_disable (CoglHandle handle,
const char *attribute_name); const char *attribute_name);
/** /**
* cogl_mesh_draw_arrays: * cogl_vertex_buffer_draw:
* @handle: A Cogl mesh handle * @handle: A vertex buffer handle
* @mode: Specifies how the vertices should be interpreted, and should be * @mode: Specifies how the vertices should be interpreted, and should be
* a valid GL primitive type: * a valid GL primitive type:
* <itemizedlist> * <itemizedlist>
@ -215,17 +235,17 @@ cogl_mesh_disable_attribute (CoglHandle handle,
* @count: Specifies the number of vertices you want to draw. * @count: Specifies the number of vertices you want to draw.
* *
* This function lets you draw geometry using all or a subset of the * This function lets you draw geometry using all or a subset of the
* vertices in a mesh object. * vertices in a vertex buffer.
*/ */
void void
cogl_mesh_draw_arrays (CoglHandle handle, cogl_vertex_buffer_draw (CoglHandle handle,
GLenum mode, GLenum mode,
GLint first, GLint first,
GLsizei count); GLsizei count);
/** /**
* cogl_mesh_draw_range_elements: * cogl_vertex_buffer_draw_range_elements:
* @handle: A Cogl mesh handle * @handle: A vertex buffer handle
* @mode: Specifies how the vertices should be interpreted, and should be * @mode: Specifies how the vertices should be interpreted, and should be
* a valid GL primitive type: * a valid GL primitive type:
* <itemizedlist> * <itemizedlist>
@ -238,11 +258,11 @@ cogl_mesh_draw_arrays (CoglHandle handle,
* <listitem>GL_TRIANGLES</listitem> * <listitem>GL_TRIANGLES</listitem>
* </itemizedlist> * </itemizedlist>
* (Note: only types available in GLES are listed) * (Note: only types available in GLES are listed)
* @start: Specifies the minimum vertex index contained in indices * @min_index: Specifies the minimum vertex index contained in indices
* @end: Specifies the maximum vertex index contained in indices * @max_index: Specifies the maximum vertex index contained in indices
* @count: Specifies the number of vertices you want to draw. * @count: Specifies the number of vertices you want to draw.
* @type: Specifies the data type used for the indices, and must be * @indices_type: Specifies the data type used for the indices, and must be
* one of: * one of:
* <itemizedlist> * <itemizedlist>
* <listitem>GL_UNSIGNED_BYTE</listitem> * <listitem>GL_UNSIGNED_BYTE</listitem>
* <listitem>GL_UNSIGNED_SHORT</listitem> * <listitem>GL_UNSIGNED_SHORT</listitem>
@ -251,49 +271,38 @@ cogl_mesh_draw_arrays (CoglHandle handle,
* @indices: Specifies the address of your array of indices * @indices: Specifies the address of your array of indices
* *
* This function lets you use an array of indices to specify the vertices * This function lets you use an array of indices to specify the vertices
* within your mesh pbject that you want to draw. * within your vertex buffer that you want to draw.
*/ */
void void
cogl_mesh_draw_range_elements (CoglHandle handle, cogl_vertex_buffer_draw_range_elements (CoglHandle handle,
GLenum mode, GLenum mode,
GLuint start, GLuint min_index,
GLuint end, GLuint max_index,
GLsizei count, GLsizei count,
GLenum type, GLenum indices_type,
const GLvoid *indices); const GLvoid *indices);
/** /**
* cogl_mesh_submit: * cogl_vertex_buffer_ref:
* @handle: A Cogl mesh handle
*
* This function copies all the user added attributes into a buffer object
* managed by the OpenGL driver.
*
* After the attributes have been submitted, then you may no longer add or
* remove attributes from a mesh, though you can enable or disable them.
*/
void
cogl_mesh_submit (CoglHandle handle);
/**
* cogl_mesh_ref:
* @handle: a @CoglHandle. * @handle: a @CoglHandle.
* *
* Increment the reference count for a cogl mesh. * Increment the reference count for a vertex buffer
* *
* Returns: the @handle. * Returns: the @handle.
*/ */
CoglHandle cogl_mesh_ref (CoglHandle handle); CoglHandle
cogl_vertex_buffer_ref (CoglHandle handle);
/** /**
* cogl_mesh_unref: * cogl_vertex_buffer_unref:
* @handle: a @CoglHandle. * @handle: a @CoglHandle.
* *
* Deccrement the reference count for a cogl mesh. * Decrement the reference count for a vertex buffer
*/ */
void cogl_mesh_unref (CoglHandle handle); void
cogl_vertex_buffer_unref (CoglHandle handle);
G_END_DECLS G_END_DECLS
#endif /* __COGL_MESH_H__ */ #endif /* __COGL_VERTEX_BUFFER_H__ */

113
cogl.h.in
View File

@ -34,6 +34,7 @@
#include <cogl/cogl-mesh.h> #include <cogl/cogl-mesh.h>
#include <cogl/cogl-matrix.h> #include <cogl/cogl-matrix.h>
#include <cogl/cogl-vertex-buffer.h>
#include <cogl/cogl-fixed.h> #include <cogl/cogl-fixed.h>
#include <cogl/cogl-color.h> #include <cogl/cogl-color.h>
#include <cogl/cogl-offscreen.h> #include <cogl/cogl-offscreen.h>
@ -145,10 +146,10 @@ void cogl_get_bitmasks (gint *red,
* Replaces the current projection matrix with a perspective matrix * Replaces the current projection matrix with a perspective matrix
* based on the provided values. * based on the provided values.
*/ */
void cogl_perspective (CoglFixed fovy, void cogl_perspective (float fovy,
CoglFixed aspect, float aspect,
CoglFixed z_near, float z_near,
CoglFixed z_far); float z_far);
/** /**
* cogl_frustum: * cogl_frustum:
@ -164,12 +165,12 @@ void cogl_perspective (CoglFixed fovy,
* *
* Since: 0.8.2 * Since: 0.8.2
*/ */
void cogl_frustum (CoglFixed left, void cogl_frustum (float left,
CoglFixed right, float right,
CoglFixed bottom, float bottom,
CoglFixed top, float top,
CoglFixed z_near, float z_near,
CoglFixed z_far); float z_far);
/** /**
* cogl_setup_viewport: * cogl_setup_viewport:
@ -189,10 +190,10 @@ void cogl_frustum (CoglFixed left,
*/ */
void cogl_setup_viewport (guint width, void cogl_setup_viewport (guint width,
guint height, guint height,
CoglFixed fovy, float fovy,
CoglFixed aspect, float aspect,
CoglFixed z_near, float z_near,
CoglFixed z_far); float z_far);
/** /**
* cogl_viewport: * cogl_viewport:
@ -229,21 +230,8 @@ void cogl_pop_matrix (void);
* Multiplies the current model-view matrix by one that scales the x * Multiplies the current model-view matrix by one that scales the x
* and y axes by the given values. * and y axes by the given values.
*/ */
void cogl_scale (CoglFixed x, void cogl_scale (float x,
CoglFixed y); float y);
/**
* cogl_translatex:
* @x: Distance to translate along the x-axis
* @y: Distance to translate along the y-axis
* @z: Distance to translate along the z-axis
*
* Multiplies the current model-view matrix by one that translates the
* model along all three axes according to the given values.
*/
void cogl_translatex (CoglFixed x,
CoglFixed y,
CoglFixed z);
/** /**
* cogl_translate: * cogl_translate:
@ -251,16 +239,15 @@ void cogl_translatex (CoglFixed x,
* @y: Distance to translate along the y-axis * @y: Distance to translate along the y-axis
* @z: Distance to translate along the z-axis * @z: Distance to translate along the z-axis
* *
* Integer version of cogl_translatex(). Multiplies the current * Multiplies the current model-view matrix by one that translates the
* model-view matrix by one that translates the model along all three * model along all three axes according to the given values.
* axes according to the given values.
*/ */
void cogl_translate (gint x, void cogl_translate (float x,
gint y, float y,
gint z); float z);
/** /**
* cogl_rotatex: * cogl_rotate:
* @angle: Angle in degrees to rotate. * @angle: Angle in degrees to rotate.
* @x: X-component of vertex to rotate around. * @x: X-component of vertex to rotate around.
* @y: Y-component of vertex to rotate around. * @y: Y-component of vertex to rotate around.
@ -272,55 +259,39 @@ void cogl_translate (gint x,
* degrees about the vertex (0, 0, 1) causes a small counter-clockwise * degrees about the vertex (0, 0, 1) causes a small counter-clockwise
* rotation. * rotation.
*/ */
void cogl_rotatex (CoglFixed angle, void cogl_rotate (float angle,
gint x, float x,
gint y, float y,
gint z); float z);
/**
* cogl_rotate:
* @angle: Angle in degrees to rotate.
* @x: X-component of vertex to rotate around.
* @y: Y-component of vertex to rotate around.
* @z: Z-component of vertex to rotate around.
*
* Integer version of cogl_rotatex(). Multiplies the current
* model-view matrix by one that rotates the model around the vertex
* specified by @x, @y and @z.
*/
void cogl_rotate (gint angle,
gint x,
gint y,
gint z);
/** /**
* cogl_get_modelview_matrix: * cogl_get_modelview_matrix:
* @m: pointer to a 4x4 array of #CoglFixed<!-- -->s to receive the matrix * @m: pointer to a 4x4 array of #float<!-- -->s to receive the matrix
* *
* Stores the current model-view matrix in @m. The matrix is in * Stores the current model-view matrix in @m. The matrix is in
* column-major order. * column-major order.
*/ */
void cogl_get_modelview_matrix (CoglFixed m[16]); void cogl_get_modelview_matrix (float m[16]);
/** /**
* cogl_get_projection_matrix: * cogl_get_projection_matrix:
* @m: pointer to a 4x4 array of #CoglFixed<!-- -->s to receive the matrix * @m: pointer to a 4x4 array of #float<!-- -->s to receive the matrix
* *
* Stores the current projection matrix in @m. The matrix is in * Stores the current projection matrix in @m. The matrix is in
* column-major order. * column-major order.
*/ */
void cogl_get_projection_matrix (CoglFixed m[16]); void cogl_get_projection_matrix (float m[16]);
/** /**
* cogl_get_viewport: * cogl_get_viewport:
* @v: pointer to a 4 element array of #CoglFixed<!-- -->s to * @v: pointer to a 4 element array of #float<!-- -->s to
* receive the viewport dimensions. * receive the viewport dimensions.
* *
* Stores the current viewport in @v. @v[0] and @v[1] get the x and y * Stores the current viewport in @v. @v[0] and @v[1] get the x and y
* position of the viewport and @v[2] and @v[3] get the width and * position of the viewport and @v[2] and @v[3] get the width and
* height. * height.
*/ */
void cogl_get_viewport (CoglFixed v[4]); void cogl_get_viewport (float v[4]);
/** /**
* cogl_clip_set: * cogl_clip_set:
@ -338,10 +309,10 @@ void cogl_get_viewport (CoglFixed v[4]);
* The rectangle is intersected with the current clip region. To undo * The rectangle is intersected with the current clip region. To undo
* the effect of this function, call cogl_clip_unset(). * the effect of this function, call cogl_clip_unset().
*/ */
void cogl_clip_set (CoglFixed x_offset, void cogl_clip_set (float x_offset,
CoglFixed y_offset, float y_offset,
CoglFixed width, float width,
CoglFixed height); float height);
/** /**
* cogl_clip_set_from_path: * cogl_clip_set_from_path:
@ -444,8 +415,8 @@ void cogl_enable_backface_culling (gboolean setting);
* comparing with the value in @ref. The default function is CGL_ALWAYS the * comparing with the value in @ref. The default function is CGL_ALWAYS the
* initial reference value is 1.0. * initial reference value is 1.0.
*/ */
void cogl_alpha_func (COGLenum func, void cogl_alpha_func (COGLenum func,
CoglFixed ref); float ref);
/** /**
* cogl_fog_set: * cogl_fog_set:
@ -462,9 +433,9 @@ void cogl_alpha_func (COGLenum func,
* cogl_paint_init(). * cogl_paint_init().
*/ */
void cogl_fog_set (const CoglColor *fog_color, void cogl_fog_set (const CoglColor *fog_color,
CoglFixed density, float density,
CoglFixed z_near, float z_near,
CoglFixed z_far); float z_far);
/** /**
* cogl_paint_init: * cogl_paint_init:

View File

@ -30,6 +30,7 @@ libclutter_cogl_common_la_SOURCES = \
cogl-clip-stack.c \ cogl-clip-stack.c \
cogl-fixed.c \ cogl-fixed.c \
cogl-color.c \ cogl-color.c \
cogl-mesh.c \ cogl-vertex-buffer-private.h \
cogl-vertex-buffer.c \
cogl-matrix.c \ cogl-matrix.c \
cogl-material.c cogl-material.c

View File

@ -84,6 +84,20 @@ cogl_bitmap_error_quark (void)
return g_quark_from_static_string ("cogl-bitmap-error-quark"); return g_quark_from_static_string ("cogl-bitmap-error-quark");
} }
gboolean
_cogl_bitmap_get_size_from_file (const gchar *filename,
gint *width,
gint *height)
{
if (width)
*width = 0;
if (height)
*height = 0;
return TRUE;
}
/* the error does not contain the filename as the caller already has it */ /* the error does not contain the filename as the caller already has it */
gboolean gboolean
_cogl_bitmap_from_file (CoglBitmap *bmp, _cogl_bitmap_from_file (CoglBitmap *bmp,
@ -177,9 +191,22 @@ _cogl_bitmap_from_file (CoglBitmap *bmp,
#elif defined(USE_GDKPIXBUF) #elif defined(USE_GDKPIXBUF)
gboolean gboolean
_cogl_bitmap_from_file (CoglBitmap *bmp, _cogl_bitmap_get_size_from_file (const gchar *filename,
const gchar *filename, gint *width,
GError **error) gint *height)
{
g_return_val_if_fail (filename != NULL, FALSE);
if (gdk_pixbuf_get_file_info (filename, width, height) != NULL)
return TRUE;
return FALSE;
}
gboolean
_cogl_bitmap_from_file (CoglBitmap *bmp,
const gchar *filename,
GError **error)
{ {
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
gboolean has_alpha; gboolean has_alpha;
@ -198,11 +225,13 @@ _cogl_bitmap_from_file (CoglBitmap *bmp,
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (bmp == NULL) return FALSE; if (bmp == NULL)
return FALSE;
/* Load from file using GdkPixbuf */ /* Load from file using GdkPixbuf */
pixbuf = gdk_pixbuf_new_from_file (filename, error); pixbuf = gdk_pixbuf_new_from_file (filename, error);
if (pixbuf == NULL) return FALSE; if (pixbuf == NULL)
return FALSE;
/* Get pixbuf properties */ /* Get pixbuf properties */
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf); has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
@ -278,6 +307,20 @@ _cogl_bitmap_from_file (CoglBitmap *bmp,
#include "stb_image.c" #include "stb_image.c"
gboolean
_cogl_bitmap_get_size_from_file (const gchar *filename,
gint *width,
gint *height)
{
if (width)
*width = 0;
if (height)
*height = 0;
return TRUE;
}
gboolean gboolean
_cogl_bitmap_from_file (CoglBitmap *bmp, _cogl_bitmap_from_file (CoglBitmap *bmp,
const gchar *filename, const gchar *filename,
@ -290,11 +333,15 @@ _cogl_bitmap_from_file (CoglBitmap *bmp,
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (bmp == NULL) return FALSE; if (bmp == NULL)
return FALSE;
/* Load from file using stb */ /* Load from file using stb */
pixels = stbi_load (filename, &width, &height, &stb_pixel_format, STBI_rgb_alpha); pixels = stbi_load (filename,
if (pixels == NULL) return FALSE; &width, &height, &stb_pixel_format,
STBI_rgb_alpha);
if (pixels == NULL)
return FALSE;
/* Store bitmap info */ /* Store bitmap info */
bmp->data = g_memdup (pixels, height * width * 4); bmp->data = g_memdup (pixels, height * width * 4);

View File

@ -148,3 +148,42 @@ _cogl_bitmap_copy_subregion (CoglBitmap *src,
dstdata += dst->rowstride; dstdata += dst->rowstride;
} }
} }
gboolean
cogl_bitmap_get_size_from_file (const gchar *filename,
gint *width,
gint *height)
{
return _cogl_bitmap_get_size_from_file (filename, width, height);
}
CoglBitmap *
cogl_bitmap_new_from_file (const gchar *filename,
GError **error)
{
CoglBitmap bmp;
g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_HANDLE);
/* Try loading with imaging backend */
if (!_cogl_bitmap_from_file (&bmp, filename, error))
{
/* Try fallback */
if (!_cogl_bitmap_fallback_from_file (&bmp, filename))
return NULL;
else if (error && *error)
{
g_error_free (*error);
*error = NULL;
}
}
return (CoglBitmap *) g_memdup (&bmp, sizeof (CoglBitmap));
}
void
cogl_bitmap_free (CoglBitmap *bmp)
{
g_free (bmp->data);
g_free (bmp);
}

View File

@ -28,8 +28,6 @@
#include <glib.h> #include <glib.h>
typedef struct _CoglBitmap CoglBitmap;
struct _CoglBitmap struct _CoglBitmap
{ {
guchar *data; guchar *data;
@ -92,4 +90,9 @@ _cogl_bitmap_copy_subregion (CoglBitmap *src,
gint width, gint width,
gint height); gint height);
gboolean
_cogl_bitmap_get_size_from_file (const gchar *filename,
gint *width,
gint *height);
#endif /* __COGL_BITMAP_H */ #endif /* __COGL_BITMAP_H */

View File

@ -35,24 +35,24 @@
/* These are defined in the particular backend (float in GL vs fixed /* These are defined in the particular backend (float in GL vs fixed
in GL ES) */ in GL ES) */
void _cogl_set_clip_planes (CoglFixed x, void _cogl_set_clip_planes (float x,
CoglFixed y, float y,
CoglFixed width, float width,
CoglFixed height); float height);
void _cogl_add_stencil_clip (CoglFixed x, void _cogl_add_stencil_clip (float x,
CoglFixed y, float y,
CoglFixed width, float width,
CoglFixed height, float height,
gboolean first); gboolean first);
void _cogl_add_path_to_stencil_buffer (CoglFixedVec2 nodes_min, void _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min,
CoglFixedVec2 nodes_max, floatVec2 nodes_max,
guint path_size, guint path_size,
CoglPathNode *path, CoglPathNode *path,
gboolean merge); gboolean merge);
void _cogl_enable_clip_planes (void); void _cogl_enable_clip_planes (void);
void _cogl_disable_clip_planes (void); void _cogl_disable_clip_planes (void);
void _cogl_disable_stencil_buffer (void); void _cogl_disable_stencil_buffer (void);
void _cogl_set_matrix (const CoglFixed *matrix); void _cogl_set_matrix (const float *matrix);
typedef struct _CoglClipStack CoglClipStack; typedef struct _CoglClipStack CoglClipStack;
@ -75,13 +75,13 @@ struct _CoglClipStackEntryRect
CoglClipStackEntryType type; CoglClipStackEntryType type;
/* The rectangle for this clip */ /* The rectangle for this clip */
CoglFixed x_offset; float x_offset;
CoglFixed y_offset; float y_offset;
CoglFixed width; float width;
CoglFixed height; float height;
/* The matrix that was current when the clip was set */ /* The matrix that was current when the clip was set */
CoglFixed matrix[16]; float matrix[16];
}; };
struct _CoglClipStackEntryPath struct _CoglClipStackEntryPath
@ -89,20 +89,20 @@ struct _CoglClipStackEntryPath
CoglClipStackEntryType type; CoglClipStackEntryType type;
/* The matrix that was current when the clip was set */ /* The matrix that was current when the clip was set */
CoglFixed matrix[16]; float matrix[16];
CoglFixedVec2 path_nodes_min; floatVec2 path_nodes_min;
CoglFixedVec2 path_nodes_max; floatVec2 path_nodes_max;
guint path_size; guint path_size;
CoglPathNode path[1]; CoglPathNode path[1];
}; };
void void
cogl_clip_set (CoglFixed x_offset, cogl_clip_set (float x_offset,
CoglFixed y_offset, float y_offset,
CoglFixed width, float width,
CoglFixed height) float height)
{ {
CoglClipStackEntryRect *entry; CoglClipStackEntryRect *entry;
CoglClipStack *stack; CoglClipStack *stack;

View File

@ -58,18 +58,18 @@ cogl_color_set_from_4d (CoglColor *dest,
} }
void void
cogl_color_set_from_4x (CoglColor *dest, cogl_color_set_from_4f (CoglColor *dest,
CoglFixed red, float red,
CoglFixed green, float green,
CoglFixed blue, float blue,
CoglFixed alpha) float alpha)
{ {
g_return_if_fail (dest != NULL); g_return_if_fail (dest != NULL);
dest->red = COGL_FIXED_TO_INT (red * 255); dest->red = (red * 255);
dest->green = COGL_FIXED_TO_INT (green * 255); dest->green = (green * 255);
dest->blue = COGL_FIXED_TO_INT (blue * 255); dest->blue = (blue * 255);
dest->alpha = COGL_FIXED_TO_INT (alpha * 255); dest->alpha = (alpha * 255);
} }
unsigned char unsigned char
@ -84,10 +84,10 @@ cogl_color_get_red_float (const CoglColor *color)
return (float) color->red / 255.0; return (float) color->red / 255.0;
} }
CoglFixed float
cogl_color_get_red (const CoglColor *color) cogl_color_get_red (const CoglColor *color)
{ {
return COGL_FIXED_FROM_FLOAT ((float) color->red / 255.0); return ((float) color->red / 255.0);
} }
unsigned char unsigned char
@ -102,10 +102,10 @@ cogl_color_get_green_float (const CoglColor *color)
return (float) color->green / 255.0; return (float) color->green / 255.0;
} }
CoglFixed float
cogl_color_get_green (const CoglColor *color) cogl_color_get_green (const CoglColor *color)
{ {
return COGL_FIXED_FROM_FLOAT ((float) color->green / 255.0); return ((float) color->green / 255.0);
} }
unsigned char unsigned char
@ -120,10 +120,10 @@ cogl_color_get_blue_float (const CoglColor *color)
return (float) color->blue / 255.0; return (float) color->blue / 255.0;
} }
CoglFixed float
cogl_color_get_blue (const CoglColor *color) cogl_color_get_blue (const CoglColor *color)
{ {
return COGL_FIXED_FROM_FLOAT ((float) color->blue / 255.0); return ((float) color->blue / 255.0);
} }
unsigned char unsigned char
@ -138,10 +138,10 @@ cogl_color_get_alpha_float (const CoglColor *color)
return (float) color->alpha / 255.0; return (float) color->alpha / 255.0;
} }
CoglFixed float
cogl_color_get_alpha (const CoglColor *color) cogl_color_get_alpha (const CoglColor *color)
{ {
return COGL_FIXED_FROM_FLOAT ((float) color->alpha / 255.0); return ((float) color->alpha / 255.0);
} }
void void
@ -157,13 +157,13 @@ cogl_set_source_color4ub (guint8 red,
} }
void void
cogl_set_source_color4x (CoglFixed red, cogl_set_source_color4f (float red,
CoglFixed green, float green,
CoglFixed blue, float blue,
CoglFixed alpha) float alpha)
{ {
CoglColor c = { 0, }; CoglColor c = { 0, };
cogl_color_set_from_4x (&c, red, green, blue, alpha); cogl_color_set_from_4f (&c, red, green, blue, alpha);
cogl_set_source_color (&c); cogl_set_source_color (&c);
} }

View File

@ -10,10 +10,12 @@
* *
* Currently contains 257 entries. * Currently contains 257 entries.
* *
* The current error (compared to system sin) is about * The current maximum absolute error is about 1.9e-0.5
* 0.5% for values near the start of the table where the * and is greatest around pi/2 where the second derivative
* curve is steep, but improving rapidly. If this precision * of sin(x) is greatest. If greater accuracy is needed,
* is not enough, we can increase the size of the table * modestly increasing the table size, or maybe using
* quadratic interpolation would drop the interpolation
* error below the precision limits of CoglFixed.
*/ */
static const CoglFixed sin_tbl[] = static const CoglFixed sin_tbl[] =
{ {
@ -270,7 +272,7 @@ static const CoglFixed sqrt_tbl[] =
/* the difference of the angle for two adjacent values in the /* the difference of the angle for two adjacent values in the
* sin_tbl table, expressed as CoglFixed number * sin_tbl table, expressed as CoglFixed number
*/ */
#define COGL_SIN_STEP 0x00000192 static const gint sin_tbl_size = G_N_ELEMENTS (sin_tbl) - 1;
static const double _magic = 68719476736.0 * 1.5; static const double _magic = 68719476736.0 * 1.5;
@ -363,7 +365,9 @@ CoglFixed
cogl_fixed_sin (CoglFixed angle) cogl_fixed_sin (CoglFixed angle)
{ {
int sign = 1, indx1, indx2; int sign = 1, indx1, indx2;
CoglFixed low, high, d1, d2; CoglFixed low, high;
CoglFixed p1, p2;
CoglFixed d1, d2;
/* convert negative angle to positive + sign */ /* convert negative angle to positive + sign */
if ((int) angle < 0) if ((int) angle < 0)
@ -401,14 +405,17 @@ cogl_fixed_sin (CoglFixed angle)
} }
/* Calculate indices of the two nearest values in our table /* Calculate indices of the two nearest values in our table
* and return weighted average * and return weighted average.
*
* We multiple first than divide to preserve precision. Since
* angle is in the first quadrant, angle * SIN_TBL_SIZE (=256)
* can't overflow.
* *
* Handle the end of the table gracefully * Handle the end of the table gracefully
*/ */
indx1 = COGL_FIXED_DIV (angle, COGL_SIN_STEP); indx1 = (angle * sin_tbl_size) / COGL_FIXED_PI_2;
indx1 = COGL_FIXED_TO_INT (indx1);
if (indx1 == (G_N_ELEMENTS (sin_tbl) - 1)) if (indx1 == sin_tbl_size)
{ {
indx2 = indx1; indx2 = indx1;
indx1 = indx2 - 1; indx1 = indx2 - 1;
@ -421,10 +428,13 @@ cogl_fixed_sin (CoglFixed angle)
low = sin_tbl[indx1]; low = sin_tbl[indx1];
high = sin_tbl[indx2]; high = sin_tbl[indx2];
d1 = angle - indx1 * COGL_SIN_STEP; /* Again multiply the divide; no danger of overflow */
d2 = indx2 * COGL_SIN_STEP - angle; p1 = (indx1 * COGL_FIXED_PI_2) / sin_tbl_size;
p2 = (indx2 * COGL_FIXED_PI_2) / sin_tbl_size;
d1 = angle - p1;
d2 = p2 - angle;
angle = ((low * d2 + high * d1) / (COGL_SIN_STEP)); angle = ((low * d2 + high * d1) / (p2 - p1));
if (sign < 0) if (sign < 0)
angle = -angle; angle = -angle;
@ -481,6 +491,12 @@ cogl_angle_sin (CoglAngle angle)
return result; return result;
} }
CoglFixed
cogl_fixed_tan (CoglFixed angle)
{
return cogl_angle_tan (COGL_ANGLE_FROM_DEGX (angle));
}
CoglFixed CoglFixed
cogl_angle_tan (CoglAngle angle) cogl_angle_tan (CoglAngle angle)
{ {

View File

@ -1,143 +0,0 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Robert Bragg <bob@o-hand.com>
*
* Copyright (C) 2008 Intel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __COGL_MESH_H
#define __COGL_MESH_H
/* Note we put quite a bit into the flags here to help keep
* the down size of the CoglMeshAttribute struct below. */
typedef enum _CoglMeshAttributeFlags
{
/* Types */
/* NB: update the _TYPE_MASK below if these are changed */
COGL_MESH_ATTRIBUTE_FLAG_COLOR_ARRAY = 1<<0,
COGL_MESH_ATTRIBUTE_FLAG_NORMAL_ARRAY = 1<<1,
COGL_MESH_ATTRIBUTE_FLAG_TEXTURE_COORD_ARRAY = 1<<2,
COGL_MESH_ATTRIBUTE_FLAG_VERTEX_ARRAY = 1<<3,
COGL_MESH_ATTRIBUTE_FLAG_CUSTOM_ARRAY = 1<<4,
COGL_MESH_ATTRIBUTE_FLAG_INVALID = 1<<5,
COGL_MESH_ATTRIBUTE_FLAG_NORMALIZED = 1<<6,
COGL_MESH_ATTRIBUTE_FLAG_ENABLED = 1<<7,
/* Usage hints */
/* FIXME - flatten into one flag, since its used as a boolean */
COGL_MESH_ATTRIBUTE_FLAG_INFREQUENT_RESUBMIT = 1<<8,
COGL_MESH_ATTRIBUTE_FLAG_FREQUENT_RESUBMIT = 1<<9,
/* GL Data types */
/* NB: Update the _GL_TYPE_MASK below if these are changed */
COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_BYTE = 1<<10,
COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_UNSIGNED_BYTE = 1<<11,
COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_SHORT = 1<<12,
COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_UNSIGNED_SHORT = 1<<13,
COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_INT = 1<<14,
COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_UNSIGNED_INT = 1<<15,
COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_FLOAT = 1<<16,
COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_DOUBLE = 1<<17,
COGL_MESH_ATTRIBUTE_FLAG_SUBMITTED = 1<<18,
COGL_MESH_ATTRIBUTE_FLAG_UNUSED = 1<<19
/* XXX NB: If we need > 24 bits then look at changing the layout
* of struct _CoglMeshAttribute below */
} CoglMeshAttributeFlags;
#define COGL_MESH_ATTRIBUTE_FLAG_TYPE_MASK \
(COGL_MESH_ATTRIBUTE_FLAG_COLOR_ARRAY \
| COGL_MESH_ATTRIBUTE_FLAG_NORMAL_ARRAY \
| COGL_MESH_ATTRIBUTE_FLAG_TEXTURE_COORD_ARRAY \
| COGL_MESH_ATTRIBUTE_FLAG_VERTEX_ARRAY \
| COGL_MESH_ATTRIBUTE_FLAG_CUSTOM_ARRAY \
| COGL_MESH_ATTRIBUTE_FLAG_INVALID)
#define COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_MASK \
(COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_BYTE \
| COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_UNSIGNED_BYTE \
| COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_SHORT \
| COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_UNSIGNED_SHORT \
| COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_INT \
| COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_UNSIGNED_INT \
| COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_FLOAT \
| COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_DOUBLE)
typedef struct _CoglMeshAttribute
{
/* TODO: look at breaking up the flags into seperate
* bitfields and seperate enums */
CoglMeshAttributeFlags flags:24;
guint8 id;
GQuark name;
union _u
{
const void *pointer;
gsize vbo_offset;
} u;
gsize span_bytes;
guint16 stride;
guint8 n_components;
guint8 texture_unit;
} CoglMeshAttribute;
typedef enum _CoglMeshVBOFlags
{
COGL_MESH_VBO_FLAG_UNSTRIDED = 1<<0,
COGL_MESH_VBO_FLAG_STRIDED = 1<<1,
COGL_MESH_VBO_FLAG_MULTIPACK = 1<<2,
/* FIXME - flatten into one flag, since its used as a boolean */
COGL_MESH_VBO_FLAG_INFREQUENT_RESUBMIT = 1<<3,
COGL_MESH_VBO_FLAG_FREQUENT_RESUBMIT = 1<<4,
COGL_MESH_VBO_FLAG_SUBMITTED = 1<<5
} CoglMeshVBOFlags;
/*
* A CoglMeshVBO represents one or more attributes in a single buffer object
*/
typedef struct _CoglMeshVBO
{
CoglMeshVBOFlags flags;
GLuint vbo_name; /*!< The name of the corresponding buffer object */
gsize vbo_bytes; /*!< The lengh of the allocated buffer object in bytes */
GList *attributes;
} CoglMeshVBO;
typedef struct _CoglMesh
{
guint ref_count;
guint n_vertices; /*!< The number of vertices in the mesh */
GList *submitted_vbos; /* The VBOs currently submitted to the GPU */
/* Note: new_attributes is normally NULL and only valid while
* modifying a mesh object. */
GList *new_attributes; /*!< attributes pending submission */
} CoglMesh;
#endif /* __COGL_MESH_H */

View File

@ -33,46 +33,31 @@
#include <string.h> #include <string.h>
#include <gmodule.h> #include <gmodule.h>
#include <math.h>
#define _COGL_MAX_BEZ_RECURSE_DEPTH 16 #define _COGL_MAX_BEZ_RECURSE_DEPTH 16
/* these are defined in the particular backend(float in gl vs fixed in gles)*/ /* these are defined in the particular backend(float in gl vs fixed in gles)*/
void _cogl_path_add_node (gboolean new_sub_path, void _cogl_path_add_node (gboolean new_sub_path,
CoglFixed x, float x,
CoglFixed y); float y);
void _cogl_path_fill_nodes (); void _cogl_path_fill_nodes ();
void _cogl_path_stroke_nodes (); void _cogl_path_stroke_nodes ();
void _cogl_rectangle (gint x, void _cogl_rectangle (float x,
gint y, float y,
guint width, float width,
guint height); float height);
void _cogl_rectanglex (CoglFixed x,
CoglFixed y,
CoglFixed width,
CoglFixed height);
void void
cogl_rectangle (gint x, cogl_rectangle (float x,
gint y, float y,
guint width, float width,
guint height) float height)
{ {
cogl_clip_ensure (); cogl_clip_ensure ();
_cogl_rectangle (x, y, width, height); _cogl_rectangle (x, y, width, height);
} }
void
cogl_rectanglex (CoglFixed x,
CoglFixed y,
CoglFixed width,
CoglFixed height)
{
cogl_clip_ensure ();
_cogl_rectanglex (x, y, width, height);
}
void void
cogl_path_fill (void) cogl_path_fill (void)
{ {
@ -116,8 +101,8 @@ cogl_path_stroke_preserve (void)
} }
void void
cogl_path_move_to (CoglFixed x, cogl_path_move_to (float x,
CoglFixed y) float y)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -132,8 +117,8 @@ cogl_path_move_to (CoglFixed x,
} }
void void
cogl_path_rel_move_to (CoglFixed x, cogl_path_rel_move_to (float x,
CoglFixed y) float y)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -142,8 +127,8 @@ cogl_path_rel_move_to (CoglFixed x,
} }
void void
cogl_path_line_to (CoglFixed x, cogl_path_line_to (float x,
CoglFixed y) float y)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -154,8 +139,8 @@ cogl_path_line_to (CoglFixed x,
} }
void void
cogl_path_rel_line_to (CoglFixed x, cogl_path_rel_line_to (float x,
CoglFixed y) float y)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -181,17 +166,17 @@ cogl_path_new (void)
} }
void void
cogl_path_line (CoglFixed x1, cogl_path_line (float x1,
CoglFixed y1, float y1,
CoglFixed x2, float x2,
CoglFixed y2) float y2)
{ {
cogl_path_move_to (x1, y1); cogl_path_move_to (x1, y1);
cogl_path_line_to (x2, y2); cogl_path_line_to (x2, y2);
} }
void void
cogl_path_polyline (CoglFixed *coords, cogl_path_polyline (float *coords,
gint num_points) gint num_points)
{ {
gint c = 0; gint c = 0;
@ -203,7 +188,7 @@ cogl_path_polyline (CoglFixed *coords,
} }
void void
cogl_path_polygon (CoglFixed *coords, cogl_path_polygon (float *coords,
gint num_points) gint num_points)
{ {
cogl_path_polyline (coords, num_points); cogl_path_polyline (coords, num_points);
@ -211,10 +196,10 @@ cogl_path_polygon (CoglFixed *coords,
} }
void void
cogl_path_rectangle (CoglFixed x, cogl_path_rectangle (float x,
CoglFixed y, float y,
CoglFixed width, float width,
CoglFixed height) float height)
{ {
cogl_path_move_to (x, y); cogl_path_move_to (x, y);
cogl_path_line_to (x + width, y); cogl_path_line_to (x + width, y);
@ -224,20 +209,20 @@ cogl_path_rectangle (CoglFixed x,
} }
static void static void
_cogl_path_arc (CoglFixed center_x, _cogl_path_arc (float center_x,
CoglFixed center_y, float center_y,
CoglFixed radius_x, float radius_x,
CoglFixed radius_y, float radius_y,
CoglAngle angle_1, float angle_1,
CoglAngle angle_2, float angle_2,
CoglAngle angle_step, float angle_step,
guint move_first) guint move_first)
{ {
CoglAngle a = 0x0; float a = 0x0;
CoglFixed cosa = 0x0; float cosa = 0x0;
CoglFixed sina = 0x0; float sina = 0x0;
CoglFixed px = 0x0; float px = 0x0;
CoglFixed py = 0x0; float py = 0x0;
/* Fix invalid angles */ /* Fix invalid angles */
@ -252,11 +237,11 @@ _cogl_path_arc (CoglFixed center_x,
a = angle_1; a = angle_1;
while (a != angle_2) while (a != angle_2)
{ {
cosa = cogl_angle_cos (a); cosa = cosf (a * (G_PI/180.0));
sina = cogl_angle_sin (a); sina = sinf (a * (G_PI/180.0));
px = center_x + COGL_FIXED_MUL (cosa, radius_x); px = center_x + (cosa * radius_x);
py = center_y + COGL_FIXED_MUL (sina, radius_y); py = center_y + (sina * radius_y);
if (a == angle_1 && move_first) if (a == angle_1 && move_first)
cogl_path_move_to (px, py); cogl_path_move_to (px, py);
@ -279,24 +264,24 @@ _cogl_path_arc (CoglFixed center_x,
/* Make sure the final point is drawn */ /* Make sure the final point is drawn */
cosa = cogl_angle_cos (angle_2); cosa = cosf (angle_2 * (G_PI/180.0));
sina = cogl_angle_sin (angle_2); sina = sinf (angle_2 * (G_PI/180.0));
px = center_x + COGL_FIXED_MUL (cosa, radius_x); px = center_x + (cosa * radius_x);
py = center_y + COGL_FIXED_MUL (sina, radius_y); py = center_y + (sina * radius_y);
cogl_path_line_to (px, py); cogl_path_line_to (px, py);
} }
void void
cogl_path_arc (CoglFixed center_x, cogl_path_arc (float center_x,
CoglFixed center_y, float center_y,
CoglFixed radius_x, float radius_x,
CoglFixed radius_y, float radius_y,
CoglAngle angle_1, float angle_1,
CoglAngle angle_2) float angle_2)
{ {
CoglAngle angle_step = 10; float angle_step = 10;
/* it is documented that a move to is needed to create a freestanding /* it is documented that a move to is needed to create a freestanding
* arc * arc
*/ */
@ -308,13 +293,13 @@ cogl_path_arc (CoglFixed center_x,
void void
cogl_path_arc_rel (CoglFixed center_x, cogl_path_arc_rel (float center_x,
CoglFixed center_y, float center_y,
CoglFixed radius_x, float radius_x,
CoglFixed radius_y, float radius_y,
CoglAngle angle_1, float angle_1,
CoglAngle angle_2, float angle_2,
CoglAngle angle_step) float angle_step)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -326,50 +311,50 @@ cogl_path_arc_rel (CoglFixed center_x,
} }
void void
cogl_path_ellipse (CoglFixed center_x, cogl_path_ellipse (float center_x,
CoglFixed center_y, float center_y,
CoglFixed radius_x, float radius_x,
CoglFixed radius_y) float radius_y)
{ {
CoglAngle angle_step = 10; float angle_step = 10;
/* FIXME: if shows to be slow might be optimized /* FIXME: if shows to be slow might be optimized
* by mirroring just a quarter of it */ * by mirroring just a quarter of it */
_cogl_path_arc (center_x, center_y, _cogl_path_arc (center_x, center_y,
radius_x, radius_y, radius_x, radius_y,
0, COGL_ANGLE_FROM_DEG (360), 0, 360,
angle_step, 1 /* move first */); angle_step, 1 /* move first */);
cogl_path_close(); cogl_path_close();
} }
void void
cogl_path_round_rectangle (CoglFixed x, cogl_path_round_rectangle (float x,
CoglFixed y, float y,
CoglFixed width, float width,
CoglFixed height, float height,
CoglFixed radius, float radius,
CoglAngle arc_step) float arc_step)
{ {
CoglFixed inner_width = width - (radius << 1); float inner_width = width - (radius * 2);
CoglFixed inner_height = height - (radius << 1); float inner_height = height - (radius * 2);
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
cogl_path_move_to (x, y + radius); cogl_path_move_to (x, y + radius);
cogl_path_arc_rel (radius, 0, cogl_path_arc_rel (radius, 0,
radius, radius, radius, radius,
COGL_ANGLE_FROM_DEG (180), 180,
COGL_ANGLE_FROM_DEG (270), 270,
arc_step); arc_step);
cogl_path_line_to (ctx->path_pen.x + inner_width, cogl_path_line_to (ctx->path_pen.x + inner_width,
ctx->path_pen.y); ctx->path_pen.y);
cogl_path_arc_rel (0, radius, cogl_path_arc_rel (0, radius,
radius, radius, radius, radius,
COGL_ANGLE_FROM_DEG (-90), -90,
COGL_ANGLE_FROM_DEG (0), 0,
arc_step); arc_step);
cogl_path_line_to (ctx->path_pen.x, cogl_path_line_to (ctx->path_pen.x,
@ -377,16 +362,16 @@ cogl_path_round_rectangle (CoglFixed x,
cogl_path_arc_rel (-radius, 0, cogl_path_arc_rel (-radius, 0,
radius, radius, radius, radius,
COGL_ANGLE_FROM_DEG (0), 0,
COGL_ANGLE_FROM_DEG (90), 90,
arc_step); arc_step);
cogl_path_line_to (ctx->path_pen.x - inner_width, cogl_path_line_to (ctx->path_pen.x - inner_width,
ctx->path_pen.y); ctx->path_pen.y);
cogl_path_arc_rel (0, -radius, cogl_path_arc_rel (0, -radius,
radius, radius, radius, radius,
COGL_ANGLE_FROM_DEG (90), 90,
COGL_ANGLE_FROM_DEG (180), 180,
arc_step); arc_step);
cogl_path_close (); cogl_path_close ();
@ -400,14 +385,14 @@ _cogl_path_bezier3_sub (CoglBezCubic *cubic)
CoglBezCubic *cleft; CoglBezCubic *cleft;
CoglBezCubic *cright; CoglBezCubic *cright;
CoglBezCubic *c; CoglBezCubic *c;
CoglFixedVec2 dif1; floatVec2 dif1;
CoglFixedVec2 dif2; floatVec2 dif2;
CoglFixedVec2 mm; floatVec2 mm;
CoglFixedVec2 c1; floatVec2 c1;
CoglFixedVec2 c2; floatVec2 c2;
CoglFixedVec2 c3; floatVec2 c3;
CoglFixedVec2 c4; floatVec2 c4;
CoglFixedVec2 c5; floatVec2 c5;
gint cindex; gint cindex;
/* Put first curve on stack */ /* Put first curve on stack */
@ -418,16 +403,13 @@ _cogl_path_bezier3_sub (CoglBezCubic *cubic)
{ {
c = &cubics[cindex]; c = &cubics[cindex];
#define CFX_MUL2(x) ((x) << 1)
#define CFX_MUL3(x) (((x) << 1) + (x))
#define CFX_SQ(x) COGL_FIXED_MUL (x, x)
/* Calculate distance of control points from their /* Calculate distance of control points from their
* counterparts on the line between end points */ * counterparts on the line between end points */
dif1.x = CFX_MUL3 (c->p2.x) - CFX_MUL2 (c->p1.x) - c->p4.x; dif1.x = (c->p2.x * 3) - (c->p1.x * 2) - c->p4.x;
dif1.y = CFX_MUL3 (c->p2.y) - CFX_MUL2 (c->p1.y) - c->p4.y; dif1.y = (c->p2.y * 3) - (c->p1.y * 2) - c->p4.y;
dif2.x = CFX_MUL3 (c->p3.x) - CFX_MUL2 (c->p4.x) - c->p1.x; dif2.x = (c->p3.x * 3) - (c->p4.x * 2) - c->p1.x;
dif2.y = CFX_MUL3 (c->p3.y) - CFX_MUL2 (c->p4.y) - c->p1.y; dif2.y = (c->p3.y * 3) - (c->p4.y * 2) - c->p1.y;
if (dif1.x < 0) if (dif1.x < 0)
dif1.x = -dif1.x; dif1.x = -dif1.x;
@ -438,16 +420,13 @@ _cogl_path_bezier3_sub (CoglBezCubic *cubic)
if (dif2.y < 0) if (dif2.y < 0)
dif2.y = -dif2.y; dif2.y = -dif2.y;
#undef CFX_MUL2
#undef CFX_MUL3
#undef CFX_SQ
/* Pick the greatest of two distances */ /* Pick the greatest of two distances */
if (dif1.x < dif2.x) dif1.x = dif2.x; if (dif1.x < dif2.x) dif1.x = dif2.x;
if (dif1.y < dif2.y) dif1.y = dif2.y; if (dif1.y < dif2.y) dif1.y = dif2.y;
/* Cancel if the curve is flat enough */ /* Cancel if the curve is flat enough */
if (dif1.x + dif1.y <= COGL_FIXED_1 || if (dif1.x + dif1.y <= 1.0 ||
cindex == _COGL_MAX_BEZ_RECURSE_DEPTH-1) cindex == _COGL_MAX_BEZ_RECURSE_DEPTH-1)
{ {
/* Add subdivision point (skip last) */ /* Add subdivision point (skip last) */
@ -465,20 +444,20 @@ _cogl_path_bezier3_sub (CoglBezCubic *cubic)
cright = c; cleft = &cubics[++cindex]; cright = c; cleft = &cubics[++cindex];
/* Subdivide into 2 sub-curves */ /* Subdivide into 2 sub-curves */
c1.x = ((c->p1.x + c->p2.x) >> 1); c1.x = ((c->p1.x + c->p2.x) / 2);
c1.y = ((c->p1.y + c->p2.y) >> 1); c1.y = ((c->p1.y + c->p2.y) / 2);
mm.x = ((c->p2.x + c->p3.x) >> 1); mm.x = ((c->p2.x + c->p3.x) / 2);
mm.y = ((c->p2.y + c->p3.y) >> 1); mm.y = ((c->p2.y + c->p3.y) / 2);
c5.x = ((c->p3.x + c->p4.x) >> 1); c5.x = ((c->p3.x + c->p4.x) / 2);
c5.y = ((c->p3.y + c->p4.y) >> 1); c5.y = ((c->p3.y + c->p4.y) / 2);
c2.x = ((c1.x + mm.x) >> 1); c2.x = ((c1.x + mm.x) / 2);
c2.y = ((c1.y + mm.y) >> 1); c2.y = ((c1.y + mm.y) / 2);
c4.x = ((mm.x + c5.x) >> 1); c4.x = ((mm.x + c5.x) / 2);
c4.y = ((mm.y + c5.y) >> 1); c4.y = ((mm.y + c5.y) / 2);
c3.x = ((c2.x + c4.x) >> 1); c3.x = ((c2.x + c4.x) / 2);
c3.y = ((c2.y + c4.y) >> 1); c3.y = ((c2.y + c4.y) / 2);
/* Add left recursion to stack */ /* Add left recursion to stack */
cleft->p1 = c->p1; cleft->p1 = c->p1;
@ -495,12 +474,12 @@ _cogl_path_bezier3_sub (CoglBezCubic *cubic)
} }
void void
cogl_path_curve_to (CoglFixed x1, cogl_path_curve_to (float x1,
CoglFixed y1, float y1,
CoglFixed x2, float x2,
CoglFixed y2, float y2,
CoglFixed x3, float x3,
CoglFixed y3) float y3)
{ {
CoglBezCubic cubic; CoglBezCubic cubic;
@ -524,12 +503,12 @@ cogl_path_curve_to (CoglFixed x1,
} }
void void
cogl_path_rel_curve_to (CoglFixed x1, cogl_path_rel_curve_to (float x1,
CoglFixed y1, float y1,
CoglFixed x2, float x2,
CoglFixed y2, float y2,
CoglFixed x3, float x3,
CoglFixed y3) float y3)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -554,11 +533,11 @@ _cogl_path_bezier2_sub (CoglBezQuad *quad)
CoglBezQuad *qleft; CoglBezQuad *qleft;
CoglBezQuad *qright; CoglBezQuad *qright;
CoglBezQuad *q; CoglBezQuad *q;
CoglFixedVec2 mid; floatVec2 mid;
CoglFixedVec2 dif; floatVec2 dif;
CoglFixedVec2 c1; floatVec2 c1;
CoglFixedVec2 c2; floatVec2 c2;
CoglFixedVec2 c3; floatVec2 c3;
gint qindex; gint qindex;
/* Put first curve on stack */ /* Put first curve on stack */
@ -573,15 +552,15 @@ _cogl_path_bezier2_sub (CoglBezQuad *quad)
/* Calculate distance of control point from its /* Calculate distance of control point from its
* counterpart on the line between end points */ * counterpart on the line between end points */
mid.x = ((q->p1.x + q->p3.x) >> 1); mid.x = ((q->p1.x + q->p3.x) / 2);
mid.y = ((q->p1.y + q->p3.y) >> 1); mid.y = ((q->p1.y + q->p3.y) / 2);
dif.x = (q->p2.x - mid.x); dif.x = (q->p2.x - mid.x);
dif.y = (q->p2.y - mid.y); dif.y = (q->p2.y - mid.y);
if (dif.x < 0) dif.x = -dif.x; if (dif.x < 0) dif.x = -dif.x;
if (dif.y < 0) dif.y = -dif.y; if (dif.y < 0) dif.y = -dif.y;
/* Cancel if the curve is flat enough */ /* Cancel if the curve is flat enough */
if (dif.x + dif.y <= COGL_FIXED_1 || if (dif.x + dif.y <= 1.0 ||
qindex == _COGL_MAX_BEZ_RECURSE_DEPTH - 1) qindex == _COGL_MAX_BEZ_RECURSE_DEPTH - 1)
{ {
/* Add subdivision point (skip last) */ /* Add subdivision point (skip last) */
@ -594,12 +573,12 @@ _cogl_path_bezier2_sub (CoglBezQuad *quad)
qright = q; qleft = &quads[++qindex]; qright = q; qleft = &quads[++qindex];
/* Subdivide into 2 sub-curves */ /* Subdivide into 2 sub-curves */
c1.x = ((q->p1.x + q->p2.x) >> 1); c1.x = ((q->p1.x + q->p2.x) / 2);
c1.y = ((q->p1.y + q->p2.y) >> 1); c1.y = ((q->p1.y + q->p2.y) / 2);
c3.x = ((q->p2.x + q->p3.x) >> 1); c3.x = ((q->p2.x + q->p3.x) / 2);
c3.y = ((q->p2.y + q->p3.y) >> 1); c3.y = ((q->p2.y + q->p3.y) / 2);
c2.x = ((c1.x + c3.x) >> 1); c2.x = ((c1.x + c3.x) / 2);
c2.y = ((c1.y + c3.y) >> 1); c2.y = ((c1.y + c3.y) / 2);
/* Add left recursion onto stack */ /* Add left recursion onto stack */
qleft->p1 = q->p1; qleft->p1 = q->p1;
@ -614,10 +593,10 @@ _cogl_path_bezier2_sub (CoglBezQuad *quad)
} }
void void
cogl_path_curve2_to (CoglFixed x1, cogl_path_curve2_to (float x1,
CoglFixed y1, float y1,
CoglFixed x2, float x2,
CoglFixed y2) float y2)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -639,10 +618,10 @@ cogl_path_curve2_to (CoglFixed x1,
} }
void void
cogl_rel_curve2_to (CoglFixed x1, cogl_rel_curve2_to (float x1,
CoglFixed y1, float y1,
CoglFixed x2, float x2,
CoglFixed y2) float y2)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);

View File

@ -26,15 +26,15 @@
#ifndef __COGL_PRIMITIVES_H #ifndef __COGL_PRIMITIVES_H
#define __COGL_PRIMITIVES_H #define __COGL_PRIMITIVES_H
typedef struct _CoglFixedVec2 CoglFixedVec2; typedef struct _floatVec2 floatVec2;
typedef struct _CoglBezQuad CoglBezQuad; typedef struct _CoglBezQuad CoglBezQuad;
typedef struct _CoglBezCubic CoglBezCubic; typedef struct _CoglBezCubic CoglBezCubic;
typedef struct _CoglPathNode CoglPathNode; typedef struct _CoglPathNode CoglPathNode;
struct _CoglFixedVec2 struct _floatVec2
{ {
CoglFixed x; float x;
CoglFixed y; float y;
}; };
#ifdef CLUTTER_COGL_HAS_GL #ifdef CLUTTER_COGL_HAS_GL
@ -67,17 +67,17 @@ struct _CoglPathNode
struct _CoglBezQuad struct _CoglBezQuad
{ {
CoglFixedVec2 p1; floatVec2 p1;
CoglFixedVec2 p2; floatVec2 p2;
CoglFixedVec2 p3; floatVec2 p3;
}; };
struct _CoglBezCubic struct _CoglBezCubic
{ {
CoglFixedVec2 p1; floatVec2 p1;
CoglFixedVec2 p2; floatVec2 p2;
CoglFixedVec2 p3; floatVec2 p3;
CoglFixedVec2 p4; floatVec2 p4;
}; };
#endif /* __COGL_PRIMITIVES_H */ #endif /* __COGL_PRIMITIVES_H */

View File

@ -0,0 +1,142 @@
/*
* Cogl.
*
* An OpenGL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2008 Intel Corporation.
*
* Authored By: Robert Bragg <robert@linux.intel.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __COGL_VERTEX_BUFFER_H
#define __COGL_VERTEX_BUFFER_H
/* Note we put quite a bit into the flags here to help keep
* the down size of the CoglVertexBufferAttrib struct below. */
typedef enum _CoglVertexBufferAttribFlags
{
/* Types */
/* NB: update the _TYPE_MASK below if these are changed */
COGL_VERTEX_BUFFER_ATTRIB_FLAG_COLOR_ARRAY = 1<<0,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_NORMAL_ARRAY = 1<<1,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_TEXTURE_COORD_ARRAY = 1<<2,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_VERTEX_ARRAY = 1<<3,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_CUSTOM_ARRAY = 1<<4,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_INVALID = 1<<5,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_NORMALIZED = 1<<6,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_ENABLED = 1<<7,
/* Usage hints */
/* FIXME - flatten into one flag, since its used as a boolean */
COGL_VERTEX_BUFFER_ATTRIB_FLAG_INFREQUENT_RESUBMIT = 1<<8,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_FREQUENT_RESUBMIT = 1<<9,
/* GL Data types */
/* NB: Update the _GL_TYPE_MASK below if these are changed */
COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_BYTE = 1<<10,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_UNSIGNED_BYTE = 1<<11,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_SHORT = 1<<12,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_UNSIGNED_SHORT = 1<<13,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_INT = 1<<14,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_UNSIGNED_INT = 1<<15,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_FLOAT = 1<<16,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_DOUBLE = 1<<17,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_SUBMITTED = 1<<18,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_UNUSED = 1<<19
/* XXX NB: If we need > 24 bits then look at changing the layout
* of struct _CoglVertexBufferAttrib below */
} CoglVertexBufferAttribFlags;
#define COGL_VERTEX_BUFFER_ATTRIB_FLAG_TYPE_MASK \
(COGL_VERTEX_BUFFER_ATTRIB_FLAG_COLOR_ARRAY \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_NORMAL_ARRAY \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_TEXTURE_COORD_ARRAY \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_VERTEX_ARRAY \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_CUSTOM_ARRAY \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_INVALID)
#define COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_MASK \
(COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_BYTE \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_UNSIGNED_BYTE \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_SHORT \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_UNSIGNED_SHORT \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_INT \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_UNSIGNED_INT \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_FLOAT \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_DOUBLE)
typedef struct _CoglVertexBufferAttrib
{
/* TODO: look at breaking up the flags into seperate
* bitfields and seperate enums */
CoglVertexBufferAttribFlags flags:24;
guint8 id;
GQuark name;
union _u
{
const void *pointer;
gsize vbo_offset;
} u;
gsize span_bytes;
guint16 stride;
guint8 n_components;
guint8 texture_unit;
} CoglVertexBufferAttrib;
typedef enum _CoglVertexBufferVBOFlags
{
COGL_VERTEX_BUFFER_VBO_FLAG_UNSTRIDED = 1<<0,
COGL_VERTEX_BUFFER_VBO_FLAG_STRIDED = 1<<1,
COGL_VERTEX_BUFFER_VBO_FLAG_MULTIPACK = 1<<2,
/* FIXME - flatten into one flag, since its used as a boolean */
COGL_VERTEX_BUFFER_VBO_FLAG_INFREQUENT_RESUBMIT = 1<<3,
COGL_VERTEX_BUFFER_VBO_FLAG_FREQUENT_RESUBMIT = 1<<4,
COGL_VERTEX_BUFFER_VBO_FLAG_SUBMITTED = 1<<5
} CoglVertexBufferVBOFlags;
/*
* A CoglVertexBufferVBO represents one or more attributes in a single
* buffer object
*/
typedef struct _CoglVertexBufferVBO
{
CoglVertexBufferVBOFlags flags;
GLuint vbo_name; /*!< The name of the corresponding buffer object */
gsize vbo_bytes; /*!< The lengh of the allocated buffer object in bytes */
GList *attributes;
} CoglVertexBufferVBO;
typedef struct _CoglVertexBuffer
{
guint ref_count;
guint n_vertices; /*!< The number of vertices in the buffer */
GList *submitted_vbos; /* The VBOs currently submitted to the GPU */
/* Note: new_attributes is normally NULL and only valid while
* modifying a buffer. */
GList *new_attributes; /*!< attributes pending submission */
} CoglVertexBuffer;
#endif /* __COGL_VERTEX_BUFFER_H */

File diff suppressed because it is too large Load Diff

View File

@ -62,7 +62,7 @@
<xi:include href="xml/cogl-offscreen.xml"/> <xi:include href="xml/cogl-offscreen.xml"/>
<xi:include href="xml/cogl-fixed.xml"/> <xi:include href="xml/cogl-fixed.xml"/>
<xi:include href="xml/cogl-color.xml"/> <xi:include href="xml/cogl-color.xml"/>
<xi:include href="xml/cogl-mesh.xml"/> <xi:include href="xml/cogl-vertex-buffer.xml"/>
</chapter> </chapter>

View File

@ -23,11 +23,10 @@ cogl_get_viewport
cogl_push_matrix cogl_push_matrix
cogl_pop_matrix cogl_pop_matrix
cogl_scale cogl_scale
cogl_translatex
cogl_translate cogl_translate
cogl_rotatex
cogl_rotate cogl_rotate
<SUBSECTION> <SUBSECTION>
CoglClipStackState
cogl_clip_set cogl_clip_set
cogl_clip_set_from_path cogl_clip_set_from_path
cogl_clip_set_from_path_preserve cogl_clip_set_from_path_preserve
@ -89,22 +88,28 @@ cogl_path_stroke
cogl_path_stroke_preserve cogl_path_stroke_preserve
cogl_set_source_color cogl_set_source_color
cogl_set_source_color4ub cogl_set_source_color4ub
cogl_set_source_color4x cogl_set_source_color4f
cogl_color
<SUBSECTION> <SUBSECTION>
cogl_rectangle cogl_rectangle
cogl_rectanglex
</SECTION> </SECTION>
<SECTION> <SECTION>
<FILE>cogl-texture</FILE> <FILE>cogl-texture</FILE>
<TITLE>Textures</TITLE> <TITLE>Textures</TITLE>
CoglTextureVertex CoglTextureVertex
CoglTextureFlags
cogl_texture_new_with_size cogl_texture_new_with_size
cogl_texture_new_from_file cogl_texture_new_from_file
cogl_texture_new_from_data cogl_texture_new_from_data
cogl_texture_new_from_foreign cogl_texture_new_from_foreign
cogl_texture_new_from_bitmap
cogl_is_texture cogl_is_texture
cogl_texture_ref
cogl_texture_unref
<SUBSECTION>
cogl_texture_get_width cogl_texture_get_width
cogl_texture_get_height cogl_texture_get_height
cogl_texture_get_format cogl_texture_get_format
@ -117,11 +122,18 @@ cogl_texture_get_gl_texture
cogl_texture_get_data cogl_texture_get_data
cogl_texture_set_filters cogl_texture_set_filters
cogl_texture_set_region cogl_texture_set_region
cogl_texture_ref
cogl_texture_unref <SUBSECTION>
cogl_texture_rectangle cogl_texture_rectangle
cogl_texture_multiple_rectangles cogl_texture_multiple_rectangles
cogl_texture_polygon cogl_texture_polygon
<SUBSECTION>
CoglBitmap
cogl_bitmap_new_from_file
cogl_bitmap_free
cogl_bitmap_get_size_from_file
</SECTION> </SECTION>
<SECTION> <SECTION>
@ -145,6 +157,7 @@ cogl_program_link
cogl_program_use cogl_program_use
cogl_program_get_uniform_location cogl_program_get_uniform_location
cogl_program_uniform_1f cogl_program_uniform_1f
cogl_program_uniform_1i
cogl_program_uniform_float cogl_program_uniform_float
cogl_program_uniform_int cogl_program_uniform_int
cogl_program_uniform_matrix cogl_program_uniform_matrix
@ -228,6 +241,7 @@ cogl_fixed_pow
cogl_fixed_pow2 cogl_fixed_pow2
cogl_fixed_sin cogl_fixed_sin
cogl_fixed_sqrt cogl_fixed_sqrt
cogl_fixed_tan
<SUBSECTION> <SUBSECTION>
CoglAngle CoglAngle
@ -257,7 +271,7 @@ cogl_color_copy
cogl_color_free cogl_color_free
cogl_color_set_from_4ub cogl_color_set_from_4ub
cogl_color_set_from_4d cogl_color_set_from_4d
cogl_color_set_from_4x cogl_color_set_from_4f
<SUBSECTION> <SUBSECTION>
cogl_color_get_red cogl_color_get_red
@ -279,19 +293,21 @@ cogl_color_get_alpha_float
</SECTION> </SECTION>
<SECTION> <SECTION>
<FILE>cogl-mesh</FILE> <FILE>cogl-vertex-buffer</FILE>
<TITLE>Mesh API</TITLE> <TITLE>Vertex Buffers</TITLE>
cogl_mesh_new CoglVertexBufferAttribFlags
cogl_mesh_ref COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_MASK
cogl_mesh_unref COGL_VERTEX_BUFFER_ATTRIB_FLAG_TYPE_MASK
CoglMeshAttributeFlags cogl_vertex_buffer_new
cogl_mesh_add_attribute cogl_vertex_buffer_ref
cogl_mesh_delete_attribute cogl_vertex_buffer_unref
cogl_mesh_enable_attribute cogl_vertex_buffer_add
cogl_mesh_disable_attribute cogl_vertex_buffer_delete
cogl_mesh_draw_arrays cogl_vertex_buffer_enable
cogl_mesh_draw_range_elements cogl_vertex_buffer_disable
cogl_mesh_submit cogl_vertex_buffer_submit
cogl_vertex_buffer_draw
cogl_vertex_buffer_draw_range_elements
</SECTION> </SECTION>
<SECTION> <SECTION>

View File

@ -10,7 +10,7 @@ libclutterinclude_HEADERS = \
$(top_builddir)/clutter/cogl/cogl-shader.h \ $(top_builddir)/clutter/cogl/cogl-shader.h \
$(top_builddir)/clutter/cogl/cogl-texture.h \ $(top_builddir)/clutter/cogl/cogl-texture.h \
$(top_builddir)/clutter/cogl/cogl-types.h \ $(top_builddir)/clutter/cogl/cogl-types.h \
$(top_builddir)/clutter/cogl/cogl-mesh.h \ $(top_builddir)/clutter/cogl/cogl-vertex-buffer.h \
$(top_builddir)/clutter/cogl/cogl-material.h \ $(top_builddir)/clutter/cogl/cogl-material.h \
$(top_builddir)/clutter/cogl/cogl-matrix.h $(top_builddir)/clutter/cogl/cogl-matrix.h

View File

@ -76,7 +76,7 @@ cogl_create_context ()
_context->program_handles = NULL; _context->program_handles = NULL;
_context->mesh_handles = NULL; _context->vertex_buffer_handles = NULL;
_context->pf_glGenRenderbuffersEXT = NULL; _context->pf_glGenRenderbuffersEXT = NULL;
_context->pf_glBindRenderbufferEXT = NULL; _context->pf_glBindRenderbufferEXT = NULL;

View File

@ -51,12 +51,12 @@ typedef struct
gboolean enable_backface_culling; gboolean enable_backface_culling;
/* Primitives */ /* Primitives */
CoglFixedVec2 path_start; floatVec2 path_start;
CoglFixedVec2 path_pen; floatVec2 path_pen;
GArray *path_nodes; GArray *path_nodes;
guint last_path; guint last_path;
CoglFixedVec2 path_nodes_min; floatVec2 path_nodes_min;
CoglFixedVec2 path_nodes_max; floatVec2 path_nodes_max;
/* Cache of inverse projection matrix */ /* Cache of inverse projection matrix */
GLfloat inverse_projection[16]; GLfloat inverse_projection[16];
@ -91,8 +91,8 @@ typedef struct
/* Clip stack */ /* Clip stack */
CoglClipStackState clip; CoglClipStackState clip;
/* Mesh */ /* Vertex buffers */
GArray *mesh_handles; GArray *vertex_buffer_handles;
/* Relying on glext.h to define these */ /* Relying on glext.h to define these */
COGL_PFNGLGENRENDERBUFFERSEXTPROC pf_glGenRenderbuffersEXT; COGL_PFNGLGENRENDERBUFFERSEXTPROC pf_glGenRenderbuffersEXT;

View File

@ -34,52 +34,35 @@
#include <string.h> #include <string.h>
#include <gmodule.h> #include <gmodule.h>
#include <math.h>
#define _COGL_MAX_BEZ_RECURSE_DEPTH 16 #define _COGL_MAX_BEZ_RECURSE_DEPTH 16
void void
_cogl_rectangle (gint x, _cogl_rectangle (float x,
gint y, float y,
guint width, float width,
guint height) float height)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
cogl_enable (ctx->color_alpha < 255 cogl_enable (ctx->color_alpha < 255
? COGL_ENABLE_BLEND : 0); ? COGL_ENABLE_BLEND : 0);
GE( glRecti (x, y, x + width, y + height) ); GE( glRectf (x, y, x + width, y + height) );
}
void
_cogl_rectanglex (CoglFixed x,
CoglFixed y,
CoglFixed width,
CoglFixed height)
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
cogl_enable (ctx->color_alpha < 255
? COGL_ENABLE_BLEND : 0);
GE( glRectf (COGL_FIXED_TO_FLOAT (x),
COGL_FIXED_TO_FLOAT (y),
COGL_FIXED_TO_FLOAT (x + width),
COGL_FIXED_TO_FLOAT (y + height)) );
} }
void void
_cogl_path_add_node (gboolean new_sub_path, _cogl_path_add_node (gboolean new_sub_path,
CoglFixed x, float x,
CoglFixed y) float y)
{ {
CoglPathNode new_node; CoglPathNode new_node;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
new_node.x = COGL_FIXED_TO_FLOAT (x); new_node.x = (x);
new_node.y = COGL_FIXED_TO_FLOAT (y); new_node.y = (y);
new_node.path_size = 0; new_node.path_size = 0;
if (new_sub_path || ctx->path_nodes->len == 0) if (new_sub_path || ctx->path_nodes->len == 0)
@ -129,34 +112,32 @@ _cogl_path_stroke_nodes ()
} }
static void static void
_cogl_path_get_bounds (CoglFixedVec2 nodes_min, _cogl_path_get_bounds (floatVec2 nodes_min,
CoglFixedVec2 nodes_max, floatVec2 nodes_max,
gint *bounds_x, float *bounds_x,
gint *bounds_y, float *bounds_y,
guint *bounds_w, float *bounds_w,
guint *bounds_h) float *bounds_h)
{ {
*bounds_x = COGL_FIXED_FLOOR (nodes_min.x); *bounds_x = nodes_min.x;
*bounds_y = COGL_FIXED_FLOOR (nodes_min.y); *bounds_y = nodes_min.y;
*bounds_w = COGL_FIXED_CEIL (nodes_max.x *bounds_w = nodes_max.x - *bounds_x;
- COGL_FIXED_FROM_INT (*bounds_x)); *bounds_h = nodes_max.y - *bounds_y;
*bounds_h = COGL_FIXED_CEIL (nodes_max.y
- COGL_FIXED_FROM_INT (*bounds_y));
} }
void void
_cogl_add_path_to_stencil_buffer (CoglFixedVec2 nodes_min, _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min,
CoglFixedVec2 nodes_max, floatVec2 nodes_max,
guint path_size, guint path_size,
CoglPathNode *path, CoglPathNode *path,
gboolean merge) gboolean merge)
{ {
guint path_start = 0; guint path_start = 0;
guint sub_path_num = 0; guint sub_path_num = 0;
gint bounds_x; float bounds_x;
gint bounds_y; float bounds_y;
guint bounds_w; float bounds_w;
guint bounds_h; float bounds_h;
_cogl_path_get_bounds (nodes_min, nodes_max, _cogl_path_get_bounds (nodes_min, nodes_max,
&bounds_x, &bounds_y, &bounds_w, &bounds_h); &bounds_x, &bounds_y, &bounds_w, &bounds_h);
@ -238,10 +219,10 @@ _cogl_add_path_to_stencil_buffer (CoglFixedVec2 nodes_min,
void void
_cogl_path_fill_nodes () _cogl_path_fill_nodes ()
{ {
gint bounds_x; float bounds_x;
gint bounds_y; float bounds_y;
guint bounds_w; float bounds_w;
guint bounds_h; float bounds_h;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);

View File

@ -38,6 +38,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h>
/* /*
#define COGL_DEBUG 1 #define COGL_DEBUG 1
@ -59,15 +60,15 @@ struct _CoglSpanIter
gint index; gint index;
GArray *array; GArray *array;
CoglTexSliceSpan *span; CoglTexSliceSpan *span;
CoglFixed pos; float pos;
CoglFixed next_pos; float next_pos;
CoglFixed origin; float origin;
CoglFixed cover_start; float cover_start;
CoglFixed cover_end; float cover_end;
CoglFixed intersect_start; float intersect_start;
CoglFixed intersect_end; float intersect_end;
CoglFixed intersect_start_local; float intersect_start_local;
CoglFixed intersect_end_local; float intersect_end_local;
gboolean intersects; gboolean intersects;
}; };
@ -102,7 +103,7 @@ _cogl_span_iter_update (CoglSpanIter *iter)
/* Offset next position by span size */ /* Offset next position by span size */
iter->next_pos = iter->pos + iter->next_pos = iter->pos +
COGL_FIXED_FROM_INT (iter->span->size - iter->span->waste); (float)(iter->span->size - iter->span->waste);
/* Check if span intersects the area to cover */ /* Check if span intersects the area to cover */
if (iter->next_pos <= iter->cover_start || if (iter->next_pos <= iter->cover_start ||
@ -131,9 +132,9 @@ _cogl_span_iter_update (CoglSpanIter *iter)
static void static void
_cogl_span_iter_begin (CoglSpanIter *iter, _cogl_span_iter_begin (CoglSpanIter *iter,
GArray *array, GArray *array,
CoglFixed origin, float origin,
CoglFixed cover_start, float cover_start,
CoglFixed cover_end) float cover_end)
{ {
/* Copy info */ /* Copy info */
iter->index = 0; iter->index = 0;
@ -471,8 +472,8 @@ _cogl_texture_upload_subregion_to_gl (CoglTexture *tex,
/* Iterate vertical spans */ /* Iterate vertical spans */
for (source_y = src_y, for (source_y = src_y,
_cogl_span_iter_begin (&y_iter, tex->slice_y_spans, _cogl_span_iter_begin (&y_iter, tex->slice_y_spans,
0, COGL_FIXED_FROM_INT (dst_y), 0, (float)(dst_y),
COGL_FIXED_FROM_INT (dst_y + height)); (float)(dst_y + height));
!_cogl_span_iter_end (&y_iter); !_cogl_span_iter_end (&y_iter);
@ -492,8 +493,8 @@ _cogl_texture_upload_subregion_to_gl (CoglTexture *tex,
/* Iterate horizontal spans */ /* Iterate horizontal spans */
for (source_x = src_x, for (source_x = src_x,
_cogl_span_iter_begin (&x_iter, tex->slice_x_spans, _cogl_span_iter_begin (&x_iter, tex->slice_x_spans,
0, COGL_FIXED_FROM_INT (dst_x), 0, (float)(dst_x),
COGL_FIXED_FROM_INT (dst_x + width)); (float)(dst_x + width));
!_cogl_span_iter_end (&x_iter); !_cogl_span_iter_end (&x_iter);
@ -511,15 +512,15 @@ _cogl_texture_upload_subregion_to_gl (CoglTexture *tex,
x_iter.index); x_iter.index);
/* Pick intersection width and height */ /* Pick intersection width and height */
inter_w = COGL_FIXED_TO_INT (x_iter.intersect_end - inter_w = (x_iter.intersect_end -
x_iter.intersect_start); x_iter.intersect_start);
inter_h = COGL_FIXED_TO_INT (y_iter.intersect_end - inter_h = (y_iter.intersect_end -
y_iter.intersect_start); y_iter.intersect_start);
/* Localize intersection top-left corner to slice*/ /* Localize intersection top-left corner to slice*/
local_x = COGL_FIXED_TO_INT (x_iter.intersect_start - local_x = (x_iter.intersect_start -
x_iter.pos); x_iter.pos);
local_y = COGL_FIXED_TO_INT (y_iter.intersect_start - local_y = (y_iter.intersect_start -
y_iter.pos); y_iter.pos);
/* Pick slice GL handle */ /* Pick slice GL handle */
@ -555,7 +556,7 @@ _cogl_texture_upload_subregion_to_gl (CoglTexture *tex,
guint wx, wy; guint wx, wy;
src = source_bmp->data src = source_bmp->data
+ (src_y + COGL_FIXED_TO_INT (y_iter.intersect_start) + (src_y + ((int)y_iter.intersect_start)
- dst_y) - dst_y)
* source_bmp->rowstride * source_bmp->rowstride
+ (src_x + x_span->start + x_span->size - x_span->waste + (src_x + x_span->start + x_span->size - x_span->waste
@ -600,7 +601,7 @@ _cogl_texture_upload_subregion_to_gl (CoglTexture *tex,
guint copy_width; guint copy_width;
src = source_bmp->data src = source_bmp->data
+ (src_x + COGL_FIXED_TO_INT (x_iter.intersect_start) + (src_x + ((int)x_iter.intersect_start)
- dst_x) - dst_x)
* bpp * bpp
+ (src_y + y_span->start + y_span->size - y_span->waste + (src_y + y_span->start + y_span->size - y_span->waste
@ -1188,11 +1189,11 @@ _cogl_texture_free (CoglTexture *tex)
} }
CoglHandle CoglHandle
cogl_texture_new_with_size (guint width, cogl_texture_new_with_size (guint width,
guint height, guint height,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat internal_format) CoglPixelFormat internal_format)
{ {
CoglTexture *tex; CoglTexture *tex;
gint bpp; gint bpp;
@ -1213,7 +1214,7 @@ cogl_texture_new_with_size (guint width,
COGL_HANDLE_DEBUG_NEW (texture, tex); COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = auto_mipmap; tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
tex->bitmap.width = width; tex->bitmap.width = width;
tex->bitmap.height = height; tex->bitmap.height = height;
@ -1248,14 +1249,14 @@ cogl_texture_new_with_size (guint width,
} }
CoglHandle CoglHandle
cogl_texture_new_from_data (guint width, cogl_texture_new_from_data (guint width,
guint height, guint height,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
guint rowstride, guint rowstride,
const guchar *data) const guchar *data)
{ {
CoglTexture *tex; CoglTexture *tex;
gint bpp; gint bpp;
@ -1277,7 +1278,7 @@ cogl_texture_new_from_data (guint width,
COGL_HANDLE_DEBUG_NEW (texture, tex); COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = auto_mipmap; tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
tex->bitmap.width = width; tex->bitmap.width = width;
tex->bitmap.height = height; tex->bitmap.height = height;
@ -1323,30 +1324,13 @@ cogl_texture_new_from_data (guint width,
} }
CoglHandle CoglHandle
cogl_texture_new_from_file (const gchar *filename, cogl_texture_new_from_bitmap (CoglBitmap *bmp,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat internal_format, CoglPixelFormat internal_format)
GError **error)
{ {
CoglBitmap bmp;
CoglTexture *tex; CoglTexture *tex;
g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_HANDLE);
/* Try loading with imaging backend */
if (!_cogl_bitmap_from_file (&bmp, filename, error))
{
/* Try fallback */
if (!_cogl_bitmap_fallback_from_file (&bmp, filename))
return COGL_INVALID_HANDLE;
else if (error && *error)
{
g_error_free (*error);
*error = NULL;
}
}
/* Create new texture and fill with loaded data */ /* Create new texture and fill with loaded data */
tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture)); tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture));
@ -1354,10 +1338,11 @@ cogl_texture_new_from_file (const gchar *filename,
COGL_HANDLE_DEBUG_NEW (texture, tex); COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = auto_mipmap; tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
tex->bitmap = bmp; tex->bitmap = *bmp;
tex->bitmap_owner = TRUE; tex->bitmap_owner = TRUE;
bmp->data = NULL;
tex->slice_x_spans = NULL; tex->slice_x_spans = NULL;
tex->slice_y_spans = NULL; tex->slice_y_spans = NULL;
@ -1398,6 +1383,30 @@ cogl_texture_new_from_file (const gchar *filename,
return _cogl_texture_handle_new (tex); return _cogl_texture_handle_new (tex);
} }
CoglHandle
cogl_texture_new_from_file (const gchar *filename,
gint max_waste,
CoglTextureFlags flags,
CoglPixelFormat internal_format,
GError **error)
{
CoglBitmap *bmp;
CoglHandle handle;
g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_HANDLE);
if (!(bmp = cogl_bitmap_new_from_file (filename, error)))
return COGL_INVALID_HANDLE;
handle = cogl_texture_new_from_bitmap (bmp,
max_waste,
flags,
internal_format);
cogl_bitmap_free (bmp);
return handle;
}
CoglHandle CoglHandle
cogl_texture_new_from_foreign (GLuint gl_handle, cogl_texture_new_from_foreign (GLuint gl_handle,
GLenum gl_target, GLenum gl_target,
@ -2002,24 +2011,24 @@ _cogl_texture_add_quad_vertices (GLfloat x1, GLfloat y1,
static void static void
_cogl_texture_quad_sw (CoglTexture *tex, _cogl_texture_quad_sw (CoglTexture *tex,
CoglFixed x1, float x1,
CoglFixed y1, float y1,
CoglFixed x2, float x2,
CoglFixed y2, float y2,
CoglFixed tx1, float tx1,
CoglFixed ty1, float ty1,
CoglFixed tx2, float tx2,
CoglFixed ty2) float ty2)
{ {
CoglSpanIter iter_x , iter_y; CoglSpanIter iter_x , iter_y;
CoglFixed tw , th; float tw , th;
CoglFixed tqx , tqy; float tqx , tqy;
CoglFixed first_tx , first_ty; float first_tx , first_ty;
CoglFixed first_qx , first_qy; float first_qx , first_qy;
CoglFixed slice_tx1 , slice_ty1; float slice_tx1 , slice_ty1;
CoglFixed slice_tx2 , slice_ty2; float slice_tx2 , slice_ty2;
CoglFixed slice_qx1 , slice_qy1; float slice_qx1 , slice_qy1;
CoglFixed slice_qx2 , slice_qy2; float slice_qx2 , slice_qy2;
GLuint gl_handle; GLuint gl_handle;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -2042,7 +2051,7 @@ _cogl_texture_quad_sw (CoglTexture *tex,
slices */ slices */
if (tx2 < tx1) if (tx2 < tx1)
{ {
CoglFixed temp = x1; float temp = x1;
x1 = x2; x1 = x2;
x2 = temp; x2 = temp;
temp = tx1; temp = tx1;
@ -2051,7 +2060,7 @@ _cogl_texture_quad_sw (CoglTexture *tex,
} }
if (ty2 < ty1) if (ty2 < ty1)
{ {
CoglFixed temp = y1; float temp = y1;
y1 = y2; y1 = y2;
y2 = temp; y2 = temp;
temp = ty1; temp = ty1;
@ -2060,27 +2069,27 @@ _cogl_texture_quad_sw (CoglTexture *tex,
} }
/* Scale ratio from texture to quad widths */ /* Scale ratio from texture to quad widths */
tw = COGL_FIXED_FROM_INT (tex->bitmap.width); tw = (float)(tex->bitmap.width);
th = COGL_FIXED_FROM_INT (tex->bitmap.height); th = (float)(tex->bitmap.height);
tqx = COGL_FIXED_DIV (x2 - x1, COGL_FIXED_MUL (tw, (tx2 - tx1))); tqx = (x2 - x1) / (tw * (tx2 - tx1));
tqy = COGL_FIXED_DIV (y2 - y1, COGL_FIXED_MUL (th, (ty2 - ty1))); tqy = (y2 - y1) / (th * (ty2 - ty1));
/* Integral texture coordinate for first tile */ /* Integral texture coordinate for first tile */
first_tx = COGL_FIXED_FROM_INT (COGL_FIXED_FLOOR (tx1)); first_tx = (float)(floorf (tx1));
first_ty = COGL_FIXED_FROM_INT (COGL_FIXED_FLOOR (ty1)); first_ty = (float)(floorf (ty1));
/* Denormalize texture coordinates */ /* Denormalize texture coordinates */
first_tx = COGL_FIXED_MUL (first_tx, tw); first_tx = (first_tx * tw);
first_ty = COGL_FIXED_MUL (first_ty, th); first_ty = (first_ty * th);
tx1 = COGL_FIXED_MUL (tx1, tw); tx1 = (tx1 * tw);
ty1 = COGL_FIXED_MUL (ty1, th); ty1 = (ty1 * th);
tx2 = COGL_FIXED_MUL (tx2, tw); tx2 = (tx2 * tw);
ty2 = COGL_FIXED_MUL (ty2, th); ty2 = (ty2 * th);
/* Quad coordinate of the first tile */ /* Quad coordinate of the first tile */
first_qx = x1 - COGL_FIXED_MUL (tx1 - first_tx, tqx); first_qx = x1 - (tx1 - first_tx) * tqx;
first_qy = y1 - COGL_FIXED_MUL (ty1 - first_ty, tqy); first_qy = y1 - (ty1 - first_ty) * tqy;
/* Iterate until whole quad height covered */ /* Iterate until whole quad height covered */
@ -2093,11 +2102,9 @@ _cogl_texture_quad_sw (CoglTexture *tex,
if (!iter_y.intersects) continue; if (!iter_y.intersects) continue;
/* Span-quad intersection in quad coordinates */ /* Span-quad intersection in quad coordinates */
slice_qy1 = first_qy + slice_qy1 = first_qy + (iter_y.intersect_start - first_ty) * tqy;
COGL_FIXED_MUL (iter_y.intersect_start - first_ty, tqy);
slice_qy2 = first_qy + slice_qy2 = first_qy + (iter_y.intersect_end - first_ty) * tqy;
COGL_FIXED_MUL (iter_y.intersect_end - first_ty, tqy);
/* Localize slice texture coordinates */ /* Localize slice texture coordinates */
slice_ty1 = iter_y.intersect_start - iter_y.pos; slice_ty1 = iter_y.intersect_start - iter_y.pos;
@ -2121,11 +2128,9 @@ _cogl_texture_quad_sw (CoglTexture *tex,
if (!iter_x.intersects) continue; if (!iter_x.intersects) continue;
/* Span-quad intersection in quad coordinates */ /* Span-quad intersection in quad coordinates */
slice_qx1 = first_qx + slice_qx1 = first_qx + (iter_x.intersect_start - first_tx) * tqx;
COGL_FIXED_MUL (iter_x.intersect_start - first_tx, tqx);
slice_qx2 = first_qx + slice_qx2 = first_qx + (iter_x.intersect_end - first_tx) * tqx;
COGL_FIXED_MUL (iter_x.intersect_end - first_tx, tqx);
/* Localize slice texture coordinates */ /* Localize slice texture coordinates */
slice_tx1 = iter_x.intersect_start - iter_x.pos; slice_tx1 = iter_x.intersect_start - iter_x.pos;
@ -2141,14 +2146,14 @@ _cogl_texture_quad_sw (CoglTexture *tex,
#if COGL_DEBUG #if COGL_DEBUG
printf("~~~~~ slice (%d,%d)\n", iter_x.index, iter_y.index); printf("~~~~~ slice (%d,%d)\n", iter_x.index, iter_y.index);
printf("qx1: %f\n", COGL_FIXED_TO_FLOAT (slice_qx1)); printf("qx1: %f\n", (slice_qx1));
printf("qy1: %f\n", COGL_FIXED_TO_FLOAT (slice_qy1)); printf("qy1: %f\n", (slice_qy1));
printf("qx2: %f\n", COGL_FIXED_TO_FLOAT (slice_qx2)); printf("qx2: %f\n", (slice_qx2));
printf("qy2: %f\n", COGL_FIXED_TO_FLOAT (slice_qy2)); printf("qy2: %f\n", (slice_qy2));
printf("tx1: %f\n", COGL_FIXED_TO_FLOAT (slice_tx1)); printf("tx1: %f\n", (slice_tx1));
printf("ty1: %f\n", COGL_FIXED_TO_FLOAT (slice_ty1)); printf("ty1: %f\n", (slice_ty1));
printf("tx2: %f\n", COGL_FIXED_TO_FLOAT (slice_tx2)); printf("tx2: %f\n", (slice_tx2));
printf("ty2: %f\n", COGL_FIXED_TO_FLOAT (slice_ty2)); printf("ty2: %f\n", (slice_ty2));
#endif #endif
/* Pick and bind opengl texture object */ /* Pick and bind opengl texture object */
@ -2164,28 +2169,28 @@ _cogl_texture_quad_sw (CoglTexture *tex,
ctx->texture_target = tex->gl_target; ctx->texture_target = tex->gl_target;
ctx->texture_current = gl_handle; ctx->texture_current = gl_handle;
_cogl_texture_add_quad_vertices (COGL_FIXED_TO_FLOAT (slice_qx1), _cogl_texture_add_quad_vertices ( (slice_qx1),
COGL_FIXED_TO_FLOAT (slice_qy1), (slice_qy1),
COGL_FIXED_TO_FLOAT (slice_qx2), (slice_qx2),
COGL_FIXED_TO_FLOAT (slice_qy2), (slice_qy2),
COGL_FIXED_TO_FLOAT (slice_tx1), (slice_tx1),
COGL_FIXED_TO_FLOAT (slice_ty1), (slice_ty1),
COGL_FIXED_TO_FLOAT (slice_tx2), (slice_tx2),
COGL_FIXED_TO_FLOAT (slice_ty2)); (slice_ty2));
} }
} }
} }
static void static void
_cogl_texture_quad_hw (CoglTexture *tex, _cogl_texture_quad_hw (CoglTexture *tex,
CoglFixed x1, float x1,
CoglFixed y1, float y1,
CoglFixed x2, float x2,
CoglFixed y2, float y2,
CoglFixed tx1, float tx1,
CoglFixed ty1, float ty1,
CoglFixed tx2, float tx2,
CoglFixed ty2) float ty2)
{ {
GLuint gl_handle; GLuint gl_handle;
CoglTexSliceSpan *x_span; CoglTexSliceSpan *x_span;
@ -2201,10 +2206,10 @@ _cogl_texture_quad_hw (CoglTexture *tex,
/* If the texture coords are all in the range [0,1] then we want to /* If the texture coords are all in the range [0,1] then we want to
clamp the coords to the edge otherwise it can pull in edge pixels clamp the coords to the edge otherwise it can pull in edge pixels
from the wrong side when scaled */ from the wrong side when scaled */
if (tx1 >= 0 && tx1 <= COGL_FIXED_1 if (tx1 >= 0 && tx1 <= 1.0
&& tx2 >= 0 && tx2 <= COGL_FIXED_1 && tx2 >= 0 && tx2 <= 1.0
&& ty1 >= 0 && ty1 <= COGL_FIXED_1 && ty1 >= 0 && ty1 <= 1.0
&& ty2 >= 0 && ty2 <= COGL_FIXED_1) && ty2 >= 0 && ty2 <= 1.0)
wrap_mode = GL_CLAMP_TO_EDGE; wrap_mode = GL_CLAMP_TO_EDGE;
else else
wrap_mode = GL_REPEAT; wrap_mode = GL_REPEAT;
@ -2243,19 +2248,19 @@ _cogl_texture_quad_hw (CoglTexture *tex,
ty2 *= y_span->size; ty2 *= y_span->size;
} }
_cogl_texture_add_quad_vertices (COGL_FIXED_TO_FLOAT (x1), _cogl_texture_add_quad_vertices ( (x1),
COGL_FIXED_TO_FLOAT (y1), (y1),
COGL_FIXED_TO_FLOAT (x2), (x2),
COGL_FIXED_TO_FLOAT (y2), (y2),
COGL_FIXED_TO_FLOAT (tx1), (tx1),
COGL_FIXED_TO_FLOAT (ty1), (ty1),
COGL_FIXED_TO_FLOAT (tx2), (tx2),
COGL_FIXED_TO_FLOAT (ty2)); (ty2));
} }
void void
cogl_texture_multiple_rectangles (CoglHandle handle, cogl_texture_multiple_rectangles (CoglHandle handle,
const CoglFixed *verts, const float *verts,
guint n_rects) guint n_rects)
{ {
CoglTexture *tex; CoglTexture *tex;
@ -2306,10 +2311,10 @@ cogl_texture_multiple_rectangles (CoglHandle handle,
if (tex->slice_gl_handles->len == 1 if (tex->slice_gl_handles->len == 1
&& ((cogl_features_available (COGL_FEATURE_TEXTURE_NPOT) && ((cogl_features_available (COGL_FEATURE_TEXTURE_NPOT)
&& tex->gl_target == GL_TEXTURE_2D) && tex->gl_target == GL_TEXTURE_2D)
|| (verts[4] >= 0 && verts[4] <= COGL_FIXED_1 || (verts[4] >= 0 && verts[4] <= 1.0
&& verts[6] >= 0 && verts[6] <= COGL_FIXED_1 && verts[6] >= 0 && verts[6] <= 1.0
&& verts[5] >= 0 && verts[5] <= COGL_FIXED_1 && verts[5] >= 0 && verts[5] <= 1.0
&& verts[7] >= 0 && verts[7] <= COGL_FIXED_1))) && verts[7] >= 0 && verts[7] <= 1.0)))
_cogl_texture_quad_hw (tex, verts[0],verts[1], verts[2],verts[3], _cogl_texture_quad_hw (tex, verts[0],verts[1], verts[2],verts[3],
verts[4],verts[5], verts[6],verts[7]); verts[4],verts[5], verts[6],verts[7]);
else else
@ -2325,16 +2330,16 @@ cogl_texture_multiple_rectangles (CoglHandle handle,
void void
cogl_texture_rectangle (CoglHandle handle, cogl_texture_rectangle (CoglHandle handle,
CoglFixed x1, float x1,
CoglFixed y1, float y1,
CoglFixed x2, float x2,
CoglFixed y2, float y2,
CoglFixed tx1, float tx1,
CoglFixed ty1, float ty1,
CoglFixed tx2, float tx2,
CoglFixed ty2) float ty2)
{ {
CoglFixed verts[8]; float verts[8];
verts[0] = x1; verts[0] = x1;
verts[1] = y1; verts[1] = y1;
@ -2447,16 +2452,16 @@ cogl_texture_polygon (CoglHandle handle,
OpenGL */ OpenGL */
for (i = 0; i < n_vertices; i++, p++) for (i = 0; i < n_vertices; i++, p++)
{ {
CoglFixed tx, ty; float tx, ty;
#define CFX_F COGL_FIXED_TO_FLOAT #define CFX_F
tx = ((vertices[i].tx tx = ((vertices[i].tx
- (COGL_FIXED_FROM_INT (x_span->start) - ((float)(x_span->start)
/ tex->bitmap.width)) / tex->bitmap.width))
* tex->bitmap.width / x_span->size); * tex->bitmap.width / x_span->size);
ty = ((vertices[i].ty ty = ((vertices[i].ty
- (COGL_FIXED_FROM_INT (y_span->start) - ((float)(y_span->start)
/ tex->bitmap.height)) / tex->bitmap.height))
* tex->bitmap.height / y_span->size); * tex->bitmap.height / y_span->size);

327
gl/cogl.c
View File

@ -209,40 +209,23 @@ cogl_pop_matrix (void)
} }
void void
cogl_scale (CoglFixed x, CoglFixed y) cogl_scale (float x, float y)
{ {
glScaled (COGL_FIXED_TO_DOUBLE (x), glScalef ((float)(x),
COGL_FIXED_TO_DOUBLE (y), (float)(y),
1.0); 1.0);
} }
void void
cogl_translatex (CoglFixed x, CoglFixed y, CoglFixed z) cogl_translate (float x, float y, float z)
{ {
glTranslated (COGL_FIXED_TO_DOUBLE (x), glTranslatef (x, y, z);
COGL_FIXED_TO_DOUBLE (y),
COGL_FIXED_TO_DOUBLE (z));
} }
void void
cogl_translate (gint x, gint y, gint z) cogl_rotate (float angle, float x, float y, float z)
{ {
glTranslatef ((float)x, (float)y, (float)z); glRotatef (angle, x, y, z);
}
void
cogl_rotatex (CoglFixed angle, gint x, gint y, gint z)
{
glRotated (COGL_FIXED_TO_DOUBLE (angle),
COGL_FIXED_TO_DOUBLE (x),
COGL_FIXED_TO_DOUBLE (y),
COGL_FIXED_TO_DOUBLE (z));
}
void
cogl_rotate (gint angle, gint x, gint y, gint z)
{
glRotatef ((float)angle, (float)x, (float)y, (float)z);
} }
static inline gboolean static inline gboolean
@ -466,24 +449,24 @@ set_clip_plane (GLint plane_num,
} }
void void
_cogl_set_clip_planes (CoglFixed x_offset, _cogl_set_clip_planes (float x_offset,
CoglFixed y_offset, float y_offset,
CoglFixed width, float width,
CoglFixed height) float height)
{ {
GLfloat modelview[16], projection[16]; GLfloat modelview[16], projection[16];
GLfloat vertex_tl[4] = { COGL_FIXED_TO_FLOAT (x_offset), GLfloat vertex_tl[4] = { (x_offset),
COGL_FIXED_TO_FLOAT (y_offset), (y_offset),
0.0f, 1.0f }; 0.0f, 1.0f };
GLfloat vertex_tr[4] = { COGL_FIXED_TO_FLOAT (x_offset + width), GLfloat vertex_tr[4] = { (x_offset + width),
COGL_FIXED_TO_FLOAT (y_offset), (y_offset),
0.0f, 1.0f }; 0.0f, 1.0f };
GLfloat vertex_bl[4] = { COGL_FIXED_TO_FLOAT (x_offset), GLfloat vertex_bl[4] = { (x_offset),
COGL_FIXED_TO_FLOAT (y_offset + height), (y_offset + height),
0.0f, 1.0f }; 0.0f, 1.0f };
GLfloat vertex_br[4] = { COGL_FIXED_TO_FLOAT (x_offset + width), GLfloat vertex_br[4] = { (x_offset + width),
COGL_FIXED_TO_FLOAT (y_offset + height), (y_offset + height),
0.0f, 1.0f }; 0.0f, 1.0f };
GE( glGetFloatv (GL_MODELVIEW_MATRIX, modelview) ); GE( glGetFloatv (GL_MODELVIEW_MATRIX, modelview) );
@ -518,10 +501,10 @@ _cogl_set_clip_planes (CoglFixed x_offset,
} }
void void
_cogl_add_stencil_clip (CoglFixed x_offset, _cogl_add_stencil_clip (float x_offset,
CoglFixed y_offset, float y_offset,
CoglFixed width, float width,
CoglFixed height, float height,
gboolean first) gboolean first)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -537,10 +520,10 @@ _cogl_add_stencil_clip (CoglFixed x_offset,
/* Punch out a hole to allow the rectangle */ /* Punch out a hole to allow the rectangle */
GE( glStencilFunc (GL_NEVER, 0x1, 0x1) ); GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
GE( glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE) ); GE( glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE) );
GE( glRectf (COGL_FIXED_TO_FLOAT (x_offset), GE( glRectf ( (x_offset),
COGL_FIXED_TO_FLOAT (y_offset), (y_offset),
COGL_FIXED_TO_FLOAT (x_offset + width), (x_offset + width),
COGL_FIXED_TO_FLOAT (y_offset + height)) ); (y_offset + height)) );
} }
else else
{ {
@ -548,10 +531,10 @@ _cogl_add_stencil_clip (CoglFixed x_offset,
rectangle */ rectangle */
GE( glStencilFunc (GL_NEVER, 0x1, 0x3) ); GE( glStencilFunc (GL_NEVER, 0x1, 0x3) );
GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) ); GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
GE( glRectf (COGL_FIXED_TO_FLOAT (x_offset), GE( glRectf ( (x_offset),
COGL_FIXED_TO_FLOAT (y_offset), (y_offset),
COGL_FIXED_TO_FLOAT (x_offset + width), (x_offset + width),
COGL_FIXED_TO_FLOAT (y_offset + height)) ); (y_offset + height)) );
/* Subtract one from all pixels in the stencil buffer so that /* Subtract one from all pixels in the stencil buffer so that
only pixels where both the original stencil buffer and the only pixels where both the original stencil buffer and the
@ -574,13 +557,13 @@ _cogl_add_stencil_clip (CoglFixed x_offset,
} }
void void
_cogl_set_matrix (const CoglFixed *matrix) _cogl_set_matrix (const float *matrix)
{ {
float float_matrix[16]; float float_matrix[16];
int i; int i;
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
float_matrix[i] = COGL_FIXED_TO_FLOAT (matrix[i]); float_matrix[i] = (matrix[i]);
GE( glLoadIdentity () ); GE( glLoadIdentity () );
GE( glMultMatrixf (float_matrix) ); GE( glMultMatrixf (float_matrix) );
@ -612,20 +595,20 @@ _cogl_disable_clip_planes (void)
void void
cogl_alpha_func (COGLenum func, cogl_alpha_func (COGLenum func,
CoglFixed ref) float ref)
{ {
GE( glAlphaFunc (func, COGL_FIXED_TO_FLOAT(ref)) ); GE( glAlphaFunc (func, (ref)) );
} }
void void
cogl_perspective (CoglFixed fovy, cogl_perspective (float fovy,
CoglFixed aspect, float aspect,
CoglFixed zNear, float zNear,
CoglFixed zFar) float zFar)
{ {
CoglFixed xmax, ymax; float xmax, ymax;
CoglFixed x, y, c, d; float x, y, c, d;
CoglFixed fovy_rad_half = COGL_FIXED_MUL (fovy, COGL_FIXED_PI) / 360; float fovy_rad_half = (fovy * G_PI) / 360;
GLfloat m[16]; GLfloat m[16];
@ -645,23 +628,19 @@ cogl_perspective (CoglFixed fovy,
* 2) When working with small numbers, we are loosing significant * 2) When working with small numbers, we are loosing significant
* precision * precision
*/ */
ymax = ymax = (zNear * (sinf (fovy_rad_half) / cosf (fovy_rad_half)));
COGL_FIXED_MUL (zNear, xmax = (ymax * aspect);
COGL_FIXED_FAST_DIV (cogl_fixed_sin (fovy_rad_half),
cogl_fixed_cos (fovy_rad_half)));
xmax = COGL_FIXED_MUL (ymax, aspect); x = (zNear / xmax);
y = (zNear / ymax);
x = COGL_FIXED_FAST_DIV (zNear, xmax); c = (-(zFar + zNear) / ( zFar - zNear));
y = COGL_FIXED_FAST_DIV (zNear, ymax); d = (-(2 * zFar) * zNear) / (zFar - zNear);
c = COGL_FIXED_FAST_DIV (-(zFar + zNear), ( zFar - zNear));
d = cogl_fixed_mul_div (-(2 * zFar), zNear, (zFar - zNear));
#define M(row,col) m[col*4+row] #define M(row,col) m[col*4+row]
M(0,0) = COGL_FIXED_TO_FLOAT (x); M(0,0) = (x);
M(1,1) = COGL_FIXED_TO_FLOAT (y); M(1,1) = (y);
M(2,2) = COGL_FIXED_TO_FLOAT (c); M(2,2) = (c);
M(2,3) = COGL_FIXED_TO_FLOAT (d); M(2,3) = (d);
M(3,2) = -1.0F; M(3,2) = -1.0F;
GE( glMultMatrixf (m) ); GE( glMultMatrixf (m) );
@ -672,22 +651,22 @@ cogl_perspective (CoglFixed fovy,
memset (ctx->inverse_projection, 0, sizeof (GLfloat) * 16); memset (ctx->inverse_projection, 0, sizeof (GLfloat) * 16);
#define m ctx->inverse_projection #define m ctx->inverse_projection
M(0, 0) = 1.0f / COGL_FIXED_TO_FLOAT (x); M(0, 0) = 1.0f / (x);
M(1, 1) = 1.0f / COGL_FIXED_TO_FLOAT (y); M(1, 1) = 1.0f / (y);
M(2, 3) = -1.0f; M(2, 3) = -1.0f;
M(3, 2) = 1.0f / COGL_FIXED_TO_FLOAT (d); M(3, 2) = 1.0f / (d);
M(3, 3) = COGL_FIXED_TO_FLOAT (c) / COGL_FIXED_TO_FLOAT (d); M(3, 3) = (c) / (d);
#undef m #undef m
#undef M #undef M
} }
void void
cogl_frustum (CoglFixed left, cogl_frustum (float left,
CoglFixed right, float right,
CoglFixed bottom, float bottom,
CoglFixed top, float top,
CoglFixed z_near, float z_near,
CoglFixed z_far) float z_far)
{ {
GLfloat c, d; GLfloat c, d;
@ -696,32 +675,32 @@ cogl_frustum (CoglFixed left,
GE( glMatrixMode (GL_PROJECTION) ); GE( glMatrixMode (GL_PROJECTION) );
GE( glLoadIdentity () ); GE( glLoadIdentity () );
GE( glFrustum (COGL_FIXED_TO_DOUBLE (left), GE( glFrustum ((GLdouble)(left),
COGL_FIXED_TO_DOUBLE (right), (GLdouble)(right),
COGL_FIXED_TO_DOUBLE (bottom), (GLdouble)(bottom),
COGL_FIXED_TO_DOUBLE (top), (GLdouble)(top),
COGL_FIXED_TO_DOUBLE (z_near), (GLdouble)(z_near),
COGL_FIXED_TO_DOUBLE (z_far)) ); (GLdouble)(z_far)) );
GE( glMatrixMode (GL_MODELVIEW) ); GE( glMatrixMode (GL_MODELVIEW) );
/* Calculate and store the inverse of the matrix */ /* Calculate and store the inverse of the matrix */
memset (ctx->inverse_projection, 0, sizeof (GLfloat) * 16); memset (ctx->inverse_projection, 0, sizeof (GLfloat) * 16);
c = -COGL_FIXED_TO_FLOAT (z_far + z_near) c = - (z_far + z_near)
/ COGL_FIXED_TO_FLOAT (z_far - z_near); / (z_far - z_near);
d = -COGL_FIXED_TO_FLOAT (2 * COGL_FIXED_MUL (z_far, z_near)) d = - (2 * (z_far * z_near))
/ COGL_FIXED_TO_FLOAT (z_far - z_near); / (z_far - z_near);
#define M(row,col) ctx->inverse_projection[col*4+row] #define M(row,col) ctx->inverse_projection[col*4+row]
M(0,0) = COGL_FIXED_TO_FLOAT (right - left) M(0,0) = (right - left)
/ COGL_FIXED_TO_FLOAT (2 * z_near); / (2 * z_near);
M(0,3) = COGL_FIXED_TO_FLOAT (right + left) M(0,3) = (right + left)
/ COGL_FIXED_TO_FLOAT (2 * z_near); / (2 * z_near);
M(1,1) = COGL_FIXED_TO_FLOAT (top - bottom) M(1,1) = (top - bottom)
/ COGL_FIXED_TO_FLOAT (2 * z_near); / (2 * z_near);
M(1,3) = COGL_FIXED_TO_FLOAT (top + bottom) M(1,3) = (top + bottom)
/ COGL_FIXED_TO_FLOAT (2 * z_near); / (2 * z_near);
M(2,3) = -1.0f; M(2,3) = -1.0f;
M(3,2) = 1.0f / d; M(3,2) = 1.0f / d;
M(3,3) = c / d; M(3,3) = c / d;
@ -738,45 +717,61 @@ cogl_viewport (guint width,
void void
cogl_setup_viewport (guint width, cogl_setup_viewport (guint width,
guint height, guint height,
CoglFixed fovy, float fovy,
CoglFixed aspect, float aspect,
CoglFixed z_near, float z_near,
CoglFixed z_far) float z_far)
{ {
GLfloat z_camera; GLfloat z_camera;
GLfloat projection_matrix[16];
GE( glViewport (0, 0, width, height) ); GE( glViewport (0, 0, width, height) );
cogl_perspective (fovy, aspect, z_near, z_far); cogl_perspective (fovy, aspect, z_near, z_far);
GE( glLoadIdentity () );
/* /*
* camera distance from screen, 0.5 * tan (FOV) * In theory, we can compute the camera distance from screen as:
* *
* We have been having some problems with this; the theoretically correct * 0.5 * tan (FOV)
* value of 0.866025404f for the default 60 deg fovy angle happens to be
* touch to small in reality, which on full-screen stage with an actor of
* the same size results in about 1px on the left and top edges of the
* actor being offscreen. Perhaps more significantly, it also causes
* hinting artifacts when rendering text.
* *
* So for the default 60 deg angle we worked out that the value of 0.869 * However, it's better to compute the z_camera from our projection
* is giving correct stretch and no noticeable artifacts on text. Seems * matrix so that we get a 1:1 mapping at the screen distance. Consider
* good on all drivers too. * the upper-left corner of the screen. It has object coordinates
* (0,0,0), so by the transform below, ends up with eye coordinate
*
* x_eye = x_object / width - 0.5 = - 0.5
* y_eye = (height - y_object) / width - 0.5 = 0.5
* z_eye = z_object / width - z_camera = - z_camera
*
* From cogl_perspective(), we know that the projection matrix has
* the form:
*
* (x, 0, 0, 0)
* (0, y, 0, 0)
* (0, 0, c, d)
* (0, 0, -1, 0)
*
* Applied to the above, we get clip coordinates of
*
* x_clip = x * (- 0.5)
* y_clip = y * 0.5
* w_clip = - 1 * (- z_camera) = z_camera
*
* Dividing through by w to get normalized device coordinates, we
* have, x_nd = x * 0.5 / z_camera, y_nd = - y * 0.5 / z_camera.
* The upper left corner of the screen has normalized device coordinates,
* (-1, 1), so to have the correct 1:1 mapping, we have to have:
*
* z_camera = 0.5 * x = 0.5 * y
*
* If x != y, then we have a non-uniform aspect ration, and a 1:1 mapping
* doesn't make sense.
*/ */
#define DEFAULT_Z_CAMERA 0.869f
z_camera = DEFAULT_Z_CAMERA;
cogl_get_projection_matrix (projection_matrix);
z_camera = 0.5 * projection_matrix[0];
if (fovy != COGL_FIXED_60) GE( glLoadIdentity () );
{
CoglFixed fovy_rad = COGL_FIXED_MUL (fovy, COGL_FIXED_PI) / 180;
z_camera =
COGL_FIXED_TO_FLOAT (COGL_FIXED_DIV (cogl_fixed_sin (fovy_rad),
cogl_fixed_cos (fovy_rad)) >> 1);
}
GE( glTranslatef (-0.5f, -0.5f, -z_camera) ); GE( glTranslatef (-0.5f, -0.5f, -z_camera) );
GE( glScalef ( 1.0f / width, GE( glScalef ( 1.0f / width,
@ -1164,75 +1159,21 @@ cogl_features_available (CoglFeatureFlags features)
} }
void void
cogl_get_modelview_matrix (CoglFixed m[16]) cogl_get_modelview_matrix (float m[16])
{ {
GLdouble md[16]; glGetFloatv (GL_MODELVIEW_MATRIX, m);
glGetDoublev(GL_MODELVIEW_MATRIX, &md[0]);
#define M(m,row,col) m[col*4+row]
M(m,0,0) = COGL_FIXED_FROM_FLOAT (M(md,0,0));
M(m,0,1) = COGL_FIXED_FROM_FLOAT (M(md,0,1));
M(m,0,2) = COGL_FIXED_FROM_FLOAT (M(md,0,2));
M(m,0,3) = COGL_FIXED_FROM_FLOAT (M(md,0,3));
M(m,1,0) = COGL_FIXED_FROM_FLOAT (M(md,1,0));
M(m,1,1) = COGL_FIXED_FROM_FLOAT (M(md,1,1));
M(m,1,2) = COGL_FIXED_FROM_FLOAT (M(md,1,2));
M(m,1,3) = COGL_FIXED_FROM_FLOAT (M(md,1,3));
M(m,2,0) = COGL_FIXED_FROM_FLOAT (M(md,2,0));
M(m,2,1) = COGL_FIXED_FROM_FLOAT (M(md,2,1));
M(m,2,2) = COGL_FIXED_FROM_FLOAT (M(md,2,2));
M(m,2,3) = COGL_FIXED_FROM_FLOAT (M(md,2,3));
M(m,3,0) = COGL_FIXED_FROM_FLOAT (M(md,3,0));
M(m,3,1) = COGL_FIXED_FROM_FLOAT (M(md,3,1));
M(m,3,2) = COGL_FIXED_FROM_FLOAT (M(md,3,2));
M(m,3,3) = COGL_FIXED_FROM_FLOAT (M(md,3,3));
#undef M
} }
void void
cogl_get_projection_matrix (CoglFixed m[16]) cogl_get_projection_matrix (float m[16])
{ {
GLdouble md[16]; glGetFloatv (GL_PROJECTION_MATRIX, m);
glGetDoublev(GL_PROJECTION_MATRIX, &md[0]);
#define M(m,row,col) m[col*4+row]
M(m,0,0) = COGL_FIXED_FROM_FLOAT (M(md,0,0));
M(m,0,1) = COGL_FIXED_FROM_FLOAT (M(md,0,1));
M(m,0,2) = COGL_FIXED_FROM_FLOAT (M(md,0,2));
M(m,0,3) = COGL_FIXED_FROM_FLOAT (M(md,0,3));
M(m,1,0) = COGL_FIXED_FROM_FLOAT (M(md,1,0));
M(m,1,1) = COGL_FIXED_FROM_FLOAT (M(md,1,1));
M(m,1,2) = COGL_FIXED_FROM_FLOAT (M(md,1,2));
M(m,1,3) = COGL_FIXED_FROM_FLOAT (M(md,1,3));
M(m,2,0) = COGL_FIXED_FROM_FLOAT (M(md,2,0));
M(m,2,1) = COGL_FIXED_FROM_FLOAT (M(md,2,1));
M(m,2,2) = COGL_FIXED_FROM_FLOAT (M(md,2,2));
M(m,2,3) = COGL_FIXED_FROM_FLOAT (M(md,2,3));
M(m,3,0) = COGL_FIXED_FROM_FLOAT (M(md,3,0));
M(m,3,1) = COGL_FIXED_FROM_FLOAT (M(md,3,1));
M(m,3,2) = COGL_FIXED_FROM_FLOAT (M(md,3,2));
M(m,3,3) = COGL_FIXED_FROM_FLOAT (M(md,3,3));
#undef M
} }
void void
cogl_get_viewport (CoglFixed v[4]) cogl_get_viewport (float v[4])
{ {
GLdouble vd[4]; glGetFloatv (GL_VIEWPORT, v);
glGetDoublev(GL_VIEWPORT, &vd[0]);
v[0] = COGL_FIXED_FROM_FLOAT (vd[0]);
v[1] = COGL_FIXED_FROM_FLOAT (vd[1]);
v[2] = COGL_FIXED_FROM_FLOAT (vd[2]);
v[3] = COGL_FIXED_FROM_FLOAT (vd[3]);
} }
void void
@ -1263,9 +1204,9 @@ cogl_get_bitmasks (gint *red, gint *green, gint *blue, gint *alpha)
void void
cogl_fog_set (const CoglColor *fog_color, cogl_fog_set (const CoglColor *fog_color,
CoglFixed density, float density,
CoglFixed start, float start,
CoglFixed stop) float stop)
{ {
GLfloat fogColor[4]; GLfloat fogColor[4];
@ -1281,8 +1222,8 @@ cogl_fog_set (const CoglColor *fog_color,
glFogi (GL_FOG_MODE, GL_LINEAR); glFogi (GL_FOG_MODE, GL_LINEAR);
glHint (GL_FOG_HINT, GL_NICEST); glHint (GL_FOG_HINT, GL_NICEST);
glFogf (GL_FOG_DENSITY, COGL_FIXED_TO_FLOAT (density)); glFogf (GL_FOG_DENSITY, (density));
glFogf (GL_FOG_START, COGL_FIXED_TO_FLOAT (start)); glFogf (GL_FOG_START, (start));
glFogf (GL_FOG_END, COGL_FIXED_TO_FLOAT (stop)); glFogf (GL_FOG_END, (stop));
} }

View File

@ -10,7 +10,7 @@ libclutterinclude_HEADERS = \
$(top_builddir)/clutter/cogl/cogl-shader.h \ $(top_builddir)/clutter/cogl/cogl-shader.h \
$(top_builddir)/clutter/cogl/cogl-texture.h \ $(top_builddir)/clutter/cogl/cogl-texture.h \
$(top_builddir)/clutter/cogl/cogl-types.h \ $(top_builddir)/clutter/cogl/cogl-types.h \
$(top_builddir)/clutter/cogl/cogl-mesh.h \ $(top_builddir)/clutter/cogl/cogl-vertex-buffer.h \
$(top_builddir)/clutter/cogl/cogl-material.h \ $(top_builddir)/clutter/cogl/cogl-material.h \
$(top_builddir)/clutter/cogl/cogl-matrix.h $(top_builddir)/clutter/cogl/cogl-matrix.h

View File

@ -73,7 +73,7 @@ cogl_create_context ()
_context->shader_handles = NULL; _context->shader_handles = NULL;
_context->draw_buffer = COGL_WINDOW_BUFFER; _context->draw_buffer = COGL_WINDOW_BUFFER;
_context->mesh_handles = NULL; _context->vertex_buffer_handles = NULL;
_context->blend_src_factor = CGL_SRC_ALPHA; _context->blend_src_factor = CGL_SRC_ALPHA;
_context->blend_dst_factor = CGL_ONE_MINUS_SRC_ALPHA; _context->blend_dst_factor = CGL_ONE_MINUS_SRC_ALPHA;
@ -84,7 +84,7 @@ cogl_create_context ()
#endif #endif
/* Init OpenGL state */ /* Init OpenGL state */
GE( cogl_wrap_glTexEnvx (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) ); GE( cogl_wrap_glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) );
GE( glColorMask (TRUE, TRUE, TRUE, FALSE) ); GE( glColorMask (TRUE, TRUE, TRUE, FALSE) );
GE( glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ); GE( glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) );
cogl_enable (0); cogl_enable (0);

View File

@ -53,15 +53,15 @@ typedef struct
gboolean enable_backface_culling; gboolean enable_backface_culling;
/* Primitives */ /* Primitives */
CoglFixedVec2 path_start; floatVec2 path_start;
CoglFixedVec2 path_pen; floatVec2 path_pen;
GArray *path_nodes; GArray *path_nodes;
guint last_path; guint last_path;
CoglFixedVec2 path_nodes_min; floatVec2 path_nodes_min;
CoglFixedVec2 path_nodes_max; floatVec2 path_nodes_max;
/* Cache of inverse projection matrix */ /* Cache of inverse projection matrix */
CoglFixed inverse_projection[16]; float inverse_projection[16];
/* Textures */ /* Textures */
GArray *texture_handles; GArray *texture_handles;
@ -72,6 +72,7 @@ typedef struct
can be flushed */ can be flushed */
GLuint texture_current; GLuint texture_current;
GLenum texture_target; GLenum texture_target;
GLenum texture_format;
/* Materials */ /* Materials */
GArray *material_handles; GArray *material_handles;
@ -86,8 +87,8 @@ typedef struct
GArray *program_handles; GArray *program_handles;
GArray *shader_handles; GArray *shader_handles;
/* Mesh */ /* Vertex buffers */
GArray *mesh_handles; GArray *vertex_buffer_handles;
/* Clip stack */ /* Clip stack */
CoglClipStackState clip; CoglClipStackState clip;

View File

@ -227,12 +227,12 @@ cogl_draw_buffer (CoglBufferTarget target, CoglHandle offscreen)
/* Setup new viewport and matrices */ /* Setup new viewport and matrices */
GE( glViewport (0, 0, fbo->width, fbo->height) ); GE( glViewport (0, 0, fbo->width, fbo->height) );
GE( cogl_wrap_glTranslatex (-COGL_FIXED_1, -COGL_FIXED_1, 0) ); GE( cogl_wrap_glTranslatef (-1.0, -1.0, 0) );
GE( cogl_wrap_glScalex (COGL_FIXED_DIV (COGL_FIXED_FROM_INT (2), GE( cogl_wrap_glScalef (((float)(2) /
COGL_FIXED_FROM_INT (fbo->width)), (float)(fbo->width)),
COGL_FIXED_DIV (COGL_FIXED_FROM_INT (2), ((float)(2) /
COGL_FIXED_FROM_INT (fbo->height)), (float)(fbo->height)),
COGL_FIXED_1) ); 1.0) );
/* Bind offscreen framebuffer object */ /* Bind offscreen framebuffer object */
GE( glBindFramebuffer (GL_FRAMEBUFFER, fbo->gl_handle) ); GE( glBindFramebuffer (GL_FRAMEBUFFER, fbo->gl_handle) );

View File

@ -105,7 +105,7 @@ cogl_gles2_wrapper_create_shader (GLenum type, const char *source)
void void
cogl_gles2_wrapper_init (CoglGles2Wrapper *wrapper) cogl_gles2_wrapper_init (CoglGles2Wrapper *wrapper)
{ {
GLfixed default_fog_color[4] = { 0, 0, 0, 0 }; GLfloat default_fog_color[4] = { 0, 0, 0, 0 };
memset (wrapper, 0, sizeof (CoglGles2Wrapper)); memset (wrapper, 0, sizeof (CoglGles2Wrapper));
@ -125,11 +125,11 @@ cogl_gles2_wrapper_init (CoglGles2Wrapper *wrapper)
/* Initialize the fogging options */ /* Initialize the fogging options */
cogl_wrap_glDisable (GL_FOG); cogl_wrap_glDisable (GL_FOG);
cogl_wrap_glFogx (GL_FOG_MODE, GL_LINEAR); cogl_wrap_glFogf (GL_FOG_MODE, GL_LINEAR);
cogl_wrap_glFogx (GL_FOG_DENSITY, COGL_FIXED_1); cogl_wrap_glFogf (GL_FOG_DENSITY, 1.0);
cogl_wrap_glFogx (GL_FOG_START, 0); cogl_wrap_glFogf (GL_FOG_START, 0);
cogl_wrap_glFogx (GL_FOG_END, 1); cogl_wrap_glFogf (GL_FOG_END, 1);
cogl_wrap_glFogxv (GL_FOG_COLOR, default_fog_color); cogl_wrap_glFogfv (GL_FOG_COLOR, default_fog_color);
/* Initialize alpha testing */ /* Initialize alpha testing */
cogl_wrap_glDisable (GL_ALPHA_TEST); cogl_wrap_glDisable (GL_ALPHA_TEST);
@ -639,15 +639,6 @@ cogl_gles2_wrapper_update_matrix (CoglGles2Wrapper *wrapper, GLenum matrix_num)
} }
} }
void
cogl_wrap_glClearColorx (GLclampx r, GLclampx g, GLclampx b, GLclampx a)
{
glClearColor (COGL_FIXED_TO_FLOAT (r),
COGL_FIXED_TO_FLOAT (g),
COGL_FIXED_TO_FLOAT (b),
COGL_FIXED_TO_FLOAT (a));
}
void void
cogl_wrap_glPushMatrix () cogl_wrap_glPushMatrix ()
{ {
@ -810,58 +801,58 @@ cogl_wrap_glMultMatrix (const float *m)
} }
void void
cogl_wrap_glMultMatrixx (const GLfixed *m) cogl_wrap_glMultMatrixf (const GLfloat *m)
{ {
float new_matrix[16]; float new_matrix[16];
int i; int i;
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
new_matrix[i] = COGL_FIXED_TO_FLOAT (m[i]); new_matrix[i] = (m[i]);
cogl_wrap_glMultMatrix (new_matrix); cogl_wrap_glMultMatrix (new_matrix);
} }
void void
cogl_wrap_glFrustumx (GLfixed left, GLfixed right, cogl_wrap_glFrustumf (GLfloat left, GLfloat right,
GLfixed bottom, GLfixed top, GLfloat bottom, GLfloat top,
GLfixed z_near, GLfixed z_far) GLfloat z_near, GLfloat z_far)
{ {
float matrix[16]; float matrix[16];
float two_near = COGL_FIXED_TO_FLOAT (2 * z_near); float two_near = (2 * z_near);
memset (matrix, 0, sizeof (matrix)); memset (matrix, 0, sizeof (matrix));
matrix[0] = two_near / COGL_FIXED_TO_FLOAT (right - left); matrix[0] = two_near / (right - left);
matrix[5] = two_near / COGL_FIXED_TO_FLOAT (top - bottom); matrix[5] = two_near / (top - bottom);
matrix[8] = COGL_FIXED_TO_FLOAT (right + left) matrix[8] = (right + left)
/ COGL_FIXED_TO_FLOAT (right - left); / (right - left);
matrix[9] = COGL_FIXED_TO_FLOAT (top + bottom) matrix[9] = (top + bottom)
/ COGL_FIXED_TO_FLOAT (top - bottom); / (top - bottom);
matrix[10] = -COGL_FIXED_TO_FLOAT (z_far + z_near) matrix[10] = - (z_far + z_near)
/ COGL_FIXED_TO_FLOAT (z_far - z_near); / (z_far - z_near);
matrix[11] = -1.0f; matrix[11] = -1.0f;
matrix[14] = -two_near * COGL_FIXED_TO_FLOAT (z_far) matrix[14] = -two_near * (z_far)
/ COGL_FIXED_TO_FLOAT (z_far - z_near); / (z_far - z_near);
cogl_wrap_glMultMatrix (matrix); cogl_wrap_glMultMatrix (matrix);
} }
void void
cogl_wrap_glScalex (GLfixed x, GLfixed y, GLfixed z) cogl_wrap_glScalef (GLfloat x, GLfloat y, GLfloat z)
{ {
float matrix[16]; float matrix[16];
memset (matrix, 0, sizeof (matrix)); memset (matrix, 0, sizeof (matrix));
matrix[0] = COGL_FIXED_TO_FLOAT (x); matrix[0] = (x);
matrix[5] = COGL_FIXED_TO_FLOAT (y); matrix[5] = (y);
matrix[10] = COGL_FIXED_TO_FLOAT (z); matrix[10] = (z);
matrix[15] = 1.0f; matrix[15] = 1.0f;
cogl_wrap_glMultMatrix (matrix); cogl_wrap_glMultMatrix (matrix);
} }
void void
cogl_wrap_glTranslatex (GLfixed x, GLfixed y, GLfixed z) cogl_wrap_glTranslatef (GLfloat x, GLfloat y, GLfloat z)
{ {
float matrix[16]; float matrix[16];
@ -869,22 +860,22 @@ cogl_wrap_glTranslatex (GLfixed x, GLfixed y, GLfixed z)
matrix[0] = 1.0f; matrix[0] = 1.0f;
matrix[5] = 1.0f; matrix[5] = 1.0f;
matrix[10] = 1.0f; matrix[10] = 1.0f;
matrix[12] = COGL_FIXED_TO_FLOAT (x); matrix[12] = (x);
matrix[13] = COGL_FIXED_TO_FLOAT (y); matrix[13] = (y);
matrix[14] = COGL_FIXED_TO_FLOAT (z); matrix[14] = (z);
matrix[15] = 1.0f; matrix[15] = 1.0f;
cogl_wrap_glMultMatrix (matrix); cogl_wrap_glMultMatrix (matrix);
} }
void void
cogl_wrap_glRotatex (GLfixed angle, GLfixed x, GLfixed y, GLfixed z) cogl_wrap_glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
{ {
float matrix[16]; float matrix[16];
float xf = COGL_FIXED_TO_FLOAT (x); float xf = (x);
float yf = COGL_FIXED_TO_FLOAT (y); float yf = (y);
float zf = COGL_FIXED_TO_FLOAT (z); float zf = (z);
float anglef = COGL_FIXED_TO_FLOAT (angle) * G_PI / 180.0f; float anglef = (angle) * G_PI / 180.0f;
float c = cosf (anglef); float c = cosf (anglef);
float s = sinf (anglef); float s = sinf (anglef);
@ -912,21 +903,21 @@ cogl_wrap_glRotatex (GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
} }
void void
cogl_wrap_glOrthox (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, cogl_wrap_glOrthof (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top,
GLfixed near, GLfixed far) GLfloat near, GLfloat far)
{ {
float matrix[16]; float matrix[16];
float xrange = COGL_FIXED_TO_FLOAT (right - left); float xrange = (right - left);
float yrange = COGL_FIXED_TO_FLOAT (top - bottom); float yrange = (top - bottom);
float zrange = COGL_FIXED_TO_FLOAT (far - near); float zrange = (far - near);
memset (matrix, 0, sizeof (matrix)); memset (matrix, 0, sizeof (matrix));
matrix[0] = 2.0f / xrange; matrix[0] = 2.0f / xrange;
matrix[5] = 2.0f / yrange; matrix[5] = 2.0f / yrange;
matrix[10] = 2.0f / zrange; matrix[10] = 2.0f / zrange;
matrix[12] = COGL_FIXED_TO_FLOAT (right + left) / xrange; matrix[12] = (right + left) / xrange;
matrix[13] = COGL_FIXED_TO_FLOAT (top + bottom) / yrange; matrix[13] = (top + bottom) / yrange;
matrix[14] = COGL_FIXED_TO_FLOAT (far + near) / zrange; matrix[14] = (far + near) / zrange;
matrix[15] = 1.0f; matrix[15] = 1.0f;
cogl_wrap_glMultMatrix (matrix); cogl_wrap_glMultMatrix (matrix);
@ -1049,8 +1040,8 @@ cogl_gles2_do_set_uniform (GLint location, CoglBoxedValue *value)
} }
} }
void static void
cogl_wrap_glDrawArrays (GLenum mode, GLint first, GLsizei count) cogl_wrap_prepare_for_draw (void)
{ {
CoglGles2WrapperProgram *program; CoglGles2WrapperProgram *program;
@ -1247,9 +1238,25 @@ cogl_wrap_glDrawArrays (GLenum mode, GLint first, GLsizei count)
w->dirty_vertex_attrib_enables = 0; w->dirty_vertex_attrib_enables = 0;
} }
} }
}
void
cogl_wrap_glDrawArrays (GLenum mode, GLint first, GLsizei count)
{
cogl_wrap_prepare_for_draw ();
glDrawArrays (mode, first, count); glDrawArrays (mode, first, count);
} }
void
cogl_wrap_glDrawElements (GLenum mode, GLsizei count, GLenum type,
const GLvoid *indices)
{
cogl_wrap_prepare_for_draw ();
glDrawElements (mode, count, type, indices);
}
void void
cogl_gles2_wrapper_bind_texture (GLenum target, GLuint texture, cogl_gles2_wrapper_bind_texture (GLenum target, GLuint texture,
GLenum internal_format) GLenum internal_format)
@ -1268,7 +1275,7 @@ cogl_gles2_wrapper_bind_texture (GLenum target, GLuint texture,
} }
void void
cogl_wrap_glTexEnvx (GLenum target, GLenum pname, GLfixed param) cogl_wrap_glTexEnvf (GLenum target, GLenum pname, GLfloat param)
{ {
/* This function is only used to set the texture mode once to /* This function is only used to set the texture mode once to
GL_MODULATE. The shader is hard-coded to modulate the texture so GL_MODULATE. The shader is hard-coded to modulate the texture so
@ -1479,30 +1486,17 @@ cogl_wrap_glAlphaFunc (GLenum func, GLclampf ref)
} }
void void
cogl_wrap_glColor4x (GLclampx r, GLclampx g, GLclampx b, GLclampx a) cogl_wrap_glColor4f (GLclampf r, GLclampf g, GLclampf b, GLclampf a)
{ {
glVertexAttrib4f (COGL_GLES2_WRAPPER_COLOR_ATTRIB, glVertexAttrib4f (COGL_GLES2_WRAPPER_COLOR_ATTRIB, r, g, b, a);
COGL_FIXED_TO_FLOAT (r),
COGL_FIXED_TO_FLOAT (g),
COGL_FIXED_TO_FLOAT (b),
COGL_FIXED_TO_FLOAT (a));
} }
void void
cogl_wrap_glClipPlanex (GLenum plane, GLfixed *equation) cogl_wrap_glClipPlanef (GLenum plane, GLfloat *equation)
{ {
/* FIXME */ /* FIXME */
} }
static void
cogl_gles2_float_array_to_fixed (int size,
const GLfloat *floats,
GLfixed *fixeds)
{
while (size-- > 0)
*(fixeds++) = COGL_FIXED_FROM_FLOAT (*(floats++));
}
void void
cogl_wrap_glGetIntegerv (GLenum pname, GLint *params) cogl_wrap_glGetIntegerv (GLenum pname, GLint *params)
{ {
@ -1525,37 +1519,30 @@ cogl_wrap_glGetIntegerv (GLenum pname, GLint *params)
} }
void void
cogl_wrap_glGetFixedv (GLenum pname, GLfixed *params) cogl_wrap_glGetFloatv (GLenum pname, GLfloat *params)
{ {
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL); _COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
switch (pname) switch (pname)
{ {
case GL_MODELVIEW_MATRIX: case GL_MODELVIEW_MATRIX:
cogl_gles2_float_array_to_fixed (16, w->modelview_stack memcpy (params, w->modelview_stack + w->modelview_stack_pos * 16,
+ w->modelview_stack_pos * 16, sizeof (GLfloat) * 16);
params);
break; break;
case GL_PROJECTION_MATRIX: case GL_PROJECTION_MATRIX:
cogl_gles2_float_array_to_fixed (16, w->projection_stack memcpy (params, w->projection_stack + w->projection_stack_pos * 16,
+ w->projection_stack_pos * 16, sizeof (GLfloat) * 16);
params);
break; break;
case GL_VIEWPORT: case GL_VIEWPORT:
{ glGetFloatv (GL_VIEWPORT, params);
GLfloat v[4];
glGetFloatv (GL_VIEWPORT, v);
cogl_gles2_float_array_to_fixed (4, v, params);
}
break; break;
} }
} }
void void
cogl_wrap_glFogx (GLenum pname, GLfixed param) cogl_wrap_glFogf (GLenum pname, GLfloat param)
{ {
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL); _COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
@ -1567,23 +1554,23 @@ cogl_wrap_glFogx (GLenum pname, GLfixed param)
case GL_FOG_DENSITY: case GL_FOG_DENSITY:
_COGL_GLES2_CHANGE_UNIFORM (w, FOG_DENSITY, fog_density, _COGL_GLES2_CHANGE_UNIFORM (w, FOG_DENSITY, fog_density,
COGL_FIXED_TO_FLOAT (param)); (param));
break; break;
case GL_FOG_START: case GL_FOG_START:
_COGL_GLES2_CHANGE_UNIFORM (w, FOG_START, fog_start, _COGL_GLES2_CHANGE_UNIFORM (w, FOG_START, fog_start,
COGL_FIXED_TO_FLOAT (param)); (param));
break; break;
case GL_FOG_END: case GL_FOG_END:
_COGL_GLES2_CHANGE_UNIFORM (w, FOG_END, fog_end, _COGL_GLES2_CHANGE_UNIFORM (w, FOG_END, fog_end,
COGL_FIXED_TO_FLOAT (param)); (param));
break; break;
} }
} }
void void
cogl_wrap_glFogxv (GLenum pname, const GLfixed *params) cogl_wrap_glFogfv (GLenum pname, const GLfloat *params)
{ {
int i; int i;
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL); _COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
@ -1591,7 +1578,7 @@ cogl_wrap_glFogxv (GLenum pname, const GLfixed *params)
if (pname == GL_FOG_COLOR) if (pname == GL_FOG_COLOR)
{ {
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
w->fog_color[i] = COGL_FIXED_TO_FLOAT (params[i]); w->fog_color[i] = (params[i]);
w->dirty_uniforms |= COGL_GLES2_DIRTY_FOG_COLOR; w->dirty_uniforms |= COGL_GLES2_DIRTY_FOG_COLOR;
} }

View File

@ -264,22 +264,20 @@ struct _CoglGles2WrapperShader
void cogl_gles2_wrapper_init (CoglGles2Wrapper *wrapper); void cogl_gles2_wrapper_init (CoglGles2Wrapper *wrapper);
void cogl_gles2_wrapper_deinit (CoglGles2Wrapper *wrapper); void cogl_gles2_wrapper_deinit (CoglGles2Wrapper *wrapper);
void cogl_wrap_glClearColorx (GLclampx r, GLclampx g, GLclampx b, GLclampx a);
void cogl_wrap_glPushMatrix (); void cogl_wrap_glPushMatrix ();
void cogl_wrap_glPopMatrix (); void cogl_wrap_glPopMatrix ();
void cogl_wrap_glMatrixMode (GLenum mode); void cogl_wrap_glMatrixMode (GLenum mode);
void cogl_wrap_glLoadIdentity (); void cogl_wrap_glLoadIdentity ();
void cogl_wrap_glMultMatrixx (const GLfixed *m); void cogl_wrap_glMultMatrixf (const GLfloat *m);
void cogl_wrap_glFrustumx (GLfixed left, GLfixed right, void cogl_wrap_glFrustumf (GLfloat left, GLfloat right,
GLfixed bottom, GLfixed top, GLfloat bottom, GLfloat top,
GLfixed z_near, GLfixed z_far); GLfloat z_near, GLfloat z_far);
void cogl_wrap_glScalex (GLfixed x, GLfixed y, GLfixed z); void cogl_wrap_glScalef (GLfloat x, GLfloat y, GLfloat z);
void cogl_wrap_glTranslatex (GLfixed x, GLfixed y, GLfixed z); void cogl_wrap_glTranslatef (GLfloat x, GLfloat y, GLfloat z);
void cogl_wrap_glRotatex (GLfixed angle, GLfixed x, GLfixed y, GLfixed z); void cogl_wrap_glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
void cogl_wrap_glOrthox (GLfixed left, GLfixed right, void cogl_wrap_glOrthof (GLfloat left, GLfloat right,
GLfixed bottom, GLfixed top, GLfloat bottom, GLfloat top,
GLfixed near, GLfixed far); GLfloat near, GLfloat far);
void cogl_wrap_glEnable (GLenum cap); void cogl_wrap_glEnable (GLenum cap);
void cogl_wrap_glDisable (GLenum cap); void cogl_wrap_glDisable (GLenum cap);
@ -293,7 +291,7 @@ void cogl_wrap_glColorPointer (GLint size, GLenum type, GLsizei stride,
void cogl_wrap_glNormalPointer (GLenum type, GLsizei stride, void cogl_wrap_glNormalPointer (GLenum type, GLsizei stride,
const GLvoid *pointer); const GLvoid *pointer);
void cogl_wrap_glTexEnvx (GLenum target, GLenum pname, GLfixed param); void cogl_wrap_glTexEnvf (GLenum target, GLenum pname, GLfloat param);
void cogl_wrap_glClientActiveTexture (GLenum texture); void cogl_wrap_glClientActiveTexture (GLenum texture);
void cogl_wrap_glActiveTexture (GLenum texture); void cogl_wrap_glActiveTexture (GLenum texture);
@ -303,18 +301,19 @@ void cogl_wrap_glDisableClientState (GLenum array);
void cogl_wrap_glAlphaFunc (GLenum func, GLclampf ref); void cogl_wrap_glAlphaFunc (GLenum func, GLclampf ref);
void cogl_wrap_glColor4x (GLclampx r, GLclampx g, GLclampx b, GLclampx a); void cogl_wrap_glColor4f (GLclampf r, GLclampf g, GLclampf b, GLclampf a);
void cogl_wrap_glClipPlanex (GLenum plane, GLfixed *equation); void cogl_wrap_glClipPlanef (GLenum plane, GLfloat *equation);
void cogl_wrap_glGetIntegerv (GLenum pname, GLint *params); void cogl_wrap_glGetIntegerv (GLenum pname, GLint *params);
void cogl_wrap_glGetFixedv (GLenum pname, GLfixed *params); void cogl_wrap_glGetFloatv (GLenum pname, GLfloat *params);
void cogl_wrap_glFogx (GLenum pname, GLfixed param); void cogl_wrap_glFogf (GLenum pname, GLfloat param);
void cogl_wrap_glFogxv (GLenum pname, const GLfixed *params); void cogl_wrap_glFogfv (GLenum pname, const GLfloat *params);
void cogl_wrap_glDrawArrays (GLenum mode, GLint first, GLsizei count); void cogl_wrap_glDrawArrays (GLenum mode, GLint first, GLsizei count);
void cogl_wrap_glDrawElements (GLenum mode, GLsizei count, GLenum type,
const GLvoid *indices);
void cogl_wrap_glTexParameteri (GLenum target, GLenum pname, GLfloat param); void cogl_wrap_glTexParameteri (GLenum target, GLenum pname, GLfloat param);
void cogl_gles2_wrapper_bind_texture (GLenum target, GLuint texture, void cogl_gles2_wrapper_bind_texture (GLenum target, GLuint texture,
@ -330,35 +329,35 @@ void _cogl_gles2_clear_cache_for_program (CoglHandle program);
/* If we're not using GL ES 2 then just use the GL functions /* If we're not using GL ES 2 then just use the GL functions
directly */ directly */
#define cogl_wrap_glClearColorx glClearColorx
#define cogl_wrap_glDrawArrays glDrawArrays #define cogl_wrap_glDrawArrays glDrawArrays
#define cogl_wrap_glDrawElements glDrawElements
#define cogl_wrap_glPushMatrix glPushMatrix #define cogl_wrap_glPushMatrix glPushMatrix
#define cogl_wrap_glPopMatrix glPopMatrix #define cogl_wrap_glPopMatrix glPopMatrix
#define cogl_wrap_glMatrixMode glMatrixMode #define cogl_wrap_glMatrixMode glMatrixMode
#define cogl_wrap_glLoadIdentity glLoadIdentity #define cogl_wrap_glLoadIdentity glLoadIdentity
#define cogl_wrap_glMultMatrixx glMultMatrixx #define cogl_wrap_glMultMatrixf glMultMatrixf
#define cogl_wrap_glFrustumx glFrustumx #define cogl_wrap_glFrustumf glFrustumf
#define cogl_wrap_glScalex glScalex #define cogl_wrap_glScalef glScalef
#define cogl_wrap_glTranslatex glTranslatex #define cogl_wrap_glTranslatef glTranslatef
#define cogl_wrap_glRotatex glRotatex #define cogl_wrap_glRotatef glRotatef
#define cogl_wrap_glOrthox glOrthox #define cogl_wrap_glOrthof glOrthof
#define cogl_wrap_glEnable glEnable #define cogl_wrap_glEnable glEnable
#define cogl_wrap_glDisable glDisable #define cogl_wrap_glDisable glDisable
#define cogl_wrap_glTexCoordPointer glTexCoordPointer #define cogl_wrap_glTexCoordPointer glTexCoordPointer
#define cogl_wrap_glVertexPointer glVertexPointer #define cogl_wrap_glVertexPointer glVertexPointer
#define cogl_wrap_glColorPointer glColorPointer #define cogl_wrap_glColorPointer glColorPointer
#define cogl_wrap_glNormalPointer glNormalPointer #define cogl_wrap_glNormalPointer glNormalPointer
#define cogl_wrap_glTexEnvx glTexEnvx #define cogl_wrap_glTexEnvf glTexEnvf
#define cogl_wrap_glActiveTexture glActiveTexture #define cogl_wrap_glActiveTexture glActiveTexture
#define cogl_wrap_glEnableClientState glEnableClientState #define cogl_wrap_glEnableClientState glEnableClientState
#define cogl_wrap_glDisableClientState glDisableClientState #define cogl_wrap_glDisableClientState glDisableClientState
#define cogl_wrap_glAlphaFunc glAlphaFunc #define cogl_wrap_glAlphaFunc glAlphaFunc
#define cogl_wrap_glColor4x glColor4x #define cogl_wrap_glColor4f glColor4f
#define cogl_wrap_glClipPlanex glClipPlanex #define cogl_wrap_glClipPlanef glClipPlanef
#define cogl_wrap_glGetIntegerv glGetIntegerv #define cogl_wrap_glGetIntegerv glGetIntegerv
#define cogl_wrap_glGetFixedv glGetFixedv #define cogl_wrap_glGetFloatv glGetFloatv
#define cogl_wrap_glFogx glFogx #define cogl_wrap_glFogf glFogf
#define cogl_wrap_glFogxv glFogxv #define cogl_wrap_glFogfv glFogfv
#define cogl_wrap_glTexParameteri glTexParameteri #define cogl_wrap_glTexParameteri glTexParameteri
/* The extra third parameter of the bind texture wrapper isn't needed /* The extra third parameter of the bind texture wrapper isn't needed

View File

@ -34,63 +34,35 @@
#include <string.h> #include <string.h>
#include <gmodule.h> #include <gmodule.h>
#include <math.h>
#define _COGL_MAX_BEZ_RECURSE_DEPTH 16 #define _COGL_MAX_BEZ_RECURSE_DEPTH 16
void void
_cogl_rectangle (gint x, _cogl_rectangle (float x,
gint y, float y,
guint width, float width,
guint height) float height)
{ {
/* 32-bit integers are not supported as coord types GLfloat rect_verts[8] = {
in GLES . Fixed type has got 16 bits left of the (GLfloat) x, (GLfloat) y,
point which is equal to short anyway. */ (GLfloat) (x + width), (GLfloat) y,
(GLfloat) x, (GLfloat) (y + height),
GLshort rect_verts[8] = { (GLfloat) (x + width), (GLfloat) (y + height)
(GLshort) x, (GLshort) y,
(GLshort) (x + width), (GLshort) y,
(GLshort) x, (GLshort) (y + height),
(GLshort) (x + width), (GLshort) (y + height)
}; };
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
cogl_enable (COGL_ENABLE_VERTEX_ARRAY cogl_enable (COGL_ENABLE_VERTEX_ARRAY
| (ctx->color_alpha < 255 ? COGL_ENABLE_BLEND : 0)); | (ctx->color_alpha < 255 ? COGL_ENABLE_BLEND : 0));
GE ( cogl_wrap_glVertexPointer (2, GL_SHORT, 0, rect_verts ) ); GE ( cogl_wrap_glVertexPointer (2, GL_FLOAT, 0, rect_verts ) );
GE ( cogl_wrap_glDrawArrays (GL_TRIANGLE_STRIP, 0, 4) ); GE ( cogl_wrap_glDrawArrays (GL_TRIANGLE_STRIP, 0, 4) );
} }
void
_cogl_rectanglex (CoglFixed x,
CoglFixed y,
CoglFixed width,
CoglFixed height)
{
GLfixed rect_verts[8] = {
x, y,
x + width, y,
x, y + height,
x + width, y + height
};
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
cogl_enable (COGL_ENABLE_VERTEX_ARRAY
| (ctx->color_alpha < 255
? COGL_ENABLE_BLEND : 0));
GE( cogl_wrap_glVertexPointer (2, GL_FIXED, 0, rect_verts) );
GE( cogl_wrap_glDrawArrays (GL_TRIANGLE_STRIP, 0, 4) );
}
void void
_cogl_path_add_node (gboolean new_sub_path, _cogl_path_add_node (gboolean new_sub_path,
CoglFixed x, float x,
CoglFixed y) float y)
{ {
CoglPathNode new_node; CoglPathNode new_node;
@ -147,19 +119,17 @@ _cogl_path_stroke_nodes ()
} }
static void static void
_cogl_path_get_bounds (CoglFixedVec2 nodes_min, _cogl_path_get_bounds (floatVec2 nodes_min,
CoglFixedVec2 nodes_max, floatVec2 nodes_max,
gint *bounds_x, float *bounds_x,
gint *bounds_y, float *bounds_y,
guint *bounds_w, float *bounds_w,
guint *bounds_h) float *bounds_h)
{ {
*bounds_x = COGL_FIXED_FLOOR (nodes_min.x); *bounds_x = nodes_min.x;
*bounds_y = COGL_FIXED_FLOOR (nodes_min.y); *bounds_y = nodes_min.y;
*bounds_w = COGL_FIXED_CEIL (nodes_max.x *bounds_w = nodes_max.x - *bounds_x;
- COGL_FIXED_FROM_INT (*bounds_x)); *bounds_h = nodes_max.y - *bounds_y;
*bounds_h = COGL_FIXED_CEIL (nodes_max.y
- COGL_FIXED_FROM_INT (*bounds_y));
} }
static gint compare_ints (gconstpointer a, static gint compare_ints (gconstpointer a,
@ -169,18 +139,18 @@ static gint compare_ints (gconstpointer a,
} }
void void
_cogl_add_path_to_stencil_buffer (CoglFixedVec2 nodes_min, _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min,
CoglFixedVec2 nodes_max, floatVec2 nodes_max,
guint path_size, guint path_size,
CoglPathNode *path, CoglPathNode *path,
gboolean merge) gboolean merge)
{ {
guint path_start = 0; guint path_start = 0;
guint sub_path_num = 0; guint sub_path_num = 0;
gint bounds_x; float bounds_x;
gint bounds_y; float bounds_y;
guint bounds_w; float bounds_w;
guint bounds_h; float bounds_h;
_cogl_path_get_bounds (nodes_min, nodes_max, _cogl_path_get_bounds (nodes_min, nodes_max,
&bounds_x, &bounds_y, &bounds_w, &bounds_h); &bounds_x, &bounds_y, &bounds_w, &bounds_h);
@ -244,12 +214,8 @@ _cogl_add_path_to_stencil_buffer (CoglFixedVec2 nodes_min,
GE( cogl_wrap_glMatrixMode (GL_PROJECTION) ); GE( cogl_wrap_glMatrixMode (GL_PROJECTION) );
GE( cogl_wrap_glPushMatrix () ); GE( cogl_wrap_glPushMatrix () );
GE( cogl_wrap_glLoadIdentity () ); GE( cogl_wrap_glLoadIdentity () );
cogl_rectanglex (-COGL_FIXED_1, -COGL_FIXED_1, cogl_rectangle (-1.0, -1.0, 2, 2);
COGL_FIXED_FROM_INT (2), cogl_rectangle (-1.0, -1.0, 2, 2);
COGL_FIXED_FROM_INT (2));
cogl_rectanglex (-COGL_FIXED_1, -COGL_FIXED_1,
COGL_FIXED_FROM_INT (2),
COGL_FIXED_FROM_INT (2));
GE( cogl_wrap_glPopMatrix () ); GE( cogl_wrap_glPopMatrix () );
GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) ); GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) );
GE( cogl_wrap_glPopMatrix () ); GE( cogl_wrap_glPopMatrix () );
@ -292,14 +258,14 @@ _cogl_path_fill_nodes_scanlines (CoglPathNode *path,
for (i=0; i < bounds_h; i++) for (i=0; i < bounds_h; i++)
scanlines[i]=NULL; scanlines[i]=NULL;
first_x = prev_x = COGL_FIXED_TO_INT (path->x); first_x = prev_x = (path->x);
first_y = prev_y = COGL_FIXED_TO_INT (path->y); first_y = prev_y = (path->y);
/* create scanline intersection list */ /* create scanline intersection list */
for (i=1; i < path_size; i++) for (i=1; i < path_size; i++)
{ {
gint dest_x = COGL_FIXED_TO_INT (path[i].x); gint dest_x = (path[i].x);
gint dest_y = COGL_FIXED_TO_INT (path[i].y); gint dest_y = (path[i].y);
gint ydir; gint ydir;
gint dx; gint dx;
gint dy; gint dy;
@ -362,7 +328,7 @@ _cogl_path_fill_nodes_scanlines (CoglPathNode *path,
{ {
gint spans = 0; gint spans = 0;
gint span_no; gint span_no;
GLfixed *coords; GLfloat *coords;
/* count number of spans */ /* count number of spans */
for (i=0; i < bounds_h; i++) for (i=0; i < bounds_h; i++)
@ -380,7 +346,7 @@ _cogl_path_fill_nodes_scanlines (CoglPathNode *path,
iter = next->next; iter = next->next;
} }
} }
coords = g_malloc0 (spans * sizeof (GLfixed) * 3 * 2 * 2); coords = g_malloc0 (spans * sizeof (GLfloat) * 3 * 2 * 2);
span_no = 0; span_no = 0;
/* build list of triangles */ /* build list of triangles */
@ -390,15 +356,15 @@ _cogl_path_fill_nodes_scanlines (CoglPathNode *path,
while (iter) while (iter)
{ {
GSList *next = iter->next; GSList *next = iter->next;
GLfixed x0, x1; GLfloat x0, x1;
GLfixed y0, y1; GLfloat y0, y1;
if (!next) if (!next)
break; break;
x0 = COGL_FIXED_FROM_INT (GPOINTER_TO_INT (iter->data)); x0 = (float)(GPOINTER_TO_INT (iter->data));
x1 = COGL_FIXED_FROM_INT (GPOINTER_TO_INT (next->data)); x1 = (float)(GPOINTER_TO_INT (next->data));
y0 = COGL_FIXED_FROM_INT (bounds_y + i); y0 = (float)(bounds_y + i);
y1 = COGL_FIXED_FROM_INT (bounds_y + i + 1) + 2048; y1 = (float)(bounds_y + i + 1) + 2048;
/* render scanlines 1.0625 high to avoid gaps when /* render scanlines 1.0625 high to avoid gaps when
transformed */ transformed */
@ -435,10 +401,10 @@ _cogl_path_fill_nodes_scanlines (CoglPathNode *path,
void void
_cogl_path_fill_nodes () _cogl_path_fill_nodes ()
{ {
gint bounds_x; float bounds_x;
gint bounds_y; float bounds_y;
guint bounds_w; float bounds_w;
guint bounds_h; float bounds_h;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);

View File

@ -40,12 +40,14 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h>
#if HAVE_COGL_GLES2 #if HAVE_COGL_GLES2
#define glVertexPointer cogl_wrap_glVertexPointer #define glVertexPointer cogl_wrap_glVertexPointer
#define glTexCoordPointer cogl_wrap_glTexCoordPointer #define glTexCoordPointer cogl_wrap_glTexCoordPointer
#define glColorPointer cogl_wrap_glColorPointer #define glColorPointer cogl_wrap_glColorPointer
#define glDrawArrays cogl_wrap_glDrawArrays #define glDrawArrays cogl_wrap_glDrawArrays
#define glDrawElements cogl_wrap_glDrawElements
#define glTexParameteri cogl_wrap_glTexParameteri #define glTexParameteri cogl_wrap_glTexParameteri
#define glClientActiveTexture cogl_wrap_glClientActiveTexture #define glClientActiveTexture cogl_wrap_glClientActiveTexture
#define glActiveTexture cogl_wrap_glActiveTexture #define glActiveTexture cogl_wrap_glActiveTexture
@ -71,15 +73,15 @@ struct _CoglSpanIter
gint index; gint index;
GArray *array; GArray *array;
CoglTexSliceSpan *span; CoglTexSliceSpan *span;
CoglFixed pos; float pos;
CoglFixed next_pos; float next_pos;
CoglFixed origin; float origin;
CoglFixed cover_start; float cover_start;
CoglFixed cover_end; float cover_end;
CoglFixed intersect_start; float intersect_start;
CoglFixed intersect_end; float intersect_end;
CoglFixed intersect_start_local; float intersect_start_local;
CoglFixed intersect_end_local; float intersect_end_local;
gboolean intersects; gboolean intersects;
}; };
@ -118,7 +120,7 @@ _cogl_span_iter_update (CoglSpanIter *iter)
/* Offset next position by span size */ /* Offset next position by span size */
iter->next_pos = iter->pos + iter->next_pos = iter->pos +
COGL_FIXED_FROM_INT (iter->span->size - iter->span->waste); (float)(iter->span->size - iter->span->waste);
/* Check if span intersects the area to cover */ /* Check if span intersects the area to cover */
if (iter->next_pos <= iter->cover_start || if (iter->next_pos <= iter->cover_start ||
@ -147,9 +149,9 @@ _cogl_span_iter_update (CoglSpanIter *iter)
static void static void
_cogl_span_iter_begin (CoglSpanIter *iter, _cogl_span_iter_begin (CoglSpanIter *iter,
GArray *array, GArray *array,
CoglFixed origin, float origin,
CoglFixed cover_start, float cover_start,
CoglFixed cover_end) float cover_end)
{ {
/* Copy info */ /* Copy info */
iter->index = 0; iter->index = 0;
@ -400,10 +402,10 @@ _cogl_texture_draw_and_read (CoglTexture *tex,
GLint *viewport) GLint *viewport)
{ {
gint bpp; gint bpp;
CoglFixed rx1, ry1; float rx1, ry1;
CoglFixed rx2, ry2; float rx2, ry2;
CoglFixed tx1, ty1; float tx1, ty1;
CoglFixed tx2, ty2; float tx2, ty2;
int bw, bh; int bw, bh;
CoglBitmap rect_bmp; CoglBitmap rect_bmp;
CoglHandle handle; CoglHandle handle;
@ -424,9 +426,9 @@ _cogl_texture_draw_and_read (CoglTexture *tex,
/* Draw the texture image */ /* Draw the texture image */
cogl_texture_rectangle (handle, cogl_texture_rectangle (handle,
0, 0, 0, 0,
COGL_FIXED_FROM_INT (tex->bitmap.width), (float)(tex->bitmap.width),
COGL_FIXED_FROM_INT (tex->bitmap.height), (float)(tex->bitmap.height),
0, 0, COGL_FIXED_1, COGL_FIXED_1); 0, 0, 1.0, 1.0);
/* Read into target bitmap */ /* Read into target bitmap */
prep_for_gl_pixels_download (tex->bitmap.rowstride); prep_for_gl_pixels_download (tex->bitmap.rowstride);
@ -441,7 +443,7 @@ _cogl_texture_draw_and_read (CoglTexture *tex,
ry1 = 0; ry2 = 0; ry1 = 0; ry2 = 0;
ty1 = 0; ty2 = 0; ty1 = 0; ty2 = 0;
#define CFIX COGL_FIXED_FROM_INT #define CFIX (float)
/* Walk Y axis until whole bitmap height consumed */ /* Walk Y axis until whole bitmap height consumed */
for (bh = tex->bitmap.height; bh > 0; bh -= viewport[3]) for (bh = tex->bitmap.height; bh > 0; bh -= viewport[3])
@ -452,7 +454,7 @@ _cogl_texture_draw_and_read (CoglTexture *tex,
/* Normalized texture Y coords */ /* Normalized texture Y coords */
ty1 = ty2; ty1 = ty2;
ty2 = COGL_FIXED_DIV (CFIX (ry2), CFIX (tex->bitmap.height)); ty2 = (CFIX (ry2) / CFIX (tex->bitmap.height));
rx1 = 0; rx2 = 0; rx1 = 0; rx2 = 0;
tx1 = 0; tx2 = 0; tx1 = 0; tx2 = 0;
@ -466,7 +468,7 @@ _cogl_texture_draw_and_read (CoglTexture *tex,
/* Normalized texture X coords */ /* Normalized texture X coords */
tx1 = tx2; tx1 = tx2;
tx2 = COGL_FIXED_DIV (CFIX (rx2), CFIX (tex->bitmap.width)); tx2 = (CFIX (rx2) / CFIX (tex->bitmap.width));
/* Clear buffer with transparent black, draw with white /* Clear buffer with transparent black, draw with white
for direct copy to framebuffer */ for direct copy to framebuffer */
@ -546,10 +548,10 @@ _cogl_texture_download_from_gl (CoglTexture *tex,
GE( cogl_wrap_glPushMatrix () ); GE( cogl_wrap_glPushMatrix () );
GE( cogl_wrap_glLoadIdentity () ); GE( cogl_wrap_glLoadIdentity () );
GE( cogl_wrap_glOrthox (0, COGL_FIXED_FROM_INT (viewport[2]), GE( cogl_wrap_glOrthof (0, (float)(viewport[2]),
0, COGL_FIXED_FROM_INT (viewport[3]), 0, (float)(viewport[3]),
COGL_FIXED_FROM_INT (0), (float)(0),
COGL_FIXED_FROM_INT (100)) ); (float)(100)) );
GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) ); GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) );
GE( cogl_wrap_glPushMatrix () ); GE( cogl_wrap_glPushMatrix () );
@ -664,8 +666,8 @@ _cogl_texture_upload_subregion_to_gl (CoglTexture *tex,
/* Iterate vertical spans */ /* Iterate vertical spans */
for (source_y = src_y, for (source_y = src_y,
_cogl_span_iter_begin (&y_iter, tex->slice_y_spans, _cogl_span_iter_begin (&y_iter, tex->slice_y_spans,
0, COGL_FIXED_FROM_INT (dst_y), 0, (float)(dst_y),
COGL_FIXED_FROM_INT (dst_y + height)); (float)(dst_y + height));
!_cogl_span_iter_end (&y_iter); !_cogl_span_iter_end (&y_iter);
@ -685,8 +687,8 @@ _cogl_texture_upload_subregion_to_gl (CoglTexture *tex,
/* Iterate horizontal spans */ /* Iterate horizontal spans */
for (source_x = src_x, for (source_x = src_x,
_cogl_span_iter_begin (&x_iter, tex->slice_x_spans, _cogl_span_iter_begin (&x_iter, tex->slice_x_spans,
0, COGL_FIXED_FROM_INT (dst_x), 0, (float)(dst_x),
COGL_FIXED_FROM_INT (dst_x + width)); (float)(dst_x + width));
!_cogl_span_iter_end (&x_iter); !_cogl_span_iter_end (&x_iter);
@ -704,15 +706,15 @@ _cogl_texture_upload_subregion_to_gl (CoglTexture *tex,
x_iter.index); x_iter.index);
/* Pick intersection width and height */ /* Pick intersection width and height */
inter_w = COGL_FIXED_TO_INT (x_iter.intersect_end - inter_w = (x_iter.intersect_end -
x_iter.intersect_start); x_iter.intersect_start);
inter_h = COGL_FIXED_TO_INT (y_iter.intersect_end - inter_h = (y_iter.intersect_end -
y_iter.intersect_start); y_iter.intersect_start);
/* Localize intersection top-left corner to slice*/ /* Localize intersection top-left corner to slice*/
local_x = COGL_FIXED_TO_INT (x_iter.intersect_start - local_x = (x_iter.intersect_start -
x_iter.pos); x_iter.pos);
local_y = COGL_FIXED_TO_INT (y_iter.intersect_start - local_y = (y_iter.intersect_start -
y_iter.pos); y_iter.pos);
/* Pick slice GL handle */ /* Pick slice GL handle */
@ -770,7 +772,7 @@ _cogl_texture_upload_subregion_to_gl (CoglTexture *tex,
guint wx, wy; guint wx, wy;
src = source_bmp->data src = source_bmp->data
+ (src_y + COGL_FIXED_TO_INT (y_iter.intersect_start) + (src_y + ((int)y_iter.intersect_start)
- dst_y) - dst_y)
* source_bmp->rowstride * source_bmp->rowstride
+ (src_x + x_span->start + x_span->size - x_span->waste + (src_x + x_span->start + x_span->size - x_span->waste
@ -815,7 +817,7 @@ _cogl_texture_upload_subregion_to_gl (CoglTexture *tex,
guint copy_width; guint copy_width;
src = source_bmp->data src = source_bmp->data
+ (src_x + COGL_FIXED_TO_INT (x_iter.intersect_start) + (src_x + ((int)x_iter.intersect_start)
- dst_x) - dst_x)
* bpp * bpp
+ (src_y + y_span->start + y_span->size - y_span->waste + (src_y + y_span->start + y_span->size - y_span->waste
@ -1314,11 +1316,11 @@ _cogl_texture_free (CoglTexture *tex)
} }
CoglHandle CoglHandle
cogl_texture_new_with_size (guint width, cogl_texture_new_with_size (guint width,
guint height, guint height,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat internal_format) CoglPixelFormat internal_format)
{ {
CoglTexture *tex; CoglTexture *tex;
gint bpp; gint bpp;
@ -1339,7 +1341,7 @@ cogl_texture_new_with_size (guint width,
COGL_HANDLE_DEBUG_NEW (texture, tex); COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = auto_mipmap; tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
tex->bitmap.width = width; tex->bitmap.width = width;
tex->bitmap.height = height; tex->bitmap.height = height;
@ -1374,14 +1376,14 @@ cogl_texture_new_with_size (guint width,
} }
CoglHandle CoglHandle
cogl_texture_new_from_data (guint width, cogl_texture_new_from_data (guint width,
guint height, guint height,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
guint rowstride, guint rowstride,
const guchar *data) const guchar *data)
{ {
CoglTexture *tex; CoglTexture *tex;
gint bpp; gint bpp;
@ -1403,7 +1405,7 @@ cogl_texture_new_from_data (guint width,
COGL_HANDLE_DEBUG_NEW (texture, tex); COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = auto_mipmap; tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
tex->bitmap.width = width; tex->bitmap.width = width;
tex->bitmap.height = height; tex->bitmap.height = height;
@ -1449,30 +1451,13 @@ cogl_texture_new_from_data (guint width,
} }
CoglHandle CoglHandle
cogl_texture_new_from_file (const gchar *filename, cogl_texture_new_from_bitmap (CoglBitmap *bmp,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat internal_format, CoglPixelFormat internal_format)
GError **error)
{ {
CoglBitmap bmp;
CoglTexture *tex; CoglTexture *tex;
g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_HANDLE);
/* Try loading with imaging backend */
if (!_cogl_bitmap_from_file (&bmp, filename, error))
{
/* Try fallback */
if (!_cogl_bitmap_fallback_from_file (&bmp, filename))
return COGL_INVALID_HANDLE;
else if (error && *error)
{
g_error_free (*error);
*error = NULL;
}
}
/* Create new texture and fill with loaded data */ /* Create new texture and fill with loaded data */
tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture)); tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture));
@ -1480,10 +1465,11 @@ cogl_texture_new_from_file (const gchar *filename,
COGL_HANDLE_DEBUG_NEW (texture, tex); COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = auto_mipmap; tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
tex->bitmap = bmp; tex->bitmap = *bmp;
tex->bitmap_owner = TRUE; tex->bitmap_owner = TRUE;
bmp->data = NULL;
tex->slice_x_spans = NULL; tex->slice_x_spans = NULL;
tex->slice_y_spans = NULL; tex->slice_y_spans = NULL;
@ -1524,6 +1510,30 @@ cogl_texture_new_from_file (const gchar *filename,
return _cogl_texture_handle_new (tex); return _cogl_texture_handle_new (tex);
} }
CoglHandle
cogl_texture_new_from_file (const gchar *filename,
gint max_waste,
CoglTextureFlags flags,
CoglPixelFormat internal_format,
GError **error)
{
CoglBitmap *bmp;
CoglHandle handle;
g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_HANDLE);
if (!(bmp = cogl_bitmap_new_from_file (filename, error)))
return COGL_INVALID_HANDLE;
handle = cogl_texture_new_from_bitmap (bmp,
max_waste,
flags,
internal_format);
cogl_bitmap_free (bmp);
return handle;
}
CoglHandle CoglHandle
cogl_texture_new_from_foreign (GLuint gl_handle, cogl_texture_new_from_foreign (GLuint gl_handle,
GLenum gl_target, GLenum gl_target,
@ -2097,7 +2107,9 @@ _cogl_texture_flush_vertices (void)
GE( glTexCoordPointer (2, GL_FLOAT, GE( glTexCoordPointer (2, GL_FLOAT,
sizeof (CoglTextureGLVertex), p->t ) ); sizeof (CoglTextureGLVertex), p->t ) );
GE( glBindTexture (ctx->texture_target, ctx->texture_current) ); GE( cogl_gles2_wrapper_bind_texture (ctx->texture_target,
ctx->texture_current,
ctx->texture_format) );
GE( glDrawElements (GL_TRIANGLES, GE( glDrawElements (GL_TRIANGLES,
needed_indices, needed_indices,
GL_UNSIGNED_SHORT, GL_UNSIGNED_SHORT,
@ -2140,24 +2152,24 @@ _cogl_texture_add_quad_vertices (GLfloat x1, GLfloat y1,
static void static void
_cogl_texture_quad_sw (CoglTexture *tex, _cogl_texture_quad_sw (CoglTexture *tex,
CoglFixed x1, float x1,
CoglFixed y1, float y1,
CoglFixed x2, float x2,
CoglFixed y2, float y2,
CoglFixed tx1, float tx1,
CoglFixed ty1, float ty1,
CoglFixed tx2, float tx2,
CoglFixed ty2) float ty2)
{ {
CoglSpanIter iter_x , iter_y; CoglSpanIter iter_x , iter_y;
CoglFixed tw , th; float tw , th;
CoglFixed tqx , tqy; float tqx , tqy;
CoglFixed first_tx , first_ty; float first_tx , first_ty;
CoglFixed first_qx , first_qy; float first_qx , first_qy;
CoglFixed slice_tx1 , slice_ty1; float slice_tx1 , slice_ty1;
CoglFixed slice_tx2 , slice_ty2; float slice_tx2 , slice_ty2;
CoglFixed slice_qx1 , slice_qy1; float slice_qx1 , slice_qy1;
CoglFixed slice_qx2 , slice_qy2; float slice_qx2 , slice_qy2;
GLuint gl_handle; GLuint gl_handle;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -2172,7 +2184,7 @@ _cogl_texture_quad_sw (CoglTexture *tex,
slices */ slices */
if (tx2 < tx1) if (tx2 < tx1)
{ {
CoglFixed temp = x1; float temp = x1;
x1 = x2; x1 = x2;
x2 = temp; x2 = temp;
temp = tx1; temp = tx1;
@ -2181,7 +2193,7 @@ _cogl_texture_quad_sw (CoglTexture *tex,
} }
if (ty2 < ty1) if (ty2 < ty1)
{ {
CoglFixed temp = y1; float temp = y1;
y1 = y2; y1 = y2;
y2 = temp; y2 = temp;
temp = ty1; temp = ty1;
@ -2190,27 +2202,27 @@ _cogl_texture_quad_sw (CoglTexture *tex,
} }
/* Scale ratio from texture to quad widths */ /* Scale ratio from texture to quad widths */
tw = COGL_FIXED_FROM_INT (tex->bitmap.width); tw = (float)(tex->bitmap.width);
th = COGL_FIXED_FROM_INT (tex->bitmap.height); th = (float)(tex->bitmap.height);
tqx = COGL_FIXED_DIV (x2 - x1, COGL_FIXED_MUL (tw, (tx2 - tx1))); tqx = (x2 - x1) / (tw * (tx2 - tx1));
tqy = COGL_FIXED_DIV (y2 - y1, COGL_FIXED_MUL (th, (ty2 - ty1))); tqy = (y2 - y1) / (th * (ty2 - ty1));
/* Integral texture coordinate for first tile */ /* Integral texture coordinate for first tile */
first_tx = COGL_FIXED_FROM_INT (COGL_FIXED_FLOOR (tx1)); first_tx = (float)(floorf (tx1));
first_ty = COGL_FIXED_FROM_INT (COGL_FIXED_FLOOR (ty1)); first_ty = (float)(floorf (ty1));
/* Denormalize texture coordinates */ /* Denormalize texture coordinates */
first_tx = COGL_FIXED_MUL (first_tx, tw); first_tx = (first_tx * tw);
first_ty = COGL_FIXED_MUL (first_ty, th); first_ty = (first_ty * th);
tx1 = COGL_FIXED_MUL (tx1, tw); tx1 = (tx1 * tw);
ty1 = COGL_FIXED_MUL (ty1, th); ty1 = (ty1 * th);
tx2 = COGL_FIXED_MUL (tx2, tw); tx2 = (tx2 * tw);
ty2 = COGL_FIXED_MUL (ty2, th); ty2 = (ty2 * th);
/* Quad coordinate of the first tile */ /* Quad coordinate of the first tile */
first_qx = x1 - COGL_FIXED_MUL (tx1 - first_tx, tqx); first_qx = x1 - (tx1 - first_tx) * tqx;
first_qy = y1 - COGL_FIXED_MUL (ty1 - first_ty, tqy); first_qy = y1 - (ty1 - first_ty) * tqy;
/* Iterate until whole quad height covered */ /* Iterate until whole quad height covered */
@ -2223,11 +2235,9 @@ _cogl_texture_quad_sw (CoglTexture *tex,
if (!iter_y.intersects) continue; if (!iter_y.intersects) continue;
/* Span-quad intersection in quad coordinates */ /* Span-quad intersection in quad coordinates */
slice_qy1 = first_qy + slice_qy1 = first_qy + (iter_y.intersect_start - first_ty) * tqy;
COGL_FIXED_MUL (iter_y.intersect_start - first_ty, tqy);
slice_qy2 = first_qy + slice_qy2 = first_qy + (iter_y.intersect_end - first_ty) * tqy;
COGL_FIXED_MUL (iter_y.intersect_end - first_ty, tqy);
/* Localize slice texture coordinates */ /* Localize slice texture coordinates */
slice_ty1 = iter_y.intersect_start - iter_y.pos; slice_ty1 = iter_y.intersect_start - iter_y.pos;
@ -2248,11 +2258,9 @@ _cogl_texture_quad_sw (CoglTexture *tex,
if (!iter_x.intersects) continue; if (!iter_x.intersects) continue;
/* Span-quad intersection in quad coordinates */ /* Span-quad intersection in quad coordinates */
slice_qx1 = first_qx + slice_qx1 = first_qx + (iter_x.intersect_start - first_tx) * tqx;
COGL_FIXED_MUL (iter_x.intersect_start - first_tx, tqx);
slice_qx2 = first_qx + slice_qx2 = first_qx + (iter_x.intersect_end - first_tx) * tqx;
COGL_FIXED_MUL (iter_x.intersect_end - first_tx, tqx);
/* Localize slice texture coordinates */ /* Localize slice texture coordinates */
slice_tx1 = iter_x.intersect_start - iter_x.pos; slice_tx1 = iter_x.intersect_start - iter_x.pos;
@ -2265,14 +2273,14 @@ _cogl_texture_quad_sw (CoglTexture *tex,
#if COGL_DEBUG #if COGL_DEBUG
printf("~~~~~ slice (%d,%d)\n", iter_x.index, iter_y.index); printf("~~~~~ slice (%d,%d)\n", iter_x.index, iter_y.index);
printf("qx1: %f\n", COGL_FIXED_TO_FLOAT (slice_qx1)); printf("qx1: %f\n", (slice_qx1));
printf("qy1: %f\n", COGL_FIXED_TO_FLOAT (slice_qy1)); printf("qy1: %f\n", (slice_qy1));
printf("qx2: %f\n", COGL_FIXED_TO_FLOAT (slice_qx2)); printf("qx2: %f\n", (slice_qx2));
printf("qy2: %f\n", COGL_FIXED_TO_FLOAT (slice_qy2)); printf("qy2: %f\n", (slice_qy2));
printf("tx1: %f\n", COGL_FIXED_TO_FLOAT (slice_tx1)); printf("tx1: %f\n", (slice_tx1));
printf("ty1: %f\n", COGL_FIXED_TO_FLOAT (slice_ty1)); printf("ty1: %f\n", (slice_ty1));
printf("tx2: %f\n", COGL_FIXED_TO_FLOAT (slice_tx2)); printf("tx2: %f\n", (slice_tx2));
printf("ty2: %f\n", COGL_FIXED_TO_FLOAT (slice_ty2)); printf("ty2: %f\n", (slice_ty2));
#endif #endif
/* Pick and bind opengl texture object */ /* Pick and bind opengl texture object */
@ -2287,29 +2295,30 @@ _cogl_texture_quad_sw (CoglTexture *tex,
_cogl_texture_flush_vertices (); _cogl_texture_flush_vertices ();
ctx->texture_target = tex->gl_target; ctx->texture_target = tex->gl_target;
ctx->texture_current = gl_handle; ctx->texture_current = gl_handle;
ctx->texture_format = tex->gl_intformat;
_cogl_texture_add_quad_vertices (COGL_FIXED_TO_FLOAT (slice_qx1), _cogl_texture_add_quad_vertices ( (slice_qx1),
COGL_FIXED_TO_FLOAT (slice_qy1), (slice_qy1),
COGL_FIXED_TO_FLOAT (slice_qx2), (slice_qx2),
COGL_FIXED_TO_FLOAT (slice_qy2), (slice_qy2),
COGL_FIXED_TO_FLOAT (slice_tx1), (slice_tx1),
COGL_FIXED_TO_FLOAT (slice_ty1), (slice_ty1),
COGL_FIXED_TO_FLOAT (slice_tx2), (slice_tx2),
COGL_FIXED_TO_FLOAT (slice_ty2)); (slice_ty2));
} }
} }
} }
static void static void
_cogl_texture_quad_hw (CoglTexture *tex, _cogl_texture_quad_hw (CoglTexture *tex,
CoglFixed x1, float x1,
CoglFixed y1, float y1,
CoglFixed x2, float x2,
CoglFixed y2, float y2,
CoglFixed tx1, float tx1,
CoglFixed ty1, float ty1,
CoglFixed tx2, float tx2,
CoglFixed ty2) float ty2)
{ {
GLuint gl_handle; GLuint gl_handle;
CoglTexSliceSpan *x_span; CoglTexSliceSpan *x_span;
@ -2331,6 +2340,7 @@ _cogl_texture_quad_hw (CoglTexture *tex,
_cogl_texture_flush_vertices (); _cogl_texture_flush_vertices ();
ctx->texture_target = tex->gl_target; ctx->texture_target = tex->gl_target;
ctx->texture_current = gl_handle; ctx->texture_current = gl_handle;
ctx->texture_format = tex->gl_intformat;
/* Don't include the waste in the texture coordinates */ /* Don't include the waste in the texture coordinates */
x_span = &g_array_index (tex->slice_x_spans, CoglTexSliceSpan, 0); x_span = &g_array_index (tex->slice_x_spans, CoglTexSliceSpan, 0);
@ -2342,19 +2352,19 @@ _cogl_texture_quad_hw (CoglTexture *tex,
ty1 = ty1 * (y_span->size - y_span->waste) / y_span->size; ty1 = ty1 * (y_span->size - y_span->waste) / y_span->size;
ty2 = ty2 * (y_span->size - y_span->waste) / y_span->size; ty2 = ty2 * (y_span->size - y_span->waste) / y_span->size;
_cogl_texture_add_quad_vertices (COGL_FIXED_TO_FLOAT (x1), _cogl_texture_add_quad_vertices ( (x1),
COGL_FIXED_TO_FLOAT (y1), (y1),
COGL_FIXED_TO_FLOAT (x2), (x2),
COGL_FIXED_TO_FLOAT (y2), (y2),
COGL_FIXED_TO_FLOAT (tx1), (tx1),
COGL_FIXED_TO_FLOAT (ty1), (ty1),
COGL_FIXED_TO_FLOAT (tx2), (tx2),
COGL_FIXED_TO_FLOAT (ty2)); (ty2));
} }
void void
cogl_texture_multiple_rectangles (CoglHandle handle, cogl_texture_multiple_rectangles (CoglHandle handle,
const CoglFixed *verts, const float *verts,
guint n_rects) guint n_rects)
{ {
CoglTexture *tex; CoglTexture *tex;
@ -2401,10 +2411,10 @@ cogl_texture_multiple_rectangles (CoglHandle handle,
if (tex->slice_gl_handles->len == 1 if (tex->slice_gl_handles->len == 1
&& ((cogl_features_available (COGL_FEATURE_TEXTURE_NPOT) && ((cogl_features_available (COGL_FEATURE_TEXTURE_NPOT)
&& tex->gl_target == GL_TEXTURE_2D) && tex->gl_target == GL_TEXTURE_2D)
|| (verts[4] >= 0 && verts[4] <= COGL_FIXED_1 || (verts[4] >= 0 && verts[4] <= 1.0
&& verts[6] >= 0 && verts[6] <= COGL_FIXED_1 && verts[6] >= 0 && verts[6] <= 1.0
&& verts[5] >= 0 && verts[5] <= COGL_FIXED_1 && verts[5] >= 0 && verts[5] <= 1.0
&& verts[7] >= 0 && verts[7] <= COGL_FIXED_1))) && verts[7] >= 0 && verts[7] <= 1.0)))
_cogl_texture_quad_hw (tex, verts[0],verts[1], verts[2],verts[3], _cogl_texture_quad_hw (tex, verts[0],verts[1], verts[2],verts[3],
verts[4],verts[5], verts[6],verts[7]); verts[4],verts[5], verts[6],verts[7]);
else else
@ -2420,16 +2430,16 @@ cogl_texture_multiple_rectangles (CoglHandle handle,
void void
cogl_texture_rectangle (CoglHandle handle, cogl_texture_rectangle (CoglHandle handle,
CoglFixed x1, float x1,
CoglFixed y1, float y1,
CoglFixed x2, float x2,
CoglFixed y2, float y2,
CoglFixed tx1, float tx1,
CoglFixed ty1, float ty1,
CoglFixed tx2, float tx2,
CoglFixed ty2) float ty2)
{ {
CoglFixed verts[8]; float verts[8];
verts[0] = x1; verts[0] = x1;
verts[1] = y1; verts[1] = y1;
@ -2531,7 +2541,7 @@ cogl_texture_polygon (CoglHandle handle,
OpenGL */ OpenGL */
for (i = 0; i < n_vertices; i++, p++) for (i = 0; i < n_vertices; i++, p++)
{ {
#define CFX_F COGL_FIXED_TO_FLOAT #define CFX_F
p->v[0] = CFX_F(vertices[i].x); p->v[0] = CFX_F(vertices[i].x);
p->v[1] = CFX_F(vertices[i].y); p->v[1] = CFX_F(vertices[i].y);

View File

@ -37,6 +37,7 @@
#include "cogl-context.h" #include "cogl-context.h"
#include "cogl-gles2-wrapper.h" #include "cogl-gles2-wrapper.h"
#include <math.h>
/* GL error to string conversion */ /* GL error to string conversion */
#if COGL_DEBUG #if COGL_DEBUG
@ -92,10 +93,10 @@ cogl_paint_init (const CoglColor *color)
fprintf(stderr, "\n ============== Paint Start ================ \n"); fprintf(stderr, "\n ============== Paint Start ================ \n");
#endif #endif
cogl_wrap_glClearColorx (cogl_color_get_red (color), glClearColor (cogl_color_get_red (color),
cogl_color_get_green (color), cogl_color_get_green (color),
cogl_color_get_blue (color), cogl_color_get_blue (color),
0); 0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
cogl_wrap_glDisable (GL_LIGHTING); cogl_wrap_glDisable (GL_LIGHTING);
@ -116,41 +117,21 @@ cogl_pop_matrix (void)
} }
void void
cogl_scale (CoglFixed x, CoglFixed y) cogl_scale (float x, float y)
{ {
GE( cogl_wrap_glScalex (x, y, COGL_FIXED_1) ); GE( cogl_wrap_glScalef (x, y, 1.0) );
} }
void void
cogl_translatex (CoglFixed x, CoglFixed y, CoglFixed z) cogl_translate (float x, float y, float z)
{ {
GE( cogl_wrap_glTranslatex (x, y, z) ); GE( cogl_wrap_glTranslatef (x, y, z) );
} }
void void
cogl_translate (gint x, gint y, gint z) cogl_rotate (float angle, float x, float y, float z)
{ {
GE( cogl_wrap_glTranslatex (COGL_FIXED_FROM_INT(x), GE( cogl_wrap_glRotatef (angle, x, y, z) );
COGL_FIXED_FROM_INT(y),
COGL_FIXED_FROM_INT(z)) );
}
void
cogl_rotatex (CoglFixed angle,
CoglFixed x,
CoglFixed y,
CoglFixed z)
{
GE( cogl_wrap_glRotatex (angle,x,y,z) );
}
void
cogl_rotate (gint angle, gint x, gint y, gint z)
{
GE( cogl_wrap_glRotatex (COGL_FIXED_FROM_INT(angle),
COGL_FIXED_FROM_INT(x),
COGL_FIXED_FROM_INT(y),
COGL_FIXED_FROM_INT(z)) );
} }
static inline gboolean static inline gboolean
@ -315,7 +296,7 @@ cogl_set_source_color (const CoglColor *color)
#else #else
/* conversion can cause issues with picking on some gles implementations */ /* conversion can cause issues with picking on some gles implementations */
GE( cogl_wrap_glColor4x (cogl_color_get_red (color), GE( cogl_wrap_glColor4f (cogl_color_get_red (color),
cogl_color_get_green (color), cogl_color_get_green (color),
cogl_color_get_blue (color), cogl_color_get_blue (color),
cogl_color_get_alpha (color)) ); cogl_color_get_alpha (color)) );
@ -326,22 +307,22 @@ cogl_set_source_color (const CoglColor *color)
} }
static void static void
apply_matrix (const CoglFixed *matrix, CoglFixed *vertex) apply_matrix (const float *matrix, float *vertex)
{ {
int x, y; int x, y;
CoglFixed vertex_out[4] = { 0 }; float vertex_out[4] = { 0 };
for (y = 0; y < 4; y++) for (y = 0; y < 4; y++)
for (x = 0; x < 4; x++) for (x = 0; x < 4; x++)
vertex_out[y] += cogl_fixed_mul (vertex[x], matrix[y + x * 4]); vertex_out[y] += (vertex[x] * matrix[y + x * 4]);
memcpy (vertex, vertex_out, sizeof (vertex_out)); memcpy (vertex, vertex_out, sizeof (vertex_out));
} }
static void static void
project_vertex (CoglFixed *modelview, project_vertex (float *modelview,
CoglFixed *project, float *project,
CoglFixed *vertex) float *vertex)
{ {
int i; int i;
@ -351,62 +332,61 @@ project_vertex (CoglFixed *modelview,
apply_matrix (project, vertex); apply_matrix (project, vertex);
/* Convert from homogenized coordinates */ /* Convert from homogenized coordinates */
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
vertex[i] = cogl_fixed_div (vertex[i], vertex[3]); vertex[i] = (vertex[i] / vertex[3]);
} }
static void static void
set_clip_plane (GLint plane_num, set_clip_plane (GLint plane_num,
const CoglFixed *vertex_a, const float *vertex_a,
const CoglFixed *vertex_b) const float *vertex_b)
{ {
GLfixed plane[4]; GLfloat plane[4];
GLfixed angle; GLfloat angle;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
/* Calculate the angle between the axes and the line crossing the /* Calculate the angle between the axes and the line crossing the
two points */ two points */
angle = cogl_fixed_mul (cogl_fixed_atan2 (vertex_b[1] - vertex_a[1], angle = atan2f (vertex_b[1] - vertex_a[1],
vertex_b[0] - vertex_a[0]), vertex_b[0] - vertex_a[0]) * (180.0/G_PI);
COGL_RADIANS_TO_DEGREES);
GE( cogl_wrap_glPushMatrix () ); GE( cogl_wrap_glPushMatrix () );
/* Load the identity matrix and multiply by the reverse of the /* Load the identity matrix and multiply by the reverse of the
projection matrix so we can specify the plane in screen projection matrix so we can specify the plane in screen
coordinates */ coordinates */
GE( cogl_wrap_glLoadIdentity () ); GE( cogl_wrap_glLoadIdentity () );
GE( cogl_wrap_glMultMatrixx ((GLfixed *) ctx->inverse_projection) ); GE( cogl_wrap_glMultMatrixf ((GLfloat *) ctx->inverse_projection) );
/* Rotate about point a */ /* Rotate about point a */
GE( cogl_wrap_glTranslatex (vertex_a[0], vertex_a[1], vertex_a[2]) ); GE( cogl_wrap_glTranslatef (vertex_a[0], vertex_a[1], vertex_a[2]) );
/* Rotate the plane by the calculated angle so that it will connect /* Rotate the plane by the calculated angle so that it will connect
the two points */ the two points */
GE( cogl_wrap_glRotatex (angle, 0.0f, 0.0f, 1.0f) ); GE( cogl_wrap_glRotatef (angle, 0.0f, 0.0f, 1.0f) );
GE( cogl_wrap_glTranslatex (-vertex_a[0], -vertex_a[1], -vertex_a[2]) ); GE( cogl_wrap_glTranslatef (-vertex_a[0], -vertex_a[1], -vertex_a[2]) );
plane[0] = 0; plane[0] = 0;
plane[1] = -COGL_FIXED_1; plane[1] = -1.0;
plane[2] = 0; plane[2] = 0;
plane[3] = vertex_a[1]; plane[3] = vertex_a[1];
GE( cogl_wrap_glClipPlanex (plane_num, plane) ); GE( cogl_wrap_glClipPlanef (plane_num, plane) );
GE( cogl_wrap_glPopMatrix () ); GE( cogl_wrap_glPopMatrix () );
} }
void void
_cogl_set_clip_planes (CoglFixed x_offset, _cogl_set_clip_planes (float x_offset,
CoglFixed y_offset, float y_offset,
CoglFixed width, float width,
CoglFixed height) float height)
{ {
GLfixed modelview[16], projection[16]; GLfloat modelview[16], projection[16];
CoglFixed vertex_tl[4] = { x_offset, y_offset, 0, COGL_FIXED_1 }; float vertex_tl[4] = { x_offset, y_offset, 0, 1.0 };
CoglFixed vertex_tr[4] = { x_offset + width, y_offset, 0, COGL_FIXED_1 }; float vertex_tr[4] = { x_offset + width, y_offset, 0, 1.0 };
CoglFixed vertex_bl[4] = { x_offset, y_offset + height, 0, COGL_FIXED_1 }; float vertex_bl[4] = { x_offset, y_offset + height, 0, 1.0 };
CoglFixed vertex_br[4] = { x_offset + width, y_offset + height, float vertex_br[4] = { x_offset + width, y_offset + height,
0, COGL_FIXED_1 }; 0, 1.0 };
GE( cogl_wrap_glGetFixedv (GL_MODELVIEW_MATRIX, modelview) ); GE( cogl_wrap_glGetFloatv (GL_MODELVIEW_MATRIX, modelview) );
GE( cogl_wrap_glGetFixedv (GL_PROJECTION_MATRIX, projection) ); GE( cogl_wrap_glGetFloatv (GL_PROJECTION_MATRIX, projection) );
project_vertex (modelview, projection, vertex_tl); project_vertex (modelview, projection, vertex_tl);
project_vertex (modelview, projection, vertex_tr); project_vertex (modelview, projection, vertex_tr);
@ -421,7 +401,7 @@ _cogl_set_clip_planes (CoglFixed x_offset,
if ((vertex_tl[0] < vertex_tr[0] ? 1 : 0) if ((vertex_tl[0] < vertex_tr[0] ? 1 : 0)
!= (vertex_bl[1] < vertex_tl[1] ? 1 : 0)) != (vertex_bl[1] < vertex_tl[1] ? 1 : 0))
{ {
CoglFixed temp[4]; float temp[4];
memcpy (temp, vertex_tl, sizeof (temp)); memcpy (temp, vertex_tl, sizeof (temp));
memcpy (vertex_tl, vertex_tr, sizeof (temp)); memcpy (vertex_tl, vertex_tr, sizeof (temp));
memcpy (vertex_tr, temp, sizeof (temp)); memcpy (vertex_tr, temp, sizeof (temp));
@ -437,10 +417,10 @@ _cogl_set_clip_planes (CoglFixed x_offset,
} }
void void
_cogl_add_stencil_clip (CoglFixed x_offset, _cogl_add_stencil_clip (float x_offset,
CoglFixed y_offset, float y_offset,
CoglFixed width, float width,
CoglFixed height, float height,
gboolean first) gboolean first)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -457,7 +437,7 @@ _cogl_add_stencil_clip (CoglFixed x_offset,
GE( glStencilFunc (GL_NEVER, 0x1, 0x1) ); GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
GE( glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE) ); GE( glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE) );
cogl_rectanglex (x_offset, y_offset, width, height); cogl_rectangle (x_offset, y_offset, width, height);
} }
else else
{ {
@ -465,7 +445,7 @@ _cogl_add_stencil_clip (CoglFixed x_offset,
rectangle */ rectangle */
GE( glStencilFunc (GL_NEVER, 0x1, 0x3) ); GE( glStencilFunc (GL_NEVER, 0x1, 0x3) );
GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) ); GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
cogl_rectanglex (x_offset, y_offset, width, height); cogl_rectangle (x_offset, y_offset, width, height);
/* Subtract one from all pixels in the stencil buffer so that /* Subtract one from all pixels in the stencil buffer so that
only pixels where both the original stencil buffer and the only pixels where both the original stencil buffer and the
@ -476,9 +456,7 @@ _cogl_add_stencil_clip (CoglFixed x_offset,
GE( cogl_wrap_glMatrixMode (GL_PROJECTION) ); GE( cogl_wrap_glMatrixMode (GL_PROJECTION) );
GE( cogl_wrap_glPushMatrix () ); GE( cogl_wrap_glPushMatrix () );
GE( cogl_wrap_glLoadIdentity () ); GE( cogl_wrap_glLoadIdentity () );
cogl_rectanglex (-COGL_FIXED_1, -COGL_FIXED_1, cogl_rectangle (-1.0, -1.0, 2, 2);
COGL_FIXED_FROM_INT (2),
COGL_FIXED_FROM_INT (2));
GE( cogl_wrap_glPopMatrix () ); GE( cogl_wrap_glPopMatrix () );
GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) ); GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) );
GE( cogl_wrap_glPopMatrix () ); GE( cogl_wrap_glPopMatrix () );
@ -490,10 +468,10 @@ _cogl_add_stencil_clip (CoglFixed x_offset,
} }
void void
_cogl_set_matrix (const CoglFixed *matrix) _cogl_set_matrix (const float *matrix)
{ {
GE( cogl_wrap_glLoadIdentity () ); GE( cogl_wrap_glLoadIdentity () );
GE( cogl_wrap_glMultMatrixx (matrix) ); GE( cogl_wrap_glMultMatrixf (matrix) );
} }
void void
@ -522,25 +500,25 @@ _cogl_disable_clip_planes (void)
void void
cogl_alpha_func (COGLenum func, cogl_alpha_func (COGLenum func,
CoglFixed ref) float ref)
{ {
GE( cogl_wrap_glAlphaFunc (func, COGL_FIXED_TO_FLOAT(ref)) ); GE( cogl_wrap_glAlphaFunc (func, (ref)) );
} }
/* /*
* Fixed point implementation of the perspective function * Fixed point implementation of the perspective function
*/ */
void void
cogl_perspective (CoglFixed fovy, cogl_perspective (float fovy,
CoglFixed aspect, float aspect,
CoglFixed zNear, float zNear,
CoglFixed zFar) float zFar)
{ {
CoglFixed xmax, ymax; float xmax, ymax;
CoglFixed x, y, c, d; float x, y, c, d;
CoglFixed fovy_rad_half = cogl_fixed_mul (fovy, COGL_FIXED_PI) / 360; float fovy_rad_half = (fovy * G_PI) / 360;
GLfixed m[16]; GLfloat m[16];
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -558,76 +536,74 @@ cogl_perspective (CoglFixed fovy,
* 2) When working with small numbers, we can are loosing significant * 2) When working with small numbers, we can are loosing significant
* precision * precision
*/ */
ymax = cogl_fixed_mul (zNear, ymax = (zNear * (sinf (fovy_rad_half) / cosf (fovy_rad_half)));
cogl_fixed_div (cogl_fixed_sin (fovy_rad_half), xmax = (ymax * aspect);
cogl_fixed_cos (fovy_rad_half)));
xmax = cogl_fixed_mul (ymax, aspect);
x = cogl_fixed_div (zNear, xmax); x = (zNear / xmax);
y = cogl_fixed_div (zNear, ymax); y = (zNear / ymax);
c = cogl_fixed_div (-(zFar + zNear), ( zFar - zNear)); c = (-(zFar + zNear) / ( zFar - zNear));
d = cogl_fixed_div (-(cogl_fixed_mul (2 * zFar, zNear)), (zFar - zNear)); d = (-(2 * zFar) * zNear) / (zFar - zNear);
#define M(row,col) m[col*4+row] #define M(row,col) m[col*4+row]
M(0,0) = x; M(0,0) = x;
M(1,1) = y; M(1,1) = y;
M(2,2) = c; M(2,2) = c;
M(2,3) = d; M(2,3) = d;
M(3,2) = -COGL_FIXED_1; M(3,2) = -1.0;
GE( cogl_wrap_glMultMatrixx (m) ); GE( cogl_wrap_glMultMatrixf (m) );
GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) ); GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) );
/* Calculate and store the inverse of the matrix */ /* Calculate and store the inverse of the matrix */
memset (ctx->inverse_projection, 0, sizeof (CoglFixed) * 16); memset (ctx->inverse_projection, 0, sizeof (float) * 16);
#define m ctx->inverse_projection #define m ctx->inverse_projection
M(0, 0) = cogl_fixed_div (COGL_FIXED_1, x); M(0, 0) = (1.0 / x);
M(1, 1) = cogl_fixed_div (COGL_FIXED_1, y); M(1, 1) = (1.0 / y);
M(2, 3) = -COGL_FIXED_1; M(2, 3) = -1.0;
M(3, 2) = cogl_fixed_div (COGL_FIXED_1, d); M(3, 2) = (1.0 / d);
M(3, 3) = cogl_fixed_div (c, d); M(3, 3) = (c / d);
#undef m #undef m
#undef M #undef M
} }
void void
cogl_frustum (CoglFixed left, cogl_frustum (float left,
CoglFixed right, float right,
CoglFixed bottom, float bottom,
CoglFixed top, float top,
CoglFixed z_near, float z_near,
CoglFixed z_far) float z_far)
{ {
CoglFixed c, d; float c, d;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
GE( cogl_wrap_glMatrixMode (GL_PROJECTION) ); GE( cogl_wrap_glMatrixMode (GL_PROJECTION) );
GE( cogl_wrap_glLoadIdentity () ); GE( cogl_wrap_glLoadIdentity () );
GE( cogl_wrap_glFrustumx (left, right, GE( cogl_wrap_glFrustumf (left, right,
bottom, top, bottom, top,
z_near, z_far) ); z_near, z_far) );
GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) ); GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) );
/* Calculate and store the inverse of the matrix */ /* Calculate and store the inverse of the matrix */
memset (ctx->inverse_projection, 0, sizeof (CoglFixed) * 16); memset (ctx->inverse_projection, 0, sizeof (float) * 16);
c = -cogl_fixed_div (z_far + z_near, z_far - z_near); c = -(z_far + z_near / z_far - z_near);
d = -cogl_fixed_div (2 * cogl_fixed_mul (z_far, z_near), z_far - z_near); d = -(2 * (z_far * z_near) / z_far - z_near);
#define M(row,col) ctx->inverse_projection[col*4+row] #define M(row,col) ctx->inverse_projection[col*4+row]
M(0,0) = cogl_fixed_div (right - left, 2 * z_near); M(0,0) = (right - left / 2 * z_near);
M(0,3) = cogl_fixed_div (right + left, 2 * z_near); M(0,3) = (right + left / 2 * z_near);
M(1,1) = cogl_fixed_div (top - bottom, 2 * z_near); M(1,1) = (top - bottom / 2 * z_near);
M(1,3) = cogl_fixed_div (top + bottom, 2 * z_near); M(1,3) = (top + bottom / 2 * z_near);
M(2,3) = -COGL_FIXED_1; M(2,3) = -1.0;
M(3,2) = cogl_fixed_div (COGL_FIXED_1, d); M(3,2) = (1.0 / d);
M(3,3) = cogl_fixed_div (c, d); M(3,3) = (c / d);
#undef M #undef M
} }
@ -639,51 +615,44 @@ cogl_viewport (guint width,
} }
void void
cogl_setup_viewport (guint w, cogl_setup_viewport (guint w,
guint h, guint h,
CoglFixed fovy, float fovy,
CoglFixed aspect, float aspect,
CoglFixed z_near, float z_near,
CoglFixed z_far) float z_far)
{ {
gint width = (gint) w; gint width = (gint) w;
gint height = (gint) h; gint height = (gint) h;
CoglFixed z_camera; float z_camera;
float projection_matrix[16];
GE( glViewport (0, 0, width, height) ); GE( glViewport (0, 0, width, height) );
/* For Ortho projection. /* For Ortho projection.
* cogl_wrap_glOrthox (0, width << 16, 0, height << 16, -1 << 16, 1 << 16); * cogl_wrap_glOrthof (0, width << 16, 0, height << 16, -1 << 16, 1 << 16);
*/ */
cogl_perspective (fovy, aspect, z_near, z_far); cogl_perspective (fovy, aspect, z_near, z_far);
GE( cogl_wrap_glLoadIdentity () );
/* /*
* camera distance from screen, 0.5 * tan (FOV) * camera distance from screen
* *
* See comments in ../gl/cogl.c * See comments in ../gl/cogl.c
*/ */
#define DEFAULT_Z_CAMERA 0.869f
z_camera = COGL_FIXED_FROM_FLOAT (DEFAULT_Z_CAMERA);
if (fovy != COGL_FIXED_60) cogl_get_projection_matrix (projection_matrix);
{ z_camera = 0.5 * projection_matrix[0];
CoglFixed fovy_rad = cogl_fixed_mul (fovy, COGL_FIXED_PI) / 180;
z_camera = cogl_fixed_div (cogl_fixed_sin (fovy_rad),
cogl_fixed_cos (fovy_rad)) >> 1;
}
GE( cogl_wrap_glTranslatex (-1 << 15, -1 << 15, -z_camera) ); GE( cogl_wrap_glLoadIdentity () );
GE( cogl_wrap_glScalex ( COGL_FIXED_1 / width, GE( cogl_wrap_glTranslatef (-0.5f, -0.5f, -z_camera) );
-COGL_FIXED_1 / height,
COGL_FIXED_1 / width) );
GE( cogl_wrap_glTranslatex (0, -COGL_FIXED_1 * height, 0) ); GE( cogl_wrap_glScalef ( 1.0 / width,
-1.0 / height,
1.0 / width) );
GE( cogl_wrap_glTranslatef (0, -1.0 * height, 0) );
} }
static void static void
@ -735,19 +704,19 @@ cogl_features_available (CoglFeatureFlags features)
} }
void void
cogl_get_modelview_matrix (CoglFixed m[16]) cogl_get_modelview_matrix (float m[16])
{ {
cogl_wrap_glGetFixedv(GL_MODELVIEW_MATRIX, &m[0]); cogl_wrap_glGetFloatv (GL_MODELVIEW_MATRIX, m);
} }
void void
cogl_get_projection_matrix (CoglFixed m[16]) cogl_get_projection_matrix (float m[16])
{ {
cogl_wrap_glGetFixedv(GL_PROJECTION_MATRIX, &m[0]); cogl_wrap_glGetFloatv (GL_PROJECTION_MATRIX, m);
} }
void void
cogl_get_viewport (CoglFixed v[4]) cogl_get_viewport (float v[4])
{ {
GLint viewport[4]; GLint viewport[4];
int i; int i;
@ -755,7 +724,7 @@ cogl_get_viewport (CoglFixed v[4])
cogl_wrap_glGetIntegerv (GL_VIEWPORT, viewport); cogl_wrap_glGetIntegerv (GL_VIEWPORT, viewport);
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
v[i] = COGL_FIXED_FROM_INT (viewport[i]); v[i] = (float)(viewport[i]);
} }
void void
@ -773,11 +742,11 @@ cogl_get_bitmasks (gint *red, gint *green, gint *blue, gint *alpha)
void void
cogl_fog_set (const CoglColor *fog_color, cogl_fog_set (const CoglColor *fog_color,
CoglFixed density, float density,
CoglFixed z_near, float z_near,
CoglFixed z_far) float z_far)
{ {
GLfixed fogColor[4]; GLfloat fogColor[4];
fogColor[0] = cogl_color_get_red (fog_color); fogColor[0] = cogl_color_get_red (fog_color);
fogColor[1] = cogl_color_get_green (fog_color); fogColor[1] = cogl_color_get_green (fog_color);
@ -786,12 +755,12 @@ cogl_fog_set (const CoglColor *fog_color,
cogl_wrap_glEnable (GL_FOG); cogl_wrap_glEnable (GL_FOG);
cogl_wrap_glFogxv (GL_FOG_COLOR, fogColor); cogl_wrap_glFogfv (GL_FOG_COLOR, fogColor);
cogl_wrap_glFogx (GL_FOG_MODE, GL_LINEAR); cogl_wrap_glFogf (GL_FOG_MODE, GL_LINEAR);
glHint (GL_FOG_HINT, GL_NICEST); glHint (GL_FOG_HINT, GL_NICEST);
cogl_wrap_glFogx (GL_FOG_DENSITY, (GLfixed) density); cogl_wrap_glFogf (GL_FOG_DENSITY, (GLfloat) density);
cogl_wrap_glFogx (GL_FOG_START, (GLfixed) z_near); cogl_wrap_glFogf (GL_FOG_START, (GLfloat) z_near);
cogl_wrap_glFogx (GL_FOG_END, (GLfixed) z_far); cogl_wrap_glFogf (GL_FOG_END, (GLfloat) z_far);
} }