2009-09-23 10:11:55 -04:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2009-09-23 10:11:55 -04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2009-09-23 10:11:55 -04:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2009-09-23 10:11:55 -04:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-03-01 07:56:10 -05:00
|
|
|
*
|
|
|
|
*
|
2009-09-23 10:11:55 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "math.h"
|
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
#include "cogl-util.h"
|
2009-09-23 10:11:55 -04:00
|
|
|
#include "cogl-spans.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_span_iter_update (CoglSpanIter *iter)
|
|
|
|
{
|
|
|
|
/* Pick current span */
|
2011-10-08 09:13:03 -04:00
|
|
|
iter->span = &iter->spans[iter->index];
|
2009-09-23 10:11:55 -04:00
|
|
|
|
|
|
|
/* Offset next position by span size */
|
2011-10-23 15:20:49 -04:00
|
|
|
iter->next_pos = iter->pos + iter->span->size - iter->span->waste;
|
2009-09-23 10:11:55 -04:00
|
|
|
|
|
|
|
/* Check if span intersects the area to cover */
|
|
|
|
if (iter->next_pos <= iter->cover_start ||
|
|
|
|
iter->pos >= iter->cover_end)
|
|
|
|
{
|
|
|
|
/* Intersection undefined */
|
|
|
|
iter->intersects = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter->intersects = TRUE;
|
|
|
|
|
|
|
|
/* Clip start position to coverage area */
|
|
|
|
if (iter->pos < iter->cover_start)
|
|
|
|
iter->intersect_start = iter->cover_start;
|
|
|
|
else
|
|
|
|
iter->intersect_start = iter->pos;
|
|
|
|
|
|
|
|
/* Clip end position to coverage area */
|
|
|
|
if (iter->next_pos > iter->cover_end)
|
|
|
|
iter->intersect_end = iter->cover_end;
|
|
|
|
else
|
|
|
|
iter->intersect_end = iter->next_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_span_iter_begin (CoglSpanIter *iter,
|
2011-10-08 09:13:03 -04:00
|
|
|
const CoglSpan *spans,
|
|
|
|
int n_spans,
|
|
|
|
float normalize_factor,
|
|
|
|
float cover_start,
|
|
|
|
float cover_end,
|
|
|
|
CoglPipelineWrapMode wrap_mode)
|
2009-09-23 10:11:55 -04:00
|
|
|
{
|
2011-10-08 09:13:03 -04:00
|
|
|
/* XXX: If CLAMP_TO_EDGE needs to be emulated then it needs to be
|
|
|
|
* done at a higher level than here... */
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (wrap_mode == COGL_PIPELINE_WRAP_MODE_REPEAT ||
|
|
|
|
wrap_mode == COGL_PIPELINE_WRAP_MODE_MIRRORED_REPEAT);
|
2011-10-08 09:13:03 -04:00
|
|
|
|
2009-09-23 10:11:55 -04:00
|
|
|
iter->span = NULL;
|
|
|
|
|
2011-10-08 09:13:03 -04:00
|
|
|
iter->spans = spans;
|
|
|
|
iter->n_spans = n_spans;
|
2009-09-23 10:11:55 -04:00
|
|
|
|
|
|
|
/* We always iterate in a positive direction from the origin. If
|
|
|
|
* iter->flipped == TRUE that means whoever is using this API should
|
|
|
|
* interpreted the current span as extending in the opposite direction. I.e.
|
|
|
|
* it extends to the left if iterating the X axis, or up if the Y axis. */
|
|
|
|
if (cover_start > cover_end)
|
|
|
|
{
|
|
|
|
float tmp = cover_start;
|
|
|
|
cover_start = cover_end;
|
|
|
|
cover_end = tmp;
|
|
|
|
iter->flipped = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
iter->flipped = FALSE;
|
|
|
|
|
|
|
|
/* The texture spans cover the normalized texture coordinate space ranging
|
|
|
|
* from [0,1] but to help support repeating of sliced textures we allow
|
|
|
|
* iteration of any range so we need to relate the start of the range to the
|
|
|
|
* nearest point equivalent to 0.
|
|
|
|
*/
|
2011-10-23 15:23:15 -04:00
|
|
|
if (normalize_factor != 1.0)
|
|
|
|
{
|
|
|
|
float cover_start_normalized = cover_start / normalize_factor;
|
|
|
|
iter->origin = floorf (cover_start_normalized) * normalize_factor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
iter->origin = floorf (cover_start);
|
2009-09-23 10:11:55 -04:00
|
|
|
|
2011-10-08 09:13:03 -04:00
|
|
|
iter->wrap_mode = wrap_mode;
|
|
|
|
|
2011-10-13 09:02:37 -04:00
|
|
|
if (wrap_mode == COGL_PIPELINE_WRAP_MODE_REPEAT)
|
|
|
|
iter->index = 0;
|
|
|
|
else if (wrap_mode == COGL_PIPELINE_WRAP_MODE_MIRRORED_REPEAT)
|
|
|
|
{
|
|
|
|
if ((int)iter->origin % 2)
|
|
|
|
{
|
|
|
|
iter->index = iter->n_spans - 1;
|
|
|
|
iter->mirror_direction = -1;
|
|
|
|
iter->flipped = !iter->flipped;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iter->index = 0;
|
|
|
|
iter->mirror_direction = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_warn_if_reached ();
|
|
|
|
|
2009-09-23 10:11:55 -04:00
|
|
|
iter->cover_start = cover_start;
|
|
|
|
iter->cover_end = cover_end;
|
|
|
|
iter->pos = iter->origin;
|
|
|
|
|
|
|
|
/* Update intersection */
|
|
|
|
_cogl_span_iter_update (iter);
|
2011-10-11 05:16:54 -04:00
|
|
|
|
|
|
|
while (iter->next_pos <= iter->cover_start)
|
|
|
|
_cogl_span_iter_next (iter);
|
2009-09-23 10:11:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_span_iter_next (CoglSpanIter *iter)
|
|
|
|
{
|
|
|
|
/* Move current position */
|
|
|
|
iter->pos = iter->next_pos;
|
|
|
|
|
2011-10-13 09:02:37 -04:00
|
|
|
if (iter->wrap_mode == COGL_PIPELINE_WRAP_MODE_REPEAT)
|
|
|
|
iter->index = (iter->index + 1) % iter->n_spans;
|
|
|
|
else if (iter->wrap_mode == COGL_PIPELINE_WRAP_MODE_MIRRORED_REPEAT)
|
|
|
|
{
|
|
|
|
iter->index += iter->mirror_direction;
|
|
|
|
if (iter->index == iter->n_spans || iter->index == -1)
|
|
|
|
{
|
|
|
|
iter->mirror_direction = -iter->mirror_direction;
|
|
|
|
iter->index += iter->mirror_direction;
|
|
|
|
iter->flipped = !iter->flipped;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_warn_if_reached ();
|
2009-09-23 10:11:55 -04:00
|
|
|
|
|
|
|
/* Update intersection */
|
|
|
|
_cogl_span_iter_update (iter);
|
|
|
|
}
|
|
|
|
|
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 16:56:40 -04:00
|
|
|
CoglBool
|
2009-09-23 10:11:55 -04:00
|
|
|
_cogl_span_iter_end (CoglSpanIter *iter)
|
|
|
|
{
|
|
|
|
/* End reached when whole area covered */
|
|
|
|
return iter->pos >= iter->cover_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
|