Adds cogl_framebuffer_draw_[*_]rectangle functions

This adds experimental 2.0 api replacements for the cogl_rectangle[_*]
functions that don't depend on having a current pipeline set on the
context via cogl_{set,push}_source() or having a current framebuffer set
on the context via cogl_push_framebuffer(). The aim for 2.0 is to switch
away from having a statefull context that affects drawing to having
framebuffer drawing apis that are explicitly passed a framebuffer and
pipeline.

To test this change several of the conformance tests were updated to use
this api instead of cogl_rectangle and
cogl_rectangle_with_texture_coords. Since it's quite laborious going
through all of the conformance tests the opportunity was taken to make
other clean ups in the conformance tests to replace other uses of
1.x api with experimental 2.0 api so long as that didn't affect what was
being tested.
This commit is contained in:
Robert Bragg 2012-03-16 19:54:13 +00:00
parent 596b508653
commit 3881fd3259
48 changed files with 1235 additions and 790 deletions

View File

@ -46,6 +46,7 @@
#include "cogl-offscreen.h"
#include "cogl1-context.h"
#include "cogl-private.h"
#include "cogl-primitives-private.h"
#ifndef GL_FRAMEBUFFER
#define GL_FRAMEBUFFER 0x8D40
@ -3244,3 +3245,151 @@ cogl_framebuffer_draw_primitive (CoglFramebuffer *framebuffer,
_cogl_framebuffer_draw_primitive (framebuffer, pipeline, primitive,
COGL_DRAW_SKIP_LEGACY_STATE);
}
void
cogl_framebuffer_draw_rectangle (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
float x_1,
float y_1,
float x_2,
float y_2)
{
const float position[4] = {x_1, y_1, x_2, y_2};
CoglMultiTexturedRect rect;
/* XXX: All the _*_rectangle* APIs normalize their input into an array of
* _CoglMultiTexturedRect rectangles and pass these on to our work horse;
* _cogl_framebuffer_draw_multitextured_rectangles.
*/
rect.position = position;
rect.tex_coords = NULL;
rect.tex_coords_len = 0;
_cogl_framebuffer_draw_multitextured_rectangles (framebuffer,
pipeline,
&rect,
1,
TRUE);
}
void
cogl_framebuffer_draw_textured_rectangle (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
float x_1,
float y_1,
float x_2,
float y_2,
float s_1,
float t_1,
float s_2,
float t_2)
{
const float position[4] = {x_1, y_1, x_2, y_2};
const float tex_coords[4] = {s_1, t_1, s_2, t_2};
CoglMultiTexturedRect rect;
/* XXX: All the _*_rectangle* APIs normalize their input into an array of
* CoglMultiTexturedRect rectangles and pass these on to our work horse;
* _cogl_framebuffer_draw_multitextured_rectangles.
*/
rect.position = position;
rect.tex_coords = tex_coords;
rect.tex_coords_len = 4;
_cogl_framebuffer_draw_multitextured_rectangles (framebuffer,
pipeline,
&rect,
1,
TRUE);
}
void
cogl_framebuffer_draw_multitextured_rectangle (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
float x_1,
float y_1,
float x_2,
float y_2,
const float *tex_coords,
int tex_coords_len)
{
const float position[4] = {x_1, y_1, x_2, y_2};
CoglMultiTexturedRect rect;
/* XXX: All the _*_rectangle* APIs normalize their input into an array of
* CoglMultiTexturedRect rectangles and pass these on to our work horse;
* _cogl_framebuffer_draw_multitextured_rectangles.
*/
rect.position = position;
rect.tex_coords = tex_coords;
rect.tex_coords_len = tex_coords_len;
_cogl_framebuffer_draw_multitextured_rectangles (framebuffer,
pipeline,
&rect,
1,
TRUE);
}
void
cogl_framebuffer_draw_rectangles (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
const float *coordinates,
unsigned int n_rectangles)
{
CoglMultiTexturedRect *rects;
int i;
/* XXX: All the _*_rectangle* APIs normalize their input into an array of
* CoglMultiTexturedRect rectangles and pass these on to our work horse;
* _cogl_framebuffer_draw_multitextured_rectangles.
*/
rects = g_alloca (n_rectangles * sizeof (CoglMultiTexturedRect));
for (i = 0; i < n_rectangles; i++)
{
rects[i].position = &coordinates[i * 4];
rects[i].tex_coords = NULL;
rects[i].tex_coords_len = 0;
}
_cogl_framebuffer_draw_multitextured_rectangles (framebuffer,
pipeline,
rects,
n_rectangles,
TRUE);
}
void
cogl_framebuffer_draw_textured_rectangles (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
const float *coordinates,
unsigned int n_rectangles)
{
CoglMultiTexturedRect *rects;
int i;
/* XXX: All the _*_rectangle* APIs normalize their input into an array of
* _CoglMultiTexturedRect rectangles and pass these on to our work horse;
* _cogl_framebuffer_draw_multitextured_rectangles.
*/
rects = g_alloca (n_rectangles * sizeof (CoglMultiTexturedRect));
for (i = 0; i < n_rectangles; i++)
{
rects[i].position = &coordinates[i * 8];
rects[i].tex_coords = &coordinates[i * 8 + 4];
rects[i].tex_coords_len = 4;
}
_cogl_framebuffer_draw_multitextured_rectangles (framebuffer,
pipeline,
rects,
n_rectangles,
TRUE);
}

View File

@ -990,7 +990,13 @@ cogl_framebuffer_clear4f (CoglFramebuffer *framebuffer,
* @primitive: A #CoglPrimitive geometry object
*
* Draws the given @primitive geometry to the specified destination
* @framebuffer using the graphics processing pipeline described by @pipeline.
* @framebuffer using the graphics processing state described by @pipeline.
*
* This drawing api doesn't support high-level meta texture types such
* as #CoglTexture2DSliced so it is the user's responsibility to
* ensure that only low-level textures that can be directly sampled by
* a GPU such as #CoglTexture2D, #CoglTextureRectangle or #CoglTexture3D
* are associated with layers of the given @pipeline.
*
* <note>This api doesn't support any of the legacy global state options such
* as cogl_set_depth_test_enabled(), cogl_set_backface_culling_enabled() or
@ -1025,6 +1031,12 @@ cogl_framebuffer_draw_primitive (CoglFramebuffer *framebuffer,
* be drawn, such as positions, colors and normals and should be %NULL
* terminated.
*
* This drawing api doesn't support high-level meta texture types such
* as #CoglTexture2DSliced so it is the user's responsibility to
* ensure that only low-level textures that can be directly sampled by
* a GPU such as #CoglTexture2D, #CoglTextureRectangle or #CoglTexture3D
* are associated with layers of the given @pipeline.
*
* Stability: unstable
* Since: 1.10
*/
@ -1059,6 +1071,12 @@ cogl_framebuffer_vdraw_attributes (CoglFramebuffer *framebuffer,
* be drawn, such as positions, colors and normals and the number of attributes
* is given as @n_attributes.
*
* This drawing api doesn't support high-level meta texture types such
* as #CoglTexture2DSliced so it is the user's responsibility to
* ensure that only low-level textures that can be directly sampled by
* a GPU such as #CoglTexture2D, #CoglTextureRectangle or #CoglTexture3D
* are associated with layers of the given @pipeline.
*
* <note>This api doesn't support any of the legacy global state options such
* as cogl_set_depth_test_enabled(), cogl_set_backface_culling_enabled() or
* cogl_program_use()</note>
@ -1107,8 +1125,8 @@ cogl_framebuffer_draw_attributes (CoglFramebuffer *framebuffer,
* multiple entries in the index array can refer back to a single
* shared vertex.
*
* <note>The @indices array must at least be as long @first_vertex +
* @n_vertices otherwise the GPU will overrun the indices array when
* <note>The @indices array must be at least as long as @first_vertex
* + @n_vertices otherwise the GPU will overrun the indices array when
* looking up vertex data.</note>
*
* Since it's very common to want to draw a run of rectangles using
@ -1116,6 +1134,12 @@ cogl_framebuffer_draw_attributes (CoglFramebuffer *framebuffer,
* cogl_get_rectangle_indices() to get a set of indices that can be
* shared.
*
* This drawing api doesn't support high-level meta texture types such
* as #CoglTexture2DSliced so it is the user's responsibility to
* ensure that only low-level textures that can be directly sampled by
* a GPU such as #CoglTexture2D, #CoglTextureRectangle or
* #CoglTexture3D are associated with layers of the given @pipeline.
*
* <note>This api doesn't support any of the legacy global state
* options such as cogl_set_depth_test_enabled(),
* cogl_set_backface_culling_enabled() or cogl_program_use()</note>
@ -1166,8 +1190,8 @@ cogl_framebuffer_vdraw_indexed_attributes (CoglFramebuffer *framebuffer,
* multiple entries in the index array can refer back to a single
* shared vertex.
*
* <note>The @indices array must at least be as long @first_vertex +
* @n_vertices otherwise the GPU will overrun the indices array when
* <note>The @indices array must be at least as long as @first_vertex
* + @n_vertices otherwise the GPU will overrun the indices array when
* looking up vertex data.</note>
*
* Since it's very common to want to draw a run of rectangles using
@ -1175,6 +1199,12 @@ cogl_framebuffer_vdraw_indexed_attributes (CoglFramebuffer *framebuffer,
* cogl_get_rectangle_indices() to get a set of indices that can be
* shared.
*
* This drawing api doesn't support high-level meta texture types such
* as #CoglTexture2DSliced so it is the user's responsibility to
* ensure that only low-level textures that can be directly sampled by
* a GPU such as #CoglTexture2D, #CoglTextureRectangle or
* #CoglTexture3D are associated with layers of the given @pipeline.
*
* <note>This api doesn't support any of the legacy global state
* options such as cogl_set_depth_test_enabled(),
* cogl_set_backface_culling_enabled() or cogl_program_use()</note>
@ -1192,6 +1222,278 @@ cogl_framebuffer_draw_indexed_attributes (CoglFramebuffer *framebuffer,
CoglAttribute **attributes,
int n_attributes);
/**
* cogl_framebuffer_draw_rectangle:
* @framebuffer: A destination #CoglFramebuffer
* @pipeline: A #CoglPipeline state object
* @x_1: X coordinate of the top-left corner
* @y_1: Y coordinate of the top-left corner
* @x_2: X coordinate of the bottom-right corner
* @y_2: Y coordinate of the bottom-right corner
*
* Draws a rectangle to @framebuffer with the given @pipeline state
* and with the top left corner positioned at (@x_1, @y_1) and the
* bottom right corner positioned at (@x_2, @y_2).
*
* <note>The position is the position before the rectangle has been
* transformed by the model-view matrix and the projection
* matrix.</note>
*
* <note>If you want to describe a rectangle with a texture mapped on
* it then you can use
* cogl_framebuffer_draw_textured_rectangle().<note>
*
* Since: 1.10
* Stability: unstable
*/
void
cogl_framebuffer_draw_rectangle (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
float x_1,
float y_1,
float x_2,
float y_2);
/**
* cogl_framebuffer_draw_textured_rectangle:
* @framebuffer: A destination #CoglFramebuffer
* @pipeline: A #CoglPipeline state object
* @x_1: x coordinate upper left on screen.
* @y_1: y coordinate upper left on screen.
* @x_2: x coordinate lower right on screen.
* @y_2: y coordinate lower right on screen.
* @s_1: S texture coordinate of the top-left coorner
* @t_1: T texture coordinate of the top-left coorner
* @s_2: S texture coordinate of the bottom-right coorner
* @t_2: T texture coordinate of the bottom-right coorner
*
* Draws a textured rectangle to @framebuffer using the given
* @pipeline state with the top left corner positioned at (@x_1, @y_1)
* and the bottom right corner positioned at (@x_2, @y_2). The top
* left corner will have texture coordinates of (@s_1, @t_1) and the
* bottom right corner will have texture coordinates of (@s_2, @t_2).
*
* <note>The position is the position before the rectangle has been
* transformed by the model-view matrix and the projection
* matrix.</note>
*
* This is a high level drawing api that can handle any kind of
* #CoglMetaTexture texture such as #CoglTexture2DSliced textures
* which may internally be comprised of multiple low-level textures.
* This is unlike low-level drawing apis such as
* cogl_framebuffer_draw_primitive() or
* cogl_framebuffer_draw_attributes() which only support low level
* texture types that are directly supported by GPUs such as
* #CoglTexture2D.
*
* <note>The given texture coordinates will only be used for the first
* texture layer of the pipeline and if your pipeline has more than
* one layer then all other layers will have default texture
* coordinates of @s_1=0.0 @t_1=0.0 @s_2=1.0 @t_2=1.0 </note>
*
* The given texture coordinates should always be normalized such that
* (0, 0) corresponds to the top left and (1, 1) corresponds to the
* bottom right. To map an entire texture across the rectangle pass
* in @s_1=%0, @t_1=%0, @s_2=%1, @t_2=%1.
*
* <note>Even if you have associated a #CoglTextureRectangle texture
* with one of your @pipeline layers which normally implies working
* with non-normalized texture coordinates this api should still be
* passed normalized texture coordinates.</note>
*
* Since: 1.10
* Stability: unstable
*/
void
cogl_framebuffer_draw_textured_rectangle (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
float x_1,
float y_1,
float x_2,
float y_2,
float s_1,
float t_1,
float s_2,
float t_2);
/**
* cogl_framebuffer_draw_multitextured_rectangle:
* @framebuffer: A destination #CoglFramebuffer
* @pipeline: A #CoglPipeline state object
* @x_1: x coordinate upper left on screen.
* @y_1: y coordinate upper left on screen.
* @x_2: x coordinate lower right on screen.
* @y_2: y coordinate lower right on screen.
* @tex_coords: (in) (array) (transfer none): An array containing groups of
* 4 float values: [s_1, t_1, s_2, t_2] that are interpreted as two texture
* coordinates; one for the top left texel, and one for the bottom right
* texel. Each value should be between 0.0 and 1.0, where the coordinate
* (0.0, 0.0) represents the top left of the texture, and (1.0, 1.0) the
* bottom right.
* @tex_coords_len: The length of the @tex_coords array. (For one layer
* and one group of texture coordinates, this would be 4)
*
* Draws a textured rectangle to @framebuffer with the given @pipeline
* state with the top left corner positioned at (@x_1, @y_1) and the
* bottom right corner positioned at (@x_2, @y_2). As a pipeline may
* contain multiple texture layers this interface lets you supply
* texture coordinates for each layer of the pipeline.
*
* <note>The position is the position before the rectangle has been
* transformed by the model-view matrix and the projection
* matrix.</note>
*
* This is a high level drawing api that can handle any kind of
* #CoglMetaTexture texture for the first layer such as
* #CoglTexture2DSliced textures which may internally be comprised of
* multiple low-level textures. This is unlike low-level drawing apis
* such as cogl_framebuffer_draw_primitive() or
* cogl_framebuffer_draw_attributes() which only support low level
* texture types that are directly supported by GPUs such as
* #CoglTexture2D.
*
* <note>This api can not currently handle multiple high-level meta
* texture layers. The first layer may be a high level meta texture
* such as #CoglTexture2DSliced but all other layers much be low
* level textures such as #CoglTexture2D and additionally they
* should be textures that can be sampled using normalized coordinates
* (so not #CoglTextureRectangle textures).</note>
*
* The top left texture coordinate for layer 0 of any pipeline will be
* (tex_coords[0], tex_coords[1]) and the bottom right coordinate will
* be (tex_coords[2], tex_coords[3]). The coordinates for layer 1
* would be (tex_coords[4], tex_coords[5]) (tex_coords[6],
* tex_coords[7]) and so on...
*
* The given texture coordinates should always be normalized such that
* (0, 0) corresponds to the top left and (1, 1) corresponds to the
* bottom right. To map an entire texture across the rectangle pass
* in tex_coords[0]=%0, tex_coords[1]=%0, tex_coords[2]=%1,
* tex_coords[3]=%1.
*
* <note>Even if you have associated a #CoglTextureRectangle texture
* which normally implies working with non-normalized texture
* coordinates this api should still be passed normalized texture
* coordinates.</note>
*
* The first pair of coordinates are for the first layer (with the
* smallest layer index) and if you supply less texture coordinates
* than there are layers in the current source material then default
* texture coordinates (0.0, 0.0, 1.0, 1.0) are generated.
*
* Since: 1.10
* Stability: unstable
*/
void
cogl_framebuffer_draw_multitextured_rectangle (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
float x_1,
float y_1,
float x_2,
float y_2,
const float *tex_coords,
int tex_coords_len);
/**
* cogl_framebuffer_draw_rectangles:
* @framebuffer: A destination #CoglFramebuffer
* @pipeline: A #CoglPipeline state object
* @coordinates: (in) (array) (transfer none): an array of coordinates
* containing groups of 4 float values: [x_1, y_1, x_2, y_2] that are
* interpreted as two position coordinates; one for the top left of
* the rectangle (x1, y1), and one for the bottom right of the
* rectangle (x2, y2).
* @n_rectangles: number of rectangles defined in @coordinates.
*
* Draws a series of rectangles to @framebuffer with the given
* @pipeline state in the same way that
* cogl_framebuffer_draw_rectangle() does.
*
* The top left corner of the first rectangle is positioned at
* (coordinates[0], coordinates[1]) and the bottom right corner is
* positioned at (coordinates[2], coordinates[3]). The positions for
* the second rectangle are (coordinates[4], coordinates[5]) and
* (coordinates[6], coordinates[7]) and so on...
*
* <note>The position is the position before the rectangle has been
* transformed by the model-view matrix and the projection
* matrix.</note>
*
* As a general rule for better performance its recommended to use
* this this API instead of calling
* cogl_framebuffer_draw_textured_rectangle() separately for multiple
* rectangles if all of the rectangles will be drawn together with the
* same @pipeline state.
*
* Since: 1.10
* Stability: unstable
*/
void
cogl_framebuffer_draw_rectangles (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
const float *verts,
unsigned int n_rects);
/**
* cogl_framebuffer_draw_textured_rectangles:
* @framebuffer: A destination #CoglFramebuffer
* @pipeline: A #CoglPipeline state object
* @coordinates: (in) (array) (transfer none): an array containing
* groups of 8 float values: [x_1, y_1, x_2, y_2, s_1, t_1, s_2, t_2]
* that have the same meaning as the arguments for
* cogl_framebuffer_draw_textured_rectangle().
* @n_rectangles: number of rectangles to @coordinates to draw
*
* Draws a series of rectangles to @framebuffer with the given
* @pipeline state in the same way that
* cogl_framebuffer_draw_textured_rectangle() does.
*
* <note>The position is the position before the rectangle has been
* transformed by the model-view matrix and the projection
* matrix.</note>
*
* This is a high level drawing api that can handle any kind of
* #CoglMetaTexture texture such as #CoglTexture2DSliced textures
* which may internally be comprised of multiple low-level textures.
* This is unlike low-level drawing apis such as
* cogl_framebuffer_draw_primitive() or
* cogl_framebuffer_draw_attributes() which only support low level
* texture types that are directly supported by GPUs such as
* #CoglTexture2D.
*
* The top left corner of the first rectangle is positioned at
* (coordinates[0], coordinates[1]) and the bottom right corner is
* positioned at (coordinates[2], coordinates[3]). The top left
* texture coordinate is (coordinates[4], coordinates[5]) and the
* bottom right texture coordinate is (coordinates[6],
* coordinates[7]). The coordinates for subsequent rectangles
* are defined similarly by the subsequent coordinates.
*
* As a general rule for better performance its recommended to use
* this this API instead of calling
* cogl_framebuffer_draw_textured_rectangle() separately for multiple
* rectangles if all of the rectangles will be drawn together with the
* same @pipeline state.
*
* The given texture coordinates should always be normalized such that
* (0, 0) corresponds to the top left and (1, 1) corresponds to the
* bottom right. To map an entire texture across the rectangle pass
* in tex_coords[0]=%0, tex_coords[1]=%0, tex_coords[2]=%1,
* tex_coords[3]=%1.
*
* <note>Even if you have associated a #CoglTextureRectangle texture
* which normally implies working with non-normalized texture
* coordinates this api should still be passed normalized texture
* coordinates.</note>
*
* Since: 1.10
* Stability: unstable
*/
void
cogl_framebuffer_draw_textured_rectangles (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
const float *coordinates,
unsigned int n_rectangles);
/* XXX: Should we take an n_buffers + buffer id array instead of using
* the CoglBufferBits type which doesn't seem future proof? */

View File

@ -1491,6 +1491,7 @@ _cogl_journal_log_quad (CoglJournal *journal,
const float *tex_coords,
unsigned int tex_coords_len)
{
CoglFramebuffer *framebuffer = journal->framebuffer;
gsize stride;
int next_vert;
float *v;
@ -1507,15 +1508,13 @@ _cogl_journal_log_quad (CoglJournal *journal,
"The time spent logging in the Cogl journal",
0 /* no application private data */);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
COGL_TIMER_START (_cogl_uprof_context, log_timer);
/* If the framebuffer was previously empty then we'll take a
reference to the current framebuffer. This reference will be
removed when the journal is flushed */
if (journal->vertices->len == 0)
cogl_object_ref (journal->framebuffer);
cogl_object_ref (framebuffer);
/* The vertex data is logged into a separate array. The data needs
to be copied into a vertex array before it's given to GL so we
@ -1594,17 +1593,18 @@ _cogl_journal_log_quad (CoglJournal *journal,
entry->pipeline = _cogl_pipeline_journal_ref (final_pipeline);
clip_stack = _cogl_framebuffer_get_clip_stack (journal->framebuffer);
clip_stack = _cogl_framebuffer_get_clip_stack (framebuffer);
entry->clip_stack = _cogl_clip_stack_ref (clip_stack);
if (G_UNLIKELY (final_pipeline != pipeline))
cogl_handle_unref (final_pipeline);
cogl_get_modelview_matrix (&entry->model_view);
cogl_framebuffer_get_modelview_matrix (framebuffer,
&entry->model_view);
_cogl_pipeline_foreach_layer_internal (pipeline,
add_framebuffer_deps_cb,
journal->framebuffer);
framebuffer);
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_BATCHING)))
_cogl_journal_flush (journal);

View File

@ -40,6 +40,21 @@ _cogl_rectangle_immediate (CoglFramebuffer *framebuffer,
float x_2,
float y_2);
typedef struct _CoglMultiTexturedRect
{
const float *position; /* x0,y0,x1,y1 */
const float *tex_coords; /* (tx0,ty0,tx1,ty1)(tx0,ty0,tx1,ty1)(... */
int tex_coords_len; /* number of floats in tex_coords? */
} CoglMultiTexturedRect;
void
_cogl_framebuffer_draw_multitextued_rectangles (
CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
CoglMultiTexturedRect *rects,
int n_rects,
gboolean disable_legacy_state);
G_END_DECLS
#endif /* __COGL_PRIMITIVES_PRIVATE_H */

View File

@ -48,6 +48,7 @@
typedef struct _TextureSlicedQuadState
{
CoglFramebuffer *framebuffer;
CoglPipeline *pipeline;
CoglTexture *main_texture;
float tex_virtual_origin_x;
@ -77,7 +78,7 @@ log_quad_sub_textures_cb (CoglTexture *texture,
void *user_data)
{
TextureSlicedQuadState *state = user_data;
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
CoglFramebuffer *framebuffer = state->framebuffer;
CoglTexture *texture_override;
float quad_coords[4];
@ -189,8 +190,9 @@ validate_first_layer_cb (CoglPipeline *pipeline,
*/
/* TODO: support multitexturing */
static void
_cogl_texture_quad_multiple_primitives (CoglTexture *texture,
_cogl_texture_quad_multiple_primitives (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
CoglTexture *texture,
int layer_index,
const float *position,
float tx_1,
@ -206,8 +208,6 @@ _cogl_texture_quad_multiple_primitives (CoglTexture *texture,
ValidateFirstLayerState validate_first_layer_state;
CoglPipelineWrapMode wrap_s, wrap_t;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
wrap_s = cogl_pipeline_get_layer_wrap_mode_s (pipeline, layer_index);
wrap_t = cogl_pipeline_get_layer_wrap_mode_t (pipeline, layer_index);
@ -216,6 +216,7 @@ _cogl_texture_quad_multiple_primitives (CoglTexture *texture,
validate_first_layer_cb,
&validate_first_layer_state);
state.framebuffer = framebuffer;
state.main_texture = texture;
if (validate_first_layer_state.override_pipeline)
@ -431,17 +432,15 @@ validate_tex_coords_cb (CoglPipeline *pipeline,
* require repeating.
*/
static gboolean
_cogl_multitexture_quad_single_primitive (const float *position,
_cogl_multitexture_quad_single_primitive (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
const float *position,
const float *user_tex_coords,
int user_tex_coords_len)
{
int n_layers = cogl_pipeline_get_n_layers (pipeline);
ValidateTexCoordsState state;
float *final_tex_coords = alloca (sizeof (float) * 4 * n_layers);
CoglFramebuffer *framebuffer;
_COGL_GET_CONTEXT (ctx, FALSE);
state.i = -1;
state.n_layers = n_layers;
@ -461,7 +460,6 @@ _cogl_multitexture_quad_single_primitive (const float *position,
if (state.override_pipeline)
pipeline = state.override_pipeline;
framebuffer = cogl_get_draw_framebuffer ();
_cogl_journal_log_quad (framebuffer->journal,
position,
pipeline,
@ -478,6 +476,7 @@ _cogl_multitexture_quad_single_primitive (const float *position,
typedef struct _ValidateLayerState
{
CoglContext *ctx;
int i;
int first_layer;
CoglPipeline *override_source;
@ -585,8 +584,6 @@ _cogl_rectangles_validate_layer_cb (CoglPipeline *pipeline,
static gboolean warning_seen = FALSE;
CoglTexture2D *tex_2d;
_COGL_GET_CONTEXT (ctx, FALSE);
if (!warning_seen)
g_warning ("Skipping layer %d of your pipeline consisting of "
"a sliced texture (unsuported for multi texturing)",
@ -594,7 +591,7 @@ _cogl_rectangles_validate_layer_cb (CoglPipeline *pipeline,
warning_seen = TRUE;
/* Note: currently only 2D textures can be sliced. */
tex_2d = ctx->default_gl_texture_2d_tex;
tex_2d = state->ctx->default_gl_texture_2d_tex;
cogl_pipeline_set_layer_texture (pipeline, layer_index,
COGL_TEXTURE (tex_2d));
return TRUE;
@ -629,29 +626,25 @@ _cogl_rectangles_validate_layer_cb (CoglPipeline *pipeline,
return TRUE;
}
struct _CoglMutiTexturedRect
void
_cogl_framebuffer_draw_multitextured_rectangles (
CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
CoglMultiTexturedRect *rects,
int n_rects,
gboolean disable_legacy_state)
{
const float *position; /* x0,y0,x1,y1 */
const float *tex_coords; /* (tx0,ty0,tx1,ty1)(tx0,ty0,tx1,ty1)(... */
int tex_coords_len; /* number of floats in tex_coords? */
};
static void
_cogl_rectangles_with_multitexture_coords (
struct _CoglMutiTexturedRect *rects,
int n_rects)
{
CoglPipeline *original_pipeline, *pipeline;
CoglContext *ctx = framebuffer->context;
CoglPipeline *original_pipeline;
ValidateLayerState state;
int i;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
pipeline = original_pipeline = cogl_get_source ();
original_pipeline = pipeline;
/*
* Validate all the layers of the current source pipeline...
*/
state.ctx = ctx;
state.i = -1;
state.first_layer = 0;
state.override_source = NULL;
@ -663,6 +656,8 @@ _cogl_rectangles_with_multitexture_coords (
if (state.override_source)
pipeline = state.override_source;
if (!disable_legacy_state)
{
if (G_UNLIKELY (ctx->legacy_state_set) &&
_cogl_get_enable_legacy_state ())
{
@ -671,6 +666,7 @@ _cogl_rectangles_with_multitexture_coords (
pipeline = cogl_pipeline_copy (pipeline);
_cogl_pipeline_apply_legacy_state (pipeline);
}
}
/*
* Emit geometry for each of the rectangles...
@ -685,8 +681,9 @@ _cogl_rectangles_with_multitexture_coords (
if (!state.all_use_sliced_quad_fallback)
{
gboolean success =
_cogl_multitexture_quad_single_primitive (rects[i].position,
_cogl_multitexture_quad_single_primitive (framebuffer,
pipeline,
rects[i].position,
rects[i].tex_coords,
rects[i].tex_coords_len);
@ -710,8 +707,9 @@ _cogl_rectangles_with_multitexture_coords (
COGL_NOTE (DRAW, "Drawing Tex Quad (Multi-Prim Mode)");
_cogl_texture_quad_multiple_primitives (texture,
_cogl_texture_quad_multiple_primitives (framebuffer,
pipeline,
texture,
state.first_layer,
rects[i].position,
tex_coords[0],
@ -724,19 +722,31 @@ _cogl_rectangles_with_multitexture_coords (
cogl_object_unref (pipeline);
}
static void
_cogl_rectangles_with_multitexture_coords (
CoglMultiTexturedRect *rects,
int n_rects)
{
_cogl_framebuffer_draw_multitextured_rectangles (cogl_get_draw_framebuffer (),
cogl_get_source (),
rects,
n_rects,
FALSE);
}
void
cogl_rectangles (const float *verts,
unsigned int n_rects)
{
struct _CoglMutiTexturedRect *rects;
CoglMultiTexturedRect *rects;
int i;
/* XXX: All the cogl_rectangle* APIs normalize their input into an array of
* _CoglMutiTexturedRect rectangles and pass these on to our work horse;
* CoglMultiTexturedRect rectangles and pass these on to our work horse;
* _cogl_rectangles_with_multitexture_coords.
*/
rects = g_alloca (n_rects * sizeof (struct _CoglMutiTexturedRect));
rects = g_alloca (n_rects * sizeof (CoglMultiTexturedRect));
for (i = 0; i < n_rects; i++)
{
@ -752,15 +762,15 @@ void
cogl_rectangles_with_texture_coords (const float *verts,
unsigned int n_rects)
{
struct _CoglMutiTexturedRect *rects;
CoglMultiTexturedRect *rects;
int i;
/* XXX: All the cogl_rectangle* APIs normalize their input into an array of
* _CoglMutiTexturedRect rectangles and pass these on to our work horse;
* CoglMultiTexturedRect rectangles and pass these on to our work horse;
* _cogl_rectangles_with_multitexture_coords.
*/
rects = g_alloca (n_rects * sizeof (struct _CoglMutiTexturedRect));
rects = g_alloca (n_rects * sizeof (CoglMultiTexturedRect));
for (i = 0; i < n_rects; i++)
{
@ -784,10 +794,10 @@ cogl_rectangle_with_texture_coords (float x_1,
{
const float position[4] = {x_1, y_1, x_2, y_2};
const float tex_coords[4] = {tx_1, ty_1, tx_2, ty_2};
struct _CoglMutiTexturedRect rect;
CoglMultiTexturedRect rect;
/* XXX: All the cogl_rectangle* APIs normalize their input into an array of
* _CoglMutiTexturedRect rectangles and pass these on to our work horse;
* CoglMultiTexturedRect rectangles and pass these on to our work horse;
* _cogl_rectangles_with_multitexture_coords.
*/
@ -807,10 +817,10 @@ cogl_rectangle_with_multitexture_coords (float x_1,
int user_tex_coords_len)
{
const float position[4] = {x_1, y_1, x_2, y_2};
struct _CoglMutiTexturedRect rect;
CoglMultiTexturedRect rect;
/* XXX: All the cogl_rectangle* APIs normalize their input into an array of
* _CoglMutiTexturedRect rectangles and pass these on to our work horse;
* CoglMultiTexturedRect rectangles and pass these on to our work horse;
* _cogl_rectangles_with_multitexture_coords.
*/
@ -828,10 +838,10 @@ cogl_rectangle (float x_1,
float y_2)
{
const float position[4] = {x_1, y_1, x_2, y_2};
struct _CoglMutiTexturedRect rect;
CoglMultiTexturedRect rect;
/* XXX: All the cogl_rectangle* APIs normalize their input into an array of
* _CoglMutiTexturedRect rectangles and pass these on to our work horse;
* CoglMultiTexturedRect rectangles and pass these on to our work horse;
* _cogl_rectangles_with_multitexture_coords.
*/
@ -854,6 +864,7 @@ _cogl_rectangle_immediate (CoglFramebuffer *framebuffer,
through the journal. This should only be used in cases where the
code might be called while the journal is already being flushed
such as when flushing the clip state */
CoglContext *ctx = framebuffer->context;
float vertices[8] =
{
x_1, y_1,
@ -864,8 +875,6 @@ _cogl_rectangle_immediate (CoglFramebuffer *framebuffer,
CoglAttributeBuffer *attribute_buffer;
CoglAttribute *attributes[1];
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
attribute_buffer =
cogl_attribute_buffer_new (ctx, sizeof (vertices), vertices);
attributes[0] = cogl_attribute_new (attribute_buffer,

View File

@ -402,6 +402,11 @@ cogl_framebuffer_read_pixels
cogl_framebuffer_draw_primitive
cogl_framebuffer_draw_attributes
cogl_framebuffer_draw_indexed_attributes
cogl_framebuffer_draw_rectangle
cogl_framebuffer_draw_textured_rectangle
cogl_framebuffer_draw_multitextured_rectangle
cogl_framebuffer_draw_rectangles
cogl_framebuffer_draw_textured_rectangles
<SUBSECTION>
cogl_framebuffer_swap_buffers

View File

@ -99,7 +99,7 @@ verify_texture (CoglHandle texture, int size)
}
void
test_cogl_atlas_migration (TestUtilsGTestFixture *fixture,
test_atlas_migration (TestUtilsGTestFixture *fixture,
void *data)
{
CoglHandle textures[N_TEXTURES];

View File

@ -17,18 +17,18 @@
typedef struct _TestState
{
CoglContext *ctx;
CoglFramebuffer *fb;
CoglHandle texture;
CoglTexture *texture;
CoglFramebuffer *offscreen;
CoglHandle offscreen_tex;
CoglTexture *offscreen_tex;
int width, height;
} TestState;
static void
validate_part (int xnum, int ynum, gboolean shown)
validate_part (CoglFramebuffer *framebuffer,
int xnum, int ynum, gboolean shown)
{
test_utils_check_region (xnum * TEXTURE_RENDER_SIZE + TEST_INSET,
test_utils_check_region (framebuffer,
xnum * TEXTURE_RENDER_SIZE + TEST_INSET,
ynum * TEXTURE_RENDER_SIZE + TEST_INSET,
TEXTURE_RENDER_SIZE - TEST_INSET * 2,
TEXTURE_RENDER_SIZE - TEST_INSET * 2,
@ -44,18 +44,22 @@ validate_part (int xnum, int ynum, gboolean shown)
#define CULL_FACE_MODE(draw_num) (((draw_num) & 0x0c) >> 2)
static void
paint_test_backface_culling (TestState *state)
paint_test_backface_culling (TestState *state,
CoglFramebuffer *framebuffer)
{
int draw_num;
CoglPipeline *base_pipeline = cogl_pipeline_new (state->ctx);
CoglColor clear_color;
CoglPipeline *base_pipeline = cogl_pipeline_new (ctx);
cogl_ortho (0, state->width, /* left, right */
state->height, 0, /* bottom, top */
-1, 100 /* z near, far */);
cogl_framebuffer_orthographic (framebuffer,
0, 0,
state->width,
state->height,
-1,
100);
cogl_color_init_from_4ub (&clear_color, 0x00, 0x00, 0x00, 0xff);
cogl_clear (&clear_color, COGL_BUFFER_BIT_COLOR | COGL_BUFFER_BIT_STENCIL);
cogl_framebuffer_clear4f (framebuffer,
COGL_BUFFER_BIT_COLOR | COGL_BUFFER_BIT_STENCIL,
0, 0, 0, 1);
cogl_pipeline_set_layer_texture (base_pipeline, 0, state->texture);
@ -63,6 +67,8 @@ paint_test_backface_culling (TestState *state)
COGL_PIPELINE_FILTER_NEAREST,
COGL_PIPELINE_FILTER_NEAREST);
cogl_push_framebuffer (framebuffer);
/* Render the scene sixteen times to test all of the combinations of
cull face mode, legacy state and winding orders */
for (draw_num = 0; draw_num < 16; draw_num++)
@ -144,11 +150,13 @@ paint_test_backface_culling (TestState *state)
cogl_object_unref (pipeline);
}
cogl_pop_framebuffer ();
cogl_object_unref (base_pipeline);
}
static void
validate_result (int y_offset)
validate_result (CoglFramebuffer *framebuffer, int y_offset)
{
int draw_num;
@ -193,26 +201,29 @@ validate_result (int y_offset)
}
/* Front-facing texture */
validate_part (0, y_offset + draw_num, !cull_front);
validate_part (framebuffer,
0, y_offset + draw_num, !cull_front);
/* Front-facing texture with flipped tex coords */
validate_part (1, y_offset + draw_num, !cull_front);
validate_part (framebuffer,
1, y_offset + draw_num, !cull_front);
/* Back-facing texture */
validate_part (2, y_offset + draw_num, !cull_back);
validate_part (framebuffer,
2, y_offset + draw_num, !cull_back);
/* Front-facing texture polygon */
validate_part (3, y_offset + draw_num, !cull_front);
validate_part (framebuffer,
3, y_offset + draw_num, !cull_front);
/* Back-facing texture polygon */
validate_part (4, y_offset + draw_num, !cull_back);
validate_part (framebuffer,
4, y_offset + draw_num, !cull_back);
}
}
static void
paint (TestState *state)
{
float stage_viewport[4];
CoglMatrix stage_projection;
CoglMatrix stage_modelview;
CoglPipeline *pipeline;
paint_test_backface_culling (state);
paint_test_backface_culling (state, fb);
/*
* Now repeat the test but rendered to an offscreen
@ -220,40 +231,28 @@ paint (TestState *state)
* always run to an offscreen buffer but we might as well have this
* check anyway in case it is being run with COGL_TEST_ONSCREEN=1
*/
paint_test_backface_culling (state, state->offscreen);
cogl_get_viewport (stage_viewport);
cogl_get_projection_matrix (&stage_projection);
cogl_get_modelview_matrix (&stage_modelview);
/* Copy the result of the offscreen rendering for validation and
* also so we can have visual feedback. */
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_layer_texture (pipeline, 0, state->offscreen_tex);
cogl_framebuffer_draw_rectangle (fb,
pipeline,
0, TEXTURE_RENDER_SIZE * 16,
state->width,
state->height + TEXTURE_RENDER_SIZE * 16);
cogl_object_unref (pipeline);
cogl_push_framebuffer (state->offscreen);
cogl_set_viewport (stage_viewport[0],
stage_viewport[1],
stage_viewport[2],
stage_viewport[3]);
cogl_set_projection_matrix (&stage_projection);
cogl_set_modelview_matrix (&stage_modelview);
paint_test_backface_culling (state);
cogl_pop_framebuffer ();
/* Incase we want feedback of what was drawn offscreen we draw it
* to the stage... */
cogl_set_source_texture (state->offscreen_tex);
cogl_rectangle (0, TEXTURE_RENDER_SIZE * 16,
stage_viewport[2],
stage_viewport[3] + TEXTURE_RENDER_SIZE * 16);
validate_result (0);
validate_result (16);
validate_result (fb, 0);
validate_result (fb, 16);
}
static CoglHandle
static CoglTexture *
make_texture (void)
{
guchar *tex_data, *p;
CoglHandle tex;
CoglTexture *tex;
tex_data = g_malloc (TEXTURE_SIZE * TEXTURE_SIZE * 4);
@ -279,19 +278,15 @@ make_texture (void)
}
void
test_cogl_backface_culling (TestUtilsGTestFixture *fixture,
void *data)
test_backface_culling (void)
{
TestUtilsSharedState *shared_state = data;
TestState state;
CoglHandle tex;
CoglTexture *tex;
state.ctx = shared_state->ctx;
state.fb = shared_state->fb;
state.width = cogl_framebuffer_get_width (shared_state->fb);
state.height = cogl_framebuffer_get_height (shared_state->fb);
state.width = cogl_framebuffer_get_width (fb);
state.height = cogl_framebuffer_get_height (fb);
state.offscreen = COGL_INVALID_HANDLE;
state.offscreen = NULL;
state.texture = make_texture ();
@ -304,8 +299,8 @@ test_cogl_backface_culling (TestUtilsGTestFixture *fixture,
paint (&state);
cogl_object_unref (state.offscreen);
cogl_handle_unref (state.offscreen_tex);
cogl_handle_unref (state.texture);
cogl_object_unref (state.offscreen_tex);
cogl_object_unref (state.texture);
if (cogl_test_verbose ())
g_print ("OK\n");

View File

@ -91,8 +91,7 @@ verify_bits (const CoglBitmask *bitmask,
}
void
test_cogl_bitmask (TestUtilsGTestFixture *fixture,
void *data)
test_bitmask (void)
{
CoglBitmask bitmask;
CoglBitmask other_bitmask;

View File

@ -60,7 +60,7 @@ test_blend (TestState *state,
int x_off;
/* First write out the destination color without any blending... */
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_color4ub (pipeline, Dr, Dg, Db, Da);
cogl_pipeline_set_blend (pipeline, "RGBA = ADD (SRC_COLOR, 0)", NULL);
cogl_set_source (pipeline);
@ -74,7 +74,7 @@ test_blend (TestState *state,
* Now blend a rectangle over our well defined destination:
*/
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_color4ub (pipeline, Sr, Sg, Sb, Sa);
status = cogl_pipeline_set_blend (pipeline, blend_string, &error);
@ -118,7 +118,7 @@ test_blend (TestState *state,
g_print (" blend constant = UNUSED\n");
}
test_utils_check_pixel (x_off, y_off, expected_result);
test_utils_check_pixel (fb, x_off, y_off, expected_result);
/*
@ -171,10 +171,10 @@ test_blend (TestState *state,
/* See what we got... */
test_utils_check_pixel (x_off, y_off, expected_result);
test_utils_check_pixel (fb, x_off, y_off, expected_result);
}
static CoglHandle
static CoglTexture *
make_texture (guint32 color)
{
guchar *tex_data, *p;
@ -182,7 +182,7 @@ make_texture (guint32 color)
guint8 g = MASK_GREEN (color);
guint8 b = MASK_BLUE (color);
guint8 a = MASK_ALPHA (color);
CoglHandle tex;
CoglTexture *tex;
tex_data = g_malloc (QUAD_WIDTH * QUAD_WIDTH * 4);
@ -219,7 +219,7 @@ test_tex_combine (TestState *state,
const char *combine_string,
guint32 expected_result)
{
CoglHandle tex0, tex1;
CoglTexture *tex0, *tex1;
/* combine constant - when applicable */
guint8 Cr = MASK_RED (combine_constant);
@ -268,8 +268,8 @@ test_tex_combine (TestState *state,
y * QUAD_WIDTH + QUAD_WIDTH);
cogl_handle_unref (material);
cogl_handle_unref (tex0);
cogl_handle_unref (tex1);
cogl_object_unref (tex0);
cogl_object_unref (tex1);
/* See what we got... */
@ -288,7 +288,7 @@ test_tex_combine (TestState *state,
g_print (" combine constant = UNUSED\n");
}
test_utils_check_pixel (x_off, y_off, expected_result);
test_utils_check_pixel (fb, x_off, y_off, expected_result);
}
static void
@ -408,19 +408,21 @@ paint (TestState *state)
}
void
test_cogl_blend_strings (TestUtilsGTestFixture *fixture,
void *data)
test_blend_strings (void)
{
TestUtilsSharedState *shared_state = data;
TestState state;
state.ctx = shared_state->ctx;
cogl_ortho (0, cogl_framebuffer_get_width (shared_state->fb), /* left, right */
cogl_framebuffer_get_height (shared_state->fb), 0, /* bottom, top */
-1, 100 /* z near, far */);
cogl_framebuffer_orthographic (fb, 0, 0,
cogl_framebuffer_get_width (fb),
cogl_framebuffer_get_height (fb),
-1,
100);
/* XXX: we have to push/pop a framebuffer since this test currently
* uses the legacy cogl_rectangle() api. */
cogl_push_framebuffer (fb);
paint (&state);
cogl_pop_framebuffer ();
if (cogl_test_verbose ())
g_print ("OK\n");

View File

@ -11,7 +11,7 @@ typedef struct _TestState
int width;
int height;
CoglHandle tex[NUM_FBOS];
CoglTexture *tex[NUM_FBOS];
CoglFramebuffer *fbo[NUM_FBOS];
} TestState;
@ -45,9 +45,12 @@ paint (TestState *state)
/* Render all of the textures to the screen */
for (i = 0; i < NUM_FBOS; i++)
{
cogl_set_source_texture (state->tex[i]);
cogl_rectangle (2.0f / NUM_FBOS * i - 1.0f, -1.0f,
CoglPipeline *pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_layer_texture (pipeline, 0, state->tex[i]);
cogl_framebuffer_draw_rectangle (fb, pipeline,
2.0f / NUM_FBOS * i - 1.0f, -1.0f,
2.0f / NUM_FBOS * (i + 1) - 1.0f, 1.0f);
cogl_object_unref (pipeline);
}
/* Verify all of the fbos drew the right color */
@ -58,7 +61,8 @@ paint (TestState *state)
{ 0x00, 0xff, 0x00, 0xff },
{ 0x00, 0x00, 0xff, 0xff } };
test_utils_check_pixel_rgb (state->width * (i + 0.5f) / NUM_FBOS,
test_utils_check_pixel_rgb (fb,
state->width * (i + 0.5f) / NUM_FBOS,
state->height / 2,
expected_colors[i][0],
expected_colors[i][1],
@ -67,18 +71,13 @@ paint (TestState *state)
}
void
test_cogl_color_mask (TestUtilsGTestFixture *fixture,
void *data)
test_color_mask (void)
{
TestUtilsSharedState *shared_state = data;
TestState state;
CoglColor bg;
int i;
state.width = cogl_framebuffer_get_width (shared_state->fb);
state.height = cogl_framebuffer_get_height (shared_state->fb);
cogl_color_init_from_4ub (&bg, 0, 0, 0, 255);
state.width = cogl_framebuffer_get_width (fb);
state.height = cogl_framebuffer_get_height (fb);
for (i = 0; i < NUM_FBOS; i++)
{
@ -91,9 +90,8 @@ test_cogl_color_mask (TestUtilsGTestFixture *fixture,
cogl_offscreen_new_to_texture (state.tex[i]));
/* Clear the texture color bits */
cogl_push_framebuffer (state.fbo[i]);
cogl_clear (&bg, COGL_BUFFER_BIT_COLOR);
cogl_pop_framebuffer ();
cogl_framebuffer_clear4f (state.fbo[i],
COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
cogl_framebuffer_set_color_mask (state.fbo[i],
i == 0 ? COGL_COLOR_MASK_RED :
@ -101,7 +99,11 @@ test_cogl_color_mask (TestUtilsGTestFixture *fixture,
COGL_COLOR_MASK_BLUE);
}
/* XXX: we have to push/pop a framebuffer since this test currently
* uses the legacy cogl_rectangle() api. */
cogl_push_framebuffer (fb);
paint (&state);
cogl_pop_framebuffer ();
if (cogl_test_verbose ())
g_print ("OK\n");

View File

@ -9,16 +9,14 @@
#include "test-utils.h"
static TestUtilsSharedState *shared_state = NULL;
/* A bit of sugar for adding new conformance tests */
#define ADD_TEST(FUNC, REQUIREMENTS) G_STMT_START { \
extern void FUNC (TestUtilsGTestFixture *, void *); \
extern void FUNC (void); \
if (strcmp (#FUNC, argv[1]) == 0) \
{ \
test_utils_init (shared_state, REQUIREMENTS); \
FUNC (NULL, shared_state); \
test_utils_fini (shared_state); \
test_utils_init (REQUIREMENTS); \
FUNC (); \
test_utils_fini (); \
exit (0); \
} \
} G_STMT_END
@ -45,65 +43,59 @@ main (int argc, char **argv)
argv[1][i] = '_';
}
/* Initialise the state you need to share with everything.
*/
shared_state = g_new0 (TestUtilsSharedState, 1);
shared_state->argc_addr = &argc;
shared_state->argv_addr = &argv;
/* This file is run through a sed script during the make step so the
* lines containing the tests need to be formatted on a single line
* each.
*/
UNPORTED_TEST (test_cogl_object);
UNPORTED_TEST (test_cogl_fixed);
UNPORTED_TEST (test_cogl_materials);
ADD_TEST (test_cogl_pipeline_user_matrix, 0);
ADD_TEST (test_cogl_blend_strings, 0);
UNPORTED_TEST (test_cogl_premult);
UNPORTED_TEST (test_cogl_readpixels);
ADD_TEST (test_cogl_path, 0);
ADD_TEST (test_cogl_depth_test, 0);
ADD_TEST (test_cogl_color_mask, 0);
ADD_TEST (test_cogl_backface_culling, TEST_REQUIREMENT_NPOT);
UNPORTED_TEST (test_object);
UNPORTED_TEST (test_fixed);
UNPORTED_TEST (test_materials);
ADD_TEST (test_pipeline_user_matrix, 0);
ADD_TEST (test_blend_strings, 0);
UNPORTED_TEST (test_premult);
UNPORTED_TEST (test_readpixels);
ADD_TEST (test_path, 0);
ADD_TEST (test_depth_test, 0);
ADD_TEST (test_color_mask, 0);
ADD_TEST (test_backface_culling, TEST_REQUIREMENT_NPOT);
ADD_TEST (test_cogl_sparse_pipeline, 0);
ADD_TEST (test_sparse_pipeline, 0);
UNPORTED_TEST (test_cogl_npot_texture);
UNPORTED_TEST (test_cogl_multitexture);
UNPORTED_TEST (test_cogl_texture_mipmaps);
ADD_TEST (test_cogl_sub_texture, 0);
ADD_TEST (test_cogl_pixel_buffer, 0);
UNPORTED_TEST (test_cogl_texture_rectangle);
ADD_TEST (test_cogl_texture_3d, 0);
ADD_TEST (test_cogl_wrap_modes, 0);
UNPORTED_TEST (test_cogl_texture_pixmap_x11);
UNPORTED_TEST (test_cogl_texture_get_set_data);
UNPORTED_TEST (test_cogl_atlas_migration);
ADD_TEST (test_cogl_read_texture_formats, 0);
ADD_TEST (test_cogl_write_texture_formats, 0);
UNPORTED_TEST (test_npot_texture);
UNPORTED_TEST (test_multitexture);
UNPORTED_TEST (test_texture_mipmaps);
ADD_TEST (test_sub_texture, 0);
ADD_TEST (test_pixel_buffer, 0);
UNPORTED_TEST (test_texture_rectangle);
ADD_TEST (test_texture_3d, 0);
ADD_TEST (test_wrap_modes, 0);
UNPORTED_TEST (test_texture_pixmap_x11);
UNPORTED_TEST (test_texture_get_set_data);
UNPORTED_TEST (test_atlas_migration);
ADD_TEST (test_read_texture_formats, 0);
ADD_TEST (test_write_texture_formats, 0);
UNPORTED_TEST (test_cogl_vertex_buffer_contiguous);
UNPORTED_TEST (test_cogl_vertex_buffer_interleved);
UNPORTED_TEST (test_cogl_vertex_buffer_mutability);
UNPORTED_TEST (test_vertex_buffer_contiguous);
UNPORTED_TEST (test_vertex_buffer_interleved);
UNPORTED_TEST (test_vertex_buffer_mutability);
ADD_TEST (test_cogl_primitive, 0);
ADD_TEST (test_primitive, 0);
ADD_TEST (test_cogl_just_vertex_shader, 0);
ADD_TEST (test_cogl_pipeline_uniforms, 0);
ADD_TEST (test_cogl_snippets, 0);
ADD_TEST (test_cogl_custom_attributes, 0);
ADD_TEST (test_just_vertex_shader, 0);
ADD_TEST (test_pipeline_uniforms, 0);
ADD_TEST (test_snippets, 0);
ADD_TEST (test_custom_attributes, 0);
ADD_TEST (test_cogl_bitmask, 0);
ADD_TEST (test_bitmask, 0);
ADD_TEST (test_cogl_offscreen, 0);
ADD_TEST (test_offscreen, 0);
ADD_TEST (test_cogl_point_size, 0);
ADD_TEST (test_cogl_point_sprite,
ADD_TEST (test_point_size, 0);
ADD_TEST (test_point_sprite,
TEST_KNOWN_FAILURE | TEST_REQUIREMENT_POINT_SPRITE);
UNPORTED_TEST (test_cogl_viewport);
UNPORTED_TEST (test_viewport);
g_printerr ("Unknown test name \"%s\"\n", argv[1]);

View File

@ -6,8 +6,6 @@
typedef struct _TestState
{
CoglContext *ctx;
CoglFramebuffer *fb;
CoglPipeline *pipeline;
} TestState;
@ -45,7 +43,7 @@ test_float_verts (TestState *state, int offset_x, int offset_y)
{ 15, 0, /**/ 0, 1, 0, 1 }
};
buffer = cogl_attribute_buffer_new (state->ctx,
buffer = cogl_attribute_buffer_new (ctx,
sizeof (float_verts), float_verts);
attributes[0] = cogl_attribute_new (buffer,
"cogl_position_in",
@ -60,10 +58,10 @@ test_float_verts (TestState *state, int offset_x, int offset_y)
4, /* n_components */
COGL_ATTRIBUTE_TYPE_FLOAT);
cogl_push_matrix ();
cogl_translate (offset_x, offset_y, 0.0f);
cogl_framebuffer_push_matrix (fb);
cogl_framebuffer_translate (fb, offset_x, offset_y, 0.0f);
cogl_framebuffer_draw_attributes (state->fb,
cogl_framebuffer_draw_attributes (fb,
state->pipeline,
COGL_VERTICES_MODE_TRIANGLES,
0, /* first_vertex */
@ -71,14 +69,14 @@ test_float_verts (TestState *state, int offset_x, int offset_y)
attributes,
2 /* n_attributes */);
cogl_pop_matrix ();
cogl_framebuffer_pop_matrix (fb);
cogl_object_unref (attributes[1]);
cogl_object_unref (attributes[0]);
cogl_object_unref (buffer);
test_utils_check_pixel (offset_x + 5, offset_y + 5, 0xff0000ff);
test_utils_check_pixel (offset_x + 15, offset_y + 5, 0x00ff00ff);
test_utils_check_pixel (fb, offset_x + 5, offset_y + 5, 0xff0000ff);
test_utils_check_pixel (fb, offset_x + 15, offset_y + 5, 0x00ff00ff);
}
static void
@ -105,7 +103,7 @@ test_byte_verts (TestState *state, int offset_x, int offset_y)
{ 0, 0, /**/ 0, 0, 1, 1 },
};
buffer = cogl_attribute_buffer_new (state->ctx,
buffer = cogl_attribute_buffer_new (ctx,
sizeof (norm_verts), norm_verts);
attributes[0] = cogl_attribute_new (buffer,
"cogl_position_in",
@ -121,10 +119,10 @@ test_byte_verts (TestState *state, int offset_x, int offset_y)
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE);
cogl_attribute_set_normalized (attributes[1], TRUE);
cogl_push_matrix ();
cogl_translate (offset_x, offset_y, 0.0f);
cogl_framebuffer_push_matrix (fb);
cogl_framebuffer_translate (fb, offset_x, offset_y, 0.0f);
cogl_framebuffer_draw_attributes (state->fb,
cogl_framebuffer_draw_attributes (fb,
state->pipeline,
COGL_VERTICES_MODE_TRIANGLES,
0, /* first_vertex */
@ -135,7 +133,7 @@ test_byte_verts (TestState *state, int offset_x, int offset_y)
cogl_object_unref (attributes[1]);
/* Test again with unnormalized attributes */
unnorm_buffer = cogl_attribute_buffer_new (state->ctx,
unnorm_buffer = cogl_attribute_buffer_new (ctx,
sizeof (unnorm_verts),
unnorm_verts);
attributes[1] = cogl_attribute_new (unnorm_buffer,
@ -145,9 +143,9 @@ test_byte_verts (TestState *state, int offset_x, int offset_y)
4, /* n_components */
COGL_ATTRIBUTE_TYPE_BYTE);
cogl_translate (20, 0, 0);
cogl_framebuffer_translate (fb, 20, 0, 0);
cogl_framebuffer_draw_attributes (state->fb,
cogl_framebuffer_draw_attributes (fb,
state->pipeline,
COGL_VERTICES_MODE_TRIANGLES,
0, /* first_vertex */
@ -155,16 +153,16 @@ test_byte_verts (TestState *state, int offset_x, int offset_y)
attributes,
2 /* n_attributes */);
cogl_pop_matrix ();
cogl_framebuffer_pop_matrix (fb);
cogl_object_unref (attributes[0]);
cogl_object_unref (attributes[1]);
cogl_object_unref (buffer);
cogl_object_unref (unnorm_buffer);
test_utils_check_pixel (offset_x + 5, offset_y + 5, 0xff0000ff);
test_utils_check_pixel (offset_x + 15, offset_y + 5, 0x00ff00ff);
test_utils_check_pixel (offset_x + 25, offset_y + 5, 0x0000ffff);
test_utils_check_pixel (fb, offset_x + 5, offset_y + 5, 0xff0000ff);
test_utils_check_pixel (fb, offset_x + 15, offset_y + 5, 0x00ff00ff);
test_utils_check_pixel (fb, offset_x + 25, offset_y + 5, 0x0000ffff);
}
static void
@ -182,7 +180,7 @@ test_short_verts (TestState *state, int offset_x, int offset_y)
{ -5, -1 }
};
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX_TRANSFORM,
"attribute vec2 pos;",
NULL);
@ -195,7 +193,7 @@ test_short_verts (TestState *state, int offset_x, int offset_y)
cogl_pipeline_set_color4ub (pipeline, 255, 0, 0, 255);
buffer = cogl_attribute_buffer_new (state->ctx,
buffer = cogl_attribute_buffer_new (ctx,
sizeof (short_verts), short_verts);
attributes[0] = cogl_attribute_new (buffer,
"pos",
@ -204,10 +202,13 @@ test_short_verts (TestState *state, int offset_x, int offset_y)
2, /* n_components */
COGL_ATTRIBUTE_TYPE_SHORT);
cogl_push_matrix ();
cogl_translate (offset_x + 10.0f, offset_y + 10.0f, 0.0f);
cogl_framebuffer_push_matrix (fb);
cogl_framebuffer_translate (fb,
offset_x + 10.0f,
offset_y + 10.0f,
0.0f);
cogl_framebuffer_draw_attributes (state->fb,
cogl_framebuffer_draw_attributes (fb,
pipeline,
COGL_VERTICES_MODE_TRIANGLES,
0, /* first_vertex */
@ -215,7 +216,7 @@ test_short_verts (TestState *state, int offset_x, int offset_y)
attributes,
1 /* n_attributes */);
cogl_pop_matrix ();
cogl_framebuffer_pop_matrix (fb);
cogl_object_unref (attributes[0]);
@ -230,10 +231,13 @@ test_short_verts (TestState *state, int offset_x, int offset_y)
pipeline2 = cogl_pipeline_copy (pipeline);
cogl_pipeline_set_color4ub (pipeline2, 0, 255, 0, 255);
cogl_push_matrix ();
cogl_translate (offset_x + 10.0f - 65525.0f, offset_y - 65525, 0.0f);
cogl_framebuffer_push_matrix (fb);
cogl_framebuffer_translate (fb,
offset_x + 10.0f - 65525.0f,
offset_y - 65525,
0.0f);
cogl_framebuffer_draw_attributes (state->fb,
cogl_framebuffer_draw_attributes (fb,
pipeline2,
COGL_VERTICES_MODE_TRIANGLES,
0, /* first_vertex */
@ -241,7 +245,7 @@ test_short_verts (TestState *state, int offset_x, int offset_y)
attributes,
1 /* n_attributes */);
cogl_pop_matrix ();
cogl_framebuffer_pop_matrix (fb);
cogl_object_unref (attributes[0]);
@ -249,17 +253,14 @@ test_short_verts (TestState *state, int offset_x, int offset_y)
cogl_object_unref (pipeline);
cogl_object_unref (buffer);
test_utils_check_pixel (offset_x + 5, offset_y + 5, 0xff0000ff);
test_utils_check_pixel (offset_x + 15, offset_y + 5, 0x00ff00ff);
test_utils_check_pixel (fb, offset_x + 5, offset_y + 5, 0xff0000ff);
test_utils_check_pixel (fb, offset_x + 15, offset_y + 5, 0x00ff00ff);
}
static void
paint (TestState *state)
{
CoglColor color;
cogl_color_init_from_4ub (&color, 0, 0, 0, 255);
cogl_clear (&color, COGL_BUFFER_BIT_COLOR);
cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
test_float_verts (state, 0, 0);
test_byte_verts (state, 0, 10);
@ -267,28 +268,22 @@ paint (TestState *state)
}
void
test_cogl_custom_attributes (TestUtilsGTestFixture *fixture,
void *user_data)
test_custom_attributes (void)
{
TestUtilsSharedState *shared_state = user_data;
/* If shaders aren't supported then we can't run the test */
if (cogl_features_available (COGL_FEATURE_SHADERS_GLSL))
{
CoglSnippet *snippet;
TestState state;
state.fb = shared_state->fb;
state.ctx = shared_state->ctx;
cogl_framebuffer_orthographic (fb,
0, 0,
cogl_framebuffer_get_width (fb),
cogl_framebuffer_get_height (fb),
-1,
100);
cogl_ortho (/* left, right */
0, cogl_framebuffer_get_width (shared_state->fb),
/* bottom, top */
cogl_framebuffer_get_height (shared_state->fb), 0,
/* z near, far */
-1, 100);
state.pipeline = cogl_pipeline_new (state.ctx);
state.pipeline = cogl_pipeline_new (ctx);
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX,
"attribute vec4 color;",
"cogl_color_out = color;");

View File

@ -18,7 +18,7 @@
typedef struct _TestState
{
CoglContext *ctx;
int padding;
} TestState;
typedef struct
@ -36,13 +36,14 @@ static gboolean
draw_rectangle (TestState *state,
int x,
int y,
TestDepthState *rect_state)
TestDepthState *rect_state,
gboolean legacy_mode)
{
guint8 Cr = MASK_RED (rect_state->color);
guint8 Cg = MASK_GREEN (rect_state->color);
guint8 Cb = MASK_BLUE (rect_state->color);
guint8 Ca = MASK_ALPHA (rect_state->color);
CoglHandle pipeline;
CoglPipeline *pipeline;
CoglDepthState depth_state;
cogl_depth_state_init (&depth_state);
@ -53,24 +54,40 @@ draw_rectangle (TestState *state,
rect_state->range_near,
rect_state->range_far);
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
if (!cogl_pipeline_set_depth_state (pipeline, &depth_state, NULL))
{
cogl_object_unref (pipeline);
return FALSE;
}
if (!legacy_mode)
{
cogl_pipeline_set_color4ub (pipeline, Cr, Cg, Cb, Ca);
cogl_set_source (pipeline);
cogl_framebuffer_push_matrix (fb);
cogl_framebuffer_translate (fb, 0, 0, rect_state->depth);
cogl_framebuffer_draw_rectangle (fb,
pipeline,
x * QUAD_WIDTH,
y * QUAD_WIDTH,
x * QUAD_WIDTH + QUAD_WIDTH,
y * QUAD_WIDTH + QUAD_WIDTH);
cogl_framebuffer_pop_matrix (fb);
}
else
{
cogl_push_framebuffer (fb);
cogl_push_matrix ();
cogl_set_source_color4ub (Cr, Cg, Cb, Ca);
cogl_translate (0, 0, rect_state->depth);
cogl_rectangle (x * QUAD_WIDTH,
y * QUAD_WIDTH,
x * QUAD_WIDTH + QUAD_WIDTH,
y * QUAD_WIDTH + QUAD_WIDTH);
cogl_pop_matrix ();
cogl_pop_framebuffer ();
}
cogl_object_unref (pipeline);
@ -84,23 +101,25 @@ test_depth (TestState *state,
TestDepthState *rect0_state,
TestDepthState *rect1_state,
TestDepthState *rect2_state,
gboolean legacy_mode,
guint32 expected_result)
{
gboolean missing_feature = FALSE;
if (rect0_state)
missing_feature |= !draw_rectangle (state, x, y, rect0_state);
missing_feature |= !draw_rectangle (state, x, y, rect0_state, legacy_mode);
if (rect1_state)
missing_feature |= !draw_rectangle (state, x, y, rect1_state);
missing_feature |= !draw_rectangle (state, x, y, rect1_state, legacy_mode);
if (rect2_state)
missing_feature |= !draw_rectangle (state, x, y, rect2_state);
missing_feature |= !draw_rectangle (state, x, y, rect2_state, legacy_mode);
/* We don't consider it an error that we can't test something
* the driver doesn't support. */
if (missing_feature)
return;
test_utils_check_pixel (x * QUAD_WIDTH + (QUAD_WIDTH / 2),
test_utils_check_pixel (fb,
x * QUAD_WIDTH + (QUAD_WIDTH / 2),
y * QUAD_WIDTH + (QUAD_WIDTH / 2),
expected_result);
}
@ -142,27 +161,32 @@ paint (TestState *state)
test_depth (state, 0, 0, /* position */
&rect0_state, &rect1_state, &rect2_state,
FALSE, /* legacy mode */
0x00ff00ff); /* expected */
rect2_state.test_function = COGL_DEPTH_TEST_FUNCTION_ALWAYS;
test_depth (state, 1, 0, /* position */
&rect0_state, &rect1_state, &rect2_state,
FALSE, /* legacy mode */
0x0000ffff); /* expected */
rect2_state.test_function = COGL_DEPTH_TEST_FUNCTION_LESS;
test_depth (state, 2, 0, /* position */
&rect0_state, &rect1_state, &rect2_state,
FALSE, /* legacy mode */
0x0000ffff); /* expected */
rect2_state.test_function = COGL_DEPTH_TEST_FUNCTION_GREATER;
test_depth (state, 3, 0, /* position */
&rect0_state, &rect1_state, &rect2_state,
FALSE, /* legacy mode */
0x00ff00ff); /* expected */
rect0_state.test_enable = TRUE;
rect1_state.write_enable = FALSE;
test_depth (state, 4, 0, /* position */
&rect0_state, &rect1_state, &rect2_state,
FALSE, /* legacy mode */
0x0000ffff); /* expected */
}
@ -191,6 +215,7 @@ paint (TestState *state)
test_depth (state, 0, 1, /* position */
&rect0_state, &rect1_state, NULL,
FALSE, /* legacy mode */
0xff0000ff); /* expected */
}
@ -220,26 +245,26 @@ paint (TestState *state)
cogl_set_depth_test_enabled (TRUE);
test_depth (state, 0, 2, /* position */
&rect0_state, &rect1_state, NULL,
TRUE, /* legacy mode */
0xff0000ff); /* expected */
cogl_set_depth_test_enabled (FALSE);
test_depth (state, 1, 2, /* position */
&rect0_state, &rect1_state, NULL,
TRUE, /* legacy mode */
0x00ff00ff); /* expected */
}
}
void
test_cogl_depth_test (TestUtilsGTestFixture *fixture,
void *data)
test_depth_test (void)
{
TestUtilsSharedState *shared_state = data;
TestState state;
state.ctx = shared_state->ctx;
cogl_ortho (0, cogl_framebuffer_get_width (shared_state->fb), /* left, right */
cogl_framebuffer_get_height (shared_state->fb), 0, /* bottom, top */
-1, 100 /* z near, far */);
cogl_framebuffer_orthographic (fb, 0, 0,
cogl_framebuffer_get_width (fb),
cogl_framebuffer_get_height (fb),
-1,
100);
paint (&state);

View File

@ -4,7 +4,7 @@
#include "test-conform-common.h"
void
test_cogl_fixed (TestUtilsGTestFixture *fixture,
test_fixed (TestUtilsGTestFixture *fixture,
void *data)
{
g_assert_cmpint (COGL_FIXED_1, ==, COGL_FIXED_FROM_FLOAT (1.0));

View File

@ -3,7 +3,7 @@
#include <cogl/cogl.h>
void
test_cogl_simple_rig (void)
test_simple_rig (void)
{
ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
stage = clutter_stage_get_default ();

View File

@ -6,10 +6,10 @@
typedef struct _TestState
{
CoglContext *ctx;
int paddiing;
} TestState;
static CoglHandle
static CoglTexture *
create_dummy_texture (void)
{
/* Create a dummy 1x1 green texture to replace the color from the
@ -28,7 +28,7 @@ static void
paint_legacy (TestState *state)
{
CoglHandle material = cogl_material_new ();
CoglHandle tex;
CoglTexture *tex;
CoglColor color;
GError *error = NULL;
CoglHandle shader, program;
@ -44,7 +44,7 @@ paint_legacy (TestState *state)
constant green color provided by a texture */
tex = create_dummy_texture ();
cogl_material_set_layer (material, 0, tex);
cogl_handle_unref (tex);
cogl_object_unref (tex);
if (!cogl_material_set_layer_combine (material, 0,
"RGBA=REPLACE(TEXTURE)",
&error))
@ -97,8 +97,8 @@ paint_legacy (TestState *state)
static void
paint (TestState *state)
{
CoglPipeline *pipeline = cogl_pipeline_new (state->ctx);
CoglHandle tex;
CoglPipeline *pipeline = cogl_pipeline_new (ctx);
CoglTexture *tex;
CoglColor color;
GError *error = NULL;
CoglHandle shader, program;
@ -114,7 +114,7 @@ paint (TestState *state)
constant green color provided by a texture */
tex = create_dummy_texture ();
cogl_pipeline_set_layer_texture (pipeline, 0, tex);
cogl_handle_unref (tex);
cogl_object_unref (tex);
if (!cogl_pipeline_set_layer_combine (pipeline, 0,
"RGBA=REPLACE(TEXTURE)",
&error))
@ -166,35 +166,40 @@ paint (TestState *state)
}
static void
validate_result (void)
validate_result (CoglFramebuffer *framebuffer)
{
/* Non-shader version */
test_utils_check_pixel (25, 25, 0x00ff0000);
test_utils_check_pixel (framebuffer, 25, 25, 0x00ff0000);
/* Shader version */
test_utils_check_pixel (75, 25, 0x00ff0000);
test_utils_check_pixel (framebuffer, 75, 25, 0x00ff0000);
}
void
test_cogl_just_vertex_shader (TestUtilsGTestFixture *fixture,
void *data)
test_just_vertex_shader (void)
{
TestUtilsSharedState *shared_state = data;
TestState state;
state.ctx = shared_state->ctx;
cogl_ortho (0, cogl_framebuffer_get_width (shared_state->fb), /* left, right */
cogl_framebuffer_get_height (shared_state->fb), 0, /* bottom, top */
-1, 100 /* z near, far */);
cogl_framebuffer_orthographic (fb,
0, 0,
cogl_framebuffer_get_width (fb),
cogl_framebuffer_get_height (fb),
-1,
100);
/* If shaders aren't supported then we can't run the test */
if (cogl_features_available (COGL_FEATURE_SHADERS_GLSL))
{
/* XXX: we have to push/pop a framebuffer since this test currently
* uses the legacy cogl_rectangle() api. */
cogl_push_framebuffer (fb);
paint_legacy (&state);
validate_result ();
validate_result (fb);
paint (&state);
validate_result ();
validate_result (fb);
cogl_pop_framebuffer ();
if (cogl_test_verbose ())
g_print ("OK\n");

View File

@ -218,7 +218,7 @@ queue_redraw (gpointer stage)
}
void
test_cogl_materials (TestUtilsGTestFixture *fixture,
test_materials (TestUtilsGTestFixture *fixture,
void *data)
{
TestState state;

View File

@ -173,7 +173,7 @@ queue_redraw (gpointer stage)
}
void
test_cogl_multitexture (TestUtilsGTestFixture *fixture,
test_multitexture (TestUtilsGTestFixture *fixture,
void *data)
{
TestState state;

View File

@ -188,7 +188,7 @@ make_texture (void)
}
void
test_cogl_npot_texture (TestUtilsGTestFixture *fixture,
test_npot_texture (TestUtilsGTestFixture *fixture,
void *data)
{
TestState state;

View File

@ -39,7 +39,7 @@ destroy2_cb (void *user_data)
}
void
test_cogl_object (TestUtilsGTestFixture *fixture,
test_object (TestUtilsGTestFixture *fixture,
void *data)
{
CoglPath *path;

View File

@ -8,7 +8,6 @@
typedef struct _TestState
{
CoglContext *context;
int fb_width;
int fb_height;
} TestState;
@ -33,7 +32,7 @@ check_quadrant (TestState *state,
width -= 4;
height -= 4;
test_utils_check_region (x, y, width, height, expected_rgba);
test_utils_check_region (fb, x, y, width, height, expected_rgba);
}
static void
@ -41,9 +40,9 @@ test_paint (TestState *state)
{
CoglTexture2D *tex_2d;
CoglTexture *tex;
CoglHandle offscreen;
CoglOffscreen *offscreen;
tex_2d = cogl_texture_2d_new_with_size (state->context,
tex_2d = cogl_texture_2d_new_with_size (ctx,
state->fb_width,
state->fb_height,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
@ -66,11 +65,11 @@ test_paint (TestState *state)
cogl_translate (0.5, 0.5, 0);
cogl_scale (-0.5, 0.5, 1);
cogl_push_framebuffer (offscreen);
cogl_push_framebuffer (COGL_FRAMEBUFFER (offscreen));
/* Cogl should release the last reference when we call cogl_pop_framebuffer()
*/
cogl_handle_unref (offscreen);
cogl_object_unref (offscreen);
/* Setup something other than the identity matrix for the modelview so we can
* verify it gets restored when we call cogl_pop_framebuffer () */
@ -116,7 +115,7 @@ test_flush (TestState *state)
{
CoglTexture2D *tex_2d;
CoglTexture *tex;
CoglHandle offscreen;
CoglOffscreen *offscreen;
CoglColor clear_color;
int i;
@ -126,7 +125,7 @@ test_flush (TestState *state)
the contents of the texture will automatically flush the
journal */
tex_2d = cogl_texture_2d_new_with_size (state->context,
tex_2d = cogl_texture_2d_new_with_size (ctx,
16, 16, /* width/height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
NULL);
@ -134,7 +133,7 @@ test_flush (TestState *state)
offscreen = cogl_offscreen_new_to_texture (tex);
cogl_push_framebuffer (offscreen);
cogl_push_framebuffer (COGL_FRAMEBUFFER (offscreen));
cogl_color_init_from_4ub (&clear_color, 0, 0, 0, 255);
cogl_clear (&clear_color, COGL_BUFFER_BIT_COLOR);
@ -144,7 +143,8 @@ test_flush (TestState *state)
if (i == 0)
/* First time check using read pixels on the offscreen */
test_utils_check_region (1, 1, 15, 15, 0xff0000ff);
test_utils_check_region (COGL_FRAMEBUFFER (offscreen),
1, 1, 15, 15, 0xff0000ff);
else if (i == 1)
{
guint8 data[16 * 4 * 16];
@ -169,30 +169,32 @@ test_flush (TestState *state)
/* Third time try drawing the texture to the screen */
cogl_set_source_texture (tex);
cogl_rectangle (-1, -1, 1, 1);
test_utils_check_region (2, 2, /* x/y */
test_utils_check_region (fb,
2, 2, /* x/y */
state->fb_width - 4,
state->fb_height - 4,
0xff0000ff);
}
cogl_object_unref (tex_2d);
cogl_handle_unref (offscreen);
cogl_object_unref (offscreen);
}
}
void
test_cogl_offscreen (TestUtilsGTestFixture *fixture,
void *data)
test_offscreen (void)
{
TestUtilsSharedState *shared_state = data;
TestState state;
state.context = shared_state->ctx;
state.fb_width = cogl_framebuffer_get_width (shared_state->fb);
state.fb_height = cogl_framebuffer_get_height (shared_state->fb);
state.fb_width = cogl_framebuffer_get_width (fb);
state.fb_height = cogl_framebuffer_get_height (fb);
/* XXX: we have to push/pop a framebuffer since this test currently
* uses the legacy cogl_rectangle() api. */
cogl_push_framebuffer (fb);
test_paint (&state);
test_flush (&state);
cogl_pop_framebuffer ();
if (cogl_test_verbose ())
g_print ("OK\n");

View File

@ -17,10 +17,10 @@ typedef struct _TestState
static void
draw_path_at (int x, int y)
{
cogl_push_matrix ();
cogl_translate (x * BLOCK_SIZE, y * BLOCK_SIZE, 0.0f);
cogl_framebuffer_push_matrix (fb);
cogl_framebuffer_translate (fb, x * BLOCK_SIZE, y * BLOCK_SIZE, 0.0f);
cogl_path_fill ();
cogl_pop_matrix ();
cogl_framebuffer_pop_matrix (fb);
}
static void
@ -33,10 +33,10 @@ check_block (int block_x, int block_y, int block_mask)
filled. The bits from 0->3 represent the top left, top right,
bottom left and bottom right respectively */
cogl_read_pixels (block_x * BLOCK_SIZE,
cogl_framebuffer_read_pixels (fb,
block_x * BLOCK_SIZE,
block_y * BLOCK_SIZE,
BLOCK_SIZE, BLOCK_SIZE,
COGL_READ_PIXELS_COLOR_BUFFER,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
(guint8 *)data);
@ -188,17 +188,22 @@ validate_result ()
}
void
test_cogl_path (TestUtilsGTestFixture *fixture,
void *data)
test_path (void)
{
TestUtilsSharedState *shared_state = data;
TestState state;
cogl_ortho (0, cogl_framebuffer_get_width (shared_state->fb), /* left, right */
cogl_framebuffer_get_height (shared_state->fb), 0, /* bottom, top */
-1, 100 /* z near, far */);
cogl_framebuffer_orthographic (fb,
0, 0,
cogl_framebuffer_get_width (fb),
cogl_framebuffer_get_height (fb),
-1,
100);
/* XXX: we have to push/pop a framebuffer since this test currently
* uses the legacy cogl_rectangle() api. */
cogl_push_framebuffer (fb);
paint (&state);
cogl_pop_framebuffer ();
validate_result ();
if (cogl_test_verbose ())

View File

@ -8,8 +8,6 @@
typedef struct _TestState
{
CoglContext *ctx;
CoglPipeline *pipeline_red;
CoglPipeline *pipeline_green;
CoglPipeline *pipeline_blue;
@ -92,7 +90,7 @@ create_pipeline_for_shader (TestState *state, const char *shader_source)
CoglHandle shader;
CoglHandle program;
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
shader = cogl_create_shader (COGL_SHADER_TYPE_FRAGMENT);
cogl_shader_source (shader, shader_source);
@ -179,9 +177,8 @@ destroy_state (TestState *state)
static void
paint_pipeline (CoglPipeline *pipeline, int pos)
{
cogl_push_source (pipeline);
cogl_rectangle (pos * 10, 0, pos * 10 + 10, 10);
cogl_pop_source ();
cogl_framebuffer_draw_rectangle (fb, pipeline,
pos * 10, 0, pos * 10 + 10, 10);
}
static void
@ -343,10 +340,7 @@ paint_long_pipeline (TestState *state)
static void
paint (TestState *state)
{
CoglColor color;
cogl_color_init_from_4ub (&color, 0, 0, 0, 255);
cogl_clear (&color, COGL_BUFFER_BIT_COLOR);
cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
paint_color_pipelines (state);
paint_matrix_pipeline (state->matrix_pipeline);
@ -357,7 +351,7 @@ paint (TestState *state)
static void
check_pos (int pos, guint32 color)
{
test_utils_check_pixel (pos * 10 + 5, 5, color);
test_utils_check_pixel (fb, pos * 10 + 5, 5, color);
}
static void
@ -387,26 +381,21 @@ validate_long_pipeline_result (void)
}
void
test_cogl_pipeline_uniforms (TestUtilsGTestFixture *fixture,
void *user_data)
test_pipeline_uniforms (void)
{
TestUtilsSharedState *shared_state = user_data;
/* If shaders aren't supported then we can't run the test */
if (cogl_features_available (COGL_FEATURE_SHADERS_GLSL))
{
TestState state;
state.ctx = shared_state->ctx;
init_state (&state);
cogl_ortho (/* left, right */
0, cogl_framebuffer_get_width (shared_state->fb),
/* bottom, top */
cogl_framebuffer_get_height (shared_state->fb), 0,
/* z near, far */
-1, 100);
cogl_framebuffer_orthographic (fb,
0, 0,
cogl_framebuffer_get_width (fb),
cogl_framebuffer_get_height (fb),
-1,
100);
paint (&state);
validate_result ();

View File

@ -6,7 +6,6 @@
typedef struct _TestState
{
CoglContext *ctx;
int width;
int height;
} TestState;
@ -23,8 +22,7 @@ validate_result (TestState *state)
verify this by reading back the entire stage */
pixels = g_malloc (state->width * state->height * 4);
cogl_read_pixels (0, 0, state->width, state->height,
COGL_READ_PIXELS_COLOR_BUFFER,
cogl_framebuffer_read_pixels (fb, 0, 0, state->width, state->height,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
(guint8 *)pixels);
@ -53,21 +51,22 @@ paint (TestState *state)
0xff, 0x00, 0xff, /* magenta -> becomes bottom right */
0x00, 0xff, 0xff /* cyan -> becomes bottom left */
};
CoglColor bg;
CoglHandle tex0, tex1;
CoglTexture *tex0, *tex1;
CoglPipeline *pipeline;
CoglMatrix matrix;
GError *error = NULL;
cogl_ortho (0, state->width, /* left, right */
state->height, 0, /* bottom, top */
-1, 100 /* z near, far */);
cogl_framebuffer_orthographic (fb,
0, 0,
state->width,
state->height,
-1,
100);
cogl_color_init_from_4ub (&bg, 0, 0, 0, 255);
cogl_clear (&bg, COGL_BUFFER_BIT_COLOR);
cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
cogl_matrix_init_identity (&matrix);
cogl_set_modelview_matrix (&matrix);
cogl_framebuffer_set_modelview_matrix (fb, &matrix);
tex0 = cogl_texture_new_from_data (2, 2,
COGL_TEXTURE_NO_ATLAS,
@ -82,7 +81,7 @@ paint (TestState *state)
6,
data1);
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
/* Set the two textures as layers */
cogl_pipeline_set_layer_texture (pipeline, 0, tex0);
@ -115,25 +114,23 @@ paint (TestState *state)
cogl_matrix_scale (&matrix, -1.0f, 1.0f, 1.0f);
cogl_pipeline_set_layer_matrix (pipeline, 1, &matrix);
cogl_set_source (pipeline);
cogl_rectangle (0, 0, state->width, state->height);
cogl_framebuffer_draw_rectangle (fb,
pipeline,
0, 0,
state->width, state->height);
cogl_handle_unref (tex1);
cogl_handle_unref (tex0);
cogl_object_unref (tex1);
cogl_object_unref (tex0);
cogl_object_unref (pipeline);
}
void
test_cogl_pipeline_user_matrix (TestUtilsGTestFixture *fixture,
void *data)
test_pipeline_user_matrix (void)
{
TestUtilsSharedState *shared_state = data;
TestState state;
state.ctx = shared_state->ctx;
state.width = cogl_framebuffer_get_width (shared_state->fb);
state.height = cogl_framebuffer_get_height (shared_state->fb);
state.width = cogl_framebuffer_get_width (fb);
state.height = cogl_framebuffer_get_height (fb);
paint (&state);
validate_result (&state);

View File

@ -188,11 +188,15 @@ draw_frame (TestState *state)
/* Paint the textures */
for (i = 0; i < NB_TILES; i++)
{
cogl_set_source_texture (state->tiles[i].texture);
cogl_rectangle (state->tiles[i].x,
CoglPipeline *pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_layer_texture (pipeline, 0, state->tiles[i].texture);
cogl_framebuffer_draw_rectangle (fb,
pipeline,
state->tiles[i].x,
state->tiles[i].y,
state->tiles[i].x + TILE_SIZE,
state->tiles[i].y + TILE_SIZE);
cogl_object_unref (pipeline);
}
}
@ -201,7 +205,8 @@ static void
validate_tile (TestState *state,
TestTile *tile)
{
test_utils_check_region (tile->x, tile->y,
test_utils_check_region (fb,
tile->x, tile->y,
TILE_SIZE, TILE_SIZE,
(tile->color[0] << 24) |
(tile->color[1] << 16) |
@ -219,10 +224,8 @@ validate_result (TestState *state)
}
void
test_cogl_pixel_buffer (TestUtilsGTestFixture *fixture,
void *data)
test_pixel_buffer (void)
{
TestUtilsSharedState *shared_state = data;
TestState state;
int i;
static TestTile tiles[NB_TILES] =
@ -239,17 +242,20 @@ test_cogl_pixel_buffer (TestUtilsGTestFixture *fixture,
{ { 0x7e, 0xff, 0x7e, 0xff }, 0.0f, TILE_SIZE, NULL, NULL }
};
state.width = cogl_framebuffer_get_width (shared_state->fb);
state.height = cogl_framebuffer_get_height (shared_state->fb);
cogl_ortho (0, state.width, /* left, right */
state.height, 0, /* bottom, top */
-1, 100 /* z near, far */);
state.width = cogl_framebuffer_get_width (fb);
state.height = cogl_framebuffer_get_height (fb);
cogl_framebuffer_orthographic (fb,
0, 0,
state.width,
state.height,
-1,
100);
create_map_tile (shared_state->ctx, &tiles[TILE_MAP]);
create_map_tile (ctx, &tiles[TILE_MAP]);
#if 0
create_set_region_tile (shared_state->ctx, &tiles[TILE_SET_REGION]);
#endif
create_set_data_tile (shared_state->ctx, &tiles[TILE_SET_DATA]);
create_set_data_tile (ctx, &tiles[TILE_SET_DATA]);
state.tiles = tiles;

View File

@ -37,30 +37,28 @@ verify_point_size (CoglFramebuffer *fb,
gboolean in_point = x >= 1 && x <= 2 && y >= 1 && y <= 2;
guint32 expected_pixel = in_point ? 0x00ff00ff : 0xff0000ff;
test_utils_check_pixel (calc_coord_offset (x_pos, x, point_size),
test_utils_check_pixel (fb,
calc_coord_offset (x_pos, x, point_size),
calc_coord_offset (y_pos, y, point_size),
expected_pixel);
}
}
void
test_cogl_point_size (TestUtilsGTestFixture *fixture,
void *data)
test_point_size (void)
{
TestUtilsSharedState *shared_state = data;
CoglContext *ctx = shared_state->ctx;
int fb_width = cogl_framebuffer_get_width (shared_state->fb);
int fb_height = cogl_framebuffer_get_height (shared_state->fb);
int fb_width = cogl_framebuffer_get_width (fb);
int fb_height = cogl_framebuffer_get_height (fb);
int point_size;
int x_pos;
cogl_framebuffer_orthographic (shared_state->fb,
cogl_framebuffer_orthographic (fb,
0, 0, /* x_1, y_1 */
fb_width, /* x_2 */
fb_height /* y_2 */,
-1, 100 /* near/far */);
cogl_framebuffer_clear4f (shared_state->fb,
cogl_framebuffer_clear4f (fb,
COGL_BUFFER_BIT_COLOR,
1.0f, 0.0f, 0.0f, 1.0f);
@ -81,7 +79,7 @@ test_cogl_point_size (TestUtilsGTestFixture *fixture,
cogl_pipeline_set_point_size (pipeline, point_size);
cogl_pipeline_set_color4ub (pipeline, 0, 255, 0, 255);
cogl_framebuffer_draw_primitive (shared_state->fb,
cogl_framebuffer_draw_primitive (fb,
pipeline,
prim);
@ -93,7 +91,7 @@ test_cogl_point_size (TestUtilsGTestFixture *fixture,
for (x_pos = 0, point_size = MAX_POINT_SIZE;
point_size >= 4;
x_pos += POINT_BOX_SIZE, point_size /= 2)
verify_point_size (shared_state->fb,
verify_point_size (fb,
x_pos + POINT_BOX_SIZE / 2,
POINT_BOX_SIZE / 2,
point_size);

View File

@ -19,26 +19,23 @@ tex_data[3 * 2 * 2] =
};
void
test_cogl_point_sprite (TestUtilsGTestFixture *fixture,
void *data)
test_point_sprite (void)
{
TestUtilsSharedState *shared_state = data;
CoglContext *ctx = shared_state->ctx;
int fb_width = cogl_framebuffer_get_width (shared_state->fb);
int fb_height = cogl_framebuffer_get_height (shared_state->fb);
int fb_width = cogl_framebuffer_get_width (fb);
int fb_height = cogl_framebuffer_get_height (fb);
CoglPrimitive *prim;
GError *error = NULL;
CoglTexture2D *tex_2d;
CoglPipeline *pipeline, *solid_pipeline;
gboolean res;
cogl_framebuffer_orthographic (shared_state->fb,
cogl_framebuffer_orthographic (fb,
0, 0, /* x_1, y_1 */
fb_width, /* x_2 */
fb_height /* y_2 */,
-1, 100 /* near/far */);
cogl_framebuffer_clear4f (shared_state->fb,
cogl_framebuffer_clear4f (fb,
COGL_BUFFER_BIT_COLOR,
1.0f, 1.0f, 1.0f, 1.0f);
@ -75,7 +72,7 @@ test_cogl_point_sprite (TestUtilsGTestFixture *fixture,
1, /* n_vertices */
&point);
cogl_framebuffer_draw_primitive (shared_state->fb,
cogl_framebuffer_draw_primitive (fb,
pipeline,
prim);
@ -88,38 +85,43 @@ test_cogl_point_sprite (TestUtilsGTestFixture *fixture,
/* enable */
FALSE,
&error);
cogl_framebuffer_push_matrix (shared_state->fb);
cogl_framebuffer_translate (shared_state->fb,
cogl_framebuffer_push_matrix (fb);
cogl_framebuffer_translate (fb,
POINT_SIZE * 2, /* x */
0.0f, /* y */
0.0f /* z */);
cogl_framebuffer_draw_primitive (shared_state->fb,
cogl_framebuffer_draw_primitive (fb,
solid_pipeline,
prim);
cogl_framebuffer_pop_matrix (shared_state->fb);
cogl_framebuffer_pop_matrix (fb);
cogl_object_unref (prim);
cogl_object_unref (solid_pipeline);
cogl_object_unref (pipeline);
cogl_object_unref (tex_2d);
test_utils_check_pixel (POINT_SIZE - POINT_SIZE / 4,
test_utils_check_pixel (fb,
POINT_SIZE - POINT_SIZE / 4,
POINT_SIZE - POINT_SIZE / 4,
0x0000ffff);
test_utils_check_pixel (POINT_SIZE + POINT_SIZE / 4,
test_utils_check_pixel (fb,
POINT_SIZE + POINT_SIZE / 4,
POINT_SIZE - POINT_SIZE / 4,
0x00ff00ff);
test_utils_check_pixel (POINT_SIZE - POINT_SIZE / 4,
test_utils_check_pixel (fb,
POINT_SIZE - POINT_SIZE / 4,
POINT_SIZE + POINT_SIZE / 4,
0x00ffffff);
test_utils_check_pixel (POINT_SIZE + POINT_SIZE / 4,
test_utils_check_pixel (fb,
POINT_SIZE + POINT_SIZE / 4,
POINT_SIZE + POINT_SIZE / 4,
0xff0000ff);
/* When rendering without the point sprites all of the texture
coordinates should be 0,0 so it should get the top-left texel
which is blue */
test_utils_check_region (POINT_SIZE * 3 - POINT_SIZE / 2 + 1,
test_utils_check_region (fb,
POINT_SIZE * 3 - POINT_SIZE / 2 + 1,
POINT_SIZE - POINT_SIZE / 2 + 1,
POINT_SIZE - 2, POINT_SIZE - 2,
0x0000ffff);

View File

@ -287,7 +287,7 @@ queue_redraw (gpointer stage)
}
void
test_cogl_premult (TestUtilsGTestFixture *fixture,
test_premult (TestUtilsGTestFixture *fixture,
void *data)
{
TestState state;

View File

@ -6,10 +6,8 @@
typedef struct _TestState
{
CoglContext *ctx;
int fb_width;
int fb_height;
CoglFramebuffer *fb;
} TestState;
#define PRIM_COLOR 0xff00ffff
@ -178,7 +176,7 @@ test_paint (TestState *state)
COGL_PIXEL_FORMAT_ANY,
6, /* rowstride */
tex_data);
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_color4ub (pipeline,
(PRIM_COLOR >> 24) & 0xff,
(PRIM_COLOR >> 16) & 0xff,
@ -192,14 +190,14 @@ test_paint (TestState *state)
CoglPrimitive *prim;
guint32 expected_color = PRIM_COLOR;
prim = test_prim_funcs[i] (state->ctx, &expected_color);
prim = test_prim_funcs[i] (ctx, &expected_color);
cogl_push_matrix ();
cogl_translate (i * 10, 0, 0);
cogl_framebuffer_draw_primitive (state->fb, pipeline, prim);
cogl_pop_matrix ();
cogl_framebuffer_push_matrix (fb);
cogl_framebuffer_translate (fb, i * 10, 0, 0);
cogl_framebuffer_draw_primitive (fb, pipeline, prim);
cogl_framebuffer_pop_matrix (fb);
test_utils_check_pixel (i * 10 + 2, 2, expected_color);
test_utils_check_pixel (fb, i * 10 + 2, 2, expected_color);
cogl_object_unref (prim);
}
@ -236,7 +234,7 @@ test_copy (TestState *state)
{
static const guint16 indices_data[2] = { 1, 2 };
CoglAttributeBuffer *buffer =
cogl_attribute_buffer_new (state->ctx, 100, NULL);
cogl_attribute_buffer_new (ctx, 100, NULL);
CoglAttribute *attributes[N_ATTRIBS];
CoglAttribute *attributes_a[N_ATTRIBS], *attributes_b[N_ATTRIBS];
CoglAttribute **p;
@ -261,7 +259,7 @@ test_copy (TestState *state)
attributes,
N_ATTRIBS);
indices = cogl_indices_new (state->ctx,
indices = cogl_indices_new (ctx,
COGL_INDICES_TYPE_UNSIGNED_SHORT,
indices_data,
2 /* n_indices */);
@ -314,20 +312,19 @@ test_copy (TestState *state)
}
void
test_cogl_primitive (TestUtilsGTestFixture *fixture,
void *data)
test_primitive (void)
{
TestUtilsSharedState *shared_state = data;
TestState state;
state.ctx = shared_state->ctx;
state.fb_width = cogl_framebuffer_get_width (shared_state->fb);
state.fb_height = cogl_framebuffer_get_height (shared_state->fb);
state.fb = shared_state->fb;
state.fb_width = cogl_framebuffer_get_width (fb);
state.fb_height = cogl_framebuffer_get_height (fb);
cogl_ortho (0, state.fb_width, /* left, right */
state.fb_height, 0, /* bottom, top */
-1, 100 /* z near, far */);
cogl_framebuffer_orthographic (fb,
0, 0,
state.fb_width,
state.fb_height,
-1,
100);
test_paint (&state);
test_copy (&state);

View File

@ -142,13 +142,11 @@ test_read_int (CoglTexture2D *tex_2d,
}
void
test_cogl_read_texture_formats (TestUtilsGTestFixture *fixture,
void *data)
test_read_texture_formats (void)
{
TestUtilsSharedState *shared_state = data;
CoglTexture2D *tex_2d;
tex_2d = cogl_texture_2d_new_from_data (shared_state->ctx,
tex_2d = cogl_texture_2d_new_from_data (ctx,
1, 1, /* width / height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,

View File

@ -147,7 +147,7 @@ queue_redraw (gpointer stage)
}
void
test_cogl_readpixels (TestUtilsGTestFixture *fixture,
test_readpixels (TestUtilsGTestFixture *fixture,
void *data)
{
unsigned int idle_source;

View File

@ -6,8 +6,7 @@
typedef struct _TestState
{
CoglContext *ctx;
CoglFramebuffer *fb;
int padding;
} TestState;
typedef void (* SnippetTestFunc) (TestState *state);
@ -16,7 +15,7 @@ static CoglPipeline *
create_texture_pipeline (TestState *state)
{
CoglPipeline *pipeline;
CoglHandle tex;
CoglTexture *tex;
static const guint8 tex_data[] =
{
0xff, 0x00, 0x00, 0xff, /* red */ 0x00, 0xff, 0x00, 0xff, /* green */
@ -30,7 +29,7 @@ create_texture_pipeline (TestState *state)
8, /* rowstride */
tex_data);
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_layer_texture (pipeline, 0, tex);
@ -38,7 +37,7 @@ create_texture_pipeline (TestState *state)
COGL_PIPELINE_FILTER_NEAREST,
COGL_PIPELINE_FILTER_NEAREST);
cogl_handle_unref (tex);
cogl_object_unref (tex);
return pipeline;
}
@ -50,7 +49,7 @@ simple_fragment_snippet (TestState *state)
CoglSnippet *snippet;
/* Simple fragment snippet */
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_color4ub (pipeline, 255, 0, 0, 255);
@ -60,13 +59,11 @@ simple_fragment_snippet (TestState *state)
cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet);
cogl_push_source (pipeline);
cogl_rectangle (0, 0, 10, 10);
cogl_pop_source ();
cogl_framebuffer_draw_rectangle (fb, pipeline, 0, 0, 10, 10);
cogl_object_unref (pipeline);
test_utils_check_pixel (5, 5, 0xffff00ff);
test_utils_check_pixel (fb, 5, 5, 0xffff00ff);
}
static void
@ -76,7 +73,7 @@ simple_vertex_snippet (TestState *state)
CoglSnippet *snippet;
/* Simple vertex snippet */
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_color4ub (pipeline, 255, 0, 0, 255);
@ -86,13 +83,11 @@ simple_vertex_snippet (TestState *state)
cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet);
cogl_push_source (pipeline);
cogl_rectangle (10, 0, 20, 10);
cogl_pop_source ();
cogl_framebuffer_draw_rectangle (fb, pipeline, 10, 0, 20, 10);
cogl_object_unref (pipeline);
test_utils_check_pixel (15, 5, 0xff00ffff);
test_utils_check_pixel (fb, 15, 5, 0xff00ffff);
}
static void
@ -104,7 +99,7 @@ shared_uniform (TestState *state)
/* Snippets sharing a uniform across the vertex and fragment
hooks */
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
location = cogl_pipeline_get_uniform_location (pipeline, "a_value");
cogl_pipeline_set_uniform_1f (pipeline, location, 0.25f);
@ -122,13 +117,13 @@ shared_uniform (TestState *state)
cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet);
cogl_push_source (pipeline);
cogl_rectangle (20, 0, 30, 10);
cogl_pop_source ();
cogl_framebuffer_draw_rectangle (fb,
pipeline,
20, 0, 30, 10);
cogl_object_unref (pipeline);
test_utils_check_pixel (25, 5, 0xff0080ff);
test_utils_check_pixel (fb, 25, 5, 0xff0080ff);
}
static void
@ -140,7 +135,7 @@ lots_snippets (TestState *state)
int i;
/* Lots of snippets on one pipeline */
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_color4ub (pipeline, 0, 0, 0, 255);
@ -168,13 +163,11 @@ lots_snippets (TestState *state)
g_free (declarations);
}
cogl_push_source (pipeline);
cogl_rectangle (30, 0, 40, 10);
cogl_pop_source ();
cogl_framebuffer_draw_rectangle (fb, pipeline, 30, 0, 40, 10);
cogl_object_unref (pipeline);
test_utils_check_pixel (35, 5, 0x19334cff);
test_utils_check_pixel (fb, 35, 5, 0x19334cff);
}
static void
@ -185,7 +178,7 @@ shared_variable_pre_post (TestState *state)
/* Test that the pre string can declare variables used by the post
string */
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_color4ub (pipeline, 255, 255, 255, 255);
@ -196,13 +189,11 @@ shared_variable_pre_post (TestState *state)
cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet);
cogl_push_source (pipeline);
cogl_rectangle (40, 0, 50, 10);
cogl_pop_source ();
cogl_framebuffer_draw_rectangle (fb, pipeline, 40, 0, 50, 10);
cogl_object_unref (pipeline);
test_utils_check_pixel (45, 5, 0xff0000ff);
test_utils_check_pixel (fb, 45, 5, 0xff0000ff);
}
static void
@ -223,24 +214,20 @@ test_pipeline_caching (TestState *state)
" unrelated pipelines */",
"cogl_color_out = vec4 (0.0, 1.0, 0.0, 1.0);\n");
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_add_snippet (pipeline, snippet);
cogl_push_source (pipeline);
cogl_rectangle (50, 0, 60, 10);
cogl_pop_source ();
cogl_framebuffer_draw_rectangle (fb, pipeline, 50, 0, 60, 10);
cogl_object_unref (pipeline);
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_add_snippet (pipeline, snippet);
cogl_push_source (pipeline);
cogl_rectangle (60, 0, 70, 10);
cogl_pop_source ();
cogl_framebuffer_draw_rectangle (fb, pipeline, 60, 0, 70, 10);
cogl_object_unref (pipeline);
cogl_object_unref (snippet);
test_utils_check_pixel (55, 5, 0x00ff00ff);
test_utils_check_pixel (65, 5, 0x00ff00ff);
test_utils_check_pixel (fb, 55, 5, 0x00ff00ff);
test_utils_check_pixel (fb, 65, 5, 0x00ff00ff);
}
static void
@ -260,16 +247,14 @@ test_replace_string (TestState *state)
cogl_snippet_set_post (snippet,
"cogl_color_out += vec4 (0.5, 0.0, 0.0, 1.0);");
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_add_snippet (pipeline, snippet);
cogl_push_source (pipeline);
cogl_rectangle (70, 0, 80, 10);
cogl_pop_source ();
cogl_framebuffer_draw_rectangle (fb, pipeline, 70, 0, 80, 10);
cogl_object_unref (pipeline);
cogl_object_unref (snippet);
test_utils_check_pixel (75, 5, 0x808000ff);
test_utils_check_pixel (fb, 75, 5, 0x808000ff);
}
static void
@ -288,15 +273,15 @@ test_texture_lookup_hook (TestState *state)
pipeline = create_texture_pipeline (state);
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
cogl_push_source (pipeline);
cogl_rectangle_with_texture_coords (80, 0, 90, 10,
cogl_framebuffer_draw_textured_rectangle (fb,
pipeline,
80, 0, 90, 10,
0, 0, 0, 0);
cogl_pop_source ();
cogl_object_unref (pipeline);
cogl_object_unref (snippet);
test_utils_check_pixel (85, 5, 0x00ffffff);
test_utils_check_pixel (fb, 85, 5, 0x00ffffff);
}
static void
@ -317,14 +302,12 @@ test_multiple_samples (TestState *state)
pipeline = create_texture_pipeline (state);
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
cogl_push_source (pipeline);
cogl_rectangle (0, 0, 10, 10);
cogl_pop_source ();
cogl_framebuffer_draw_rectangle (fb, pipeline, 0, 0, 10, 10);
cogl_object_unref (pipeline);
cogl_object_unref (snippet);
test_utils_check_pixel (5, 5, 0xffff00ff);
test_utils_check_pixel (fb, 5, 5, 0xffff00ff);
}
static void
@ -339,15 +322,15 @@ test_replace_lookup_hook (TestState *state)
pipeline = create_texture_pipeline (state);
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
cogl_push_source (pipeline);
cogl_rectangle_with_texture_coords (90, 0, 100, 10,
cogl_framebuffer_draw_textured_rectangle (fb,
pipeline,
90, 0, 100, 10,
0, 0, 0, 0);
cogl_pop_source ();
cogl_object_unref (pipeline);
cogl_object_unref (snippet);
test_utils_check_pixel (95, 5, 0x0000ffff);
test_utils_check_pixel (fb, 95, 5, 0x0000ffff);
}
static void
@ -372,13 +355,13 @@ test_replace_snippet (TestState *state)
cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet);
cogl_push_source (pipeline);
cogl_rectangle_with_texture_coords (100, 0, 110, 10,
cogl_framebuffer_draw_textured_rectangle (fb,
pipeline,
100, 0, 110, 10,
0, 0, 0, 0);
cogl_pop_source ();
cogl_object_unref (pipeline);
test_utils_check_pixel (105, 5, 0xff0000ff);
test_utils_check_pixel (fb, 105, 5, 0xff0000ff);
}
static void
@ -404,13 +387,13 @@ test_replace_fragment_layer (TestState *state)
"A = REPLACE(PREVIOUS)",
NULL);
cogl_push_source (pipeline);
cogl_rectangle_with_texture_coords (110, 0, 120, 10,
cogl_framebuffer_draw_textured_rectangle (fb,
pipeline,
110, 0, 120, 10,
0, 0, 0, 0);
cogl_pop_source ();
cogl_object_unref (pipeline);
test_utils_check_pixel (115, 5, 0xff00ffff);
test_utils_check_pixel (fb, 115, 5, 0xff00ffff);
}
static void
@ -420,7 +403,7 @@ test_modify_fragment_layer (TestState *state)
CoglSnippet *snippet;
/* Test modifying the fragment layer code */
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_uniform_1f (pipeline,
cogl_pipeline_get_uniform_location (pipeline,
@ -433,13 +416,13 @@ test_modify_fragment_layer (TestState *state)
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
cogl_object_unref (snippet);
cogl_push_source (pipeline);
cogl_rectangle_with_texture_coords (120, 0, 130, 10,
cogl_framebuffer_draw_textured_rectangle (fb,
pipeline,
120, 0, 130, 10,
0, 0, 0, 0);
cogl_pop_source ();
cogl_object_unref (pipeline);
test_utils_check_pixel (125, 5, 0xff80ffff);
test_utils_check_pixel (fb, 125, 5, 0xff80ffff);
}
static void
@ -462,13 +445,13 @@ test_modify_vertex_layer (TestState *state)
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
cogl_object_unref (snippet);
cogl_push_source (pipeline);
cogl_rectangle_with_texture_coords (130, 0, 140, 10,
cogl_framebuffer_draw_textured_rectangle (fb,
pipeline,
130, 0, 140, 10,
0, 0, 0, 0);
cogl_pop_source ();
cogl_object_unref (pipeline);
test_utils_check_pixel (135, 5, 0xffff00ff);
test_utils_check_pixel (fb, 135, 5, 0xffff00ff);
}
static void
@ -492,13 +475,13 @@ test_replace_vertex_layer (TestState *state)
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
cogl_object_unref (snippet);
cogl_push_source (pipeline);
cogl_rectangle_with_texture_coords (140, 0, 150, 10,
cogl_framebuffer_draw_textured_rectangle (fb,
pipeline,
140, 0, 150, 10,
0, 0, 0, 0);
cogl_pop_source ();
cogl_object_unref (pipeline);
test_utils_check_pixel (145, 5, 0x00ff00ff);
test_utils_check_pixel (fb, 145, 5, 0x00ff00ff);
}
static void
@ -514,7 +497,7 @@ test_vertex_transform_hook (TestState *state)
cogl_matrix_init_identity (&identity_matrix);
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_color4ub (pipeline, 255, 0, 255, 255);
@ -527,7 +510,7 @@ test_vertex_transform_hook (TestState *state)
cogl_object_unref (snippet);
/* Copy the current projection matrix to a uniform */
cogl_get_projection_matrix (&matrix);
cogl_framebuffer_get_projection_matrix (fb, &matrix);
location = cogl_pipeline_get_uniform_location (pipeline, "pmat");
cogl_pipeline_set_uniform_matrix (pipeline,
location,
@ -538,17 +521,15 @@ test_vertex_transform_hook (TestState *state)
/* Replace the real projection matrix with the identity. This should
mess up the drawing unless the snippet replacement is working */
cogl_set_projection_matrix (&identity_matrix);
cogl_framebuffer_set_projection_matrix (fb, &identity_matrix);
cogl_push_source (pipeline);
cogl_rectangle (150, 0, 160, 10);
cogl_pop_source ();
cogl_framebuffer_draw_rectangle (fb, pipeline, 150, 0, 160, 10);
cogl_object_unref (pipeline);
/* Restore the projection matrix */
cogl_set_projection_matrix (&matrix);
cogl_framebuffer_set_projection_matrix (fb, &matrix);
test_utils_check_pixel (155, 5, 0xff00ffff);
test_utils_check_pixel (fb, 155, 5, 0xff00ffff);
}
static void
@ -564,7 +545,7 @@ test_snippet_order (TestState *state)
sections in the same order as they were added. Therefore the r
component should be taken from the the second snippet and the g
component from the first */
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_color4ub (pipeline, 0, 0, 0, 255);
@ -583,12 +564,10 @@ test_snippet_order (TestState *state)
cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet);
cogl_push_source (pipeline);
cogl_rectangle (160, 0, 170, 10);
cogl_pop_source ();
cogl_framebuffer_draw_rectangle (fb, pipeline, 160, 0, 170, 10);
cogl_object_unref (pipeline);
test_utils_check_pixel (165, 5, 0x80ff00ff);
test_utils_check_pixel (fb, 165, 5, 0x80ff00ff);
}
static void
@ -609,26 +588,24 @@ test_naming_texture_units (TestState *state)
"texture2D (cogl_sampler100, vec2 (0.0, 0.0)) + "
"texture2D (cogl_sampler200, vec2 (0.0, 0.0));");
tex1 = test_utils_create_color_texture (state->ctx, 0xff0000ff);
tex2 = test_utils_create_color_texture (state->ctx, 0x00ff00ff);
tex1 = test_utils_create_color_texture (ctx, 0xff0000ff);
tex2 = test_utils_create_color_texture (ctx, 0x00ff00ff);
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_layer_texture (pipeline, 100, tex1);
cogl_pipeline_set_layer_texture (pipeline, 200, tex2);
cogl_pipeline_add_snippet (pipeline, snippet);
cogl_push_source (pipeline);
cogl_rectangle (0, 0, 10, 10);
cogl_pop_source ();
cogl_framebuffer_draw_rectangle (fb, pipeline, 0, 0, 10, 10);
cogl_object_unref (pipeline);
cogl_object_unref (snippet);
cogl_object_unref (tex1);
cogl_object_unref (tex2);
test_utils_check_pixel (5, 5, 0xffff00ff);
test_utils_check_pixel (fb, 5, 5, 0xffff00ff);
}
static void
@ -703,7 +680,7 @@ run_tests (TestState *state)
for (i = 0; i < G_N_ELEMENTS (tests); i++)
{
cogl_framebuffer_clear4f (state->fb,
cogl_framebuffer_clear4f (fb,
COGL_BUFFER_BIT_COLOR,
0, 0, 0, 1);
@ -712,25 +689,19 @@ run_tests (TestState *state)
}
void
test_cogl_snippets (TestUtilsGTestFixture *fixture,
void *user_data)
test_snippets (void)
{
TestUtilsSharedState *shared_state = user_data;
/* If shaders aren't supported then we can't run the test */
if (cogl_features_available (COGL_FEATURE_SHADERS_GLSL))
{
TestState state;
state.ctx = shared_state->ctx;
state.fb = shared_state->fb;
cogl_ortho (/* left, right */
0, cogl_framebuffer_get_width (shared_state->fb),
/* bottom, top */
cogl_framebuffer_get_height (shared_state->fb), 0,
/* z near, far */
-1, 100);
cogl_framebuffer_orthographic (fb,
0, 0,
cogl_framebuffer_get_width (fb),
cogl_framebuffer_get_height (fb),
-1,
100);
run_tests (&state);

View File

@ -5,10 +5,8 @@
typedef struct _TestState
{
CoglContext *ctx;
int fb_width;
int fb_height;
CoglFramebuffer *fb;
} TestState;
static void
@ -17,17 +15,17 @@ test_sparse_layer_combine (TestState *state)
CoglPipeline *pipeline;
CoglTexture *tex1, *tex2;
cogl_framebuffer_clear4f (state->fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
/* This tests that the TEXTURE_* numbers used in the layer combine
string refer to the layer number rather than the unit numbers by
creating a pipeline with very large layer numbers. This should
end up being mapped to much smaller unit numbers */
tex1 = test_utils_create_color_texture (state->ctx, 0xff0000ff);
tex2 = test_utils_create_color_texture (state->ctx, 0x00ff00ff);
tex1 = test_utils_create_color_texture (ctx, 0xff0000ff);
tex2 = test_utils_create_color_texture (ctx, 0x00ff00ff);
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_layer_texture (pipeline, 50, tex1);
cogl_pipeline_set_layer_texture (pipeline, 100, tex2);
@ -35,11 +33,9 @@ test_sparse_layer_combine (TestState *state)
"RGBA = ADD(TEXTURE_50, TEXTURE_100)",
NULL);
cogl_push_source (pipeline);
cogl_rectangle (-1, -1, 1, 1);
cogl_pop_source ();
cogl_framebuffer_draw_rectangle (fb, pipeline, -1, -1, 1, 1);
test_utils_check_pixel (2, 2, 0xffff00ff);
test_utils_check_pixel (fb, 2, 2, 0xffff00ff);
cogl_object_unref (pipeline);
cogl_object_unref (tex1);
@ -47,16 +43,12 @@ test_sparse_layer_combine (TestState *state)
}
void
test_cogl_sparse_pipeline (TestUtilsGTestFixture *fixture,
void *data)
test_sparse_pipeline (void)
{
TestUtilsSharedState *shared_state = data;
TestState state;
state.ctx = shared_state->ctx;
state.fb_width = cogl_framebuffer_get_width (shared_state->fb);
state.fb_height = cogl_framebuffer_get_height (shared_state->fb);
state.fb = shared_state->fb;
state.fb_width = cogl_framebuffer_get_width (fb);
state.fb_height = cogl_framebuffer_get_height (fb);
test_sparse_layer_combine (&state);

View File

@ -22,7 +22,6 @@ corner_colors[SOURCE_DIVISIONS_X * SOURCE_DIVISIONS_Y] =
typedef struct _TestState
{
CoglContext *ctx;
CoglTexture2D *tex;
} TestState;
@ -56,7 +55,7 @@ create_source (TestState *state)
}
}
tex = cogl_texture_2d_new_from_data (state->ctx,
tex = cogl_texture_2d_new_from_data (ctx,
SOURCE_SIZE, SOURCE_SIZE,
COGL_PIXEL_FORMAT_RGBA_8888,
COGL_PIXEL_FORMAT_ANY,
@ -88,7 +87,7 @@ create_test_texture (TestState *state)
*(p++) = 255;
}
tex = cogl_texture_2d_new_from_data (state->ctx,
tex = cogl_texture_2d_new_from_data (ctx,
256, 256,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_ANY,
@ -107,9 +106,10 @@ paint (TestState *state)
{
CoglTexture2D *full_texture;
CoglSubTexture *sub_texture, *sub_sub_texture;
CoglPipeline *pipeline = cogl_pipeline_new (ctx);
/* Create a sub texture of the bottom right quarter of the texture */
sub_texture = cogl_sub_texture_new (state->ctx,
sub_texture = cogl_sub_texture_new (ctx,
COGL_TEXTURE (state->tex),
DIVISION_WIDTH,
DIVISION_HEIGHT,
@ -117,40 +117,47 @@ paint (TestState *state)
DIVISION_HEIGHT);
/* Paint it */
cogl_set_source_texture (COGL_TEXTURE (sub_texture));
cogl_rectangle (0.0f, 0.0f, DIVISION_WIDTH, DIVISION_HEIGHT);
cogl_pipeline_set_layer_texture (pipeline, 0, COGL_TEXTURE (sub_texture));
cogl_object_unref (sub_texture);
cogl_framebuffer_draw_rectangle (fb, pipeline,
0.0f, 0.0f, DIVISION_WIDTH, DIVISION_HEIGHT);
/* Repeat a sub texture of the top half of the full texture. This is
documented to be undefined so it doesn't technically have to work
but it will with the current implementation */
sub_texture = cogl_sub_texture_new (state->ctx,
sub_texture = cogl_sub_texture_new (ctx,
COGL_TEXTURE (state->tex),
0, 0,
SOURCE_SIZE,
DIVISION_HEIGHT);
cogl_set_source_texture (COGL_TEXTURE (sub_texture));
cogl_rectangle_with_texture_coords (0.0f, SOURCE_SIZE,
SOURCE_SIZE * 2.0f, SOURCE_SIZE * 1.5f,
cogl_pipeline_set_layer_texture (pipeline, 0, COGL_TEXTURE (sub_texture));
cogl_object_unref (sub_texture);
cogl_framebuffer_draw_textured_rectangle (fb, pipeline,
0.0f,
SOURCE_SIZE,
SOURCE_SIZE * 2.0f,
SOURCE_SIZE * 1.5f,
0.0f, 0.0f,
2.0f, 1.0f);
cogl_object_unref (sub_texture);
/* Create a sub texture of a sub texture */
full_texture = create_test_texture (state);
sub_texture = cogl_sub_texture_new (state->ctx,
sub_texture = cogl_sub_texture_new (ctx,
COGL_TEXTURE (full_texture),
20, 10, 30, 20);
sub_sub_texture = cogl_sub_texture_new (state->ctx,
cogl_object_unref (full_texture);
sub_sub_texture = cogl_sub_texture_new (ctx,
COGL_TEXTURE (sub_texture),
20, 10, 10, 10);
cogl_set_source_texture (COGL_TEXTURE (sub_sub_texture));
cogl_rectangle (0.0f, SOURCE_SIZE * 2.0f,
10.0f, SOURCE_SIZE * 2.0f + 10.0f);
cogl_object_unref (sub_sub_texture);
cogl_object_unref (sub_texture);
cogl_object_unref (full_texture);
cogl_pipeline_set_layer_texture (pipeline, 0, COGL_TEXTURE (sub_sub_texture));
cogl_object_unref (sub_sub_texture);
cogl_framebuffer_draw_rectangle (fb, pipeline,
0.0f, SOURCE_SIZE * 2.0f,
10.0f, SOURCE_SIZE * 2.0f + 10.0f);
cogl_object_unref (pipeline);
}
static void
@ -158,7 +165,8 @@ validate_part (int xpos, int ypos,
int width, int height,
guint32 color)
{
test_utils_check_region (xpos + TEST_INSET,
test_utils_check_region (fb,
xpos + TEST_INSET,
ypos + TEST_INSET,
width - TEST_INSET - 2,
height - TEST_INSET - 2,
@ -212,8 +220,9 @@ validate_result (TestState *state)
/* Sub sub texture */
p = texture_data = g_malloc (10 * 10 * 4);
cogl_read_pixels (0, SOURCE_SIZE * 2, 10, 10,
COGL_READ_PIXELS_COLOR_BUFFER,
cogl_flush ();
cogl_framebuffer_read_pixels (fb,
0, SOURCE_SIZE * 2, 10, 10,
COGL_PIXEL_FORMAT_RGBA_8888,
p);
for (y = 0; y < 10; y++)
@ -226,7 +235,7 @@ validate_result (TestState *state)
g_free (texture_data);
/* Try reading back the texture data */
sub_texture = cogl_sub_texture_new (state->ctx,
sub_texture = cogl_sub_texture_new (ctx,
COGL_TEXTURE (state->tex),
SOURCE_SIZE / 4,
SOURCE_SIZE / 4,
@ -257,7 +266,7 @@ validate_result (TestState *state)
/* Create a 256x256 test texture */
test_tex = create_test_texture (state);
/* Create a sub texture the views the center half of the texture */
sub_texture = cogl_sub_texture_new (state->ctx,
sub_texture = cogl_sub_texture_new (ctx,
COGL_TEXTURE (test_tex),
64, 64, 128, 128);
/* Update the center half of the sub texture */
@ -299,18 +308,18 @@ validate_result (TestState *state)
}
void
test_cogl_sub_texture (TestUtilsGTestFixture *fixture,
void *data)
test_sub_texture (void)
{
TestUtilsSharedState *shared_state = data;
TestState state;
state.ctx = shared_state->ctx;
state.tex = create_source (&state);
cogl_ortho (0, cogl_framebuffer_get_width (shared_state->fb), /* left, right */
cogl_framebuffer_get_height (shared_state->fb), 0, /* bottom, top */
-1, 100 /* z near, far */);
cogl_framebuffer_orthographic (fb,
0, 0,
cogl_framebuffer_get_width (fb),
cogl_framebuffer_get_height (fb),
-1,
100);
paint (&state);
validate_result (&state);

View File

@ -13,10 +13,8 @@
typedef struct _TestState
{
CoglContext *ctx;
int fb_width;
int fb_height;
CoglFramebuffer *fb;
} TestState;
static CoglTexture3D *
@ -75,8 +73,8 @@ create_texture_3d (CoglContext *context)
static void
draw_frame (TestState *state)
{
CoglTexture *tex = COGL_TEXTURE (create_texture_3d (state->ctx));
CoglPipeline *pipeline = cogl_pipeline_new (state->ctx);
CoglTexture *tex = COGL_TEXTURE (create_texture_3d (ctx));
CoglPipeline *pipeline = cogl_pipeline_new (ctx);
typedef struct { float x, y, s, t, r; } Vert;
CoglPrimitive *primitive;
CoglAttributeBuffer *attribute_buffer;
@ -89,16 +87,14 @@ draw_frame (TestState *state)
cogl_pipeline_set_layer_filters (pipeline, 0,
COGL_PIPELINE_FILTER_NEAREST,
COGL_PIPELINE_FILTER_NEAREST);
cogl_push_source (pipeline);
/* Render the texture repeated horizontally twice using a regular
cogl rectangle. This should end up with the r texture coordinates
as zero */
cogl_rectangle_with_texture_coords (0.0f, 0.0f, TEX_WIDTH * 2, TEX_HEIGHT,
cogl_framebuffer_draw_textured_rectangle (fb, pipeline,
0.0f, 0.0f, TEX_WIDTH * 2, TEX_HEIGHT,
0.0f, 0.0f, 2.0f, 1.0f);
cogl_pop_source ();
/* Render all of the images in the texture using coordinates from a
CoglPrimitive */
v = verts = g_new (Vert, 4 * TEX_DEPTH);
@ -135,7 +131,7 @@ draw_frame (TestState *state)
v++;
}
attribute_buffer = cogl_attribute_buffer_new (state->ctx,
attribute_buffer = cogl_attribute_buffer_new (ctx,
4 * TEX_DEPTH * sizeof (Vert),
verts);
attributes[0] = cogl_attribute_new (attribute_buffer,
@ -156,11 +152,11 @@ draw_frame (TestState *state)
2 /* n_attributes */);
cogl_primitive_set_indices (primitive,
cogl_get_rectangle_indices (state->ctx,
cogl_get_rectangle_indices (ctx,
TEX_DEPTH),
6 * TEX_DEPTH);
cogl_framebuffer_draw_primitive (state->fb, pipeline, primitive);
cogl_framebuffer_draw_primitive (fb, pipeline, primitive);
g_free (verts);
@ -178,7 +174,8 @@ validate_block (int block_x, int block_y, int z)
for (y = 0; y < TEX_HEIGHT; y++)
for (x = 0; x < TEX_WIDTH; x++)
test_utils_check_pixel_rgb (block_x * TEX_WIDTH + x,
test_utils_check_pixel_rgb (fb,
block_x * TEX_WIDTH + x,
block_y * TEX_HEIGHT + y,
255 - x * 8,
y * 8,
@ -204,20 +201,20 @@ test_multi_texture (TestState *state)
CoglTexture2D *tex_2d;
guint8 tex_data[4];
cogl_framebuffer_clear4f (state->fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
/* Tests a pipeline that is using multi-texturing to combine a 3D
texture with a 2D texture. The texture from another layer is
sampled with TEXTURE_? just to pick up a specific bug that was
happening with the ARBfp fragend */
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
tex_data[0] = 0xff;
tex_data[1] = 0x00;
tex_data[2] = 0x00;
tex_data[3] = 0xff;
tex_2d = cogl_texture_2d_new_from_data (state->ctx,
tex_2d = cogl_texture_2d_new_from_data (ctx,
1, 1, /* width/height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
@ -230,7 +227,7 @@ test_multi_texture (TestState *state)
tex_data[1] = 0xff;
tex_data[2] = 0x00;
tex_data[3] = 0xff;
tex_3d = cogl_texture_3d_new_from_data (state->ctx,
tex_3d = cogl_texture_3d_new_from_data (ctx,
1, 1, 1, /* width/height/depth */
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
@ -247,11 +244,9 @@ test_multi_texture (TestState *state)
"RGBA = ADD(TEXTURE_0, TEXTURE_1)",
NULL);
cogl_push_source (pipeline);
cogl_rectangle (0, 0, 10, 10);
cogl_pop_source ();
cogl_framebuffer_draw_rectangle (fb, pipeline, 0, 0, 10, 10);
test_utils_check_pixel (5, 5, 0xffff00ff);
test_utils_check_pixel (fb, 5, 5, 0xffff00ff);
cogl_object_unref (tex_2d);
cogl_object_unref (tex_3d);
@ -259,23 +254,18 @@ test_multi_texture (TestState *state)
}
void
test_cogl_texture_3d (TestUtilsGTestFixture *fixture,
void *data)
test_texture_3d (void)
{
TestUtilsSharedState *shared_state = data;
/* Check whether GL supports the rectangle extension. If not we'll
just assume the test passes */
if (cogl_has_feature (shared_state->ctx, COGL_FEATURE_ID_TEXTURE_3D))
if (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_3D))
{
TestState state;
state.ctx = shared_state->ctx;
state.fb_width = cogl_framebuffer_get_width (shared_state->fb);
state.fb_height = cogl_framebuffer_get_height (shared_state->fb);
state.fb = shared_state->fb;
state.fb_width = cogl_framebuffer_get_width (fb);
state.fb_height = cogl_framebuffer_get_height (fb);
cogl_framebuffer_orthographic (shared_state->fb,
cogl_framebuffer_orthographic (fb,
0, 0, /* x_1, y_1 */
state.fb_width, /* x_2 */
state.fb_height /* y_2 */,

View File

@ -141,7 +141,7 @@ paint_cb (void)
}
void
test_cogl_texture_get_set_data (TestUtilsGTestFixture *fixture,
test_texture_get_set_data (TestUtilsGTestFixture *fixture,
void *data)
{
ClutterActor *stage;

View File

@ -103,7 +103,7 @@ queue_redraw (gpointer stage)
}
void
test_cogl_texture_mipmaps (TestUtilsGTestFixture *fixture,
test_texture_mipmaps (TestUtilsGTestFixture *fixture,
void *data)
{
TestState state;

View File

@ -198,7 +198,7 @@ queue_redraw (gpointer stage)
#endif /* COGL_HAS_XLIB */
void
test_cogl_texture_pixmap_x11 (TestUtilsGTestFixture *fixture,
test_texture_pixmap_x11 (TestUtilsGTestFixture *fixture,
void *data)
{
#ifdef COGL_HAS_XLIB

View File

@ -237,7 +237,7 @@ check_rectangle_extension (void)
}
void
test_cogl_texture_rectangle (TestUtilsGTestFixture *fixture,
test_texture_rectangle (TestUtilsGTestFixture *fixture,
void *data)
{
TestState state;

View File

@ -9,9 +9,11 @@
static gboolean cogl_test_is_verbose;
CoglContext *ctx;
CoglFramebuffer *fb;
void
test_utils_init (TestUtilsSharedState *state,
TestFlags flags)
test_utils_init (TestFlags flags)
{
static int counter = 0;
GError *error = NULL;
@ -43,11 +45,11 @@ test_utils_init (TestUtilsSharedState *state,
g_setenv ("COGL_X11_SYNC", "1", 0);
state->ctx = cogl_context_new (NULL, &error);
if (!state->ctx)
ctx = cogl_context_new (NULL, &error);
if (!ctx)
g_critical ("Failed to create a CoglContext: %s", error->message);
display = cogl_context_get_display (state->ctx);
display = cogl_context_get_display (ctx);
renderer = cogl_display_get_renderer (display);
if (flags & TEST_REQUIREMENT_GL &&
@ -57,19 +59,19 @@ test_utils_init (TestUtilsSharedState *state,
}
if (flags & TEST_REQUIREMENT_NPOT &&
!cogl_has_feature (state->ctx, COGL_FEATURE_ID_TEXTURE_NPOT))
!cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT))
{
missing_requirement = TRUE;
}
if (flags & TEST_REQUIREMENT_TEXTURE_3D &&
!cogl_has_feature (state->ctx, COGL_FEATURE_ID_TEXTURE_3D))
!cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_3D))
{
missing_requirement = TRUE;
}
if (flags & TEST_REQUIREMENT_POINT_SPRITE &&
!cogl_has_feature (state->ctx, COGL_FEATURE_ID_POINT_SPRITE))
!cogl_has_feature (ctx, COGL_FEATURE_ID_POINT_SPRITE))
{
missing_requirement = TRUE;
}
@ -81,13 +83,13 @@ test_utils_init (TestUtilsSharedState *state,
if (getenv ("COGL_TEST_ONSCREEN"))
{
onscreen = cogl_onscreen_new (state->ctx, 640, 480);
state->fb = COGL_FRAMEBUFFER (onscreen);
onscreen = cogl_onscreen_new (ctx, 640, 480);
fb = COGL_FRAMEBUFFER (onscreen);
}
else
{
CoglHandle offscreen;
CoglHandle tex = cogl_texture_2d_new_with_size (state->ctx,
CoglHandle tex = cogl_texture_2d_new_with_size (ctx,
FB_WIDTH, FB_HEIGHT,
COGL_PIXEL_FORMAT_ANY,
&error);
@ -95,37 +97,33 @@ test_utils_init (TestUtilsSharedState *state,
g_critical ("Failed to allocate texture: %s", error->message);
offscreen = cogl_offscreen_new_to_texture (tex);
state->fb = COGL_FRAMEBUFFER (offscreen);
fb = COGL_FRAMEBUFFER (offscreen);
}
if (!cogl_framebuffer_allocate (state->fb, &error))
if (!cogl_framebuffer_allocate (fb, &error))
g_critical ("Failed to allocate framebuffer: %s", error->message);
if (onscreen)
cogl_onscreen_show (onscreen);
cogl_framebuffer_clear4f (state->fb,
cogl_framebuffer_clear4f (fb,
COGL_BUFFER_BIT_COLOR |
COGL_BUFFER_BIT_DEPTH |
COGL_BUFFER_BIT_STENCIL,
0, 0, 0, 1);
cogl_push_framebuffer (state->fb);
if (missing_requirement)
g_print ("WARNING: Missing required feature[s] for this test\n");
}
void
test_utils_fini (TestUtilsSharedState *state)
test_utils_fini (void)
{
cogl_pop_framebuffer ();
if (fb)
cogl_object_unref (fb);
if (state->fb)
cogl_object_unref (state->fb);
if (state->ctx)
cogl_object_unref (state->ctx);
if (ctx)
cogl_object_unref (ctx);
}
static gboolean
@ -156,11 +154,13 @@ test_utils_compare_pixel (const guint8 *screen_pixel, guint32 expected_pixel)
}
void
test_utils_check_pixel (int x, int y, guint32 expected_pixel)
test_utils_check_pixel (CoglFramebuffer *fb,
int x, int y, guint32 expected_pixel)
{
guint8 pixel[4];
cogl_read_pixels (x, y, 1, 1, COGL_READ_PIXELS_COLOR_BUFFER,
cogl_framebuffer_read_pixels (fb,
x, y, 1, 1,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
pixel);
@ -168,24 +168,26 @@ test_utils_check_pixel (int x, int y, guint32 expected_pixel)
}
void
test_utils_check_pixel_rgb (int x, int y, int r, int g, int b)
test_utils_check_pixel_rgb (CoglFramebuffer *fb,
int x, int y, int r, int g, int b)
{
test_utils_check_pixel (x, y, (r << 24) | (g << 16) | (b << 8));
test_utils_check_pixel (fb, x, y, (r << 24) | (g << 16) | (b << 8));
}
void
test_utils_check_region (int x, int y,
test_utils_check_region (CoglFramebuffer *fb,
int x, int y,
int width, int height,
guint32 expected_rgba)
{
guint8 *pixels, *p;
pixels = p = g_malloc (width * height * 4);
cogl_read_pixels (x,
cogl_framebuffer_read_pixels (fb,
x,
y,
width,
height,
COGL_READ_PIXELS_COLOR_BUFFER,
COGL_PIXEL_FORMAT_RGBA_8888,
p);

View File

@ -16,77 +16,68 @@ typedef enum _TestFlags
TEST_REQUIREMENT_POINT_SPRITE = 1<<4
} TestFlags;
/* For compatability since we used to use the glib gtester
* infrastructure and all our unit tests have an entry
* point with a first argument of this type... */
typedef struct _TestUtilsGTestFixture TestUtilsGTestFixture;
/* Stuff you put in here is setup once in main() and gets passed around to
* all test functions and fixture setup/teardown functions in the data
* argument */
typedef struct _TestUtilsSharedState
{
int *argc_addr;
char ***argv_addr;
CoglContext *ctx;
CoglFramebuffer *fb;
} TestUtilsSharedState;
extern CoglContext *ctx;
extern CoglFramebuffer *fb;
void
test_utils_init (TestUtilsSharedState *state,
TestFlags flags);
test_utils_init (TestFlags flags);
void
test_utils_fini (TestUtilsSharedState *state);
test_utils_fini (void);
/*
* test_utils_check_pixel:
* @framebuffer: The #CoglFramebuffer to read from
* @x: x co-ordinate of the pixel to test
* @y: y co-ordinate of the pixel to test
* @pixel: An integer of the form 0xRRGGBBAA representing the expected
* pixel value
*
* This performs reads a pixel on the current cogl framebuffer and
* This performs reads a pixel on the given cogl @framebuffer and
* asserts that it matches the given color. The alpha channel of the
* color is ignored. The pixels are converted to a string and compared
* with g_assert_cmpstr so that if the comparison fails then the
* assert will display a meaningful message
*/
void
test_utils_check_pixel (int x, int y, guint32 expected_pixel);
test_utils_check_pixel (CoglFramebuffer *framebuffer,
int x, int y, guint32 expected_pixel);
/*
* test_utils_check_pixel:
* @framebuffer: The #CoglFramebuffer to read from
* @x: x co-ordinate of the pixel to test
* @y: y co-ordinate of the pixel to test
* @pixel: An integer of the form 0xrrggbb representing the expected pixel value
*
* This performs reads a pixel on the current cogl framebuffer and
* This performs reads a pixel on the given cogl @framebuffer and
* asserts that it matches the given color. The alpha channel of the
* color is ignored. The pixels are converted to a string and compared
* with g_assert_cmpstr so that if the comparison fails then the
* assert will display a meaningful message
*/
void
test_utils_check_pixel_rgb (int x, int y, int r, int g, int b);
test_utils_check_pixel_rgb (CoglFramebuffer *framebuffer,
int x, int y, int r, int g, int b);
/*
* test_utils_check_region:
* @framebuffer: The #CoglFramebuffer to read from
* @x: x co-ordinate of the region to test
* @y: y co-ordinate of the region to test
* @width: width of the region to test
* @height: height of the region to test
* @pixel: An integer of the form 0xrrggbb representing the expected region color
*
* Performs a read pixel on the specified region of the current cogl
* framebuffer and asserts that it matches the given color. The alpha
* Performs a read pixel on the specified region of the given cogl
* @framebuffer and asserts that it matches the given color. The alpha
* channel of the color is ignored. The pixels are converted to a
* string and compared with g_assert_cmpstr so that if the comparison
* fails then the assert will display a meaningful message
*/
void
test_utils_check_region (int x, int y,
test_utils_check_region (CoglFramebuffer *framebuffer,
int x, int y,
int width, int height,
guint32 expected_rgba);

View File

@ -152,7 +152,7 @@ queue_redraw (gpointer stage)
void
test_cogl_vertex_buffer_contiguous (TestUtilsGTestFixture *fixture,
test_vertex_buffer_contiguous (TestUtilsGTestFixture *fixture,
void *data)
{
TestState state;

View File

@ -83,7 +83,7 @@ queue_redraw (gpointer stage)
}
void
test_cogl_vertex_buffer_interleved (TestUtilsGTestFixture *fixture,
test_vertex_buffer_interleved (TestUtilsGTestFixture *fixture,
void *data)
{
TestState state;

View File

@ -126,7 +126,7 @@ queue_redraw (gpointer stage)
}
void
test_cogl_vertex_buffer_mutability (TestUtilsGTestFixture *fixture,
test_vertex_buffer_mutability (TestUtilsGTestFixture *fixture,
void *data)
{
TestState state;

View File

@ -385,7 +385,7 @@ queue_redraw (gpointer stage)
}
void
test_cogl_viewport (TestUtilsGTestFixture *fixture,
test_viewport (TestUtilsGTestFixture *fixture,
void *data)
{
unsigned int idle_source;

View File

@ -7,7 +7,6 @@
typedef struct _TestState
{
CoglContext *ctx;
int width;
int height;
CoglTexture *texture;
@ -46,7 +45,7 @@ create_pipeline (TestState *state,
{
CoglPipeline *pipeline;
pipeline = cogl_pipeline_new (state->ctx);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_layer_texture (pipeline, 0, state->texture);
cogl_pipeline_set_layer_filters (pipeline, 0,
COGL_PIPELINE_FILTER_NEAREST,
@ -58,7 +57,7 @@ create_pipeline (TestState *state,
}
static CoglPipelineWrapMode
test_wrap_modes[] =
wrap_modes[] =
{
COGL_PIPELINE_WRAP_MODE_REPEAT,
COGL_PIPELINE_WRAP_MODE_REPEAT,
@ -84,22 +83,25 @@ draw_tests (TestState *state)
{
int i;
for (i = 0; i < G_N_ELEMENTS (test_wrap_modes); i += 2)
for (i = 0; i < G_N_ELEMENTS (wrap_modes); i += 2)
{
CoglPipelineWrapMode wrap_mode_s, wrap_mode_t;
CoglPipeline *pipeline;
/* Create a separate pipeline for each pair of wrap modes so
that we can verify whether the batch splitting works */
wrap_mode_s = test_wrap_modes[i];
wrap_mode_t = test_wrap_modes[i + 1];
wrap_mode_s = wrap_modes[i];
wrap_mode_t = wrap_modes[i + 1];
pipeline = create_pipeline (state, wrap_mode_s, wrap_mode_t);
cogl_set_source (pipeline);
cogl_handle_unref (pipeline);
/* Render the pipeline at four times the size of the texture */
cogl_rectangle_with_texture_coords (i * TEX_SIZE, 0,
(i + 2) * TEX_SIZE, TEX_SIZE * 2,
cogl_framebuffer_draw_textured_rectangle (fb,
pipeline,
i * TEX_SIZE,
0,
(i + 2) * TEX_SIZE,
TEX_SIZE * 2,
0, 0, 2, 2);
cogl_object_unref (pipeline);
}
}
@ -116,16 +118,16 @@ draw_tests_polygon (TestState *state)
{
int i;
for (i = 0; i < G_N_ELEMENTS (test_wrap_modes); i += 2)
for (i = 0; i < G_N_ELEMENTS (wrap_modes); i += 2)
{
CoglPipelineWrapMode wrap_mode_s, wrap_mode_t;
CoglPipeline *pipeline;
wrap_mode_s = test_wrap_modes[i];
wrap_mode_t = test_wrap_modes[i + 1];
wrap_mode_s = wrap_modes[i];
wrap_mode_t = wrap_modes[i + 1];
pipeline = create_pipeline (state, wrap_mode_s, wrap_mode_t);
cogl_set_source (pipeline);
cogl_handle_unref (pipeline);
cogl_object_unref (pipeline);
cogl_push_matrix ();
cogl_translate (TEX_SIZE * i, 0.0f, 0.0f);
/* Render the pipeline at four times the size of the texture */
@ -151,16 +153,16 @@ draw_tests_vbo (TestState *state)
&vertices[0].tx);
cogl_vertex_buffer_submit (vbo);
for (i = 0; i < G_N_ELEMENTS (test_wrap_modes); i += 2)
for (i = 0; i < G_N_ELEMENTS (wrap_modes); i += 2)
{
CoglPipelineWrapMode wrap_mode_s, wrap_mode_t;
CoglPipeline *pipeline;
wrap_mode_s = test_wrap_modes[i];
wrap_mode_t = test_wrap_modes[i + 1];
wrap_mode_s = wrap_modes[i];
wrap_mode_t = wrap_modes[i + 1];
pipeline = create_pipeline (state, wrap_mode_s, wrap_mode_t);
cogl_set_source (pipeline);
cogl_handle_unref (pipeline);
cogl_object_unref (pipeline);
cogl_push_matrix ();
cogl_translate (TEX_SIZE * i, 0.0f, 0.0f);
/* Render the pipeline at four times the size of the texture */
@ -177,16 +179,15 @@ validate_set (TestState *state, int offset)
guint8 data[TEX_SIZE * 2 * TEX_SIZE * 2 * 4], *p;
int x, y, i;
for (i = 0; i < G_N_ELEMENTS (test_wrap_modes); i += 2)
for (i = 0; i < G_N_ELEMENTS (wrap_modes); i += 2)
{
CoglPipelineWrapMode wrap_mode_s, wrap_mode_t;
wrap_mode_s = test_wrap_modes[i];
wrap_mode_t = test_wrap_modes[i + 1];
wrap_mode_s = wrap_modes[i];
wrap_mode_t = wrap_modes[i + 1];
cogl_read_pixels (i * TEX_SIZE, offset * TEX_SIZE * 2,
cogl_framebuffer_read_pixels (fb, i * TEX_SIZE, offset * TEX_SIZE * 2,
TEX_SIZE * 2, TEX_SIZE * 2,
COGL_READ_PIXELS_COLOR_BUFFER,
COGL_PIXEL_FORMAT_RGBA_8888,
data);
@ -237,7 +238,7 @@ paint (TestState *state)
/* Draw the tests first with a non atlased texture */
state->texture = create_texture (COGL_TEXTURE_NO_ATLAS);
draw_tests (state);
cogl_handle_unref (state->texture);
cogl_object_unref (state->texture);
/* Draw the tests again with a possible atlased texture. This should
end up testing software repeats */
@ -246,7 +247,7 @@ paint (TestState *state)
cogl_translate (0.0f, TEX_SIZE * 2.0f, 0.0f);
draw_tests (state);
cogl_pop_matrix ();
cogl_handle_unref (state->texture);
cogl_object_unref (state->texture);
/* Draw the tests using cogl_polygon */
state->texture = create_texture (COGL_TEXTURE_NO_ATLAS);
@ -254,7 +255,7 @@ paint (TestState *state)
cogl_translate (0.0f, TEX_SIZE * 4.0f, 0.0f);
draw_tests_polygon (state);
cogl_pop_matrix ();
cogl_handle_unref (state->texture);
cogl_object_unref (state->texture);
/* Draw the tests using a vertex buffer */
state->texture = create_texture (COGL_TEXTURE_NO_ATLAS);
@ -262,27 +263,31 @@ paint (TestState *state)
cogl_translate (0.0f, TEX_SIZE * 6.0f, 0.0f);
draw_tests_vbo (state);
cogl_pop_matrix ();
cogl_handle_unref (state->texture);
cogl_object_unref (state->texture);
validate_result (state);
}
void
test_cogl_wrap_modes (TestUtilsGTestFixture *fixture,
void *data)
test_wrap_modes (void)
{
TestUtilsSharedState *shared_state = data;
TestState state;
state.ctx = shared_state->ctx;
state.width = cogl_framebuffer_get_width (shared_state->fb);
state.height = cogl_framebuffer_get_height (shared_state->fb);
state.width = cogl_framebuffer_get_width (fb);
state.height = cogl_framebuffer_get_height (fb);
cogl_ortho (0, state.width, /* left, right */
state.height, 0, /* bottom, top */
-1, 100 /* z near, far */);
cogl_framebuffer_orthographic (fb,
0, 0,
state.width,
state.height,
-1,
100);
/* XXX: we have to push/pop a framebuffer since this test currently
* uses the legacy cogl_vertex_buffer_draw() api. */
cogl_push_framebuffer (fb);
paint (&state);
cogl_pop_framebuffer ();
if (cogl_test_verbose ())
g_print ("OK\n");

View File

@ -139,12 +139,8 @@ test_write_int (CoglContext *context,
}
void
test_cogl_write_texture_formats (TestUtilsGTestFixture *fixture,
void *data)
test_write_texture_formats (void)
{
TestUtilsSharedState *shared_state = data;
CoglContext *ctx = shared_state->ctx;
test_write_byte (ctx, COGL_PIXEL_FORMAT_A_8, 0x34, 0x00000034);
#if 0
/* I'm not sure what's the right value to put here because Nvidia