2012-03-06 23:14:27 +00:00
|
|
|
#include <cogl/cogl2-experimental.h>
|
|
|
|
|
|
|
|
#include "test-utils.h"
|
|
|
|
|
|
|
|
/* This test assumes the GL driver supports point sizes up to 16
|
|
|
|
pixels. Cogl should probably have some way of querying the size so
|
|
|
|
we start from that instead */
|
|
|
|
#define MAX_POINT_SIZE 16
|
|
|
|
/* The size of the area that we'll paint each point in */
|
|
|
|
#define POINT_BOX_SIZE (MAX_POINT_SIZE * 2)
|
|
|
|
|
|
|
|
static int
|
|
|
|
calc_coord_offset (int pos, int pos_index, int point_size)
|
|
|
|
{
|
|
|
|
switch (pos_index)
|
|
|
|
{
|
|
|
|
case 0: return pos - point_size / 2 - 2;
|
|
|
|
case 1: return pos - point_size / 2 + 2;
|
|
|
|
case 2: return pos + point_size / 2 - 2;
|
|
|
|
case 3: return pos + point_size / 2 + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-18 17:57:06 +00:00
|
|
|
verify_point_size (CoglFramebuffer *test_fb,
|
2012-03-06 23:14:27 +00:00
|
|
|
int x_pos,
|
|
|
|
int y_pos,
|
|
|
|
int point_size)
|
|
|
|
{
|
|
|
|
int y, x;
|
|
|
|
|
|
|
|
for (y = 0; y < 4; y++)
|
|
|
|
for (x = 0; x < 4; x++)
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool in_point = x >= 1 && x <= 2 && y >= 1 && y <= 2;
|
|
|
|
uint32_t expected_pixel = in_point ? 0x00ff00ff : 0xff0000ff;
|
2012-03-06 23:14:27 +00:00
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
test_utils_check_pixel (test_fb,
|
2012-03-16 19:54:13 +00:00
|
|
|
calc_coord_offset (x_pos, x, point_size),
|
2012-03-06 23:14:27 +00:00
|
|
|
calc_coord_offset (y_pos, y, point_size),
|
|
|
|
expected_pixel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-16 19:54:13 +00:00
|
|
|
test_point_size (void)
|
2012-03-06 23:14:27 +00:00
|
|
|
{
|
2013-01-18 17:57:06 +00:00
|
|
|
int fb_width = cogl_framebuffer_get_width (test_fb);
|
|
|
|
int fb_height = cogl_framebuffer_get_height (test_fb);
|
2012-03-06 23:14:27 +00:00
|
|
|
int point_size;
|
|
|
|
int x_pos;
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_orthographic (test_fb,
|
2012-03-06 23:14:27 +00:00
|
|
|
0, 0, /* x_1, y_1 */
|
|
|
|
fb_width, /* x_2 */
|
|
|
|
fb_height /* y_2 */,
|
|
|
|
-1, 100 /* near/far */);
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_clear4f (test_fb,
|
2012-03-06 23:14:27 +00:00
|
|
|
COGL_BUFFER_BIT_COLOR,
|
|
|
|
1.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
/* Try a rendering a single point with a few different point
|
|
|
|
sizes */
|
|
|
|
for (x_pos = 0, point_size = MAX_POINT_SIZE;
|
|
|
|
point_size >= 4;
|
|
|
|
x_pos += POINT_BOX_SIZE, point_size /= 2)
|
|
|
|
{
|
2013-01-18 17:57:06 +00:00
|
|
|
CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
|
2012-03-06 23:14:27 +00:00
|
|
|
CoglVertexP2 point = { x_pos + POINT_BOX_SIZE / 2,
|
|
|
|
POINT_BOX_SIZE / 2 };
|
|
|
|
CoglPrimitive *prim =
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_primitive_new_p2 (test_ctx,
|
2012-03-06 23:14:27 +00:00
|
|
|
COGL_VERTICES_MODE_POINTS,
|
|
|
|
1, /* n_vertices */
|
|
|
|
&point);
|
|
|
|
|
|
|
|
cogl_pipeline_set_point_size (pipeline, point_size);
|
|
|
|
cogl_pipeline_set_color4ub (pipeline, 0, 255, 0, 255);
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_draw_primitive (test_fb,
|
2012-03-06 23:14:27 +00:00
|
|
|
pipeline,
|
|
|
|
prim);
|
|
|
|
|
|
|
|
cogl_object_unref (prim);
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify all of the points where drawn at the right size */
|
|
|
|
for (x_pos = 0, point_size = MAX_POINT_SIZE;
|
|
|
|
point_size >= 4;
|
|
|
|
x_pos += POINT_BOX_SIZE, point_size /= 2)
|
2013-01-18 17:57:06 +00:00
|
|
|
verify_point_size (test_fb,
|
2012-03-06 23:14:27 +00:00
|
|
|
x_pos + POINT_BOX_SIZE / 2,
|
|
|
|
POINT_BOX_SIZE / 2,
|
|
|
|
point_size);
|
|
|
|
|
|
|
|
if (cogl_test_verbose ())
|
|
|
|
g_print ("OK\n");
|
|
|
|
}
|