2009-09-25 09:34:34 -04:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
|
|
|
*
|
2012-08-31 19:04:00 -04:00
|
|
|
* Copyright (C) 2007,2008,2009,2012 Intel Corporation.
|
2009-09-25 09:34:34 -04:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-08-31 19:04:00 -04:00
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
2010-03-01 07:56:10 -05:00
|
|
|
*
|
|
|
|
*
|
2009-09-25 09:34:34 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-02-25 14:23:51 -05:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-07-25 16:36:41 -04:00
|
|
|
#include "cogl-debug.h"
|
2009-09-25 09:34:34 -04:00
|
|
|
#include "cogl-internal.h"
|
2010-11-04 18:25:52 -04:00
|
|
|
#include "cogl-context-private.h"
|
2011-02-25 06:29:08 -05:00
|
|
|
#include "cogl-display-private.h"
|
|
|
|
#include "cogl-renderer-private.h"
|
2010-07-07 09:41:54 -04:00
|
|
|
#include "cogl-object-private.h"
|
2009-09-25 09:34:34 -04:00
|
|
|
#include "cogl-util.h"
|
|
|
|
#include "cogl-texture-private.h"
|
2009-11-26 14:06:35 -05:00
|
|
|
#include "cogl-framebuffer-private.h"
|
2011-08-22 18:55:57 -04:00
|
|
|
#include "cogl-onscreen-template-private.h"
|
2009-09-25 09:34:34 -04:00
|
|
|
#include "cogl-clip-stack.h"
|
2010-02-10 13:18:30 -05:00
|
|
|
#include "cogl-journal-private.h"
|
2010-11-05 08:28:33 -04:00
|
|
|
#include "cogl-winsys-private.h"
|
2011-09-15 06:25:39 -04:00
|
|
|
#include "cogl-pipeline-state-private.h"
|
2011-11-18 07:23:49 -05:00
|
|
|
#include "cogl-matrix-private.h"
|
2012-01-07 21:59:04 -05:00
|
|
|
#include "cogl-primitive-private.h"
|
2012-02-17 16:46:39 -05:00
|
|
|
#include "cogl-offscreen.h"
|
|
|
|
#include "cogl1-context.h"
|
2012-02-25 14:23:51 -05:00
|
|
|
#include "cogl-private.h"
|
2012-03-16 15:54:13 -04:00
|
|
|
#include "cogl-primitives-private.h"
|
2012-04-18 10:57:33 -04:00
|
|
|
#include "cogl-path-private.h"
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2011-02-02 09:23:53 -05:00
|
|
|
typedef struct _CoglFramebufferStackEntry
|
|
|
|
{
|
|
|
|
CoglFramebuffer *draw_buffer;
|
|
|
|
CoglFramebuffer *read_buffer;
|
|
|
|
} CoglFramebufferStackEntry;
|
|
|
|
|
2012-01-24 11:24:26 -05:00
|
|
|
extern CoglObjectClass _cogl_onscreen_class;
|
2011-10-13 16:31:04 -04:00
|
|
|
|
2012-05-17 09:51:43 -04:00
|
|
|
#ifdef COGL_ENABLE_DEBUG
|
2012-02-19 17:50:57 -05:00
|
|
|
static CoglUserDataKey wire_pipeline_key;
|
2012-05-17 09:51:43 -04:00
|
|
|
#endif
|
2012-02-19 17:50:57 -05:00
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
static void _cogl_offscreen_free (CoglOffscreen *offscreen);
|
|
|
|
|
2012-01-24 13:16:03 -05:00
|
|
|
COGL_OBJECT_DEFINE_WITH_CODE (Offscreen, offscreen,
|
|
|
|
_cogl_offscreen_class.virt_unref =
|
|
|
|
_cogl_framebuffer_unref);
|
2010-07-09 12:59:16 -04:00
|
|
|
COGL_OBJECT_DEFINE_DEPRECATED_REF_COUNTING (offscreen);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
|
|
|
/* XXX:
|
2010-07-07 09:41:54 -04:00
|
|
|
* The CoglObject macros don't support any form of inheritance, so for
|
|
|
|
* now we implement the CoglObject support for the CoglFramebuffer
|
2009-09-25 09:34:34 -04:00
|
|
|
* abstract class manually.
|
|
|
|
*/
|
|
|
|
|
2011-08-23 08:55:12 -04:00
|
|
|
GQuark
|
|
|
|
cogl_framebuffer_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string ("cogl-framebuffer-error-quark");
|
|
|
|
}
|
|
|
|
|
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
|
2012-03-06 13:21:28 -05:00
|
|
|
cogl_is_framebuffer (void *object)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2011-10-13 16:31:04 -04:00
|
|
|
CoglObject *obj = object;
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2010-07-07 09:41:54 -04:00
|
|
|
if (obj == NULL)
|
2009-09-25 09:34:34 -04:00
|
|
|
return FALSE;
|
|
|
|
|
2012-01-24 11:24:26 -05:00
|
|
|
return (obj->klass == &_cogl_onscreen_class ||
|
|
|
|
obj->klass == &_cogl_offscreen_class);
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
2011-10-13 16:31:04 -04:00
|
|
|
void
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_init (CoglFramebuffer *framebuffer,
|
2011-02-22 12:58:47 -05:00
|
|
|
CoglContext *ctx,
|
2009-11-26 14:06:35 -05:00
|
|
|
CoglFramebufferType type,
|
2010-11-17 12:57:17 -05:00
|
|
|
CoglPixelFormat format,
|
2009-09-25 09:34:34 -04:00
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
2012-09-10 06:26:17 -04:00
|
|
|
framebuffer->context = ctx;
|
|
|
|
|
|
|
|
framebuffer->type = type;
|
|
|
|
framebuffer->width = width;
|
|
|
|
framebuffer->height = height;
|
|
|
|
framebuffer->format = format;
|
|
|
|
framebuffer->viewport_x = 0;
|
|
|
|
framebuffer->viewport_y = 0;
|
|
|
|
framebuffer->viewport_width = width;
|
|
|
|
framebuffer->viewport_height = height;
|
|
|
|
framebuffer->dither_enabled = TRUE;
|
|
|
|
|
|
|
|
framebuffer->modelview_stack = _cogl_matrix_stack_new ();
|
2009-11-26 14:06:35 -05:00
|
|
|
framebuffer->projection_stack = _cogl_matrix_stack_new ();
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2012-09-10 06:26:17 -04:00
|
|
|
framebuffer->dirty_bitmasks = TRUE;
|
2010-04-26 13:08:45 -04:00
|
|
|
|
2012-09-10 06:26:17 -04:00
|
|
|
framebuffer->color_mask = COGL_COLOR_MASK_ALL;
|
2011-07-10 21:27:54 -04:00
|
|
|
|
2011-10-08 10:47:42 -04:00
|
|
|
framebuffer->samples_per_pixel = 0;
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
/* Initialise the clip stack */
|
2010-04-14 14:41:08 -04:00
|
|
|
_cogl_clip_state_init (&framebuffer->clip_state);
|
2011-01-06 08:25:45 -05:00
|
|
|
|
2012-03-16 13:26:30 -04:00
|
|
|
framebuffer->journal = _cogl_journal_new (framebuffer);
|
2011-01-06 08:25:45 -05:00
|
|
|
|
2011-01-12 17:12:41 -05:00
|
|
|
/* Ensure we know the framebuffer->clear_color* members can't be
|
|
|
|
* referenced for our fast-path read-pixel optimization (see
|
|
|
|
* _cogl_journal_try_read_pixel()) until some region of the
|
|
|
|
* framebuffer is initialized.
|
|
|
|
*/
|
|
|
|
framebuffer->clear_clip_dirty = TRUE;
|
|
|
|
|
2011-01-06 08:25:45 -05:00
|
|
|
/* XXX: We have to maintain a central list of all framebuffers
|
|
|
|
* because at times we need to be able to flush all known journals.
|
|
|
|
*
|
|
|
|
* Examples where we need to flush all journals are:
|
|
|
|
* - because journal entries can reference OpenGL texture
|
|
|
|
* coordinates that may not survive texture-atlas reorganization
|
|
|
|
* so we need the ability to flush those entries.
|
|
|
|
* - because although we generally advise against modifying
|
|
|
|
* pipelines after construction we have to handle that possibility
|
|
|
|
* and since pipelines may be referenced in journal entries we
|
|
|
|
* need to be able to flush them before allowing the pipelines to
|
|
|
|
* be changed.
|
|
|
|
*
|
|
|
|
* Note we don't maintain a list of journals and associate
|
|
|
|
* framebuffers with journals by e.g. having a journal->framebuffer
|
|
|
|
* reference since that would introduce a circular reference.
|
|
|
|
*
|
|
|
|
* Note: As a future change to try and remove the need to index all
|
|
|
|
* journals it might be possible to defer resolving of OpenGL
|
|
|
|
* texture coordinates for rectangle primitives until we come to
|
|
|
|
* flush a journal. This would mean for instance that a single
|
|
|
|
* rectangle entry in a journal could later be expanded into
|
|
|
|
* multiple quad primitives to handle sliced textures but would mean
|
|
|
|
* we don't have to worry about retaining references to OpenGL
|
|
|
|
* texture coordinates that may later become invalid.
|
|
|
|
*/
|
|
|
|
ctx->framebuffers = g_list_prepend (ctx->framebuffers, framebuffer);
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_free (CoglFramebuffer *framebuffer)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2011-02-22 12:58:47 -05:00
|
|
|
CoglContext *ctx = framebuffer->context;
|
2011-01-06 08:25:45 -05:00
|
|
|
|
2010-04-14 14:41:08 -04:00
|
|
|
_cogl_clip_state_destroy (&framebuffer->clip_state);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2010-12-10 11:06:16 -05:00
|
|
|
cogl_object_unref (framebuffer->modelview_stack);
|
2009-11-26 14:06:35 -05:00
|
|
|
framebuffer->modelview_stack = NULL;
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2010-12-10 11:06:16 -05:00
|
|
|
cogl_object_unref (framebuffer->projection_stack);
|
2009-11-26 14:06:35 -05:00
|
|
|
framebuffer->projection_stack = NULL;
|
2011-01-06 08:25:45 -05:00
|
|
|
|
|
|
|
cogl_object_unref (framebuffer->journal);
|
2011-02-22 12:58:47 -05:00
|
|
|
|
|
|
|
ctx->framebuffers = g_list_remove (ctx->framebuffers, framebuffer);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (ctx->current_draw_buffer == framebuffer)
|
|
|
|
ctx->current_draw_buffer = NULL;
|
|
|
|
if (ctx->current_read_buffer == framebuffer)
|
|
|
|
ctx->current_read_buffer = NULL;
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
2011-10-13 16:31:04 -04:00
|
|
|
const CoglWinsysVtable *
|
2011-02-25 06:29:08 -05:00
|
|
|
_cogl_framebuffer_get_winsys (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
return framebuffer->context->display->renderer->winsys_vtable;
|
|
|
|
}
|
|
|
|
|
2011-01-05 10:30:04 -05:00
|
|
|
/* This version of cogl_clear can be used internally as an alternative
|
|
|
|
* to avoid flushing the journal or the framebuffer state. This is
|
|
|
|
* needed when doing operations that may be called whiling flushing
|
|
|
|
* the journal */
|
|
|
|
void
|
2011-08-03 12:06:10 -04:00
|
|
|
_cogl_framebuffer_clear_without_flush4f (CoglFramebuffer *framebuffer,
|
|
|
|
unsigned long buffers,
|
|
|
|
float red,
|
|
|
|
float green,
|
|
|
|
float blue,
|
|
|
|
float alpha)
|
2011-01-05 10:30:04 -05:00
|
|
|
{
|
2012-08-31 19:04:00 -04:00
|
|
|
CoglContext *ctx = framebuffer->context;
|
2011-01-05 10:30:04 -05:00
|
|
|
|
2012-08-31 19:04:00 -04:00
|
|
|
if (!buffers)
|
2011-01-05 10:30:04 -05:00
|
|
|
{
|
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
|
|
|
static CoglBool shown = FALSE;
|
2011-01-05 10:30:04 -05:00
|
|
|
|
|
|
|
if (!shown)
|
|
|
|
{
|
|
|
|
g_warning ("You should specify at least one auxiliary buffer "
|
2012-08-31 19:04:00 -04:00
|
|
|
"when calling cogl_framebuffer_clear");
|
2011-01-05 10:30:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-31 19:04:00 -04:00
|
|
|
ctx->driver_vtable->framebuffer_clear (framebuffer,
|
|
|
|
buffers,
|
|
|
|
red, green, blue, alpha);
|
2011-01-05 10:30:04 -05:00
|
|
|
}
|
|
|
|
|
2011-01-12 17:12:41 -05:00
|
|
|
void
|
|
|
|
_cogl_framebuffer_dirty (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
framebuffer->clear_clip_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
2011-01-05 10:30:04 -05:00
|
|
|
void
|
2011-08-02 11:27:59 -04:00
|
|
|
cogl_framebuffer_clear4f (CoglFramebuffer *framebuffer,
|
|
|
|
unsigned long buffers,
|
|
|
|
float red,
|
|
|
|
float green,
|
|
|
|
float blue,
|
|
|
|
float alpha)
|
2011-01-05 10:30:04 -05:00
|
|
|
{
|
2011-01-12 17:12:41 -05:00
|
|
|
CoglClipStack *clip_stack = _cogl_framebuffer_get_clip_stack (framebuffer);
|
|
|
|
int scissor_x0;
|
|
|
|
int scissor_y0;
|
|
|
|
int scissor_x1;
|
|
|
|
int scissor_y1;
|
|
|
|
|
|
|
|
_cogl_clip_stack_get_bounds (clip_stack,
|
|
|
|
&scissor_x0, &scissor_y0,
|
|
|
|
&scissor_x1, &scissor_y1);
|
|
|
|
|
|
|
|
/* NB: the previous clear could have had an arbitrary clip.
|
|
|
|
* NB: everything for the last frame might still be in the journal
|
|
|
|
* but we can't assume anything about how each entry was
|
|
|
|
* clipped.
|
|
|
|
* NB: Clutter will scissor its pick renders which would mean all
|
|
|
|
* journal entries have a common ClipStack entry, but without
|
|
|
|
* a layering violation Cogl has to explicitly walk the journal
|
|
|
|
* entries to determine if this is the case.
|
|
|
|
* NB: We have a software only read-pixel optimization in the
|
|
|
|
* journal that determines the color at a given framebuffer
|
|
|
|
* coordinate for simple scenes without rendering with the GPU.
|
|
|
|
* When Clutter is hitting this fast-path we can expect to
|
|
|
|
* receive calls to clear the framebuffer with an un-flushed
|
|
|
|
* journal.
|
|
|
|
* NB: To fully support software based picking for Clutter we
|
|
|
|
* need to be able to reliably detect when the contents of a
|
|
|
|
* journal can be discarded and when we can skip the call to
|
|
|
|
* glClear because it matches the previous clear request.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Note: we don't check for the stencil buffer being cleared here
|
|
|
|
* since there isn't any public cogl api to manipulate the stencil
|
|
|
|
* buffer.
|
|
|
|
*
|
|
|
|
* Note: we check for an exact clip match here because
|
|
|
|
* 1) a smaller clip could mean existing journal entries may
|
|
|
|
* need to contribute to regions outside the new clear-clip
|
|
|
|
* 2) a larger clip would mean we need to issue a real
|
|
|
|
* glClear and we only care about cases avoiding a
|
|
|
|
* glClear.
|
|
|
|
*
|
|
|
|
* Note: Comparing without an epsilon is considered
|
|
|
|
* appropriate here.
|
|
|
|
*/
|
|
|
|
if (buffers & COGL_BUFFER_BIT_COLOR &&
|
|
|
|
buffers & COGL_BUFFER_BIT_DEPTH &&
|
|
|
|
!framebuffer->clear_clip_dirty &&
|
|
|
|
framebuffer->clear_color_red == red &&
|
|
|
|
framebuffer->clear_color_green == green &&
|
|
|
|
framebuffer->clear_color_blue == blue &&
|
|
|
|
framebuffer->clear_color_alpha == alpha &&
|
|
|
|
scissor_x0 == framebuffer->clear_clip_x0 &&
|
|
|
|
scissor_y0 == framebuffer->clear_clip_y0 &&
|
|
|
|
scissor_x1 == framebuffer->clear_clip_x1 &&
|
|
|
|
scissor_y1 == framebuffer->clear_clip_y1)
|
|
|
|
{
|
|
|
|
/* NB: We only have to consider the clip state of journal
|
|
|
|
* entries if the current clear is clipped since otherwise we
|
|
|
|
* know every pixel of the framebuffer is affected by the clear
|
|
|
|
* and so all journal entries become redundant and can simply be
|
|
|
|
* discarded.
|
|
|
|
*/
|
|
|
|
if (clip_stack)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Note: the function for checking the journal entries is
|
|
|
|
* quite strict. It avoids detailed checking of all entry
|
|
|
|
* clip_stacks by only checking the details of the first
|
|
|
|
* entry and then it only verifies that the remaining
|
|
|
|
* entries share the same clip_stack ancestry. This means
|
|
|
|
* it's possible for some false negatives here but that will
|
|
|
|
* just result in us falling back to a real clear.
|
|
|
|
*/
|
|
|
|
if (_cogl_journal_all_entries_within_bounds (framebuffer->journal,
|
|
|
|
scissor_x0, scissor_y0,
|
|
|
|
scissor_x1, scissor_y1))
|
|
|
|
{
|
|
|
|
_cogl_journal_discard (framebuffer->journal);
|
|
|
|
goto cleared;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_cogl_journal_discard (framebuffer->journal);
|
|
|
|
goto cleared;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-05 10:30:04 -05:00
|
|
|
COGL_NOTE (DRAW, "Clear begin");
|
|
|
|
|
2011-01-06 08:25:45 -05:00
|
|
|
_cogl_framebuffer_flush_journal (framebuffer);
|
2011-01-05 10:30:04 -05:00
|
|
|
|
|
|
|
/* NB: _cogl_framebuffer_flush_state may disrupt various state (such
|
|
|
|
* as the pipeline state) when flushing the clip stack, so should
|
|
|
|
* always be done first when preparing to draw. */
|
2011-11-21 10:53:40 -05:00
|
|
|
_cogl_framebuffer_flush_state (framebuffer, framebuffer,
|
|
|
|
COGL_FRAMEBUFFER_STATE_ALL);
|
2011-01-05 10:30:04 -05:00
|
|
|
|
2011-08-03 12:06:10 -04:00
|
|
|
_cogl_framebuffer_clear_without_flush4f (framebuffer, buffers,
|
|
|
|
red, green, blue, alpha);
|
2011-01-05 10:30:04 -05:00
|
|
|
|
|
|
|
/* This is a debugging variable used to visually display the quad
|
|
|
|
* batches from the journal. It is reset here to increase the
|
|
|
|
* chances of getting the same colours for each frame during an
|
|
|
|
* animation */
|
2011-01-24 09:28:00 -05:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_RECTANGLES)) &&
|
2011-01-05 10:30:04 -05:00
|
|
|
buffers & COGL_BUFFER_BIT_COLOR)
|
|
|
|
{
|
2011-02-22 12:58:47 -05:00
|
|
|
framebuffer->context->journal_rectangles_color = 1;
|
2011-01-05 10:30:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
COGL_NOTE (DRAW, "Clear end");
|
2011-01-12 17:12:41 -05:00
|
|
|
|
|
|
|
cleared:
|
|
|
|
|
|
|
|
if (buffers & COGL_BUFFER_BIT_COLOR && buffers & COGL_BUFFER_BIT_DEPTH)
|
|
|
|
{
|
|
|
|
/* For our fast-path for reading back a single pixel of simple
|
|
|
|
* scenes where the whole frame is in the journal we need to
|
|
|
|
* track the cleared color of the framebuffer in case the point
|
|
|
|
* read doesn't intersect any of the journal rectangles. */
|
|
|
|
framebuffer->clear_clip_dirty = FALSE;
|
|
|
|
framebuffer->clear_color_red = red;
|
|
|
|
framebuffer->clear_color_green = green;
|
|
|
|
framebuffer->clear_color_blue = blue;
|
|
|
|
framebuffer->clear_color_alpha = alpha;
|
|
|
|
|
|
|
|
/* NB: A clear may be scissored so we need to track the extents
|
|
|
|
* that the clear is applicable too... */
|
|
|
|
if (clip_stack)
|
|
|
|
{
|
|
|
|
_cogl_clip_stack_get_bounds (clip_stack,
|
|
|
|
&framebuffer->clear_clip_x0,
|
|
|
|
&framebuffer->clear_clip_y0,
|
|
|
|
&framebuffer->clear_clip_x1,
|
|
|
|
&framebuffer->clear_clip_y1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FIXME: set degenerate clip */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_cogl_framebuffer_dirty (framebuffer);
|
2011-01-05 10:30:04 -05:00
|
|
|
}
|
|
|
|
|
2011-08-02 11:27:59 -04:00
|
|
|
/* Note: the 'buffers' and 'color' arguments were switched around on
|
2011-01-05 10:30:04 -05:00
|
|
|
* purpose compared to the original cogl_clear API since it was odd
|
|
|
|
* that you would be expected to specify a color before even
|
|
|
|
* necessarily choosing to clear the color buffer.
|
|
|
|
*/
|
|
|
|
void
|
2011-08-02 11:27:59 -04:00
|
|
|
cogl_framebuffer_clear (CoglFramebuffer *framebuffer,
|
|
|
|
unsigned long buffers,
|
|
|
|
const CoglColor *color)
|
2011-01-05 10:30:04 -05:00
|
|
|
{
|
2011-08-02 11:27:59 -04:00
|
|
|
cogl_framebuffer_clear4f (framebuffer, buffers,
|
|
|
|
cogl_color_get_red_float (color),
|
|
|
|
cogl_color_get_green_float (color),
|
|
|
|
cogl_color_get_blue_float (color),
|
|
|
|
cogl_color_get_alpha_float (color));
|
2011-01-05 10:30:04 -05:00
|
|
|
}
|
|
|
|
|
2009-10-21 18:20:44 -04:00
|
|
|
int
|
2011-03-01 18:12:18 -05:00
|
|
|
cogl_framebuffer_get_width (CoglFramebuffer *framebuffer)
|
2009-10-21 18:20:44 -04:00
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
return framebuffer->width;
|
2009-10-21 18:20:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-03-01 18:12:18 -05:00
|
|
|
cogl_framebuffer_get_height (CoglFramebuffer *framebuffer)
|
2009-10-21 18:20:44 -04:00
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
return framebuffer->height;
|
2009-10-21 18:20:44 -04:00
|
|
|
}
|
|
|
|
|
2010-04-14 14:41:08 -04:00
|
|
|
CoglClipState *
|
2010-07-07 09:41:54 -04:00
|
|
|
_cogl_framebuffer_get_clip_state (CoglFramebuffer *framebuffer)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
return &framebuffer->clip_state;
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
2011-01-12 14:30:30 -05:00
|
|
|
CoglClipStack *
|
|
|
|
_cogl_framebuffer_get_clip_stack (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
CoglClipState *clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
|
|
|
|
|
|
|
return _cogl_clip_state_get_stack (clip_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_framebuffer_set_clip_stack (CoglFramebuffer *framebuffer,
|
|
|
|
CoglClipStack *stack)
|
|
|
|
{
|
|
|
|
CoglClipState *clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
|
|
|
|
|
|
|
_cogl_clip_state_set_stack (clip_state, stack);
|
|
|
|
}
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
void
|
2011-06-14 19:06:29 -04:00
|
|
|
cogl_framebuffer_set_viewport (CoglFramebuffer *framebuffer,
|
|
|
|
float x,
|
|
|
|
float y,
|
|
|
|
float width,
|
|
|
|
float height)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (width > 0 && height > 0);
|
2011-05-27 07:21:26 -04:00
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
if (framebuffer->viewport_x == x &&
|
|
|
|
framebuffer->viewport_y == y &&
|
|
|
|
framebuffer->viewport_width == width &&
|
|
|
|
framebuffer->viewport_height == height)
|
2009-09-25 09:34:34 -04:00
|
|
|
return;
|
|
|
|
|
2011-01-06 08:25:45 -05:00
|
|
|
_cogl_framebuffer_flush_journal (framebuffer);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
framebuffer->viewport_x = x;
|
|
|
|
framebuffer->viewport_y = y;
|
|
|
|
framebuffer->viewport_width = width;
|
|
|
|
framebuffer->viewport_height = height;
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2011-11-21 10:53:40 -05:00
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_VIEWPORT;
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
2011-02-01 11:51:58 -05:00
|
|
|
float
|
2011-06-14 19:06:29 -04:00
|
|
|
cogl_framebuffer_get_viewport_x (CoglFramebuffer *framebuffer)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
return framebuffer->viewport_x;
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
2011-02-01 11:51:58 -05:00
|
|
|
float
|
2011-06-14 19:06:29 -04:00
|
|
|
cogl_framebuffer_get_viewport_y (CoglFramebuffer *framebuffer)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
return framebuffer->viewport_y;
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
2011-02-01 11:51:58 -05:00
|
|
|
float
|
2011-06-14 19:06:29 -04:00
|
|
|
cogl_framebuffer_get_viewport_width (CoglFramebuffer *framebuffer)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
return framebuffer->viewport_width;
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
2011-02-01 11:51:58 -05:00
|
|
|
float
|
2011-06-14 19:06:29 -04:00
|
|
|
cogl_framebuffer_get_viewport_height (CoglFramebuffer *framebuffer)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
return framebuffer->viewport_height;
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-14 19:06:29 -04:00
|
|
|
cogl_framebuffer_get_viewport4fv (CoglFramebuffer *framebuffer,
|
|
|
|
float *viewport)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
viewport[0] = framebuffer->viewport_x;
|
|
|
|
viewport[1] = framebuffer->viewport_y;
|
|
|
|
viewport[2] = framebuffer->viewport_width;
|
|
|
|
viewport[3] = framebuffer->viewport_height;
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglMatrixStack *
|
2010-07-07 09:41:54 -04:00
|
|
|
_cogl_framebuffer_get_modelview_stack (CoglFramebuffer *framebuffer)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
return framebuffer->modelview_stack;
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglMatrixStack *
|
2010-07-07 09:41:54 -04:00
|
|
|
_cogl_framebuffer_get_projection_stack (CoglFramebuffer *framebuffer)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
return framebuffer->projection_stack;
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
2011-01-06 08:25:45 -05:00
|
|
|
void
|
|
|
|
_cogl_framebuffer_add_dependency (CoglFramebuffer *framebuffer,
|
|
|
|
CoglFramebuffer *dependency)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = framebuffer->deps; l; l = l->next)
|
|
|
|
{
|
|
|
|
CoglFramebuffer *existing_dep = l->data;
|
|
|
|
if (existing_dep == dependency)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: generalize the primed-array type structure we e.g. use for
|
|
|
|
* cogl_object_set_user_data or for pipeline children as a way to
|
|
|
|
* avoid quite a lot of mid-scene micro allocations here... */
|
|
|
|
framebuffer->deps =
|
|
|
|
g_list_prepend (framebuffer->deps, cogl_object_ref (dependency));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_framebuffer_remove_all_dependencies (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
for (l = framebuffer->deps; l; l = l->next)
|
|
|
|
cogl_object_unref (l->data);
|
|
|
|
g_list_free (framebuffer->deps);
|
|
|
|
framebuffer->deps = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_framebuffer_flush_journal (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
2012-03-16 13:26:30 -04:00
|
|
|
_cogl_journal_flush (framebuffer->journal);
|
2011-01-06 08:25:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_framebuffer_flush_dependency_journals (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
for (l = framebuffer->deps; l; l = l->next)
|
|
|
|
_cogl_framebuffer_flush_journal (l->data);
|
2011-02-09 14:31:42 -05:00
|
|
|
_cogl_framebuffer_remove_all_dependencies (framebuffer);
|
2011-01-06 08:25:45 -05:00
|
|
|
}
|
|
|
|
|
2012-02-18 10:22:15 -05:00
|
|
|
CoglOffscreen *
|
2011-08-24 16:30:34 -04:00
|
|
|
_cogl_offscreen_new_to_texture_full (CoglTexture *texture,
|
2010-11-11 10:28:44 -05:00
|
|
|
CoglOffscreenFlags create_flags,
|
|
|
|
unsigned int level)
|
2009-11-30 15:04:41 -05:00
|
|
|
{
|
2011-08-23 08:55:12 -04:00
|
|
|
CoglOffscreen *offscreen;
|
|
|
|
CoglFramebuffer *fb;
|
|
|
|
int level_width;
|
|
|
|
int level_height;
|
|
|
|
int i;
|
2012-04-16 09:14:10 -04:00
|
|
|
CoglOffscreen *ret;
|
2009-11-30 15:04:41 -05:00
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NULL);
|
2011-07-07 15:44:56 -04:00
|
|
|
|
2011-10-12 17:31:12 -04:00
|
|
|
if (!cogl_has_feature (ctx, COGL_FEATURE_ID_OFFSCREEN))
|
2012-04-16 09:14:10 -04:00
|
|
|
return NULL;
|
2009-11-30 15:04:41 -05:00
|
|
|
|
2011-08-24 16:30:34 -04:00
|
|
|
/* Make texture is a valid texture object */
|
|
|
|
if (!cogl_is_texture (texture))
|
2012-04-16 09:14:10 -04:00
|
|
|
return NULL;
|
2009-11-30 15:04:41 -05:00
|
|
|
|
|
|
|
/* The texture must not be sliced */
|
2011-08-24 16:30:34 -04:00
|
|
|
if (cogl_texture_is_sliced (texture))
|
2012-04-16 09:14:10 -04:00
|
|
|
return NULL;
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2010-11-11 10:28:44 -05:00
|
|
|
/* Calculate the size of the texture at this mipmap level to ensure
|
|
|
|
that it's a valid level */
|
2011-08-23 08:55:12 -04:00
|
|
|
level_width = cogl_texture_get_width (texture);
|
|
|
|
level_height = cogl_texture_get_height (texture);
|
2010-11-11 10:28:44 -05:00
|
|
|
|
|
|
|
for (i = 0; i < level; i++)
|
|
|
|
{
|
|
|
|
/* If neither dimension can be further divided then the level is
|
|
|
|
invalid */
|
2011-08-23 08:55:12 -04:00
|
|
|
if (level_width == 1 && level_height == 1)
|
2010-11-11 10:28:44 -05:00
|
|
|
{
|
2011-08-23 08:55:12 -04:00
|
|
|
g_warning ("Invalid texture level passed to "
|
|
|
|
"_cogl_offscreen_new_to_texture_full");
|
2012-04-16 09:14:10 -04:00
|
|
|
return NULL;
|
2010-11-11 10:28:44 -05:00
|
|
|
}
|
2010-01-12 16:44:40 -05:00
|
|
|
|
2011-08-23 08:55:12 -04:00
|
|
|
if (level_width > 1)
|
|
|
|
level_width >>= 1;
|
|
|
|
if (level_height > 1)
|
|
|
|
level_height >>= 1;
|
|
|
|
}
|
2010-11-05 08:28:33 -04:00
|
|
|
|
2011-08-23 08:55:12 -04:00
|
|
|
offscreen = g_new0 (CoglOffscreen, 1);
|
|
|
|
offscreen->texture = cogl_object_ref (texture);
|
|
|
|
offscreen->texture_level = level;
|
|
|
|
offscreen->texture_level_width = level_width;
|
|
|
|
offscreen->texture_level_height = level_height;
|
|
|
|
offscreen->create_flags = create_flags;
|
2010-01-12 16:44:40 -05:00
|
|
|
|
2011-08-23 08:55:12 -04:00
|
|
|
fb = COGL_FRAMEBUFFER (offscreen);
|
2011-04-04 09:42:36 -04:00
|
|
|
|
2011-08-23 08:55:12 -04:00
|
|
|
_cogl_framebuffer_init (fb,
|
|
|
|
ctx,
|
|
|
|
COGL_FRAMEBUFFER_TYPE_OFFSCREEN,
|
|
|
|
cogl_texture_get_format (texture),
|
|
|
|
level_width,
|
|
|
|
level_height);
|
2011-04-04 09:42:36 -04:00
|
|
|
|
2011-08-23 08:55:12 -04:00
|
|
|
ret = _cogl_offscreen_object_new (offscreen);
|
2010-11-05 08:28:33 -04:00
|
|
|
|
2011-08-23 08:55:12 -04:00
|
|
|
_cogl_texture_associate_framebuffer (texture, fb);
|
2011-04-04 09:42:36 -04:00
|
|
|
|
2011-08-23 08:55:12 -04:00
|
|
|
return ret;
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
2012-02-18 10:22:15 -05:00
|
|
|
CoglOffscreen *
|
2011-08-24 16:30:34 -04:00
|
|
|
cogl_offscreen_new_to_texture (CoglTexture *texture)
|
2010-11-11 10:28:44 -05:00
|
|
|
{
|
2011-08-24 16:30:34 -04:00
|
|
|
return _cogl_offscreen_new_to_texture_full (texture, 0, 0);
|
2010-11-11 10:28:44 -05:00
|
|
|
}
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
static void
|
|
|
|
_cogl_offscreen_free (CoglOffscreen *offscreen)
|
|
|
|
{
|
2011-02-22 12:58:47 -05:00
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (offscreen);
|
|
|
|
CoglContext *ctx = framebuffer->context;
|
2009-11-30 15:04:41 -05:00
|
|
|
|
2012-08-31 19:04:00 -04:00
|
|
|
ctx->driver_vtable->offscreen_free (offscreen);
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
/* Chain up to parent */
|
2011-02-22 12:58:47 -05:00
|
|
|
_cogl_framebuffer_free (framebuffer);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
if (offscreen->texture != NULL)
|
2011-08-24 16:30:34 -04:00
|
|
|
cogl_object_unref (offscreen->texture);
|
2009-11-30 15:04:41 -05:00
|
|
|
|
2012-05-23 13:19:29 -04:00
|
|
|
if (offscreen->depth_texture != NULL)
|
|
|
|
cogl_object_unref (offscreen->depth_texture);
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
g_free (offscreen);
|
|
|
|
}
|
|
|
|
|
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
|
2010-11-05 08:28:33 -04:00
|
|
|
cogl_framebuffer_allocate (CoglFramebuffer *framebuffer,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer);
|
2011-02-25 06:29:08 -05:00
|
|
|
const CoglWinsysVtable *winsys = _cogl_framebuffer_get_winsys (framebuffer);
|
2010-11-05 08:28:33 -04:00
|
|
|
|
|
|
|
if (framebuffer->allocated)
|
|
|
|
return TRUE;
|
|
|
|
|
2011-08-23 08:55:12 -04:00
|
|
|
if (framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN)
|
|
|
|
{
|
2012-05-23 13:19:29 -04:00
|
|
|
if (framebuffer->config.depth_texture_enabled)
|
|
|
|
{
|
|
|
|
g_set_error (error, COGL_FRAMEBUFFER_ERROR,
|
|
|
|
COGL_FRAMEBUFFER_ERROR_ALLOCATE,
|
|
|
|
"Can't allocate onscreen framebuffer with a "
|
|
|
|
"texture based depth buffer");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-08-23 08:55:12 -04:00
|
|
|
if (!winsys->onscreen_init (onscreen, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-31 19:04:00 -04:00
|
|
|
CoglContext *ctx = framebuffer->context;
|
|
|
|
if (!ctx->driver_vtable->offscreen_allocate (COGL_OFFSCREEN (framebuffer), error))
|
2011-08-23 08:55:12 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-11-05 08:28:33 -04:00
|
|
|
|
|
|
|
framebuffer->allocated = TRUE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-02-02 09:23:53 -05:00
|
|
|
static CoglFramebufferStackEntry *
|
|
|
|
create_stack_entry (CoglFramebuffer *draw_buffer,
|
|
|
|
CoglFramebuffer *read_buffer)
|
|
|
|
{
|
|
|
|
CoglFramebufferStackEntry *entry = g_slice_new (CoglFramebufferStackEntry);
|
|
|
|
|
|
|
|
entry->draw_buffer = draw_buffer;
|
|
|
|
entry->read_buffer = read_buffer;
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
GSList *
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_create_framebuffer_stack (void)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2011-02-02 09:23:53 -05:00
|
|
|
CoglFramebufferStackEntry *entry;
|
2009-09-25 09:34:34 -04:00
|
|
|
GSList *stack = NULL;
|
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
entry = create_stack_entry (NULL, NULL);
|
2011-02-02 09:23:53 -05:00
|
|
|
|
|
|
|
return g_slist_prepend (stack, entry);
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_free_framebuffer_stack (GSList *stack)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
for (l = stack; l != NULL; l = l->next)
|
|
|
|
{
|
2011-02-02 09:23:53 -05:00
|
|
|
CoglFramebufferStackEntry *entry = l->data;
|
|
|
|
|
2011-05-11 09:11:31 -04:00
|
|
|
if (entry->draw_buffer)
|
2011-10-13 16:31:04 -04:00
|
|
|
cogl_object_unref (entry->draw_buffer);
|
2011-02-02 09:23:53 -05:00
|
|
|
|
2011-05-11 09:11:31 -04:00
|
|
|
if (entry->read_buffer)
|
2011-10-13 16:31:04 -04:00
|
|
|
cogl_object_unref (entry->draw_buffer);
|
2011-02-02 09:23:53 -05:00
|
|
|
|
|
|
|
g_slice_free (CoglFramebufferStackEntry, entry);
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
g_slist_free (stack);
|
|
|
|
}
|
|
|
|
|
2011-09-16 06:41:21 -04:00
|
|
|
static void
|
|
|
|
notify_buffers_changed (CoglFramebuffer *old_draw_buffer,
|
|
|
|
CoglFramebuffer *new_draw_buffer,
|
|
|
|
CoglFramebuffer *old_read_buffer,
|
|
|
|
CoglFramebuffer *new_read_buffer)
|
|
|
|
{
|
2011-11-14 10:09:13 -05:00
|
|
|
/* XXX: To support the deprecated cogl_set_draw_buffer API we keep
|
|
|
|
* track of the last onscreen framebuffer that was set so that it
|
|
|
|
* can be restored if the COGL_WINDOW_BUFFER enum is used. A
|
|
|
|
* reference isn't taken to the framebuffer because otherwise we
|
|
|
|
* would have a circular reference between the context and the
|
|
|
|
* framebuffer. Instead the pointer is set to NULL in
|
|
|
|
* _cogl_onscreen_free as a kind of a cheap weak reference */
|
2011-09-16 06:41:21 -04:00
|
|
|
if (new_draw_buffer &&
|
|
|
|
new_draw_buffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN)
|
2011-11-21 15:48:23 -05:00
|
|
|
new_draw_buffer->context->window_buffer = new_draw_buffer;
|
2011-09-16 06:41:21 -04:00
|
|
|
}
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
/* Set the current framebuffer without checking if it's already the
|
|
|
|
* current framebuffer. This is used by cogl_pop_framebuffer while
|
|
|
|
* the top of the stack is currently not up to date. */
|
|
|
|
static void
|
2011-02-02 09:23:53 -05:00
|
|
|
_cogl_set_framebuffers_real (CoglFramebuffer *draw_buffer,
|
|
|
|
CoglFramebuffer *read_buffer)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2011-02-02 09:23:53 -05:00
|
|
|
CoglFramebufferStackEntry *entry;
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2010-11-05 08:28:33 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (ctx != NULL);
|
|
|
|
_COGL_RETURN_IF_FAIL (draw_buffer && read_buffer ?
|
2010-11-05 08:28:33 -04:00
|
|
|
draw_buffer->context == read_buffer->context : TRUE);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2011-02-02 09:23:53 -05:00
|
|
|
entry = ctx->framebuffer_stack->data;
|
2009-11-26 14:06:35 -05:00
|
|
|
|
2011-09-16 06:41:21 -04:00
|
|
|
notify_buffers_changed (entry->draw_buffer,
|
|
|
|
draw_buffer,
|
|
|
|
entry->read_buffer,
|
|
|
|
read_buffer);
|
2009-11-26 14:06:35 -05:00
|
|
|
|
2011-02-02 09:23:53 -05:00
|
|
|
if (draw_buffer)
|
|
|
|
cogl_object_ref (draw_buffer);
|
|
|
|
if (entry->draw_buffer)
|
|
|
|
cogl_object_unref (entry->draw_buffer);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2011-02-02 09:23:53 -05:00
|
|
|
if (read_buffer)
|
|
|
|
cogl_object_ref (read_buffer);
|
|
|
|
if (entry->read_buffer)
|
|
|
|
cogl_object_unref (entry->read_buffer);
|
|
|
|
|
|
|
|
entry->draw_buffer = draw_buffer;
|
|
|
|
entry->read_buffer = read_buffer;
|
2009-11-26 14:06:35 -05:00
|
|
|
}
|
|
|
|
|
2011-02-02 09:23:53 -05:00
|
|
|
static void
|
|
|
|
_cogl_set_framebuffers (CoglFramebuffer *draw_buffer,
|
|
|
|
CoglFramebuffer *read_buffer)
|
2009-11-26 14:06:35 -05:00
|
|
|
{
|
2011-02-02 09:23:53 -05:00
|
|
|
CoglFramebuffer *current_draw_buffer;
|
|
|
|
CoglFramebuffer *current_read_buffer;
|
2011-01-21 14:05:23 -05:00
|
|
|
|
2012-03-06 13:21:28 -05:00
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_framebuffer (draw_buffer));
|
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_framebuffer (read_buffer));
|
2009-11-26 14:06:35 -05:00
|
|
|
|
2011-03-10 16:33:31 -05:00
|
|
|
current_draw_buffer = cogl_get_draw_framebuffer ();
|
|
|
|
current_read_buffer = _cogl_get_read_framebuffer ();
|
2011-02-02 09:23:53 -05:00
|
|
|
|
|
|
|
if (current_draw_buffer != draw_buffer ||
|
|
|
|
current_read_buffer != read_buffer)
|
2012-01-24 13:16:03 -05:00
|
|
|
_cogl_set_framebuffers_real (draw_buffer, read_buffer);
|
2009-11-26 14:06:35 -05:00
|
|
|
}
|
|
|
|
|
2011-02-02 09:23:53 -05:00
|
|
|
void
|
|
|
|
cogl_set_framebuffer (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
_cogl_set_framebuffers (framebuffer, framebuffer);
|
|
|
|
}
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
/* XXX: deprecated API */
|
|
|
|
void
|
|
|
|
cogl_set_draw_buffer (CoglBufferTarget target, CoglHandle handle)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
|
|
|
if (target == COGL_WINDOW_BUFFER)
|
|
|
|
handle = ctx->window_buffer;
|
|
|
|
|
2011-02-02 09:23:53 -05:00
|
|
|
/* This is deprecated public API. The public API doesn't currently
|
|
|
|
really expose the concept of separate draw and read buffers so
|
|
|
|
for the time being this actually just sets both buffers */
|
2009-11-26 14:06:35 -05:00
|
|
|
cogl_set_framebuffer (handle);
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
2010-07-07 09:41:54 -04:00
|
|
|
CoglFramebuffer *
|
2011-03-10 16:33:31 -05:00
|
|
|
cogl_get_draw_framebuffer (void)
|
2011-02-02 09:23:53 -05:00
|
|
|
{
|
|
|
|
CoglFramebufferStackEntry *entry;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NULL);
|
|
|
|
|
|
|
|
g_assert (ctx->framebuffer_stack);
|
|
|
|
|
|
|
|
entry = ctx->framebuffer_stack->data;
|
|
|
|
|
|
|
|
return entry->draw_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglFramebuffer *
|
2011-03-10 16:33:31 -05:00
|
|
|
_cogl_get_read_framebuffer (void)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2011-02-02 09:23:53 -05:00
|
|
|
CoglFramebufferStackEntry *entry;
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NULL);
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
g_assert (ctx->framebuffer_stack);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2011-02-02 09:23:53 -05:00
|
|
|
entry = ctx->framebuffer_stack->data;
|
|
|
|
|
|
|
|
return entry->read_buffer;
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-02 09:23:53 -05:00
|
|
|
_cogl_push_framebuffers (CoglFramebuffer *draw_buffer,
|
|
|
|
CoglFramebuffer *read_buffer)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2011-02-22 12:58:47 -05:00
|
|
|
CoglContext *ctx;
|
2011-02-02 09:23:53 -05:00
|
|
|
CoglFramebuffer *old_draw_buffer, *old_read_buffer;
|
|
|
|
|
2012-03-06 13:21:28 -05:00
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_framebuffer (draw_buffer));
|
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_framebuffer (read_buffer));
|
2011-02-22 12:58:47 -05:00
|
|
|
|
|
|
|
ctx = draw_buffer->context;
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (ctx != NULL);
|
|
|
|
_COGL_RETURN_IF_FAIL (draw_buffer->context == read_buffer->context);
|
2011-02-22 12:58:47 -05:00
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (ctx->framebuffer_stack != NULL);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2011-02-02 10:17:50 -05:00
|
|
|
/* Copy the top of the stack so that when we call cogl_set_framebuffer
|
|
|
|
it will still know what the old framebuffer was */
|
2010-11-05 08:28:33 -04:00
|
|
|
old_draw_buffer = cogl_get_draw_framebuffer ();
|
|
|
|
if (old_draw_buffer)
|
|
|
|
cogl_object_ref (old_draw_buffer);
|
|
|
|
old_read_buffer = _cogl_get_read_framebuffer ();
|
|
|
|
if (old_read_buffer)
|
|
|
|
cogl_object_ref (old_read_buffer);
|
2009-11-26 14:06:35 -05:00
|
|
|
ctx->framebuffer_stack =
|
2011-02-02 10:17:50 -05:00
|
|
|
g_slist_prepend (ctx->framebuffer_stack,
|
2011-02-02 09:23:53 -05:00
|
|
|
create_stack_entry (old_draw_buffer,
|
|
|
|
old_read_buffer));
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2011-02-02 09:23:53 -05:00
|
|
|
_cogl_set_framebuffers (draw_buffer, read_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_push_framebuffer (CoglFramebuffer *buffer)
|
|
|
|
{
|
|
|
|
_cogl_push_framebuffers (buffer, buffer);
|
2009-11-26 14:06:35 -05:00
|
|
|
}
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
/* XXX: deprecated API */
|
|
|
|
void
|
|
|
|
cogl_push_draw_buffer (void)
|
|
|
|
{
|
2011-03-10 16:33:31 -05:00
|
|
|
cogl_push_framebuffer (cogl_get_draw_framebuffer ());
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-11-26 14:06:35 -05:00
|
|
|
cogl_pop_framebuffer (void)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2011-02-02 09:23:53 -05:00
|
|
|
CoglFramebufferStackEntry *to_pop;
|
|
|
|
CoglFramebufferStackEntry *to_restore;
|
2009-09-25 09:34:34 -04:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
g_assert (ctx->framebuffer_stack != NULL);
|
|
|
|
g_assert (ctx->framebuffer_stack->next != NULL);
|
|
|
|
|
|
|
|
to_pop = ctx->framebuffer_stack->data;
|
|
|
|
to_restore = ctx->framebuffer_stack->next->data;
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2011-02-02 09:23:53 -05:00
|
|
|
if (to_pop->draw_buffer != to_restore->draw_buffer ||
|
|
|
|
to_pop->read_buffer != to_restore->read_buffer)
|
2012-01-24 13:16:03 -05:00
|
|
|
notify_buffers_changed (to_pop->draw_buffer,
|
|
|
|
to_restore->draw_buffer,
|
|
|
|
to_pop->read_buffer,
|
|
|
|
to_restore->read_buffer);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2011-02-02 09:23:53 -05:00
|
|
|
cogl_object_unref (to_pop->draw_buffer);
|
|
|
|
cogl_object_unref (to_pop->read_buffer);
|
|
|
|
g_slice_free (CoglFramebufferStackEntry, to_pop);
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
ctx->framebuffer_stack =
|
2010-09-01 10:15:20 -04:00
|
|
|
g_slist_delete_link (ctx->framebuffer_stack,
|
2009-11-26 14:06:35 -05:00
|
|
|
ctx->framebuffer_stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: deprecated API */
|
|
|
|
void
|
|
|
|
cogl_pop_draw_buffer (void)
|
|
|
|
{
|
|
|
|
cogl_pop_framebuffer ();
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
2011-11-21 10:53:40 -05:00
|
|
|
static unsigned long
|
|
|
|
_cogl_framebuffer_compare_viewport_state (CoglFramebuffer *a,
|
|
|
|
CoglFramebuffer *b)
|
|
|
|
{
|
|
|
|
if (a->viewport_x != b->viewport_x ||
|
|
|
|
a->viewport_y != b->viewport_y ||
|
|
|
|
a->viewport_width != b->viewport_width ||
|
|
|
|
a->viewport_height != b->viewport_height ||
|
|
|
|
/* NB: we render upside down to offscreen framebuffers and that
|
|
|
|
* can affect how we setup the GL viewport... */
|
|
|
|
a->type != b->type)
|
|
|
|
return COGL_FRAMEBUFFER_STATE_VIEWPORT;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long
|
|
|
|
_cogl_framebuffer_compare_clip_state (CoglFramebuffer *a,
|
|
|
|
CoglFramebuffer *b)
|
|
|
|
{
|
|
|
|
if (((a->clip_state.stacks == NULL || b->clip_state.stacks == NULL) &&
|
|
|
|
a->clip_state.stacks != b->clip_state.stacks)
|
|
|
|
||
|
|
|
|
a->clip_state.stacks->data != b->clip_state.stacks->data)
|
|
|
|
return COGL_FRAMEBUFFER_STATE_CLIP;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long
|
|
|
|
_cogl_framebuffer_compare_dither_state (CoglFramebuffer *a,
|
|
|
|
CoglFramebuffer *b)
|
|
|
|
{
|
|
|
|
return a->dither_enabled != b->dither_enabled ?
|
|
|
|
COGL_FRAMEBUFFER_STATE_DITHER : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long
|
|
|
|
_cogl_framebuffer_compare_modelview_state (CoglFramebuffer *a,
|
|
|
|
CoglFramebuffer *b)
|
|
|
|
{
|
2011-11-29 09:21:07 -05:00
|
|
|
/* We always want to flush the modelview state. All this does is set
|
|
|
|
the current modelview stack on the context to the framebuffer's
|
|
|
|
stack. */
|
|
|
|
return COGL_FRAMEBUFFER_STATE_MODELVIEW;
|
2011-11-21 10:53:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long
|
|
|
|
_cogl_framebuffer_compare_projection_state (CoglFramebuffer *a,
|
|
|
|
CoglFramebuffer *b)
|
|
|
|
{
|
2011-11-29 09:21:07 -05:00
|
|
|
/* We always want to flush the projection state. All this does is
|
|
|
|
set the current projection stack on the context to the
|
|
|
|
framebuffer's stack. */
|
|
|
|
return COGL_FRAMEBUFFER_STATE_PROJECTION;
|
2011-11-21 10:53:40 -05:00
|
|
|
}
|
|
|
|
|
2011-11-21 12:58:45 -05:00
|
|
|
static unsigned long
|
|
|
|
_cogl_framebuffer_compare_color_mask_state (CoglFramebuffer *a,
|
|
|
|
CoglFramebuffer *b)
|
|
|
|
{
|
|
|
|
if (cogl_framebuffer_get_color_mask (a) !=
|
|
|
|
cogl_framebuffer_get_color_mask (b))
|
|
|
|
return COGL_FRAMEBUFFER_STATE_COLOR_MASK;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-21 15:48:23 -05:00
|
|
|
static unsigned long
|
|
|
|
_cogl_framebuffer_compare_front_face_winding_state (CoglFramebuffer *a,
|
|
|
|
CoglFramebuffer *b)
|
|
|
|
{
|
|
|
|
if (a->type != b->type)
|
|
|
|
return COGL_FRAMEBUFFER_STATE_FRONT_FACE_WINDING;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-31 19:04:00 -04:00
|
|
|
unsigned long
|
2011-11-21 10:53:40 -05:00
|
|
|
_cogl_framebuffer_compare (CoglFramebuffer *a,
|
|
|
|
CoglFramebuffer *b,
|
|
|
|
unsigned long state)
|
|
|
|
{
|
|
|
|
unsigned long differences = 0;
|
|
|
|
int bit;
|
|
|
|
|
|
|
|
if (state & COGL_FRAMEBUFFER_STATE_BIND)
|
|
|
|
{
|
|
|
|
differences |= COGL_FRAMEBUFFER_STATE_BIND;
|
|
|
|
state &= ~COGL_FRAMEBUFFER_STATE_BIND;
|
|
|
|
}
|
|
|
|
|
|
|
|
COGL_FLAGS_FOREACH_START (&state, 1, bit)
|
|
|
|
{
|
|
|
|
/* XXX: We considered having an array of callbacks for each state index
|
|
|
|
* that we'd call here but decided that this way the compiler is more
|
|
|
|
* likely going to be able to in-line the comparison functions and use
|
|
|
|
* the index to jump straight to the required code. */
|
|
|
|
switch (bit)
|
|
|
|
{
|
|
|
|
case COGL_FRAMEBUFFER_STATE_INDEX_VIEWPORT:
|
|
|
|
differences |=
|
|
|
|
_cogl_framebuffer_compare_viewport_state (a, b);
|
|
|
|
break;
|
|
|
|
case COGL_FRAMEBUFFER_STATE_INDEX_CLIP:
|
|
|
|
differences |= _cogl_framebuffer_compare_clip_state (a, b);
|
|
|
|
break;
|
|
|
|
case COGL_FRAMEBUFFER_STATE_INDEX_DITHER:
|
|
|
|
differences |= _cogl_framebuffer_compare_dither_state (a, b);
|
|
|
|
break;
|
|
|
|
case COGL_FRAMEBUFFER_STATE_INDEX_MODELVIEW:
|
|
|
|
differences |=
|
|
|
|
_cogl_framebuffer_compare_modelview_state (a, b);
|
|
|
|
break;
|
|
|
|
case COGL_FRAMEBUFFER_STATE_INDEX_PROJECTION:
|
|
|
|
differences |=
|
|
|
|
_cogl_framebuffer_compare_projection_state (a, b);
|
|
|
|
break;
|
2011-11-21 12:58:45 -05:00
|
|
|
case COGL_FRAMEBUFFER_STATE_INDEX_COLOR_MASK:
|
|
|
|
differences |=
|
|
|
|
_cogl_framebuffer_compare_color_mask_state (a, b);
|
|
|
|
break;
|
2011-11-21 15:48:23 -05:00
|
|
|
case COGL_FRAMEBUFFER_STATE_INDEX_FRONT_FACE_WINDING:
|
|
|
|
differences |=
|
|
|
|
_cogl_framebuffer_compare_front_face_winding_state (a, b);
|
|
|
|
break;
|
2011-11-21 10:53:40 -05:00
|
|
|
default:
|
|
|
|
g_warn_if_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
COGL_FLAGS_FOREACH_END;
|
|
|
|
|
|
|
|
return differences;
|
|
|
|
}
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
void
|
2011-02-02 09:23:53 -05:00
|
|
|
_cogl_framebuffer_flush_state (CoglFramebuffer *draw_buffer,
|
|
|
|
CoglFramebuffer *read_buffer,
|
2011-11-21 10:53:40 -05:00
|
|
|
CoglFramebufferState state)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2011-02-22 12:58:47 -05:00
|
|
|
CoglContext *ctx = draw_buffer->context;
|
2011-11-21 10:53:40 -05:00
|
|
|
|
2012-08-31 19:04:00 -04:00
|
|
|
ctx->driver_vtable->framebuffer_flush_state (draw_buffer,
|
|
|
|
read_buffer,
|
|
|
|
state);
|
2009-09-25 09:34:34 -04:00
|
|
|
}
|
|
|
|
|
2010-04-26 13:08:45 -04:00
|
|
|
int
|
2011-06-30 17:50:48 -04:00
|
|
|
cogl_framebuffer_get_red_bits (CoglFramebuffer *framebuffer)
|
2010-04-26 13:08:45 -04:00
|
|
|
{
|
2012-08-31 19:04:00 -04:00
|
|
|
CoglContext *ctx = framebuffer->context;
|
|
|
|
int red, green, blue, alpha;
|
2010-04-26 13:08:45 -04:00
|
|
|
|
2012-08-31 19:04:00 -04:00
|
|
|
ctx->driver_vtable->framebuffer_query_bits (framebuffer,
|
|
|
|
&red, &green, &blue, &alpha);
|
2010-04-26 13:08:45 -04:00
|
|
|
|
2012-08-31 19:04:00 -04:00
|
|
|
return red;
|
|
|
|
}
|
2010-04-26 13:08:45 -04:00
|
|
|
int
|
2011-06-30 17:50:48 -04:00
|
|
|
cogl_framebuffer_get_green_bits (CoglFramebuffer *framebuffer)
|
2010-04-26 13:08:45 -04:00
|
|
|
{
|
2012-08-31 19:04:00 -04:00
|
|
|
CoglContext *ctx = framebuffer->context;
|
|
|
|
int red, green, blue, alpha;
|
|
|
|
|
|
|
|
ctx->driver_vtable->framebuffer_query_bits (framebuffer,
|
|
|
|
&red, &green, &blue, &alpha);
|
2010-04-26 13:08:45 -04:00
|
|
|
|
2012-08-31 19:04:00 -04:00
|
|
|
return green;
|
2010-04-26 13:08:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-06-30 17:50:48 -04:00
|
|
|
cogl_framebuffer_get_blue_bits (CoglFramebuffer *framebuffer)
|
2010-04-26 13:08:45 -04:00
|
|
|
{
|
2012-08-31 19:04:00 -04:00
|
|
|
CoglContext *ctx = framebuffer->context;
|
|
|
|
int red, green, blue, alpha;
|
2010-04-26 13:08:45 -04:00
|
|
|
|
2012-08-31 19:04:00 -04:00
|
|
|
ctx->driver_vtable->framebuffer_query_bits (framebuffer,
|
|
|
|
&red, &green, &blue, &alpha);
|
|
|
|
|
|
|
|
return blue;
|
2010-04-26 13:08:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-06-30 17:50:48 -04:00
|
|
|
cogl_framebuffer_get_alpha_bits (CoglFramebuffer *framebuffer)
|
2010-04-26 13:08:45 -04:00
|
|
|
{
|
2012-08-31 19:04:00 -04:00
|
|
|
CoglContext *ctx = framebuffer->context;
|
|
|
|
int red, green, blue, alpha;
|
2010-04-26 13:08:45 -04:00
|
|
|
|
2012-08-31 19:04:00 -04:00
|
|
|
ctx->driver_vtable->framebuffer_query_bits (framebuffer,
|
|
|
|
&red, &green, &blue, &alpha);
|
|
|
|
|
|
|
|
return alpha;
|
2010-04-26 13:08:45 -04:00
|
|
|
}
|
2010-07-07 09:41:54 -04:00
|
|
|
|
2011-07-10 21:27:54 -04:00
|
|
|
CoglColorMask
|
|
|
|
cogl_framebuffer_get_color_mask (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
return framebuffer->color_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_set_color_mask (CoglFramebuffer *framebuffer,
|
|
|
|
CoglColorMask color_mask)
|
|
|
|
{
|
2011-11-21 12:58:45 -05:00
|
|
|
/* XXX: Currently color mask changes don't go through the journal */
|
|
|
|
_cogl_framebuffer_flush_journal (framebuffer);
|
2011-07-10 21:27:54 -04:00
|
|
|
|
|
|
|
framebuffer->color_mask = color_mask;
|
|
|
|
|
2011-11-21 12:58:45 -05:00
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_COLOR_MASK;
|
2011-07-10 21:27:54 -04:00
|
|
|
}
|
|
|
|
|
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
|
2011-07-13 11:33:25 -04:00
|
|
|
cogl_framebuffer_get_dither_enabled (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
return framebuffer->dither_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_set_dither_enabled (CoglFramebuffer *framebuffer,
|
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 dither_enabled)
|
2011-07-13 11:33:25 -04:00
|
|
|
{
|
|
|
|
if (framebuffer->dither_enabled == dither_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cogl_flush (); /* Currently dithering changes aren't tracked in the journal */
|
|
|
|
framebuffer->dither_enabled = dither_enabled;
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_DITHER;
|
2011-07-13 11:33:25 -04:00
|
|
|
}
|
|
|
|
|
2011-08-23 20:37:06 -04:00
|
|
|
CoglPixelFormat
|
|
|
|
cogl_framebuffer_get_color_format (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
return framebuffer->format;
|
|
|
|
}
|
|
|
|
|
2012-05-23 13:19:29 -04:00
|
|
|
void
|
|
|
|
cogl_framebuffer_set_depth_texture_enabled (CoglFramebuffer *framebuffer,
|
|
|
|
CoglBool enabled)
|
|
|
|
{
|
|
|
|
_COGL_RETURN_IF_FAIL (!framebuffer->allocated);
|
|
|
|
|
|
|
|
framebuffer->config.depth_texture_enabled = enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglBool
|
|
|
|
cogl_framebuffer_get_depth_texture_enabled (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
return framebuffer->config.depth_texture_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglTexture *
|
|
|
|
cogl_framebuffer_get_depth_texture (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
/* lazily allocate the framebuffer... */
|
|
|
|
if (!cogl_framebuffer_allocate (framebuffer, NULL))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (cogl_is_offscreen (framebuffer), NULL);
|
|
|
|
return COGL_OFFSCREEN(framebuffer)->depth_texture;
|
|
|
|
}
|
|
|
|
|
2011-10-08 10:47:42 -04:00
|
|
|
int
|
|
|
|
cogl_framebuffer_get_samples_per_pixel (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
if (framebuffer->allocated)
|
|
|
|
return framebuffer->samples_per_pixel;
|
|
|
|
else
|
|
|
|
return framebuffer->config.samples_per_pixel;
|
|
|
|
}
|
|
|
|
|
2011-08-23 08:55:12 -04:00
|
|
|
void
|
|
|
|
cogl_framebuffer_set_samples_per_pixel (CoglFramebuffer *framebuffer,
|
|
|
|
int samples_per_pixel)
|
|
|
|
{
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (!framebuffer->allocated);
|
2011-08-23 08:55:12 -04:00
|
|
|
|
|
|
|
framebuffer->config.samples_per_pixel = samples_per_pixel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_resolve_samples (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
cogl_framebuffer_resolve_samples_region (framebuffer,
|
|
|
|
0, 0,
|
|
|
|
framebuffer->width,
|
|
|
|
framebuffer->height);
|
|
|
|
|
|
|
|
/* TODO: Make this happen implicitly when the resolve texture next gets used
|
|
|
|
* as a source, either via cogl_texture_get_data(), via cogl_read_pixels() or
|
|
|
|
* if used as a source for rendering. We would also implicitly resolve if
|
|
|
|
* necessary before freeing a CoglFramebuffer.
|
|
|
|
*
|
|
|
|
* This API should still be kept but it is optional, only necessary
|
|
|
|
* if the user wants to explicitly control when the resolve happens e.g.
|
|
|
|
* to ensure it's done in advance of it being used as a source.
|
|
|
|
*
|
|
|
|
* Every texture should have a CoglFramebuffer *needs_resolve member
|
|
|
|
* internally. When the texture gets validated before being used as a source
|
|
|
|
* we should first check the needs_resolve pointer and if set we'll
|
|
|
|
* automatically call cogl_framebuffer_resolve_samples ().
|
|
|
|
*
|
|
|
|
* Calling cogl_framebuffer_resolve_samples() or
|
|
|
|
* cogl_framebuffer_resolve_samples_region() should reset the textures
|
|
|
|
* needs_resolve pointer to NULL.
|
|
|
|
*
|
|
|
|
* Rendering anything to a framebuffer will cause the corresponding
|
|
|
|
* texture's ->needs_resolve pointer to be set.
|
|
|
|
*
|
|
|
|
* XXX: Note: we only need to address this TODO item when adding support for
|
|
|
|
* EXT_framebuffer_multisample because currently we only support hardware
|
|
|
|
* that resolves implicitly anyway.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_resolve_samples_region (CoglFramebuffer *framebuffer,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
|
|
|
/* NOP for now since we don't support EXT_framebuffer_multisample yet which
|
|
|
|
* requires an explicit resolve. */
|
|
|
|
}
|
|
|
|
|
2011-08-02 10:24:02 -04:00
|
|
|
CoglContext *
|
|
|
|
cogl_framebuffer_get_context (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (framebuffer != NULL, NULL);
|
2011-08-02 10:24:02 -04:00
|
|
|
|
|
|
|
return framebuffer->context;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static CoglBool
|
2011-01-12 17:12:41 -05:00
|
|
|
_cogl_framebuffer_try_fast_read_pixel (CoglFramebuffer *framebuffer,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
CoglReadPixelsFlags source,
|
2012-02-25 14:23:51 -05:00
|
|
|
CoglBitmap *bitmap)
|
2011-01-12 17:12:41 -05:00
|
|
|
{
|
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 found_intersection;
|
2012-02-25 14:23:51 -05:00
|
|
|
CoglPixelFormat format;
|
2011-01-12 17:12:41 -05:00
|
|
|
|
2011-01-24 09:28:00 -05:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_FAST_READ_PIXEL)))
|
2011-01-20 09:41:51 -05:00
|
|
|
return FALSE;
|
|
|
|
|
2011-01-12 17:12:41 -05:00
|
|
|
if (source != COGL_READ_PIXELS_COLOR_BUFFER)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-02-25 15:18:05 -05:00
|
|
|
format = cogl_bitmap_get_format (bitmap);
|
2012-02-25 14:23:51 -05:00
|
|
|
|
2011-01-12 17:12:41 -05:00
|
|
|
if (format != COGL_PIXEL_FORMAT_RGBA_8888_PRE &&
|
|
|
|
format != COGL_PIXEL_FORMAT_RGBA_8888)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!_cogl_journal_try_read_pixel (framebuffer->journal,
|
2012-02-25 14:23:51 -05:00
|
|
|
x, y, bitmap,
|
2011-01-12 17:12:41 -05:00
|
|
|
&found_intersection))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* If we can't determine the color from the primitives in the
|
|
|
|
* journal then see if we can use the last recorded clear color
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* If _cogl_journal_try_read_pixel() failed even though there was an
|
|
|
|
* intersection of the given point with a primitive in the journal
|
|
|
|
* then we can't fallback to the framebuffer's last clear color...
|
|
|
|
* */
|
|
|
|
if (found_intersection)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* If the framebuffer has been rendered too since it was last
|
|
|
|
* cleared then we can't return the last known clear color. */
|
|
|
|
if (framebuffer->clear_clip_dirty)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (x >= framebuffer->clear_clip_x0 &&
|
|
|
|
x < framebuffer->clear_clip_x1 &&
|
|
|
|
y >= framebuffer->clear_clip_y0 &&
|
|
|
|
y < framebuffer->clear_clip_y1)
|
|
|
|
{
|
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
|
|
|
uint8_t *pixel;
|
2011-01-12 17:12:41 -05:00
|
|
|
|
|
|
|
/* we currently only care about cases where the premultiplied or
|
|
|
|
* unpremultipled colors are equivalent... */
|
|
|
|
if (framebuffer->clear_color_alpha != 1.0)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-02-25 14:23:51 -05:00
|
|
|
pixel = _cogl_bitmap_map (bitmap,
|
|
|
|
COGL_BUFFER_ACCESS_WRITE,
|
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD);
|
|
|
|
if (pixel == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-01-12 17:12:41 -05:00
|
|
|
pixel[0] = framebuffer->clear_color_red * 255.0;
|
|
|
|
pixel[1] = framebuffer->clear_color_green * 255.0;
|
|
|
|
pixel[2] = framebuffer->clear_color_blue * 255.0;
|
|
|
|
pixel[3] = framebuffer->clear_color_alpha * 255.0;
|
|
|
|
|
2012-02-25 14:23:51 -05:00
|
|
|
_cogl_bitmap_unmap (bitmap);
|
|
|
|
|
2011-01-12 17:12:41 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static CoglBool
|
2012-03-27 12:24:50 -04:00
|
|
|
_cogl_framebuffer_slow_read_pixels_workaround (CoglFramebuffer *framebuffer,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
CoglReadPixelsFlags source,
|
|
|
|
CoglBitmap *bitmap)
|
|
|
|
{
|
|
|
|
CoglContext *ctx;
|
|
|
|
CoglPixelFormat format;
|
|
|
|
CoglBitmap *pbo;
|
|
|
|
int width;
|
|
|
|
int height;
|
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 res;
|
2012-03-27 12:24:50 -04:00
|
|
|
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (source & COGL_READ_PIXELS_COLOR_BUFFER, FALSE);
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (cogl_is_framebuffer (framebuffer), FALSE);
|
|
|
|
|
|
|
|
ctx = cogl_framebuffer_get_context (framebuffer);
|
|
|
|
|
|
|
|
width = cogl_bitmap_get_width (bitmap);
|
|
|
|
height = cogl_bitmap_get_height (bitmap);
|
|
|
|
format = cogl_bitmap_get_format (bitmap);
|
|
|
|
|
|
|
|
pbo = cogl_bitmap_new_with_size (ctx, width, height, format);
|
|
|
|
if (pbo == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Read into the pbo. We need to disable the flipping because the
|
|
|
|
blit fast path in the driver does not work with
|
|
|
|
GL_PACK_INVERT_MESA is set */
|
|
|
|
res = cogl_framebuffer_read_pixels_into_bitmap (framebuffer,
|
|
|
|
x, y,
|
|
|
|
source |
|
|
|
|
COGL_READ_PIXELS_NO_FLIP,
|
|
|
|
pbo);
|
|
|
|
|
|
|
|
if (res)
|
|
|
|
{
|
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
|
|
|
uint8_t *dst;
|
2012-03-27 12:24:50 -04:00
|
|
|
|
|
|
|
/* Copy the pixels back into application's buffer */
|
|
|
|
dst = _cogl_bitmap_map (bitmap,
|
|
|
|
COGL_BUFFER_ACCESS_WRITE,
|
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD);
|
|
|
|
|
|
|
|
if (dst == NULL)
|
|
|
|
res = FALSE;
|
|
|
|
else
|
|
|
|
{
|
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
|
|
|
const uint8_t *src;
|
2012-03-27 12:24:50 -04:00
|
|
|
|
|
|
|
src = _cogl_bitmap_map (pbo,
|
|
|
|
COGL_BUFFER_ACCESS_READ,
|
|
|
|
0 /* hints */);
|
|
|
|
if (src == NULL)
|
|
|
|
res = FALSE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int src_rowstride = cogl_bitmap_get_rowstride (pbo);
|
|
|
|
int dst_rowstride = cogl_bitmap_get_rowstride (bitmap);
|
|
|
|
int to_copy =
|
|
|
|
_cogl_pixel_format_get_bytes_per_pixel (format) * width;
|
|
|
|
int y;
|
|
|
|
|
|
|
|
/* If the framebuffer is onscreen we need to flip the
|
|
|
|
data while copying */
|
|
|
|
if (!cogl_is_offscreen (framebuffer))
|
|
|
|
{
|
|
|
|
src += src_rowstride * (height - 1);
|
|
|
|
src_rowstride = -src_rowstride;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
memcpy (dst, src, to_copy);
|
|
|
|
dst += dst_rowstride;
|
|
|
|
src += src_rowstride;
|
|
|
|
}
|
|
|
|
|
|
|
|
_cogl_bitmap_unmap (pbo);
|
|
|
|
}
|
|
|
|
|
|
|
|
_cogl_bitmap_unmap (bitmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_object_unref (pbo);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
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
|
2012-02-25 14:23:51 -05:00
|
|
|
cogl_framebuffer_read_pixels_into_bitmap (CoglFramebuffer *framebuffer,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
CoglReadPixelsFlags source,
|
|
|
|
CoglBitmap *bitmap)
|
|
|
|
{
|
|
|
|
CoglContext *ctx;
|
|
|
|
int framebuffer_height;
|
|
|
|
CoglPixelFormat format;
|
|
|
|
CoglPixelFormat required_format;
|
|
|
|
GLenum gl_intformat;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
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 pack_invert_set;
|
2012-02-25 14:23:51 -05:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
|
2012-03-27 12:24:50 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (source & COGL_READ_PIXELS_COLOR_BUFFER, FALSE);
|
2012-03-06 13:21:28 -05:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (cogl_is_framebuffer (framebuffer), FALSE);
|
2012-02-25 14:23:51 -05:00
|
|
|
|
2012-03-31 08:29:01 -04:00
|
|
|
if (!cogl_framebuffer_allocate (framebuffer, NULL))
|
|
|
|
return FALSE;
|
|
|
|
|
2012-02-25 14:23:51 -05:00
|
|
|
ctx = cogl_framebuffer_get_context (framebuffer);
|
|
|
|
|
2012-02-25 15:18:05 -05:00
|
|
|
width = cogl_bitmap_get_width (bitmap);
|
|
|
|
height = cogl_bitmap_get_height (bitmap);
|
2012-03-27 12:24:50 -04:00
|
|
|
format = cogl_bitmap_get_format (bitmap);
|
2012-02-25 14:23:51 -05:00
|
|
|
|
|
|
|
if (width == 1 && height == 1 && !framebuffer->clear_clip_dirty)
|
|
|
|
{
|
|
|
|
/* If everything drawn so far for this frame is still in the
|
|
|
|
* Journal then if all of the rectangles only have a flat
|
|
|
|
* opaque color we have a fast-path for reading a single pixel
|
|
|
|
* that avoids the relatively high cost of flushing primitives
|
|
|
|
* to be drawn on the GPU (considering how simple the geometry
|
|
|
|
* is in this case) and then blocking on the long GPU pipelines
|
|
|
|
* for the result.
|
|
|
|
*/
|
|
|
|
if (_cogl_framebuffer_try_fast_read_pixel (framebuffer,
|
|
|
|
x, y, source, bitmap))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-27 12:24:50 -04:00
|
|
|
/* Workaround for cases where its faster to read into a temporary
|
|
|
|
* PBO. This is only worth doing if:
|
|
|
|
*
|
|
|
|
* • The GPU is an Intel GPU. In that case there is a known
|
|
|
|
* fast-path when reading into a PBO that will use the blitter
|
|
|
|
* instead of the Mesa fallback code. The driver bug will only be
|
|
|
|
* set if this is the case.
|
|
|
|
* • We're not already reading into a PBO.
|
|
|
|
* • The target format is BGRA. The fast-path blit does not get hit
|
|
|
|
* otherwise.
|
|
|
|
* • The size of the data is not trivially small. This isn't a
|
|
|
|
* requirement to hit the fast-path blit but intuitively it feels
|
|
|
|
* like if the amount of data is too small then the cost of
|
|
|
|
* allocating a PBO will outweigh the cost of temporarily
|
|
|
|
* converting the data to floats.
|
|
|
|
*/
|
|
|
|
if ((ctx->gpu.driver_bugs &
|
|
|
|
COGL_GPU_INFO_DRIVER_BUG_MESA_46631_SLOW_READ_PIXELS) &&
|
|
|
|
(width > 8 || height > 8) &&
|
|
|
|
(format & ~COGL_PREMULT_BIT) == COGL_PIXEL_FORMAT_BGRA_8888 &&
|
|
|
|
cogl_bitmap_get_buffer (bitmap) == NULL)
|
|
|
|
return _cogl_framebuffer_slow_read_pixels_workaround (framebuffer,
|
|
|
|
x, y,
|
|
|
|
source,
|
|
|
|
bitmap);
|
|
|
|
|
2012-02-25 14:23:51 -05:00
|
|
|
/* make sure any batched primitives get emitted to the GL driver
|
|
|
|
* before issuing our read pixels...
|
|
|
|
*/
|
|
|
|
_cogl_framebuffer_flush_journal (framebuffer);
|
|
|
|
|
|
|
|
_cogl_framebuffer_flush_state (framebuffer,
|
|
|
|
framebuffer,
|
|
|
|
COGL_FRAMEBUFFER_STATE_BIND);
|
|
|
|
|
|
|
|
framebuffer_height = cogl_framebuffer_get_height (framebuffer);
|
|
|
|
|
|
|
|
/* The y co-ordinate should be given in OpenGL's coordinate system
|
|
|
|
* so 0 is the bottom row
|
|
|
|
*
|
|
|
|
* NB: all offscreen rendering is done upside down so no conversion
|
|
|
|
* is necissary in this case.
|
|
|
|
*/
|
|
|
|
if (!cogl_is_offscreen (framebuffer))
|
|
|
|
y = framebuffer_height - y - height;
|
|
|
|
|
2012-03-22 12:32:56 -04:00
|
|
|
required_format = ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
format,
|
|
|
|
&gl_intformat,
|
|
|
|
&gl_format,
|
|
|
|
&gl_type);
|
2012-02-25 14:23:51 -05:00
|
|
|
|
|
|
|
/* NB: All offscreen rendering is done upside down so there is no need
|
|
|
|
* to flip in this case... */
|
|
|
|
if ((ctx->private_feature_flags & COGL_PRIVATE_FEATURE_MESA_PACK_INVERT) &&
|
2012-03-27 12:24:50 -04:00
|
|
|
(source & COGL_READ_PIXELS_NO_FLIP) == 0 &&
|
2012-02-25 14:23:51 -05:00
|
|
|
!cogl_is_offscreen (framebuffer))
|
|
|
|
{
|
|
|
|
GE (ctx, glPixelStorei (GL_PACK_INVERT_MESA, TRUE));
|
|
|
|
pack_invert_set = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pack_invert_set = FALSE;
|
|
|
|
|
|
|
|
/* Under GLES only GL_RGBA with GL_UNSIGNED_BYTE as well as an
|
|
|
|
implementation specific format under
|
|
|
|
GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES and
|
|
|
|
GL_IMPLEMENTATION_COLOR_READ_TYPE_OES is supported. We could try
|
|
|
|
to be more clever and check if the requested type matches that
|
|
|
|
but we would need some reliable functions to convert from GL
|
|
|
|
types to Cogl types. For now, lets just always read in
|
|
|
|
GL_RGBA/GL_UNSIGNED_BYTE and convert if necessary. We also need
|
|
|
|
to use this intermediate buffer if the rowstride has padding
|
|
|
|
because GLES does not support setting GL_ROW_LENGTH */
|
|
|
|
if ((ctx->driver != COGL_DRIVER_GL &&
|
|
|
|
(gl_format != GL_RGBA || gl_type != GL_UNSIGNED_BYTE ||
|
2012-02-25 15:18:05 -05:00
|
|
|
cogl_bitmap_get_rowstride (bitmap) != 4 * width)) ||
|
2012-02-25 14:23:51 -05:00
|
|
|
(required_format & ~COGL_PREMULT_BIT) != (format & ~COGL_PREMULT_BIT))
|
|
|
|
{
|
|
|
|
CoglBitmap *tmp_bmp;
|
|
|
|
CoglPixelFormat read_format;
|
|
|
|
int bpp, rowstride;
|
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
|
|
|
uint8_t *tmp_data;
|
2012-02-25 14:23:51 -05:00
|
|
|
int succeeded;
|
|
|
|
|
|
|
|
if (ctx->driver == COGL_DRIVER_GL)
|
|
|
|
read_format = required_format;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
read_format = COGL_PIXEL_FORMAT_RGBA_8888;
|
|
|
|
gl_format = GL_RGBA;
|
|
|
|
gl_type = GL_UNSIGNED_BYTE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT (read_format))
|
|
|
|
read_format = ((read_format & ~COGL_PREMULT_BIT) |
|
|
|
|
(framebuffer->format & COGL_PREMULT_BIT));
|
|
|
|
|
2012-03-13 10:46:18 -04:00
|
|
|
tmp_bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
|
|
|
|
width, height,
|
|
|
|
read_format);
|
2012-02-25 14:23:51 -05:00
|
|
|
bpp = _cogl_pixel_format_get_bytes_per_pixel (read_format);
|
2012-03-13 10:46:18 -04:00
|
|
|
rowstride = cogl_bitmap_get_rowstride (tmp_bmp);
|
2012-02-25 14:23:51 -05:00
|
|
|
|
2012-03-22 07:40:16 -04:00
|
|
|
ctx->texture_driver->prep_gl_for_pixels_download (ctx,
|
|
|
|
rowstride,
|
|
|
|
width,
|
|
|
|
bpp);
|
2012-02-25 14:23:51 -05:00
|
|
|
|
2012-03-13 10:46:18 -04:00
|
|
|
tmp_data = _cogl_bitmap_bind (tmp_bmp,
|
|
|
|
COGL_BUFFER_ACCESS_WRITE,
|
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD);
|
|
|
|
|
2012-02-25 14:23:51 -05:00
|
|
|
GE( ctx, glReadPixels (x, y, width, height,
|
|
|
|
gl_format, gl_type,
|
|
|
|
tmp_data) );
|
|
|
|
|
2012-03-13 10:46:18 -04:00
|
|
|
_cogl_bitmap_unbind (tmp_bmp);
|
|
|
|
|
2012-02-25 14:23:51 -05:00
|
|
|
succeeded = _cogl_bitmap_convert_into_bitmap (tmp_bmp, bitmap);
|
|
|
|
|
|
|
|
cogl_object_unref (tmp_bmp);
|
|
|
|
|
|
|
|
if (!succeeded)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CoglBitmap *shared_bmp;
|
|
|
|
CoglPixelFormat bmp_format;
|
|
|
|
int bpp, rowstride;
|
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 succeeded = FALSE;
|
|
|
|
uint8_t *pixels;
|
2012-02-25 14:23:51 -05:00
|
|
|
|
2012-02-25 15:18:05 -05:00
|
|
|
rowstride = cogl_bitmap_get_rowstride (bitmap);
|
2012-02-25 14:23:51 -05:00
|
|
|
|
|
|
|
/* We match the premultiplied state of the target buffer to the
|
|
|
|
* premultiplied state of the framebuffer so that it will get
|
|
|
|
* converted to the right format below */
|
|
|
|
if (COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT (format))
|
|
|
|
bmp_format = ((format & ~COGL_PREMULT_BIT) |
|
|
|
|
(framebuffer->format & COGL_PREMULT_BIT));
|
|
|
|
else
|
|
|
|
bmp_format = format;
|
|
|
|
|
|
|
|
if (bmp_format != format)
|
|
|
|
shared_bmp = _cogl_bitmap_new_shared (bitmap,
|
|
|
|
bmp_format,
|
|
|
|
width, height,
|
|
|
|
rowstride);
|
|
|
|
else
|
|
|
|
shared_bmp = cogl_object_ref (bitmap);
|
|
|
|
|
|
|
|
bpp = _cogl_pixel_format_get_bytes_per_pixel (bmp_format);
|
|
|
|
|
2012-03-22 07:40:16 -04:00
|
|
|
ctx->texture_driver->prep_gl_for_pixels_download (ctx,
|
|
|
|
rowstride,
|
|
|
|
width,
|
|
|
|
bpp);
|
2012-02-25 14:23:51 -05:00
|
|
|
|
|
|
|
pixels = _cogl_bitmap_bind (shared_bmp,
|
|
|
|
COGL_BUFFER_ACCESS_WRITE,
|
|
|
|
0 /* hints */);
|
|
|
|
|
|
|
|
GE( ctx, glReadPixels (x, y,
|
|
|
|
width, height,
|
|
|
|
gl_format, gl_type,
|
|
|
|
pixels) );
|
|
|
|
|
|
|
|
_cogl_bitmap_unbind (shared_bmp);
|
|
|
|
|
|
|
|
/* Convert to the premult format specified by the caller
|
|
|
|
in-place. This will do nothing if the premult status is already
|
|
|
|
correct. */
|
|
|
|
if (_cogl_bitmap_convert_premult_status (shared_bmp, format))
|
|
|
|
succeeded = TRUE;
|
|
|
|
|
|
|
|
cogl_object_unref (shared_bmp);
|
|
|
|
|
|
|
|
if (!succeeded)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Currently this function owns the pack_invert state and we don't want this
|
|
|
|
* to interfere with other Cogl components so all other code can assume that
|
|
|
|
* we leave the pack_invert state off. */
|
|
|
|
if (pack_invert_set)
|
|
|
|
GE (ctx, glPixelStorei (GL_PACK_INVERT_MESA, FALSE));
|
|
|
|
|
|
|
|
/* NB: All offscreen rendering is done upside down so there is no need
|
|
|
|
* to flip in this case... */
|
2012-03-27 12:24:50 -04:00
|
|
|
if (!cogl_is_offscreen (framebuffer) &&
|
|
|
|
(source & COGL_READ_PIXELS_NO_FLIP) == 0 &&
|
|
|
|
!pack_invert_set)
|
2012-02-25 14:23:51 -05:00
|
|
|
{
|
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
|
|
|
uint8_t *temprow;
|
2012-02-25 14:23:51 -05:00
|
|
|
int rowstride;
|
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
|
|
|
uint8_t *pixels;
|
2012-02-25 14:23:51 -05:00
|
|
|
|
2012-02-25 15:18:05 -05:00
|
|
|
rowstride = cogl_bitmap_get_rowstride (bitmap);
|
2012-02-25 14:23:51 -05:00
|
|
|
pixels = _cogl_bitmap_map (bitmap,
|
|
|
|
COGL_BUFFER_ACCESS_READ |
|
|
|
|
COGL_BUFFER_ACCESS_WRITE,
|
|
|
|
0 /* hints */);
|
|
|
|
|
|
|
|
if (pixels == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
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
|
|
|
temprow = g_alloca (rowstride * sizeof (uint8_t));
|
2012-02-25 14:23:51 -05:00
|
|
|
|
|
|
|
/* vertically flip the buffer in-place */
|
|
|
|
for (y = 0; y < height / 2; y++)
|
|
|
|
{
|
|
|
|
if (y != height - y - 1) /* skip center row */
|
|
|
|
{
|
|
|
|
memcpy (temprow,
|
|
|
|
pixels + y * rowstride, rowstride);
|
|
|
|
memcpy (pixels + y * rowstride,
|
|
|
|
pixels + (height - y - 1) * rowstride, rowstride);
|
|
|
|
memcpy (pixels + (height - y - 1) * rowstride,
|
|
|
|
temprow,
|
|
|
|
rowstride);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_cogl_bitmap_unmap (bitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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
|
2012-03-19 10:18:25 -04:00
|
|
|
cogl_framebuffer_read_pixels (CoglFramebuffer *framebuffer,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglPixelFormat format,
|
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
|
|
|
uint8_t *pixels)
|
2012-03-19 10:18:25 -04:00
|
|
|
{
|
|
|
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
|
|
|
|
CoglBitmap *bitmap;
|
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 ret;
|
2012-03-19 10:18:25 -04:00
|
|
|
|
|
|
|
bitmap = cogl_bitmap_new_for_data (framebuffer->context,
|
|
|
|
width, height,
|
|
|
|
format,
|
|
|
|
bpp * width, /* rowstride */
|
|
|
|
pixels);
|
|
|
|
ret = cogl_framebuffer_read_pixels_into_bitmap (framebuffer,
|
|
|
|
x, y,
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
|
|
|
bitmap);
|
|
|
|
cogl_object_unref (bitmap);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-02-05 06:19:52 -05:00
|
|
|
void
|
|
|
|
_cogl_blit_framebuffer (unsigned int src_x,
|
|
|
|
unsigned int src_y,
|
|
|
|
unsigned int dst_x,
|
|
|
|
unsigned int dst_y,
|
|
|
|
unsigned int width,
|
|
|
|
unsigned int height)
|
|
|
|
{
|
|
|
|
CoglFramebuffer *draw_buffer;
|
|
|
|
CoglFramebuffer *read_buffer;
|
2011-02-22 12:58:47 -05:00
|
|
|
CoglContext *ctx;
|
2011-02-05 06:19:52 -05:00
|
|
|
|
2010-11-05 08:28:33 -04:00
|
|
|
/* FIXME: this function should take explit src and dst framebuffer
|
|
|
|
* arguments. */
|
2011-03-10 16:33:31 -05:00
|
|
|
draw_buffer = cogl_get_draw_framebuffer ();
|
|
|
|
read_buffer = _cogl_get_read_framebuffer ();
|
2011-02-22 12:58:47 -05:00
|
|
|
ctx = draw_buffer->context;
|
2011-02-05 06:19:52 -05:00
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (ctx->private_feature_flags &
|
2011-10-12 17:47:42 -04:00
|
|
|
COGL_PRIVATE_FEATURE_OFFSCREEN_BLIT);
|
|
|
|
|
2011-02-05 06:19:52 -05:00
|
|
|
/* We can only support blitting between offscreen buffers because
|
|
|
|
otherwise we would need to mirror the image and GLES2.0 doesn't
|
|
|
|
support this */
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_offscreen (draw_buffer));
|
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_offscreen (read_buffer));
|
2011-02-05 06:19:52 -05:00
|
|
|
/* The buffers must be the same format */
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (draw_buffer->format == read_buffer->format);
|
2011-02-05 06:19:52 -05:00
|
|
|
|
|
|
|
/* Make sure the current framebuffers are bound. We explicitly avoid
|
|
|
|
flushing the clip state so we can bind our own empty state */
|
2011-03-10 16:33:31 -05:00
|
|
|
_cogl_framebuffer_flush_state (cogl_get_draw_framebuffer (),
|
|
|
|
_cogl_get_read_framebuffer (),
|
2011-11-21 10:53:40 -05:00
|
|
|
COGL_FRAMEBUFFER_STATE_ALL &
|
|
|
|
~COGL_FRAMEBUFFER_STATE_CLIP);
|
2011-02-05 06:19:52 -05:00
|
|
|
|
|
|
|
/* Flush any empty clip stack because glBlitFramebuffer is affected
|
|
|
|
by the scissor and we want to hide this feature for the Cogl API
|
|
|
|
because it's not obvious to an app how the clip state will affect
|
|
|
|
the scissor */
|
2011-08-03 12:06:10 -04:00
|
|
|
_cogl_clip_stack_flush (NULL, draw_buffer);
|
2011-02-05 06:19:52 -05:00
|
|
|
|
2011-11-21 10:53:40 -05:00
|
|
|
/* XXX: Because we are manually flushing clip state here we need to
|
|
|
|
* make sure that the clip state gets updated the next time we flush
|
|
|
|
* framebuffer state by marking the current framebuffer's clip state
|
|
|
|
* as changed */
|
|
|
|
ctx->current_draw_buffer_changes |= COGL_FRAMEBUFFER_STATE_CLIP;
|
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
ctx->glBlitFramebuffer (src_x, src_y,
|
2011-02-05 06:19:52 -05:00
|
|
|
src_x + width, src_y + height,
|
|
|
|
dst_x, dst_y,
|
|
|
|
dst_x + width, dst_y + height,
|
|
|
|
GL_COLOR_BUFFER_BIT,
|
|
|
|
GL_NEAREST);
|
|
|
|
}
|
2010-11-05 08:28:33 -04:00
|
|
|
|
2011-08-19 10:53:59 -04:00
|
|
|
void
|
|
|
|
cogl_framebuffer_discard_buffers (CoglFramebuffer *framebuffer,
|
|
|
|
unsigned long buffers)
|
|
|
|
{
|
2012-08-31 19:04:00 -04:00
|
|
|
CoglContext *ctx = framebuffer->context;
|
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (buffers & COGL_BUFFER_BIT_COLOR);
|
2011-08-19 10:53:59 -04:00
|
|
|
|
2012-08-31 19:04:00 -04:00
|
|
|
ctx->driver_vtable->framebuffer_discard_buffers (framebuffer, buffers);
|
2011-08-19 10:53:59 -04:00
|
|
|
}
|
|
|
|
|
2011-09-28 10:19:38 -04:00
|
|
|
void
|
|
|
|
cogl_framebuffer_finish (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
2012-08-31 19:04:00 -04:00
|
|
|
CoglContext *ctx = framebuffer->context;
|
|
|
|
|
2011-09-28 10:19:38 -04:00
|
|
|
_cogl_framebuffer_flush_journal (framebuffer);
|
2012-08-31 19:04:00 -04:00
|
|
|
|
|
|
|
ctx->driver_vtable->framebuffer_finish (framebuffer);
|
2011-09-28 10:19:38 -04:00
|
|
|
}
|
2011-11-18 07:23:49 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_push_matrix (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
CoglMatrixStack *modelview_stack =
|
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
|
|
|
_cogl_matrix_stack_push (modelview_stack);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_MODELVIEW;
|
2011-11-18 07:23:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_pop_matrix (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
CoglMatrixStack *modelview_stack =
|
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
|
|
|
_cogl_matrix_stack_pop (modelview_stack);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_MODELVIEW;
|
2011-11-18 07:23:49 -05:00
|
|
|
}
|
|
|
|
|
2011-11-20 13:42:58 -05:00
|
|
|
void
|
|
|
|
cogl_framebuffer_identity_matrix (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
CoglMatrixStack *modelview_stack =
|
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
|
|
|
_cogl_matrix_stack_load_identity (modelview_stack);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_MODELVIEW;
|
2011-11-20 13:42:58 -05:00
|
|
|
}
|
|
|
|
|
2011-11-18 07:23:49 -05:00
|
|
|
void
|
|
|
|
cogl_framebuffer_scale (CoglFramebuffer *framebuffer,
|
|
|
|
float x,
|
|
|
|
float y,
|
|
|
|
float z)
|
|
|
|
{
|
|
|
|
CoglMatrixStack *modelview_stack =
|
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
|
|
|
_cogl_matrix_stack_scale (modelview_stack, x, y, z);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_MODELVIEW;
|
2011-11-18 07:23:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_translate (CoglFramebuffer *framebuffer,
|
|
|
|
float x,
|
|
|
|
float y,
|
|
|
|
float z)
|
|
|
|
{
|
|
|
|
CoglMatrixStack *modelview_stack =
|
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
|
|
|
_cogl_matrix_stack_translate (modelview_stack, x, y, z);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_MODELVIEW;
|
2011-11-18 07:23:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_rotate (CoglFramebuffer *framebuffer,
|
|
|
|
float angle,
|
|
|
|
float x,
|
|
|
|
float y,
|
|
|
|
float z)
|
|
|
|
{
|
|
|
|
CoglMatrixStack *modelview_stack =
|
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
|
|
|
_cogl_matrix_stack_rotate (modelview_stack, angle, x, y, z);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
2012-05-17 17:22:01 -04:00
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_MODELVIEW;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_rotate_quaternion (CoglFramebuffer *framebuffer,
|
|
|
|
const CoglQuaternion *quaternion)
|
|
|
|
{
|
|
|
|
CoglMatrixStack *modelview_stack =
|
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
|
|
|
_cogl_matrix_stack_rotate_quaternion (modelview_stack, quaternion);
|
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_MODELVIEW;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_rotate_euler (CoglFramebuffer *framebuffer,
|
|
|
|
const CoglEuler *euler)
|
|
|
|
{
|
|
|
|
CoglMatrixStack *modelview_stack =
|
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
|
|
|
_cogl_matrix_stack_rotate_euler (modelview_stack, euler);
|
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
2011-11-21 10:53:40 -05:00
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_MODELVIEW;
|
2011-11-18 07:23:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_transform (CoglFramebuffer *framebuffer,
|
|
|
|
const CoglMatrix *matrix)
|
|
|
|
{
|
|
|
|
CoglMatrixStack *modelview_stack =
|
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
|
|
|
_cogl_matrix_stack_multiply (modelview_stack, matrix);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_MODELVIEW;
|
2011-11-18 07:23:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_perspective (CoglFramebuffer *framebuffer,
|
|
|
|
float fov_y,
|
|
|
|
float aspect,
|
|
|
|
float z_near,
|
|
|
|
float z_far)
|
|
|
|
{
|
|
|
|
float ymax = z_near * tanf (fov_y * G_PI / 360.0);
|
|
|
|
|
|
|
|
cogl_framebuffer_frustum (framebuffer,
|
|
|
|
-ymax * aspect, /* left */
|
|
|
|
ymax * aspect, /* right */
|
|
|
|
-ymax, /* bottom */
|
|
|
|
ymax, /* top */
|
|
|
|
z_near,
|
|
|
|
z_far);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_PROJECTION;
|
2011-11-18 07:23:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_frustum (CoglFramebuffer *framebuffer,
|
|
|
|
float left,
|
|
|
|
float right,
|
|
|
|
float bottom,
|
|
|
|
float top,
|
|
|
|
float z_near,
|
|
|
|
float z_far)
|
|
|
|
{
|
|
|
|
CoglMatrixStack *projection_stack =
|
|
|
|
_cogl_framebuffer_get_projection_stack (framebuffer);
|
|
|
|
|
|
|
|
/* XXX: The projection matrix isn't currently tracked in the journal
|
|
|
|
* so we need to flush all journaled primitives first... */
|
|
|
|
_cogl_framebuffer_flush_journal (framebuffer);
|
|
|
|
|
|
|
|
_cogl_matrix_stack_load_identity (projection_stack);
|
|
|
|
|
|
|
|
_cogl_matrix_stack_frustum (projection_stack,
|
|
|
|
left,
|
|
|
|
right,
|
|
|
|
bottom,
|
|
|
|
top,
|
|
|
|
z_near,
|
|
|
|
z_far);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_PROJECTION;
|
2011-11-18 07:23:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_orthographic (CoglFramebuffer *framebuffer,
|
|
|
|
float x_1,
|
|
|
|
float y_1,
|
|
|
|
float x_2,
|
|
|
|
float y_2,
|
|
|
|
float near,
|
|
|
|
float far)
|
|
|
|
{
|
|
|
|
CoglMatrix ortho;
|
|
|
|
CoglMatrixStack *projection_stack =
|
|
|
|
_cogl_framebuffer_get_projection_stack (framebuffer);
|
|
|
|
|
|
|
|
/* XXX: The projection matrix isn't currently tracked in the journal
|
|
|
|
* so we need to flush all journaled primitives first... */
|
|
|
|
_cogl_framebuffer_flush_journal (framebuffer);
|
|
|
|
|
|
|
|
cogl_matrix_init_identity (&ortho);
|
|
|
|
cogl_matrix_orthographic (&ortho, x_1, y_1, x_2, y_2, near, far);
|
|
|
|
_cogl_matrix_stack_set (projection_stack, &ortho);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_PROJECTION;
|
2011-11-18 07:23:49 -05:00
|
|
|
}
|
|
|
|
|
2011-11-20 13:50:29 -05:00
|
|
|
void
|
|
|
|
_cogl_framebuffer_push_projection (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
CoglMatrixStack *projection_stack =
|
|
|
|
_cogl_framebuffer_get_projection_stack (framebuffer);
|
|
|
|
_cogl_matrix_stack_push (projection_stack);
|
|
|
|
|
2011-11-21 10:53:40 -05:00
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_PROJECTION;
|
2011-11-20 13:50:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_framebuffer_pop_projection (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
CoglMatrixStack *projection_stack =
|
|
|
|
_cogl_framebuffer_get_projection_stack (framebuffer);
|
|
|
|
_cogl_matrix_stack_pop (projection_stack);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_PROJECTION;
|
2011-11-20 13:50:29 -05:00
|
|
|
}
|
|
|
|
|
2011-11-18 07:23:49 -05:00
|
|
|
void
|
|
|
|
cogl_framebuffer_get_modelview_matrix (CoglFramebuffer *framebuffer,
|
|
|
|
CoglMatrix *matrix)
|
|
|
|
{
|
Re-design the matrix stack using a graph of ops
This re-designs the matrix stack so we now keep track of each separate
operation such as rotating, scaling, translating and multiplying as
immutable, ref-counted nodes in a graph.
Being a "graph" here means that different transformations composed of
a sequence of linked operation nodes may share nodes.
The first node in a matrix-stack is always a LOAD_IDENTITY operation.
As an example consider if an application where to draw three rectangles
A, B and C something like this:
cogl_framebuffer_scale (fb, 2, 2, 2);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_translate (fb, 10, 0, 0);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_rotate (fb, 45, 0, 0, 1);
cogl_framebuffer_draw_rectangle (...); /* A */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_draw_rectangle (...); /* B */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_set_modelview_matrix (fb, &mv);
cogl_framebuffer_draw_rectangle (...); /* C */
cogl_framebuffer_pop_matrix(fb);
That would result in a graph of nodes like this:
LOAD_IDENTITY
|
SCALE
/ \
SAVE LOAD
| |
TRANSLATE RECTANGLE(C)
| \
SAVE RECTANGLE(B)
|
ROTATE
|
RECTANGLE(A)
Each push adds a SAVE operation which serves as a marker to rewind too
when a corresponding pop is issued and also each SAVE node may also
store a cached matrix representing the composition of all its ancestor
nodes. This means if we repeatedly need to resolve a real CoglMatrix
for a given node then we don't need to repeat the composition.
Some advantages of this design are:
- A single pointer to any node in the graph can now represent a
complete, immutable transformation that can be logged for example
into a journal. Previously we were storing a full CoglMatrix in
each journal entry which is 16 floats for the matrix itself as well
as space for flags and another 16 floats for possibly storing a
cache of the inverse. This means that we significantly reduce
the size of the journal when drawing lots of primitives and we also
avoid copying over 128 bytes per entry.
- It becomes much cheaper to check for equality. In cases where some
(unlikely) false negatives are allowed simply comparing the pointers
of two matrix stack graph entries is enough. Previously we would use
memcmp() to compare matrices.
- It becomes easier to do comparisons of transformations. By looking
for the common ancestry between nodes we can determine the operations
that differentiate the transforms and use those to gain a high level
understanding of the differences. For example we use this in the
journal to be able to efficiently determine when two rectangle
transforms only differ by some translation so that we can perform
software clipping.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit f75aee93f6b293ca7a7babbd8fcc326ee6bf7aef)
2012-02-20 10:59:48 -05:00
|
|
|
CoglMatrixEntry *modelview_entry =
|
|
|
|
_cogl_framebuffer_get_modelview_entry (framebuffer);
|
|
|
|
_cogl_matrix_entry_get (modelview_entry, matrix);
|
2011-11-18 07:23:49 -05:00
|
|
|
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_set_modelview_matrix (CoglFramebuffer *framebuffer,
|
2012-08-14 12:53:02 -04:00
|
|
|
const CoglMatrix *matrix)
|
2011-11-18 07:23:49 -05:00
|
|
|
{
|
|
|
|
CoglMatrixStack *modelview_stack =
|
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
|
|
|
_cogl_matrix_stack_set (modelview_stack, matrix);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_MODELVIEW;
|
|
|
|
|
2011-11-18 07:23:49 -05:00
|
|
|
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_get_projection_matrix (CoglFramebuffer *framebuffer,
|
|
|
|
CoglMatrix *matrix)
|
|
|
|
{
|
Re-design the matrix stack using a graph of ops
This re-designs the matrix stack so we now keep track of each separate
operation such as rotating, scaling, translating and multiplying as
immutable, ref-counted nodes in a graph.
Being a "graph" here means that different transformations composed of
a sequence of linked operation nodes may share nodes.
The first node in a matrix-stack is always a LOAD_IDENTITY operation.
As an example consider if an application where to draw three rectangles
A, B and C something like this:
cogl_framebuffer_scale (fb, 2, 2, 2);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_translate (fb, 10, 0, 0);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_rotate (fb, 45, 0, 0, 1);
cogl_framebuffer_draw_rectangle (...); /* A */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_draw_rectangle (...); /* B */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_set_modelview_matrix (fb, &mv);
cogl_framebuffer_draw_rectangle (...); /* C */
cogl_framebuffer_pop_matrix(fb);
That would result in a graph of nodes like this:
LOAD_IDENTITY
|
SCALE
/ \
SAVE LOAD
| |
TRANSLATE RECTANGLE(C)
| \
SAVE RECTANGLE(B)
|
ROTATE
|
RECTANGLE(A)
Each push adds a SAVE operation which serves as a marker to rewind too
when a corresponding pop is issued and also each SAVE node may also
store a cached matrix representing the composition of all its ancestor
nodes. This means if we repeatedly need to resolve a real CoglMatrix
for a given node then we don't need to repeat the composition.
Some advantages of this design are:
- A single pointer to any node in the graph can now represent a
complete, immutable transformation that can be logged for example
into a journal. Previously we were storing a full CoglMatrix in
each journal entry which is 16 floats for the matrix itself as well
as space for flags and another 16 floats for possibly storing a
cache of the inverse. This means that we significantly reduce
the size of the journal when drawing lots of primitives and we also
avoid copying over 128 bytes per entry.
- It becomes much cheaper to check for equality. In cases where some
(unlikely) false negatives are allowed simply comparing the pointers
of two matrix stack graph entries is enough. Previously we would use
memcmp() to compare matrices.
- It becomes easier to do comparisons of transformations. By looking
for the common ancestry between nodes we can determine the operations
that differentiate the transforms and use those to gain a high level
understanding of the differences. For example we use this in the
journal to be able to efficiently determine when two rectangle
transforms only differ by some translation so that we can perform
software clipping.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit f75aee93f6b293ca7a7babbd8fcc326ee6bf7aef)
2012-02-20 10:59:48 -05:00
|
|
|
CoglMatrixEntry *projection_entry =
|
|
|
|
_cogl_framebuffer_get_projection_entry (framebuffer);
|
|
|
|
_cogl_matrix_entry_get (projection_entry, matrix);
|
2011-11-18 07:23:49 -05:00
|
|
|
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_set_projection_matrix (CoglFramebuffer *framebuffer,
|
2012-08-14 12:53:02 -04:00
|
|
|
const CoglMatrix *matrix)
|
2011-11-18 07:23:49 -05:00
|
|
|
{
|
|
|
|
CoglMatrixStack *projection_stack =
|
|
|
|
_cogl_framebuffer_get_projection_stack (framebuffer);
|
|
|
|
|
|
|
|
/* XXX: The projection matrix isn't currently tracked in the journal
|
|
|
|
* so we need to flush all journaled primitives first... */
|
|
|
|
_cogl_framebuffer_flush_journal (framebuffer);
|
|
|
|
|
|
|
|
_cogl_matrix_stack_set (projection_stack, matrix);
|
|
|
|
|
2011-11-21 10:53:40 -05:00
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_PROJECTION;
|
|
|
|
|
2011-11-18 07:23:49 -05:00
|
|
|
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
|
|
|
}
|
2011-11-18 07:25:38 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_push_scissor_clip (CoglFramebuffer *framebuffer,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
|
|
|
CoglClipState *clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
|
|
|
|
|
|
|
clip_state->stacks->data =
|
|
|
|
_cogl_clip_stack_push_window_rectangle (clip_state->stacks->data,
|
|
|
|
x, y, width, height);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_CLIP;
|
2011-11-18 07:25:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_push_rectangle_clip (CoglFramebuffer *framebuffer,
|
|
|
|
float x_1,
|
|
|
|
float y_1,
|
|
|
|
float x_2,
|
|
|
|
float y_2)
|
|
|
|
{
|
|
|
|
CoglClipState *clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
Re-design the matrix stack using a graph of ops
This re-designs the matrix stack so we now keep track of each separate
operation such as rotating, scaling, translating and multiplying as
immutable, ref-counted nodes in a graph.
Being a "graph" here means that different transformations composed of
a sequence of linked operation nodes may share nodes.
The first node in a matrix-stack is always a LOAD_IDENTITY operation.
As an example consider if an application where to draw three rectangles
A, B and C something like this:
cogl_framebuffer_scale (fb, 2, 2, 2);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_translate (fb, 10, 0, 0);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_rotate (fb, 45, 0, 0, 1);
cogl_framebuffer_draw_rectangle (...); /* A */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_draw_rectangle (...); /* B */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_set_modelview_matrix (fb, &mv);
cogl_framebuffer_draw_rectangle (...); /* C */
cogl_framebuffer_pop_matrix(fb);
That would result in a graph of nodes like this:
LOAD_IDENTITY
|
SCALE
/ \
SAVE LOAD
| |
TRANSLATE RECTANGLE(C)
| \
SAVE RECTANGLE(B)
|
ROTATE
|
RECTANGLE(A)
Each push adds a SAVE operation which serves as a marker to rewind too
when a corresponding pop is issued and also each SAVE node may also
store a cached matrix representing the composition of all its ancestor
nodes. This means if we repeatedly need to resolve a real CoglMatrix
for a given node then we don't need to repeat the composition.
Some advantages of this design are:
- A single pointer to any node in the graph can now represent a
complete, immutable transformation that can be logged for example
into a journal. Previously we were storing a full CoglMatrix in
each journal entry which is 16 floats for the matrix itself as well
as space for flags and another 16 floats for possibly storing a
cache of the inverse. This means that we significantly reduce
the size of the journal when drawing lots of primitives and we also
avoid copying over 128 bytes per entry.
- It becomes much cheaper to check for equality. In cases where some
(unlikely) false negatives are allowed simply comparing the pointers
of two matrix stack graph entries is enough. Previously we would use
memcmp() to compare matrices.
- It becomes easier to do comparisons of transformations. By looking
for the common ancestry between nodes we can determine the operations
that differentiate the transforms and use those to gain a high level
understanding of the differences. For example we use this in the
journal to be able to efficiently determine when two rectangle
transforms only differ by some translation so that we can perform
software clipping.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit f75aee93f6b293ca7a7babbd8fcc326ee6bf7aef)
2012-02-20 10:59:48 -05:00
|
|
|
CoglMatrixEntry *modelview_entry =
|
|
|
|
_cogl_framebuffer_get_modelview_entry (framebuffer);
|
|
|
|
CoglMatrixEntry *projection_entry =
|
|
|
|
_cogl_framebuffer_get_projection_entry (framebuffer);
|
|
|
|
/* XXX: It would be nicer if we stored the private viewport as a
|
|
|
|
* vec4 so we could avoid this redundant copy. */
|
|
|
|
float viewport[] = {
|
|
|
|
framebuffer->viewport_x,
|
|
|
|
framebuffer->viewport_y,
|
|
|
|
framebuffer->viewport_width,
|
|
|
|
framebuffer->viewport_height
|
|
|
|
};
|
2011-11-18 07:25:38 -05:00
|
|
|
|
|
|
|
clip_state->stacks->data =
|
|
|
|
_cogl_clip_stack_push_rectangle (clip_state->stacks->data,
|
|
|
|
x_1, y_1, x_2, y_2,
|
Re-design the matrix stack using a graph of ops
This re-designs the matrix stack so we now keep track of each separate
operation such as rotating, scaling, translating and multiplying as
immutable, ref-counted nodes in a graph.
Being a "graph" here means that different transformations composed of
a sequence of linked operation nodes may share nodes.
The first node in a matrix-stack is always a LOAD_IDENTITY operation.
As an example consider if an application where to draw three rectangles
A, B and C something like this:
cogl_framebuffer_scale (fb, 2, 2, 2);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_translate (fb, 10, 0, 0);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_rotate (fb, 45, 0, 0, 1);
cogl_framebuffer_draw_rectangle (...); /* A */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_draw_rectangle (...); /* B */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_set_modelview_matrix (fb, &mv);
cogl_framebuffer_draw_rectangle (...); /* C */
cogl_framebuffer_pop_matrix(fb);
That would result in a graph of nodes like this:
LOAD_IDENTITY
|
SCALE
/ \
SAVE LOAD
| |
TRANSLATE RECTANGLE(C)
| \
SAVE RECTANGLE(B)
|
ROTATE
|
RECTANGLE(A)
Each push adds a SAVE operation which serves as a marker to rewind too
when a corresponding pop is issued and also each SAVE node may also
store a cached matrix representing the composition of all its ancestor
nodes. This means if we repeatedly need to resolve a real CoglMatrix
for a given node then we don't need to repeat the composition.
Some advantages of this design are:
- A single pointer to any node in the graph can now represent a
complete, immutable transformation that can be logged for example
into a journal. Previously we were storing a full CoglMatrix in
each journal entry which is 16 floats for the matrix itself as well
as space for flags and another 16 floats for possibly storing a
cache of the inverse. This means that we significantly reduce
the size of the journal when drawing lots of primitives and we also
avoid copying over 128 bytes per entry.
- It becomes much cheaper to check for equality. In cases where some
(unlikely) false negatives are allowed simply comparing the pointers
of two matrix stack graph entries is enough. Previously we would use
memcmp() to compare matrices.
- It becomes easier to do comparisons of transformations. By looking
for the common ancestry between nodes we can determine the operations
that differentiate the transforms and use those to gain a high level
understanding of the differences. For example we use this in the
journal to be able to efficiently determine when two rectangle
transforms only differ by some translation so that we can perform
software clipping.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit f75aee93f6b293ca7a7babbd8fcc326ee6bf7aef)
2012-02-20 10:59:48 -05:00
|
|
|
modelview_entry,
|
|
|
|
projection_entry,
|
|
|
|
viewport);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_CLIP;
|
2011-11-18 07:25:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_push_path_clip (CoglFramebuffer *framebuffer,
|
|
|
|
CoglPath *path)
|
|
|
|
{
|
|
|
|
CoglClipState *clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
Re-design the matrix stack using a graph of ops
This re-designs the matrix stack so we now keep track of each separate
operation such as rotating, scaling, translating and multiplying as
immutable, ref-counted nodes in a graph.
Being a "graph" here means that different transformations composed of
a sequence of linked operation nodes may share nodes.
The first node in a matrix-stack is always a LOAD_IDENTITY operation.
As an example consider if an application where to draw three rectangles
A, B and C something like this:
cogl_framebuffer_scale (fb, 2, 2, 2);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_translate (fb, 10, 0, 0);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_rotate (fb, 45, 0, 0, 1);
cogl_framebuffer_draw_rectangle (...); /* A */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_draw_rectangle (...); /* B */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_set_modelview_matrix (fb, &mv);
cogl_framebuffer_draw_rectangle (...); /* C */
cogl_framebuffer_pop_matrix(fb);
That would result in a graph of nodes like this:
LOAD_IDENTITY
|
SCALE
/ \
SAVE LOAD
| |
TRANSLATE RECTANGLE(C)
| \
SAVE RECTANGLE(B)
|
ROTATE
|
RECTANGLE(A)
Each push adds a SAVE operation which serves as a marker to rewind too
when a corresponding pop is issued and also each SAVE node may also
store a cached matrix representing the composition of all its ancestor
nodes. This means if we repeatedly need to resolve a real CoglMatrix
for a given node then we don't need to repeat the composition.
Some advantages of this design are:
- A single pointer to any node in the graph can now represent a
complete, immutable transformation that can be logged for example
into a journal. Previously we were storing a full CoglMatrix in
each journal entry which is 16 floats for the matrix itself as well
as space for flags and another 16 floats for possibly storing a
cache of the inverse. This means that we significantly reduce
the size of the journal when drawing lots of primitives and we also
avoid copying over 128 bytes per entry.
- It becomes much cheaper to check for equality. In cases where some
(unlikely) false negatives are allowed simply comparing the pointers
of two matrix stack graph entries is enough. Previously we would use
memcmp() to compare matrices.
- It becomes easier to do comparisons of transformations. By looking
for the common ancestry between nodes we can determine the operations
that differentiate the transforms and use those to gain a high level
understanding of the differences. For example we use this in the
journal to be able to efficiently determine when two rectangle
transforms only differ by some translation so that we can perform
software clipping.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit f75aee93f6b293ca7a7babbd8fcc326ee6bf7aef)
2012-02-20 10:59:48 -05:00
|
|
|
CoglMatrixEntry *modelview_entry =
|
|
|
|
_cogl_framebuffer_get_modelview_entry (framebuffer);
|
|
|
|
CoglMatrixEntry *projection_entry =
|
|
|
|
_cogl_framebuffer_get_projection_entry (framebuffer);
|
|
|
|
/* XXX: It would be nicer if we stored the private viewport as a
|
|
|
|
* vec4 so we could avoid this redundant copy. */
|
|
|
|
float viewport[] = {
|
|
|
|
framebuffer->viewport_x,
|
|
|
|
framebuffer->viewport_y,
|
|
|
|
framebuffer->viewport_width,
|
|
|
|
framebuffer->viewport_height
|
|
|
|
};
|
2011-11-18 07:25:38 -05:00
|
|
|
|
|
|
|
clip_state->stacks->data =
|
|
|
|
_cogl_clip_stack_push_from_path (clip_state->stacks->data,
|
|
|
|
path,
|
Re-design the matrix stack using a graph of ops
This re-designs the matrix stack so we now keep track of each separate
operation such as rotating, scaling, translating and multiplying as
immutable, ref-counted nodes in a graph.
Being a "graph" here means that different transformations composed of
a sequence of linked operation nodes may share nodes.
The first node in a matrix-stack is always a LOAD_IDENTITY operation.
As an example consider if an application where to draw three rectangles
A, B and C something like this:
cogl_framebuffer_scale (fb, 2, 2, 2);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_translate (fb, 10, 0, 0);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_rotate (fb, 45, 0, 0, 1);
cogl_framebuffer_draw_rectangle (...); /* A */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_draw_rectangle (...); /* B */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_set_modelview_matrix (fb, &mv);
cogl_framebuffer_draw_rectangle (...); /* C */
cogl_framebuffer_pop_matrix(fb);
That would result in a graph of nodes like this:
LOAD_IDENTITY
|
SCALE
/ \
SAVE LOAD
| |
TRANSLATE RECTANGLE(C)
| \
SAVE RECTANGLE(B)
|
ROTATE
|
RECTANGLE(A)
Each push adds a SAVE operation which serves as a marker to rewind too
when a corresponding pop is issued and also each SAVE node may also
store a cached matrix representing the composition of all its ancestor
nodes. This means if we repeatedly need to resolve a real CoglMatrix
for a given node then we don't need to repeat the composition.
Some advantages of this design are:
- A single pointer to any node in the graph can now represent a
complete, immutable transformation that can be logged for example
into a journal. Previously we were storing a full CoglMatrix in
each journal entry which is 16 floats for the matrix itself as well
as space for flags and another 16 floats for possibly storing a
cache of the inverse. This means that we significantly reduce
the size of the journal when drawing lots of primitives and we also
avoid copying over 128 bytes per entry.
- It becomes much cheaper to check for equality. In cases where some
(unlikely) false negatives are allowed simply comparing the pointers
of two matrix stack graph entries is enough. Previously we would use
memcmp() to compare matrices.
- It becomes easier to do comparisons of transformations. By looking
for the common ancestry between nodes we can determine the operations
that differentiate the transforms and use those to gain a high level
understanding of the differences. For example we use this in the
journal to be able to efficiently determine when two rectangle
transforms only differ by some translation so that we can perform
software clipping.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit f75aee93f6b293ca7a7babbd8fcc326ee6bf7aef)
2012-02-20 10:59:48 -05:00
|
|
|
modelview_entry,
|
|
|
|
projection_entry,
|
|
|
|
viewport);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_CLIP;
|
2011-11-18 07:25:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_push_primitive_clip (CoglFramebuffer *framebuffer,
|
|
|
|
CoglPrimitive *primitive,
|
|
|
|
float bounds_x1,
|
|
|
|
float bounds_y1,
|
|
|
|
float bounds_x2,
|
|
|
|
float bounds_y2)
|
|
|
|
{
|
|
|
|
CoglClipState *clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
Re-design the matrix stack using a graph of ops
This re-designs the matrix stack so we now keep track of each separate
operation such as rotating, scaling, translating and multiplying as
immutable, ref-counted nodes in a graph.
Being a "graph" here means that different transformations composed of
a sequence of linked operation nodes may share nodes.
The first node in a matrix-stack is always a LOAD_IDENTITY operation.
As an example consider if an application where to draw three rectangles
A, B and C something like this:
cogl_framebuffer_scale (fb, 2, 2, 2);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_translate (fb, 10, 0, 0);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_rotate (fb, 45, 0, 0, 1);
cogl_framebuffer_draw_rectangle (...); /* A */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_draw_rectangle (...); /* B */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_set_modelview_matrix (fb, &mv);
cogl_framebuffer_draw_rectangle (...); /* C */
cogl_framebuffer_pop_matrix(fb);
That would result in a graph of nodes like this:
LOAD_IDENTITY
|
SCALE
/ \
SAVE LOAD
| |
TRANSLATE RECTANGLE(C)
| \
SAVE RECTANGLE(B)
|
ROTATE
|
RECTANGLE(A)
Each push adds a SAVE operation which serves as a marker to rewind too
when a corresponding pop is issued and also each SAVE node may also
store a cached matrix representing the composition of all its ancestor
nodes. This means if we repeatedly need to resolve a real CoglMatrix
for a given node then we don't need to repeat the composition.
Some advantages of this design are:
- A single pointer to any node in the graph can now represent a
complete, immutable transformation that can be logged for example
into a journal. Previously we were storing a full CoglMatrix in
each journal entry which is 16 floats for the matrix itself as well
as space for flags and another 16 floats for possibly storing a
cache of the inverse. This means that we significantly reduce
the size of the journal when drawing lots of primitives and we also
avoid copying over 128 bytes per entry.
- It becomes much cheaper to check for equality. In cases where some
(unlikely) false negatives are allowed simply comparing the pointers
of two matrix stack graph entries is enough. Previously we would use
memcmp() to compare matrices.
- It becomes easier to do comparisons of transformations. By looking
for the common ancestry between nodes we can determine the operations
that differentiate the transforms and use those to gain a high level
understanding of the differences. For example we use this in the
journal to be able to efficiently determine when two rectangle
transforms only differ by some translation so that we can perform
software clipping.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit f75aee93f6b293ca7a7babbd8fcc326ee6bf7aef)
2012-02-20 10:59:48 -05:00
|
|
|
CoglMatrixEntry *modelview_entry =
|
|
|
|
_cogl_framebuffer_get_modelview_entry (framebuffer);
|
|
|
|
CoglMatrixEntry *projection_entry =
|
|
|
|
_cogl_framebuffer_get_projection_entry (framebuffer);
|
|
|
|
/* XXX: It would be nicer if we stored the private viewport as a
|
|
|
|
* vec4 so we could avoid this redundant copy. */
|
|
|
|
float viewport[] = {
|
|
|
|
framebuffer->viewport_x,
|
|
|
|
framebuffer->viewport_y,
|
|
|
|
framebuffer->viewport_width,
|
|
|
|
framebuffer->viewport_height
|
|
|
|
};
|
2011-11-18 07:25:38 -05:00
|
|
|
|
|
|
|
clip_state->stacks->data =
|
|
|
|
_cogl_clip_stack_push_primitive (clip_state->stacks->data,
|
|
|
|
primitive,
|
|
|
|
bounds_x1, bounds_y1,
|
|
|
|
bounds_x2, bounds_y2,
|
Re-design the matrix stack using a graph of ops
This re-designs the matrix stack so we now keep track of each separate
operation such as rotating, scaling, translating and multiplying as
immutable, ref-counted nodes in a graph.
Being a "graph" here means that different transformations composed of
a sequence of linked operation nodes may share nodes.
The first node in a matrix-stack is always a LOAD_IDENTITY operation.
As an example consider if an application where to draw three rectangles
A, B and C something like this:
cogl_framebuffer_scale (fb, 2, 2, 2);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_translate (fb, 10, 0, 0);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_rotate (fb, 45, 0, 0, 1);
cogl_framebuffer_draw_rectangle (...); /* A */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_draw_rectangle (...); /* B */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_set_modelview_matrix (fb, &mv);
cogl_framebuffer_draw_rectangle (...); /* C */
cogl_framebuffer_pop_matrix(fb);
That would result in a graph of nodes like this:
LOAD_IDENTITY
|
SCALE
/ \
SAVE LOAD
| |
TRANSLATE RECTANGLE(C)
| \
SAVE RECTANGLE(B)
|
ROTATE
|
RECTANGLE(A)
Each push adds a SAVE operation which serves as a marker to rewind too
when a corresponding pop is issued and also each SAVE node may also
store a cached matrix representing the composition of all its ancestor
nodes. This means if we repeatedly need to resolve a real CoglMatrix
for a given node then we don't need to repeat the composition.
Some advantages of this design are:
- A single pointer to any node in the graph can now represent a
complete, immutable transformation that can be logged for example
into a journal. Previously we were storing a full CoglMatrix in
each journal entry which is 16 floats for the matrix itself as well
as space for flags and another 16 floats for possibly storing a
cache of the inverse. This means that we significantly reduce
the size of the journal when drawing lots of primitives and we also
avoid copying over 128 bytes per entry.
- It becomes much cheaper to check for equality. In cases where some
(unlikely) false negatives are allowed simply comparing the pointers
of two matrix stack graph entries is enough. Previously we would use
memcmp() to compare matrices.
- It becomes easier to do comparisons of transformations. By looking
for the common ancestry between nodes we can determine the operations
that differentiate the transforms and use those to gain a high level
understanding of the differences. For example we use this in the
journal to be able to efficiently determine when two rectangle
transforms only differ by some translation so that we can perform
software clipping.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit f75aee93f6b293ca7a7babbd8fcc326ee6bf7aef)
2012-02-20 10:59:48 -05:00
|
|
|
modelview_entry,
|
|
|
|
projection_entry,
|
|
|
|
viewport);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_CLIP;
|
2011-11-18 07:25:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_pop_clip (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
CoglClipState *clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
|
|
|
|
|
|
|
clip_state->stacks->data = _cogl_clip_stack_pop (clip_state->stacks->data);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_CLIP;
|
2011-11-18 07:25:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_framebuffer_save_clip_stack (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
CoglClipState *clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
|
|
|
_cogl_clip_state_save_clip_stack (clip_state);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_CLIP;
|
2011-11-18 07:25:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_framebuffer_restore_clip_stack (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
CoglClipState *clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
|
|
|
_cogl_clip_state_restore_clip_stack (clip_state);
|
2011-11-21 10:53:40 -05:00
|
|
|
|
|
|
|
if (framebuffer->context->current_draw_buffer == framebuffer)
|
|
|
|
framebuffer->context->current_draw_buffer_changes |=
|
|
|
|
COGL_FRAMEBUFFER_STATE_CLIP;
|
2011-11-18 07:25:38 -05:00
|
|
|
}
|
2012-01-24 13:16:03 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_framebuffer_unref (CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
/* The journal holds a reference to the framebuffer whenever it is
|
|
|
|
non-empty. Therefore if the journal is non-empty and we will have
|
|
|
|
exactly one reference then we know the journal is the only thing
|
|
|
|
keeping the framebuffer alive. In that case we want to flush the
|
|
|
|
journal and let the framebuffer die. It is fine at this point if
|
|
|
|
flushing the journal causes something else to take a reference to
|
|
|
|
it and it comes back to life */
|
|
|
|
if (framebuffer->journal->entries->len > 0)
|
|
|
|
{
|
|
|
|
unsigned int ref_count = ((CoglObject *) framebuffer)->ref_count;
|
|
|
|
|
|
|
|
/* There should be at least two references - the one we are
|
|
|
|
about to drop and the one held by the journal */
|
|
|
|
if (ref_count < 2)
|
|
|
|
g_warning ("Inconsistent ref count on a framebuffer with journal "
|
|
|
|
"entries.");
|
|
|
|
|
|
|
|
if (ref_count == 2)
|
|
|
|
_cogl_framebuffer_flush_journal (framebuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Chain-up */
|
|
|
|
_cogl_object_default_unref (framebuffer);
|
|
|
|
}
|
2012-01-07 21:59:04 -05:00
|
|
|
|
|
|
|
#ifdef COGL_ENABLE_DEBUG
|
|
|
|
static int
|
|
|
|
get_index (void *indices,
|
|
|
|
CoglIndicesType type,
|
|
|
|
int _index)
|
|
|
|
{
|
|
|
|
if (!indices)
|
|
|
|
return _index;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case COGL_INDICES_TYPE_UNSIGNED_BYTE:
|
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
|
|
|
return ((uint8_t *)indices)[_index];
|
2012-01-07 21:59:04 -05:00
|
|
|
case COGL_INDICES_TYPE_UNSIGNED_SHORT:
|
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
|
|
|
return ((uint16_t *)indices)[_index];
|
2012-01-07 21:59:04 -05:00
|
|
|
case COGL_INDICES_TYPE_UNSIGNED_INT:
|
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
|
|
|
return ((uint32_t *)indices)[_index];
|
2012-01-07 21:59:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
g_return_val_if_reached (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
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
|
|
|
add_line (uint32_t *line_indices,
|
2012-02-19 17:50:57 -05:00
|
|
|
int base,
|
|
|
|
void *user_indices,
|
|
|
|
CoglIndicesType user_indices_type,
|
|
|
|
int index0,
|
|
|
|
int index1,
|
|
|
|
int *pos)
|
|
|
|
{
|
|
|
|
index0 = get_index (user_indices, user_indices_type, index0);
|
|
|
|
index1 = get_index (user_indices, user_indices_type, index1);
|
2012-01-07 21:59:04 -05:00
|
|
|
|
2012-02-19 17:50:57 -05:00
|
|
|
line_indices[(*pos)++] = base + index0;
|
|
|
|
line_indices[(*pos)++] = base + index1;
|
|
|
|
}
|
2012-01-07 21:59:04 -05:00
|
|
|
|
2012-02-19 17:50:57 -05:00
|
|
|
static int
|
|
|
|
get_line_count (CoglVerticesMode mode, int n_vertices)
|
|
|
|
{
|
|
|
|
if (mode == COGL_VERTICES_MODE_TRIANGLES &&
|
|
|
|
(n_vertices % 3) == 0)
|
|
|
|
{
|
|
|
|
return n_vertices;
|
|
|
|
}
|
|
|
|
else if (mode == COGL_VERTICES_MODE_TRIANGLE_FAN &&
|
|
|
|
n_vertices >= 3)
|
|
|
|
{
|
|
|
|
return 2 * n_vertices - 3;
|
|
|
|
}
|
|
|
|
else if (mode == COGL_VERTICES_MODE_TRIANGLE_STRIP &&
|
|
|
|
n_vertices >= 3)
|
|
|
|
{
|
|
|
|
return 2 * n_vertices - 3;
|
|
|
|
}
|
|
|
|
/* In the journal we are a bit sneaky and actually use GL_QUADS
|
|
|
|
* which isn't actually a valid CoglVerticesMode! */
|
|
|
|
#ifdef HAVE_COGL_GL
|
|
|
|
else if (mode == GL_QUADS && (n_vertices % 4) == 0)
|
|
|
|
{
|
|
|
|
return n_vertices;
|
|
|
|
}
|
|
|
|
#endif
|
2012-01-07 21:59:04 -05:00
|
|
|
|
2012-02-19 17:50:57 -05:00
|
|
|
g_return_val_if_reached (0);
|
2012-01-07 21:59:04 -05:00
|
|
|
}
|
|
|
|
|
2012-02-19 17:50:57 -05:00
|
|
|
static CoglIndices *
|
|
|
|
get_wire_line_indices (CoglContext *ctx,
|
|
|
|
CoglVerticesMode mode,
|
|
|
|
int first_vertex,
|
|
|
|
int n_vertices_in,
|
|
|
|
CoglIndices *user_indices,
|
|
|
|
int *n_indices)
|
2012-01-07 21:59:04 -05:00
|
|
|
{
|
2012-02-19 17:50:57 -05:00
|
|
|
int n_lines;
|
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
|
|
|
uint32_t *line_indices;
|
2012-01-07 21:59:04 -05:00
|
|
|
CoglIndexBuffer *index_buffer;
|
|
|
|
void *indices;
|
|
|
|
CoglIndicesType indices_type;
|
2012-02-19 17:50:57 -05:00
|
|
|
int base = first_vertex;
|
|
|
|
int pos;
|
2012-01-07 21:59:04 -05:00
|
|
|
int i;
|
2012-02-19 17:50:57 -05:00
|
|
|
CoglIndices *ret;
|
2012-01-07 21:59:04 -05:00
|
|
|
|
2012-02-19 17:50:57 -05:00
|
|
|
if (user_indices)
|
2012-01-07 21:59:04 -05:00
|
|
|
{
|
2012-02-19 17:50:57 -05:00
|
|
|
index_buffer = cogl_indices_get_buffer (user_indices);
|
2012-01-07 21:59:04 -05:00
|
|
|
indices = cogl_buffer_map (COGL_BUFFER (index_buffer),
|
|
|
|
COGL_BUFFER_ACCESS_READ, 0);
|
2012-02-19 17:50:57 -05:00
|
|
|
indices_type = cogl_indices_get_type (user_indices);
|
2012-01-07 21:59:04 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
index_buffer = NULL;
|
|
|
|
indices = NULL;
|
|
|
|
indices_type = COGL_INDICES_TYPE_UNSIGNED_BYTE;
|
|
|
|
}
|
|
|
|
|
2012-02-19 17:50:57 -05:00
|
|
|
n_lines = get_line_count (mode, n_vertices_in);
|
|
|
|
|
|
|
|
/* Note: we are using COGL_INDICES_TYPE_UNSIGNED_INT so 4 bytes per index. */
|
|
|
|
line_indices = g_malloc (4 * n_lines * 2);
|
|
|
|
|
|
|
|
pos = 0;
|
2012-01-07 21:59:04 -05:00
|
|
|
|
|
|
|
if (mode == COGL_VERTICES_MODE_TRIANGLES &&
|
|
|
|
(n_vertices_in % 3) == 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < n_vertices_in; i += 3)
|
|
|
|
{
|
2012-02-19 17:50:57 -05:00
|
|
|
add_line (line_indices, base, indices, indices_type, i, i+1, &pos);
|
|
|
|
add_line (line_indices, base, indices, indices_type, i+1, i+2, &pos);
|
|
|
|
add_line (line_indices, base, indices, indices_type, i+2, i, &pos);
|
2012-01-07 21:59:04 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mode == COGL_VERTICES_MODE_TRIANGLE_FAN &&
|
|
|
|
n_vertices_in >= 3)
|
|
|
|
{
|
2012-02-19 17:50:57 -05:00
|
|
|
add_line (line_indices, base, indices, indices_type, 0, 1, &pos);
|
|
|
|
add_line (line_indices, base, indices, indices_type, 1, 2, &pos);
|
|
|
|
add_line (line_indices, base, indices, indices_type, 0, 2, &pos);
|
2012-01-07 21:59:04 -05:00
|
|
|
|
|
|
|
for (i = 3; i < n_vertices_in; i++)
|
|
|
|
{
|
2012-02-19 17:50:57 -05:00
|
|
|
add_line (line_indices, base, indices, indices_type, i - 1, i, &pos);
|
|
|
|
add_line (line_indices, base, indices, indices_type, 0, i, &pos);
|
2012-01-07 21:59:04 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mode == COGL_VERTICES_MODE_TRIANGLE_STRIP &&
|
|
|
|
n_vertices_in >= 3)
|
|
|
|
{
|
2012-02-19 17:50:57 -05:00
|
|
|
add_line (line_indices, base, indices, indices_type, 0, 1, &pos);
|
|
|
|
add_line (line_indices, base, indices, indices_type, 1, 2, &pos);
|
|
|
|
add_line (line_indices, base, indices, indices_type, 0, 2, &pos);
|
2012-01-07 21:59:04 -05:00
|
|
|
|
|
|
|
for (i = 3; i < n_vertices_in; i++)
|
|
|
|
{
|
2012-02-19 17:50:57 -05:00
|
|
|
add_line (line_indices, base, indices, indices_type, i - 1, i, &pos);
|
|
|
|
add_line (line_indices, base, indices, indices_type, i - 2, i, &pos);
|
2012-01-07 21:59:04 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* In the journal we are a bit sneaky and actually use GL_QUADS
|
|
|
|
* which isn't actually a valid CoglVerticesMode! */
|
|
|
|
#ifdef HAVE_COGL_GL
|
|
|
|
else if (mode == GL_QUADS && (n_vertices_in % 4) == 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < n_vertices_in; i += 4)
|
|
|
|
{
|
2012-02-19 17:50:57 -05:00
|
|
|
add_line (line_indices,
|
|
|
|
base, indices, indices_type, i, i + 1, &pos);
|
|
|
|
add_line (line_indices,
|
|
|
|
base, indices, indices_type, i + 1, i + 2, &pos);
|
|
|
|
add_line (line_indices,
|
|
|
|
base, indices, indices_type, i + 2, i + 3, &pos);
|
|
|
|
add_line (line_indices,
|
|
|
|
base, indices, indices_type, i + 3, i, &pos);
|
2012-01-07 21:59:04 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-02-19 17:50:57 -05:00
|
|
|
if (user_indices)
|
2012-01-07 21:59:04 -05:00
|
|
|
cogl_buffer_unmap (COGL_BUFFER (index_buffer));
|
|
|
|
|
2012-02-19 17:50:57 -05:00
|
|
|
*n_indices = n_lines * 2;
|
|
|
|
|
|
|
|
ret = cogl_indices_new (ctx,
|
|
|
|
COGL_INDICES_TYPE_UNSIGNED_INT,
|
|
|
|
line_indices,
|
|
|
|
*n_indices);
|
|
|
|
|
|
|
|
g_free (line_indices);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static CoglBool
|
2012-02-19 17:50:57 -05:00
|
|
|
remove_layer_cb (CoglPipeline *pipeline,
|
|
|
|
int layer_index,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
cogl_pipeline_remove_layer (pipeline, layer_index);
|
|
|
|
return TRUE;
|
2012-01-07 21:59:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-19 17:50:57 -05:00
|
|
|
pipeline_destroyed_cb (CoglPipeline *weak_pipeline, void *user_data)
|
|
|
|
{
|
|
|
|
CoglPipeline *original_pipeline = user_data;
|
|
|
|
|
|
|
|
/* XXX: I think we probably need to provide a custom unref function for
|
|
|
|
* CoglPipeline because it's possible that we will reach this callback
|
|
|
|
* because original_pipeline is being freed which means cogl_object_unref
|
|
|
|
* will have already freed any associated user data.
|
|
|
|
*
|
|
|
|
* Setting more user data here will *probably* succeed but that may allocate
|
|
|
|
* a new user-data array which could be leaked.
|
|
|
|
*
|
|
|
|
* Potentially we could have a _cogl_object_free_user_data function so
|
|
|
|
* that a custom unref function could be written that can destroy weak
|
|
|
|
* pipeline children before removing user data.
|
|
|
|
*/
|
|
|
|
cogl_object_set_user_data (COGL_OBJECT (original_pipeline),
|
|
|
|
&wire_pipeline_key, NULL, NULL);
|
|
|
|
|
|
|
|
cogl_object_unref (weak_pipeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_wireframe (CoglContext *ctx,
|
|
|
|
CoglFramebuffer *framebuffer,
|
2012-01-07 21:59:04 -05:00
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglVerticesMode mode,
|
|
|
|
int first_vertex,
|
|
|
|
int n_vertices,
|
|
|
|
CoglAttribute **attributes,
|
|
|
|
int n_attributes,
|
2012-05-19 17:47:28 -04:00
|
|
|
CoglIndices *indices,
|
|
|
|
CoglDrawFlags flags)
|
2012-01-07 21:59:04 -05:00
|
|
|
{
|
2012-02-19 17:50:57 -05:00
|
|
|
CoglIndices *wire_indices;
|
|
|
|
CoglPipeline *wire_pipeline;
|
|
|
|
int n_indices;
|
2012-01-07 21:59:04 -05:00
|
|
|
|
2012-02-19 17:50:57 -05:00
|
|
|
wire_indices = get_wire_line_indices (ctx,
|
|
|
|
mode,
|
|
|
|
first_vertex,
|
|
|
|
n_vertices,
|
|
|
|
indices,
|
|
|
|
&n_indices);
|
2012-01-07 21:59:04 -05:00
|
|
|
|
2012-02-19 17:50:57 -05:00
|
|
|
wire_pipeline = cogl_object_get_user_data (COGL_OBJECT (pipeline),
|
|
|
|
&wire_pipeline_key);
|
2012-01-07 21:59:04 -05:00
|
|
|
|
|
|
|
if (!wire_pipeline)
|
|
|
|
{
|
2012-02-19 17:50:57 -05:00
|
|
|
wire_pipeline =
|
|
|
|
_cogl_pipeline_weak_copy (pipeline, pipeline_destroyed_cb, NULL);
|
|
|
|
|
|
|
|
cogl_object_set_user_data (COGL_OBJECT (pipeline),
|
|
|
|
&wire_pipeline_key, wire_pipeline,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* If we have glsl then the pipeline may have an associated
|
|
|
|
* vertex program and since we'd like to see the results of the
|
|
|
|
* vertex program in the wireframe we just add a final clobber
|
|
|
|
* of the wire color leaving the rest of the state untouched. */
|
|
|
|
if (cogl_has_feature (framebuffer->context, COGL_FEATURE_ID_GLSL))
|
|
|
|
{
|
2012-05-19 18:07:17 -04:00
|
|
|
static CoglSnippet *snippet = NULL;
|
|
|
|
|
|
|
|
/* The snippet is cached so that it will reuse the program
|
|
|
|
* from the pipeline cache if possible */
|
|
|
|
if (snippet == NULL)
|
|
|
|
{
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
cogl_snippet_set_replace (snippet,
|
|
|
|
"cogl_color_out = "
|
|
|
|
"vec4 (0.0, 1.0, 0.0, 1.0);\n");
|
|
|
|
}
|
2012-02-19 17:50:57 -05:00
|
|
|
|
|
|
|
cogl_pipeline_add_snippet (wire_pipeline, snippet);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cogl_pipeline_foreach_layer (wire_pipeline, remove_layer_cb, NULL);
|
|
|
|
cogl_pipeline_set_color4f (wire_pipeline, 0, 1, 0, 1);
|
|
|
|
}
|
2012-01-07 21:59:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* temporarily disable the wireframe to avoid recursion! */
|
2012-05-19 17:47:28 -04:00
|
|
|
flags |= COGL_DRAW_SKIP_DEBUG_WIREFRAME;
|
2012-02-19 17:50:57 -05:00
|
|
|
_cogl_framebuffer_draw_indexed_attributes (
|
|
|
|
framebuffer,
|
|
|
|
wire_pipeline,
|
|
|
|
COGL_VERTICES_MODE_LINES,
|
|
|
|
0,
|
|
|
|
n_indices,
|
|
|
|
wire_indices,
|
|
|
|
attributes,
|
|
|
|
n_attributes,
|
2012-05-19 17:47:28 -04:00
|
|
|
flags);
|
2012-01-07 21:59:04 -05:00
|
|
|
COGL_DEBUG_SET_FLAG (COGL_DEBUG_WIREFRAME);
|
|
|
|
|
2012-02-19 17:50:57 -05:00
|
|
|
cogl_object_unref (wire_indices);
|
2012-01-07 21:59:04 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* This can be called directly by the CoglJournal to draw attributes
|
|
|
|
* skipping the implicit journal flush, the framebuffer flush and
|
|
|
|
* pipeline validation. */
|
|
|
|
void
|
|
|
|
_cogl_framebuffer_draw_attributes (CoglFramebuffer *framebuffer,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglVerticesMode mode,
|
|
|
|
int first_vertex,
|
|
|
|
int n_vertices,
|
|
|
|
CoglAttribute **attributes,
|
|
|
|
int n_attributes,
|
|
|
|
CoglDrawFlags flags)
|
|
|
|
{
|
|
|
|
#ifdef COGL_ENABLE_DEBUG
|
2012-05-19 17:47:28 -04:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_WIREFRAME) &&
|
2012-07-09 13:03:33 -04:00
|
|
|
(flags & COGL_DRAW_SKIP_DEBUG_WIREFRAME) == 0) &&
|
|
|
|
mode != COGL_VERTICES_MODE_LINES &&
|
|
|
|
mode != COGL_VERTICES_MODE_LINE_LOOP &&
|
|
|
|
mode != COGL_VERTICES_MODE_LINE_STRIP)
|
2012-02-19 17:50:57 -05:00
|
|
|
draw_wireframe (framebuffer->context,
|
|
|
|
framebuffer, pipeline,
|
2012-01-07 21:59:04 -05:00
|
|
|
mode, first_vertex, n_vertices,
|
2012-05-19 17:47:28 -04:00
|
|
|
attributes, n_attributes, NULL,
|
|
|
|
flags);
|
2012-01-09 06:57:01 -05:00
|
|
|
else
|
2012-01-07 21:59:04 -05:00
|
|
|
#endif
|
2012-01-09 06:57:01 -05:00
|
|
|
{
|
2012-08-31 19:04:00 -04:00
|
|
|
CoglContext *ctx = framebuffer->context;
|
|
|
|
|
|
|
|
ctx->driver_vtable->framebuffer_draw_attributes (framebuffer,
|
|
|
|
pipeline,
|
|
|
|
mode,
|
|
|
|
first_vertex,
|
|
|
|
n_vertices,
|
|
|
|
attributes,
|
|
|
|
n_attributes,
|
|
|
|
flags);
|
2012-01-09 06:57:01 -05:00
|
|
|
}
|
2012-01-07 21:59:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_draw_attributes (CoglFramebuffer *framebuffer,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglVerticesMode mode,
|
|
|
|
int first_vertex,
|
|
|
|
int n_vertices,
|
|
|
|
CoglAttribute **attributes,
|
|
|
|
int n_attributes)
|
|
|
|
{
|
|
|
|
_cogl_framebuffer_draw_attributes (framebuffer,
|
|
|
|
pipeline,
|
|
|
|
mode,
|
|
|
|
first_vertex,
|
|
|
|
n_vertices,
|
|
|
|
attributes, n_attributes,
|
|
|
|
COGL_DRAW_SKIP_LEGACY_STATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_vdraw_attributes (CoglFramebuffer *framebuffer,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglVerticesMode mode,
|
|
|
|
int first_vertex,
|
|
|
|
int n_vertices,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int n_attributes;
|
|
|
|
CoglAttribute *attribute;
|
|
|
|
CoglAttribute **attributes;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
va_start (ap, n_vertices);
|
|
|
|
for (n_attributes = 0; va_arg (ap, CoglAttribute *); n_attributes++)
|
|
|
|
;
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
attributes = g_alloca (sizeof (CoglAttribute *) * n_attributes);
|
|
|
|
|
|
|
|
va_start (ap, n_vertices);
|
|
|
|
for (i = 0; (attribute = va_arg (ap, CoglAttribute *)); i++)
|
|
|
|
attributes[i] = attribute;
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
_cogl_framebuffer_draw_attributes (framebuffer,
|
|
|
|
pipeline,
|
|
|
|
mode, first_vertex, n_vertices,
|
|
|
|
attributes, n_attributes,
|
|
|
|
COGL_DRAW_SKIP_LEGACY_STATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_framebuffer_draw_indexed_attributes (CoglFramebuffer *framebuffer,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglVerticesMode mode,
|
|
|
|
int first_vertex,
|
|
|
|
int n_vertices,
|
|
|
|
CoglIndices *indices,
|
|
|
|
CoglAttribute **attributes,
|
|
|
|
int n_attributes,
|
|
|
|
CoglDrawFlags flags)
|
|
|
|
{
|
|
|
|
#ifdef COGL_ENABLE_DEBUG
|
2012-05-19 17:47:28 -04:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_WIREFRAME) &&
|
2012-07-09 13:03:33 -04:00
|
|
|
(flags & COGL_DRAW_SKIP_DEBUG_WIREFRAME) == 0) &&
|
|
|
|
mode != COGL_VERTICES_MODE_LINES &&
|
|
|
|
mode != COGL_VERTICES_MODE_LINE_LOOP &&
|
|
|
|
mode != COGL_VERTICES_MODE_LINE_STRIP)
|
2012-02-19 17:50:57 -05:00
|
|
|
draw_wireframe (framebuffer->context,
|
|
|
|
framebuffer, pipeline,
|
2012-01-07 21:59:04 -05:00
|
|
|
mode, first_vertex, n_vertices,
|
2012-05-19 17:47:28 -04:00
|
|
|
attributes, n_attributes, indices,
|
|
|
|
flags);
|
2012-01-09 06:57:01 -05:00
|
|
|
else
|
2012-01-07 21:59:04 -05:00
|
|
|
#endif
|
2012-01-09 06:57:01 -05:00
|
|
|
{
|
2012-08-31 19:04:00 -04:00
|
|
|
CoglContext *ctx = framebuffer->context;
|
|
|
|
|
|
|
|
ctx->driver_vtable->framebuffer_draw_indexed_attributes (framebuffer,
|
|
|
|
pipeline,
|
|
|
|
mode,
|
|
|
|
first_vertex,
|
|
|
|
n_vertices,
|
|
|
|
indices,
|
|
|
|
attributes,
|
|
|
|
n_attributes,
|
|
|
|
flags);
|
2012-01-09 06:57:01 -05:00
|
|
|
}
|
2012-01-07 21:59:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_draw_indexed_attributes (CoglFramebuffer *framebuffer,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglVerticesMode mode,
|
|
|
|
int first_vertex,
|
|
|
|
int n_vertices,
|
|
|
|
CoglIndices *indices,
|
|
|
|
CoglAttribute **attributes,
|
|
|
|
int n_attributes)
|
|
|
|
{
|
|
|
|
_cogl_framebuffer_draw_indexed_attributes (framebuffer,
|
|
|
|
pipeline,
|
|
|
|
mode, first_vertex,
|
|
|
|
n_vertices, indices,
|
|
|
|
attributes, n_attributes,
|
|
|
|
COGL_DRAW_SKIP_LEGACY_STATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-06 13:21:28 -05:00
|
|
|
cogl_framebuffer_vdraw_indexed_attributes (CoglFramebuffer *framebuffer,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglVerticesMode mode,
|
|
|
|
int first_vertex,
|
|
|
|
int n_vertices,
|
|
|
|
CoglIndices *indices,
|
|
|
|
...)
|
2012-01-07 21:59:04 -05:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int n_attributes;
|
|
|
|
CoglAttribute **attributes;
|
|
|
|
int i;
|
|
|
|
CoglAttribute *attribute;
|
|
|
|
|
|
|
|
va_start (ap, indices);
|
|
|
|
for (n_attributes = 0; va_arg (ap, CoglAttribute *); n_attributes++)
|
|
|
|
;
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
attributes = g_alloca (sizeof (CoglAttribute *) * n_attributes);
|
|
|
|
|
|
|
|
va_start (ap, indices);
|
|
|
|
for (i = 0; (attribute = va_arg (ap, CoglAttribute *)); i++)
|
|
|
|
attributes[i] = attribute;
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
_cogl_framebuffer_draw_indexed_attributes (framebuffer,
|
|
|
|
pipeline,
|
|
|
|
mode,
|
|
|
|
first_vertex,
|
|
|
|
n_vertices,
|
|
|
|
indices,
|
|
|
|
attributes,
|
|
|
|
n_attributes,
|
|
|
|
COGL_DRAW_SKIP_LEGACY_STATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_framebuffer_draw_primitive (CoglFramebuffer *framebuffer,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglPrimitive *primitive,
|
|
|
|
CoglDrawFlags flags)
|
|
|
|
{
|
|
|
|
if (primitive->indices)
|
|
|
|
_cogl_framebuffer_draw_indexed_attributes (framebuffer,
|
|
|
|
pipeline,
|
|
|
|
primitive->mode,
|
|
|
|
primitive->first_vertex,
|
|
|
|
primitive->n_vertices,
|
|
|
|
primitive->indices,
|
|
|
|
primitive->attributes,
|
|
|
|
primitive->n_attributes,
|
|
|
|
flags);
|
|
|
|
else
|
|
|
|
_cogl_framebuffer_draw_attributes (framebuffer,
|
|
|
|
pipeline,
|
|
|
|
primitive->mode,
|
|
|
|
primitive->first_vertex,
|
|
|
|
primitive->n_vertices,
|
|
|
|
primitive->attributes,
|
|
|
|
primitive->n_attributes,
|
|
|
|
flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_draw_primitive (CoglFramebuffer *framebuffer,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglPrimitive *primitive)
|
|
|
|
{
|
|
|
|
_cogl_framebuffer_draw_primitive (framebuffer, pipeline, primitive,
|
|
|
|
COGL_DRAW_SKIP_LEGACY_STATE);
|
|
|
|
}
|
2012-03-16 15:54:13 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2012-04-18 10:57:33 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_fill_path (CoglFramebuffer *framebuffer,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglPath *path)
|
|
|
|
{
|
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_framebuffer (framebuffer));
|
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_pipeline (pipeline));
|
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_path (path));
|
|
|
|
|
|
|
|
_cogl_path_fill_nodes (path, framebuffer, pipeline, 0 /* flags */);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_framebuffer_stroke_path (CoglFramebuffer *framebuffer,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglPath *path)
|
|
|
|
{
|
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_framebuffer (framebuffer));
|
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_pipeline (pipeline));
|
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_path (path));
|
|
|
|
|
|
|
|
_cogl_path_stroke_nodes (path, framebuffer, pipeline);
|
|
|
|
}
|