Commit Graph

2454 Commits

Author SHA1 Message Date
Robert Bragg
c52d878032 [cogl-primitives] Get rid of driver specific cogl-primitives code
These files were practically identical, except the gles code had additional
support for filling paths without a stencil buffer.  All the driver code has
now been moved into cogl/cogl-primitives.c
2009-11-04 16:02:34 +00:00
Emmanuele Bassi
8ba13d6495 script: Clean up Color parsing rules
All the ClutterColor parsing rules should be coalesced inside
clutter_script_parse_color(): object, array and string notations
are the canonical ways of defining a ClutterColor inside a
ClutterScript definition. Having a single function in charge of
the parsing cleans up the code.
2009-11-04 15:21:03 +00:00
Emmanuele Bassi
3e815de32b script: Simplify boxed types parsing
We should use the typed accessors for complex JSON types, and
be more liberal in what we accept.
2009-11-04 15:20:12 +00:00
Emmanuele Bassi
4df59d330c script: Separate construction from properties application
Currently, ClutterScriptParser will construct the object (using the
construct-only and construct parameters), apply the properties from
the ClutterScript definition, and eventuall will add children and
behaviours.

The construction phase should be more compartimentalized: the objects
should be constructed first and eventual children and behaviours
added. Then, once an object is requested or when the parsing process
has terminated, all the properties should be applied.

This change allows us to set up the actors before setting their
non-construct properties.
2009-11-04 14:18:43 +00:00
Emmanuele Bassi
31e5dadb68 script: Move all parser code inside ClutterScriptParser
ClutterScript is currently a mix of parser-related code and
the ClutterScript object. All the parser-related code should
be moved inside a private class, ClutterScriptParser, inheriting
from JsonParser.
2009-11-04 13:32:26 +00:00
Emmanuele Bassi
6e571928a4 script: Take a copy of property nodes
Instead of counting on a JsonNode pointer to survive we should take
a copy. This allows keeping unresolved properties across different
ClutterScript passes.
2009-11-04 10:43:11 +00:00
Emmanuele Bassi
4ad57aa3e4 script: Use JsonObject direct accessors
Instead of getting the JsonNode for a member of which we mandate
the type we can use the typed accessors of JsonObject.
2009-11-04 10:43:11 +00:00
Robert Bragg
fec13f6202 [cogl-texture-2d-sliced] allow COGL_FORMAT_ANY with _new_with_size()
It's useful when initialzing offscreen draw buffers to be able to ask
Cogl to create a texture of a given size and with the default internal
pixel format.
2009-11-04 03:34:07 +00:00
Robert Bragg
ae57c30e93 [texture] fix rounding when calculating update_fbo viewport offset
When rendering to an fbo for supporting clutter_texture_new_from_actor we
render to an fbo with the same size as the source actor, but with a viewport
the same size as the stage.  We offset the viewport so when we render the
source actor in its normal transformed stage position it lands on the fbo.
Previously we were rounding the transformed position given as a float by
truncating the fraction (just using a C cast) but that resulted in an
incorrect pixel offset when rendering offscreen depending on the source
position.

We now simply + 0.5 before casting (or -0.5 for negative numbers)
2009-11-04 03:34:07 +00:00
Robert Bragg
309f852efb [texture] switch to a new design for handling offscreen rendering
For supporting clutter_texture_new_from_actor(): when updating a
ClutterTexture's fbo we previously set up an offset frustum in the
perspective matrix before rendering source actors to an offscreen draw
buffer so as to give a perspective as if it were being drawn at its
original stage location.

Now that Cogl supports offset viewports there is a simpler way...

When we come to render the source actor to our offscreen draw buffer we
now copy the projection matrix from the stage; we create a viewport
that's also the same size as the stage (though larger than the offscreen
draw buffer) and as before we apply the modelview transformations of
the source actors ancestry before painting it.

The only trick we need now is to offset the viewport according to the
transformed (to screen space) allocation of the source actor (something we
required previously too).  We negatively offset the stage sized viewport
such that the smaller offscreen draw buffer is positioned to sit underneath
the source actor in stage coordinates.
2009-11-04 03:34:07 +00:00
Robert Bragg
94a6028358 [texture] split out fbo update code from cluter_texture_paint
To help keep clutter_texture_paint maintainable this splits out a big
chunk of standalone code that's responsible for updating the fbo when
clutter_texture_new_from_actor has been used.
2009-11-04 03:34:06 +00:00
Robert Bragg
2762e6d9b9 [texture] push/pop draw buffer when painting actors to a texture
When updating the FBO for a source actor (to support
clutter_texture_new_from_actor()) we used to simply set an offscreen draw
buffer to be current, paint the source actor and then explicitly set the
window to be current again.  This precluded chaining texture_new_from_actor
though because updating another FBO associated with a source actor would end
up restoring the window as the current buffer instead of the previous
offscreen buffer.  Now that we use Cogl's draw buffer stack; chaining
clutter_texture_new_from_actor() should be possible.
2009-11-04 03:34:06 +00:00
Robert Bragg
c7d229585f [texture] Avoid redundant use of cogl_clip_stack_save when drawing offscreen
Since cogl draw buffers now own their clip state the stage's clip state will
automatically be saved and restored via the cogl_set_draw_buffer API.
2009-11-04 03:34:06 +00:00
Robert Bragg
90dbae5aa9 [cogl-draw-buffer] fix Cogl -> GL viewport coord conversion
Before we call glViewport we need to convert Cogl viewport coordinates
(where the origin is defined to be top left) to OpenGL coordinates
(where the origin is defined to be bottom left)

We weren't considering that offscreen rendering is always upside down
and in this case Cogl coordinates == OpenGL coordinates.
2009-11-04 03:34:05 +00:00
Robert Bragg
149e3e168a [cogl_clip_push_window_rect] fix Cogl -> GL coordinate conversion
Firstly this now uses the draw buffer height not the viewport height
when we need to perform a y = height - y conversion, since (as the
name suggests) we are dealing with window coordinates not viewport
coordinates.

Secondly this skips any conversion when the current draw buffer is an
offscreen draw buffer since offscreen rendering is always forced to be
upside down and in this case Cogl window coordinates == GL window
coordinates.
2009-11-04 03:34:05 +00:00
Robert Bragg
0369a1b84d [matrix] Adds cogl_matrix_get_inverse API
This new API takes advantage of the recently imported Mesa code to support
inverse matrix calculation.  The matrix code keeps track (via internal
flags) of the transformations a matrix represents so that it can select an
optimized inversion function.

Note: although other aspects of the Cogl matrix API have followed a similar
style to Cairo's matrix API we haven't added a cogl_matrix_invert API
because the inverse of a CoglMatrix is actually cached as part of the
CoglMatrix structure meaning a destructive API like cogl_matrix_invert
doesn't let users take advantage of this caching design.
2009-11-04 03:34:05 +00:00
Robert Bragg
8051596e96 [debug] Adds a COGL_DEBUG=matrices debug option
This adds a COGL_DEBUG=matrices debug option that can be used to trace all
matrix manipulation done using the Cogl API.  This can be handy when you
break something in such a way that a trace is still comparable with a
previous working version since you can simply diff a log of the broken
version vs the working version to home in on the bug.
2009-11-04 03:34:04 +00:00
Robert Bragg
eb438dd499 [cogl-matrix] Import Mesa's matrix manipulation code
This pulls in code from Mesa to improve our matrix manipulation support. It
includes support for calculating the inverse of matrices based on top of a
matrix categorizing system that allows optimizing certain matrix types.
(the main thing we were after) but also adds some optimisations for
rotations.

Changes compared to the original code from Mesa:

- Coding style is consistent with the rest of Cogl
- Instead of allocating matrix->m and matrix->inv using malloc, our public
  CoglMatrix typedef is large enough to directly contain the matrix, its
  inverse, a type and a set of flags.
- Instead of having a _math_matrix_analyse which updates the type, flags and
  inverse, we have _math_matrix_update_inverse which essentially does the
  same thing (internally making use of _math_matrix_update_type_and_flags())
  but with additional guards in place to bail out when the inverse matrix is
  still valid.
- When initializing a matrix with the identity matrix we don't immediately
  initialize the inverse matrix; rather we just set the dirty flag for the
  inverse (since it's likely the user won't request the inverse of the
  identity matrix)
2009-11-04 03:34:04 +00:00
Robert Bragg
d38d888f78 [cogl] avoid any state changes when cogl_set_backface_culling_enable is a nop
This is a simple optimization to bail out of cogl_set_backface_culling_enable
if it's not resulting in a change of state.
2009-11-04 03:34:04 +00:00
Robert Bragg
764cca75b4 [cogl] Use clockwise face winding for offscreen buffers with culling enabled
Because Cogl defines the origin for texture as top left and offscreen draw
buffers can be used to render to textures, we (internally) force all
offscreen rendering to be upside down. (because OpenGL defines the origin
to be bottom left)

By forcing the users scene to be rendered upside down though we also reverse
the winding order of all the drawn triangles which may interfere with the
users use of backface culling.  This patch ensures that we reverse the
winding order for a front face (if culling is in use) while rendering
offscreen so we don't conflict with the users back face culling.
2009-11-04 03:34:03 +00:00
Robert Bragg
b2ebb7db48 [main] Use cogl_read_pixels not glReadPixels in clutter-main.c
The debugging function read_pixels_to_file() and _clutter_do_pick were both
directly calling glReadPixels, but we don't wan't Clutter making direct
OpenGL calls and Cogl provides a suitable alternative.  It also means
read_pixels_to_file() doesn't need to manually flip the data read due to
differences in Clutter/Cogl coordinate systems.
2009-11-04 03:34:03 +00:00
Robert Bragg
40b8399d49 [cogl_read_pixels] don't force a 4 byte pack alignment
Technically this change shouldn't make a difference since we are
calling glReadPixels with GL_RGBA GL_UNSIGNED_BYTE which is a 4
byte format and it should always result in the same value according
to how OpenGL calculates the location of sequential rows.

i.e. k  = a/s * ceil(snl/a) where:
 a = alignment
 s = component size (1)
 n = number of components per pixel (4)
 l = number of pixels in a row
gives:
k = 4/1 * ceil(4l/4) and k = 1/1 * ceil(4l/1) which are equivalent

I'm changing it because I've seen i915 driver code that bails out of
hardware accelerated paths if the alignment isn't 1, and because
conceptually we have no alignment constraints here so even if the current
value has no effect, when we start reading back other formats it may upset
things.
2009-11-04 03:34:03 +00:00
Robert Bragg
a222ee22f9 [cogl_read_pixels] call cogl_flush() before changing glPixelStore state
We were previously calling cogl_flush() after setting up the glPixelStore
state for calling glReadPixels, but flushing the journal could itself
change the glPixelStore state.
2009-11-04 03:34:02 +00:00
Robert Bragg
ed431a3c65 [cogl_read_pixels] ensure we flush the current draw buffer state before reading
Make sure we call _cogl_draw_buffer_flush_state() before glReadPixels() to
be sure we have bound the correct framebuffer.
2009-11-04 03:34:02 +00:00
Robert Bragg
b47404c91d [cogl_read_pixels] fixes for calculating the y offset when rendering offscreen
Since offscreen rendering is forced to be upside down we don't need to do
any conversion of the users coordinates to go from Cogl window coordinates
to OpenGL window coordinates.
2009-11-04 03:34:02 +00:00
Robert Bragg
426197f51d [read-pixels] don't flip data when reading from offscreen draw buffers
Since we do all offscreen rendering upside down (so that we can have the
origin for texture coordinates be the top left of textures for the cases
where offscreen draw buffers are bound to textures) we don't need to flip
data read back from an offscreen framebuffer before we we return it to the
user.
2009-11-04 03:34:01 +00:00
Robert Bragg
21322848e0 [clip-stack] tidy up transform_point() code
I was originally expecting the code not to handle offset viewports or
viewports with a different size to the framebuffer, but it turns out the
code worked fine.  In the process though I think I made the code slightly
more readable.
2009-11-04 03:32:52 +00:00
Robert Bragg
8c3a132ecb [cogl] deprecate cogl_viewport() in favour of cogl_set_viewport()
cogl_viewport only accepted a viewport width and height, but there are times
when it's also desireable to have a viewport offset so that a scene can be
translated after projection but before hitting the framebuffer.
2009-11-04 03:23:21 +00:00
Robert Bragg
1e2d88e789 [cogl_read_pixels] use buffer not viewport height to calculate y offset
glReadPixel takes window coordinates not viewport coordinates so we
shouldn't have been assuming that the viewport height == window height.
2009-11-04 03:23:20 +00:00
Robert Bragg
e1630be35a [draw-buffer] Adds cogl_draw_buffer_get_{width,height} API
Simply adds missing API to query the width and height of any Cogl draw buffer.
2009-11-04 03:23:20 +00:00
Robert Bragg
12af275139 [cogl] Make sure Cogl always knows the current window geometry
Because Cogl defines the origin of viewport and window coordinates to be
top-left it always needs to know the size of the current window so that Cogl
window/viewport coordinates can be transformed into OpenGL coordinates.

This also fixes cogl_read_pixels to use the current draw buffer height
instead of the viewport height to determine the OpenGL y coordinate to use
for glReadPixels.
2009-11-04 03:23:20 +00:00
Robert Bragg
e3391b0173 [cogl] Make sure we draw upside down to offscreen draw buffers
First a few notes about Cogl coordinate systems:
- Cogl defines the window origin, viewport origin and texture coordinates
origin to be top left unlike OpenGL which defines them as bottom left.
- Cogl defines the modelview and projection identity matrices in exactly the
same way as OpenGL.
- I.e. we believe that for 2D centric constructs: windows/framebuffers,
viewports and textures developers are more used to dealing with a top left
origin, but when modeling objects in 3D; an origin at the center with y
going up is quite natural.

The way Cogl handles textures is by uploading data upside down in OpenGL
terms so that bottom left becomes top left.  (Note: This also has the
benefit that we don't need to flip the data we get from image decoding
libraries since they typically also consider top left to be the image
origin.)

The viewport and window coords are mostly handled with various y =
height - y tweaks before we pass y coordinates to OpenGL.

Generally speaking though the handling of coordinate spaces in Cogl is a bit
fragile.  I guess partly because none of it was design to be, it just
evolved from how Clutter defines its coordinates without much consideration
or testing.  I hope to improve this over a number of commits; starting here.

This commit deals with the fact that offscreen draw buffers may be bound to
textures but we don't "upload" the texture data upside down, and so if you
texture from an offscreen draw buffer you need to manually flip the texture
coordinates to get it the right way around.  We now force offscreen
rendering to be flipped upside down by tweaking the projection matrix right
before we submit it to OpenGL to scale y by -1.  The tweak is entirely
hidden from the user such that if you call cogl_get_projection you will not
see this scale.
2009-11-04 03:23:19 +00:00
Robert Bragg
8b4c496f2a [cogl] Ensure features are initialized first in cogl_create_context
Previously some context initializing was being done without valid feature
flags.
2009-11-04 03:23:19 +00:00
Robert Bragg
419db4dcfb [clip-stack] Handle flipped rectangles in try_pushing_rect_as_window_rect()
We were ignoring the possibility that the current modelview matrix may flip
the incoming rectangle in which case we didn't calculate a valid scissor
rectangle for clipping.

This fixes: http://bugzilla.o-hand.com/show_bug.cgi?id=1809
(Clipping doesn't work within an FBO)
2009-11-04 03:23:19 +00:00
Robert Bragg
f7d64e5abd [draw-buffers] First pass at overhauling Cogl's framebuffer management
Cogl's support for offscreen rendering was originally written just to support
the clutter_texture_new_from_actor API and due to lack of documentation and
several confusing - non orthogonal - side effects of using the API it wasn't
really possible to use directly.

This commit does a number of things:
- It removes {gl,gles}/cogl-fbo.{c,h} and adds shared cogl-draw-buffer.{c,h}
  files instead which should be easier to maintain.
- internally CoglFbo objects are now called CoglDrawBuffers. A
  CoglDrawBuffer is an abstract base class that is inherited from to
  implement CoglOnscreen and CoglOffscreen draw buffers.  CoglOffscreen draw
  buffers will initially be used to support the
  cogl_offscreen_new_to_texture API, and CoglOnscreen draw buffers will
  start to be used internally to represent windows as we aim to migrate some
  of Clutter's backend code to Cogl.
- It makes draw buffer objects the owners of the following state:
  - viewport
  - projection matrix stack
  - modelview matrix stack
  - clip state
(This means when you switch between draw buffers you will automatically be
 switching to their associated viewport, matrix and clip state)

Aside from hopefully making cogl_offscreen_new_to_texture be more useful
short term by having simpler and well defined semantics for
cogl_set_draw_buffer, as mentioned above this is the first step for a couple
of other things:
- Its a step toward moving ownership for windows down from Clutter backends
  into Cogl, by (internally at least) introducing the CoglOnscreen draw
  buffer.  Note: the plan is that cogl_set_draw_buffer will accept on or
  offscreen draw buffer handles, and the "target" argument will become
  redundant since we will instead query the type of the given draw buffer
  handle.
- Because we have a common type for on and offscreen framebuffers we can
  provide a unified API for framebuffer management. Things like:
  - blitting between buffers
  - managing ancillary buffers (e.g. attaching depth and stencil buffers)
  - size requisition
  - clearing
2009-11-03 17:23:03 +00:00
Robert Bragg
f8f8873714 [stage-x11] Ensure viewport is initialized before first stage paint
This ensures that glViewport is called before the first stage paint.
Previously _clutter_stage_maybe_setup_viewport (which is done before we
start painting) was bailing out without calling cogl_setup_viewport because
the CLUTTER_STAGE_IN_RESIZE flag may be set if the stage was resized before
the first paint.  (NB: The CLUTTER_STAGE_IN_RESIZE flag isn't removed until
we get an explicit event back from the X server since the window manager may
choose to deny/alter the resize.)

We now special case the first resize - where the viewport hasn't previously
been initialized and use the requested geometry to initialize the
glViewport without waiting for a reply from the server.
2009-11-02 16:55:02 +00:00
Robert Bragg
ad98e96d97 [cogl-fbo] Bring the gles code more in line with gl code
Over time the two cogl-fbo.c files have needlessly diverged as bug fixes or
cleanups went into one version but not the other.  This tries to bring them
back in line with each other.  It should actually be simple enough to move
cogl-fbo.c to be a common file, and simply not build it for GLES 1.1, so
maybe I'll follow up with such a patch soon.
2009-11-02 16:55:02 +00:00
Robert Bragg
613977f710 [cogl-fbo] Remove poorly documented workaround for unknown driver/hardware
The comment just said: "Some implementation require a clear before drawing
to an fbo.  Luckily it is affected by scissor test." and did a scissored
clear, which is clearly a driver bug workaround, but for what driver?  The
fact that it was copied into the gles backend (or vica versa is also
suspicious since it seems unlikely that the workaround is necessary for both
backends.)

We can easily restore the workaround with a better comment if this problem
really still exists on current drivers, but for now I'd rather minimize
hand-wavey workaround code that can't be tested.
2009-11-02 16:55:02 +00:00
Damien Lespiau
0599d12ec9 texture: Don't compare fbo_source with COGL_INVALID_HANDLE
fbo_source is a ClutterActor, it should be compared to NULL instead of
COGL_INVALID_HANDLE.
2009-11-02 14:40:43 +00:00
Emmanuele Bassi
f6e0e48ac6 build: Add missing gles/cogl-context-driver.h to dist
The gles/cogl-context-driver.h header file is missing from the
dist target, which means it's not in the tarballs.
2009-10-30 12:11:19 +00:00
Emmanuele Bassi
f551cbfb61 Add run-time version checks
Just like CLUTTER_CHECK_VERSION does version checking at compile
time, we need a way to verify the version of the library that we
are linking against. This is mostly needed for language bindings
and for run-time loadable modules -- when we'll get those.
2009-10-30 11:02:35 +00:00
Neil Roberts
f8e6727e74 [cogl_polygon] Enable COGL_ENABLE_BLEND when use_color is set
Otherwise you can't use the alpha channel of the vertex colors unless
the material has a texture with alpha or the material's color has
alpha less than 255.
2009-10-27 13:18:51 +00:00
Neil Roberts
0c32573ffa build: Add $(top_buiddir)/clutter/cogl to the include path in clutter/cogl/cogl
Some files try to include "cogl/cogl-defines-gl.h" so
$(top_builddir)/clutter/cogl needs to be in the include path for out of
tree builds to work.
2009-10-27 12:53:57 +00:00
Emmanuele Bassi
c387513a5f color: Fix HLS-to-RGB conversion
Apparently, on 64bit systems the floating point noise is enough
to screw up the float-to-int truncation.

The solution is to round up by 0.5 and then use floorf(). This
gives predictable and correct results on both 32bit and 64bit
systems.
2009-10-26 16:29:31 +00:00
Emmanuele Bassi
5a14db5089 layout: Do not create a LayoutMeta on remove
When calling remove_child_meta() we check if there is a LayoutMeta
already attached to the Actor, and if that LayoutMeta matches the
(manager, container, actor) tuple. If the LayoutMeta does not match,
though, we create a new LayoutMeta instance -- in order to remove it
right afterwards.

Instead of doing this, we can simply check for a matching LayoutMeta
and if present, remove it.

In case of an existing, non-matching LayoutMeta, we're left with a
dangling instance, but it does not matter: the removal happens in the
unparenting phase of a ClutterContainer, so either the Actor will be
destroyed and thus the LayoutMeta will be disposed along with it; or
it will be parented to another container, and thus the LayoutMeta
will be replaced.
2009-10-26 16:02:06 +00:00
Emmanuele Bassi
a5a0171cb0 box: Depth level changes should queue a relayout
ClutterBox is not ClutterGroup: a change in the level of an actor
through raise, lower or depth sorting must trigger a relayout.
2009-10-26 15:09:07 +00:00
Emmanuele Bassi
2cad7e24f0 box: Check before using the LayoutManager instance
A ClutterBox might not have a ClutterLayoutManager instance
associated -- for instance, during destruction. We should check
for one before calling methods on it.
2009-10-26 15:08:03 +00:00
Emmanuele Bassi
81c8cf3e6d texture: Error handling fix
When cogl_texture_new_from_data() fails in clutter_texture_set_from_data()
and no GError is provided, the clutter app will segfault when dereferencing
the GError ** and emitting LOAD_FINISHED signal.

Based on a patch by: Haakon Sporsheim <haakon.sporsheim@gmail.com>

http://bugzilla.openedhand.com/show_bug.cgi?id=1806
2009-10-26 11:51:30 +00:00
Emmanuele Bassi
f0b434918b docs: Add images for layout managers
It's easier to show the layout manager policy with a simple
screen shot coming from our interactive tests.
2009-10-23 17:32:18 +01:00
Emmanuele Bassi
924780ce35 cogl: Avoid C99-isms
Do not declare variables after statements.
2009-10-23 16:44:28 +01:00