1
0
Fork 0
Commit graph

945 commits

Author SHA1 Message Date
Neil Roberts
6654533e40 cogl-winsys-wgl: Plug leak on error from SetPixelFormat
When SetPixelFormat fails, the DC would get released but none of the
other resources would be freed. This patch makes it call
_cogl_winsys_onscreen_deinit on failure to clean up all of the
resources. The patch looks big because it moves the onscreen_deinit
and onscreen_bind functions.
2011-05-10 19:53:00 +01:00
Neil Roberts
6788c80342 Add a WGL winsys
This adds a full winsys to handle WGL and Win32.
2011-05-10 17:58:41 +01:00
Neil Roberts
14d1303259 cogl-winsys: Explicitly comment which vfuncs are optional
Some of the virtual functions in CoglWinsysVtable only need to be
implemented for specific backends or when a specific feature is
advertised. This splits the vtable struct into two commented sections
marking which are optional and which are required. Wherever an
optional function is used there is now a g_return_if_fail to ensure
there is an implementation.
2011-05-10 17:15:22 +01:00
Neil Roberts
614efb190b cogl-winsys: Remove the get_vsync_counter virtual
This function is only used internally within the GLX winsys so there
doesn't seem to be much point in it being a virtual winsys backend
function.
2011-05-10 17:13:23 +01:00
Neil Roberts
f2a37b27f9 CoglWinsysVtable: Remove 'has_feature'
This virtual function is no longer used or defined anywhere since the
function was moved to the common backend code in 16bfa27d43.
2011-05-10 17:13:23 +01:00
Robert Bragg
e8b83f2880 Adds wayland support to the cogl EGL winsys
Wayland now supports integration via standard eglSurfaces which makes it
possible to share more code with other EGL platforms. (though at some
point cogl-winsys-egl.c really needs to gain a more formal
CoglEGLPlatform abstraction so we can rein back on the amount of #ifdefs
we have.)
2011-05-10 16:36:40 +01:00
Robert Bragg
4b6169267c winsys-egl: fix typo in _cogl_winsys_onscreen_init
We were trying to set attr.event_mask instead of xattr.event mask which
was causing a compilation error.
2011-05-10 16:36:40 +01:00
Damien Lespiau
62b7ea5972 build: Fix make distcheck
Some header files were split but never included in the list of source
files and thus not distributed.
2011-05-06 17:13:42 +01:00
Emmanuele Bassi
48c9157e97 build: Compile the introspection data
The compilation step for the introspection data was missing.
2011-05-06 16:53:43 +01:00
Robert Bragg
8b4ee0964b Remove all the options for building cogl standalone
This removes all the remnants from being able to build Cogl standalone
while it was part of the Clutter repository. Now that Cogl has been
split out then standalone builds are the only option.
2011-05-06 12:36:39 +01:00
Robert Bragg
6f2193545e consistently refer to cogl-pango as "cogl-pango"
This renames the pango directory to cogl-pango and it renames the
installed library to libcogl-pango instead of libcoglpango.
2011-05-06 12:12:08 +01:00
Robert Bragg
fbda52d21b Give cogl-pango it's own pkg-config file
We now install cogl-pango-1.0 and cogl-pango-2.0 pkg-config files that
applications should optionally depend on if they want to use the
cogl_pango API.
2011-05-06 12:12:08 +01:00
Robert Bragg
680c173947 framebuffer: in onscreen_x11_get_xid return foreign xids
If a foreign xid has been set on a CoglOnscreen then
cogl_onscreen_x11_get_window_xid doesn't need to defer to the winsys to
get the underlying window xid. This also means it's possible to read
back the xid before the framebuffer is allocated which fixes a crash in
the x11-foreign example app.
2011-05-05 20:41:01 +01:00
Robert Bragg
3a4d0a735b Export some private symbols from libcogl for coglpango
Ideally we wouldn't have any private symbols exported, but for now there
are some APIs that coglpango needs access to that aren't public so we
have ensure they are exported. The aim is to get rid of this need at
some point.
2011-05-05 20:34:54 +01:00
Neil Roberts
14ed963b05 cogl-debug: Add an option to disable atlasing sharing
If COGL_DEBUG contains disable-shared-atlas Cogl will not try to share
the atlas between glyphs and images.
2011-05-05 17:32:31 +01:00
Neil Roberts
184527580e cogl_pipeline_equal: Handle COGL_WRAP_MODE_AUTOMATIC better
When comparing the wrap modes of two pipeline layers it now considers
COGL_WRAP_MODE_AUTOMATIC to be equivalent to CLAMP_TO_EDGE. By the
time the pipeline is in the journal, the upper primitive code is
expected to have overridden this wrap mode with something else if it
wants any other behaviour. This is important for getting text to batch
together with textures because the text explicitly sets the wrap mode
to CLAMP_TO_EDGE on its pipeline.
2011-05-05 17:32:30 +01:00
Neil Roberts
a7aad27212 cogl-bitmap-private.h: Include cogl-bitmap.h
There was a header dependency problem which meant that
cogl-texture-private.h couldn't be included without first including
cogl-bitmap.h
2011-05-05 17:32:29 +01:00
Neil Roberts
239614a375 cogl-atlas-texture: Add a callback for when any atlas reorganizes
This adds cogl_atlas_texture_* functions to register a callback that
will get invoked whenever any of the CoglAtlas's the textures use get
reorganized. The callback is global and is not tied to any particular
atlas texture.
2011-05-05 17:32:28 +01:00
Neil Roberts
c76a4f8e24 cogl-atlas-texture: Split out new_from_bitmap to new_with_size
This adds a new function called _cogl_atlas_texture_new_with_size. The
old new_from_bitmap function now just calls this and updates the
texture with the data.
2011-05-05 17:32:27 +01:00
Robert Bragg
6c23f27801 Adds a way for Cogl to control event_mask of foreign wins
This extends cogl_onscreen_x11_set_foreign_xid to take a callback to a
function that details the event mask the Cogl requires the application
to select on foreign windows. This is required because Cogl, for
example, needs to track size changes of a window and may also in the
future want other notifications such as map/unmap.

Most applications wont need to use the foreign xwindow apis, but those
that do are required to pass a valid callback and update the event mask
of their window according to Cogl's requirements.
2011-05-05 15:05:42 +01:00
Robert Bragg
97243ad9ac Adds cogl_onscreen_show/hide functions
This adds Cogl API to show and hide onscreen framebuffers. We don't want
to go too far down the road of abstracting window system APIs with Cogl
since that would be out of its scope but the previous idea that we would
automatically map framebuffers on allocation except for those made from
foreign windows wasn't good enough. The problem is that we don't want to
make Clutter always create stages from foreign windows but with the
automatic map semantics then Clutter doesn't get an opportunity to
select for all the events it requires before mapping. This meant that we
wouldn't be delivered a mouse enter event for windows mapped underneath
the cursor which would break Clutters handling of button press events.
2011-05-05 15:05:42 +01:00
Robert Bragg
2a150003ad add missing name mangle for cogl_onscreen_set_swap_throttled
We weren't mangling cogl_onscreen_set_swap_throttled to give it an _EXP
postfix to clarify that it is an experimental symbol.
2011-05-05 15:05:42 +01:00
Robert Bragg
ad56c00f7a Add missing _cogl_winsys_has_feature prototype
This adds a private prototype for _cogl_winsys_has_feature in
cogl-winsys-private.h to avoid compilation warnings.
2011-05-05 15:05:42 +01:00
Robert Bragg
195cfa7814 cogl/Makefile.am: pass EXTRA_LDFLAGS for linking
When building on windows for example we need to ensure we pass
-no-undefined to the linker. Although we were substituting a
COGL_EXTRA_LDFLAGS variable from our configure.ac we forgot to
reference that when linking cogl.
2011-05-05 15:05:41 +01:00
Robert Bragg
b3a7ee5930 cogl: remove OSX/WIN32 specific bits in favour of a stub winsys
Until Cogl gains native win32/OSX support this remove the osx and win32
winsys files and instead we'll just rely on the stub-winsys.c to handle
these platforms. Since the only thing the platform specific files were
providing anyway was a get_proc_address function; it was trivial to
simply update the clutter backend code to handle this directly for now.
2011-05-05 15:05:41 +01:00
Robert Bragg
a8c7f43a7c cogl-gl.c: remove really_enable_npot hack for OSX
This is a workaround for a bug on OSX for some radeon hardware that
we can't verify and the referenced bug link is no longer valid.

If this is really still a problem then a new bug should be opened and we
can look at putting the fix in some more appropriate place than
cogl-gl.c
2011-05-05 15:05:41 +01:00
Robert Bragg
cd6d561f6f winsys-glx: map X window automatically if not foreign
For now we are going for the semantics that when a CoglOnscreen is first
allocated then it will automatically be mapped. This is for convenience
and if you don't want that behaviour then it is possible to instead
create an Onscreen from a foreign X window and in that case it wont be
mapped automatically.

This approach means that Cogl doesn't need onscreen_map/unmap functions
but it's possible we'll decide later that we can't avoid adding such
functions and we'll have to change these semantics.
2011-05-05 14:46:03 +01:00
Robert Bragg
711d035f44 cogl/configure.ac: add options to control driver/egl platform
This allows more detailed control over the driver and winsys features
that Cogl should have. Cogl is designed so it can support multiple
window systems simultaneously so we have enable/disable options for
the drivers (gl vs gles1 vs gles2) and options for the individual window
systems; currently glx and egl. Egl is broken down into an option
for each platform.
2011-05-05 14:46:03 +01:00
Robert Bragg
7037812ae6 EGL: Updates GDL platform support
The GDL API is used for example on intel ce4100 (aka Sodaville) based
systems as a way to allocate memory that can be composited using the
platforms overlay hardware. This updates the Cogl EGL winsys and the
support in Clutter so we can continue to support these platforms.
2011-05-05 14:46:02 +01:00
Robert Bragg
ce2da79440 Don't reference GL_STACK_OVERFLOW/UNDERFLOW for GLES
These symbols aren't available when building with GLES so only reference
them when building with OpenGL.
2011-05-05 14:46:02 +01:00
Robert Bragg
31ee65784d winsys: Expose environment variable to choose winsys
This makes it possible to override the winsys that cogl uses by setting
the COGL_RENDERER environment variable e.g. to "GLX" or "EGL"
2011-05-05 14:46:01 +01:00
Robert Bragg
dc7383b714 Add a vtable of indirection to the winsys code
So that we can dynamically select what winsys backend to use at runtime
we need to have some indirection to how code accesses the winsys instead
of simply calling _cogl_winsys* functions that would collide if we
wanted to compile more than one backend into Cogl.
2011-05-05 14:46:01 +01:00
Robert Bragg
d52e3f0cc2 texture-pixmap-x11: Move GLX code to cogl-winsys-glx.c
This moves the GLX specific code from cogl-texture-pixmap-x11.c into
cogl-winsys-glx.c. If we want the winsys components to by dynamically
loadable then we can't have GLX code scattered outside of
cogl-winsys-glx.c. This also sets us up for supporting the
EGL_texture_from_pixmap extension which is almost identical to the
GLX_texture_from_pixmap extension.
2011-05-05 14:46:01 +01:00
Robert Bragg
d5d11f1878 Moves all EGL code down from Clutter to Cogl
As was recently done for the GLX window system code, this commit moves
the EGL window system code down from the Clutter backend code into a
Cogl winsys.

Note: currently the cogl/configure.ac is hard coded to only build the GLX
winsys so currently this is only available when building Cogl as part
of Clutter.
2011-05-05 14:46:01 +01:00
Robert Bragg
8399f5e61c remove references to unused DRM_SURFACELESS EGL platform
The "DRM_SURFACELESS" EGL platform was invented when we were adding the
wayland backend to Clutter but in the end we added a dedicated backend
instead of extending the EGL backend so actually the platform name isn't
used.
2011-05-05 14:46:01 +01:00
Neil Roberts
d832172988 cogl-context: Initialize context->stub_winsys
If Cogl is built using a full Winsys then it wasn't initialising
context->stub_winsys which sometimes made it crash later on.
2011-04-21 16:45:21 +01:00
Neil Roberts
14b6c0459f cogl-winsys-stub: Remove _cogl_winsys_has_feature
Commit b061f737 moved _cogl_winsys_has_feature to the common winsys
code so there's no need to define it in the stub winsys any more. This
was breaking builds for backends using the stub winsys.
2011-04-20 18:43:02 +01:00
Neil Roberts
dcd23dc220 cogl-winsys-glx: Fix the comparison in find_onscreen_for_xid
The comparison for finding onscreen framebuffers in
find_onscreen_for_xid had a small thinko so that it would ignore
framebuffers when the negation of the type is onscreen. This ends up
doing the right thing anyway because the onscreen type has the value 0
and the offscreen type has the value 1 but presumably it would fail if
we ever added any other framebuffer types.
2011-04-20 18:20:25 +01:00
Neil Roberts
16bfa27d43 cogl-winsys: Move _cogl_winsys_has_feature to cogl-winsys.c
The code for _cogl_winsys_has_feature will be identical in all of the
winsys backends for the time being, so it seems to make sense to have
it in the common cogl-winsys.c file.
2011-04-20 18:20:20 +01:00
Neil Roberts
4a7762d6d7 cogl-context: Store winsys features in an array of unsigned ints
Previously the mask of available winsys features was stored in a
CoglBitmask. That isn't the ideal type to use for this because it is
intended for a growable array of bits so it can allocate extra memory
if there are more than 31 flags set. For the winsys feature flags the
highest used bit is known at compile time so it makes sense to
allocate a fixed array instead. This is conceptually similar to the
CoglDebugFlags which are stored in an array of integers with macros to
test a bit in the array. This moves the macros used for CoglDebugFlags
to cogl-flags.h and makes them more generic so they can be shared with
CoglContext.
2011-04-20 18:20:10 +01:00
Neil Roberts
f6ae9decaa cogl-renderer: Move the XEvent filters to be generic for all renderers
Instead of having cogl_renderer_xlib_add_filter and friends there is
now cogl_renderer_add_native_filter which can be used regardless of
the backend. The callback function for the filter now just takes a
void pointer instead of an XEvent pointer which should be interpreted
differently depending on the backend. For example, on Xlib it would
still be an XEvent but on Windows it could be a MSG. This simplifies
the code somewhat because the _cogl_xlib_add_filter no longer needs to
have its own filter list when a stub renderer is used because there is
always a renderer available.

cogl_renderer_xlib_handle_event has also been renamed to
cogl_renderer_handle_native_event. This just forwards the event on to
all of the listeners. The backend renderer is expected to register its
own event filter if it wants to process the events in some way.
2011-04-20 18:17:06 +01:00
Emmanuele Bassi
cbbf76f280 cogl/glx: Silence a compiler warning 2011-04-18 15:53:25 +01:00
James Athey
d0739ca0ba GL_IMG_TEXTURE_NPOT extension enables TEXTURE_NPOT features on GLES
Older drivers for PowerVR SGX hardware have the vendor-specific
GL_IMG_TEXTURE_NPOT extension instead of the
functionally-equivalent GL_OES_TEXTURE_NPOT extension.
2011-04-13 14:34:31 +01:00
Emmanuele Bassi
5e530ca9bb Silence another compiler warning 2011-04-12 21:02:14 +01:00
Emmanuele Bassi
9840321501 Silence the compiler by removing unused variables 2011-04-12 20:37:22 +01:00
Emmanuele Bassi
29e5531486 glx: Protect GLX SwapEvent symbols
We need to guard the usage of symbols related to the
GLX_INTEL_swap_event extension, to avoid breaking on platforms and/or
versions of Mesa that do not expose that extension.
2011-04-12 20:37:22 +01:00
Robert Bragg
2bbb0d895b Make cogl_framebuffer_get_width/height experimental public API
It's generally useful to be able to query the width and height of a
framebuffer and we expect to need this in Clutter when we move the
eglnative backend code into Cogl since Clutter will need to read back
the fixed size of the framebuffer when realizing the stage.
2011-04-11 17:54:36 +01:00
Robert Bragg
1928f7ec0e backend: remove untested fruity backend
This backend hasn't been used for years now and so because it is
untested code and almost certainly doesn't work any more it would be a
burdon to continue trying to maintain it. Considering that we are now
looking at moving OpenGL window system integration code down from
Clutter backends into Cogl that will be easier if we don't have to
consider this backend.
2011-04-11 17:54:36 +01:00
Robert Bragg
efb570fdae Adds the ability to build Cogl standalone
This adds an autogen.sh, configure.ac and build/autotool files etc under
clutter/cogl and makes some corresponding Makefile.am changes that make
it possible to build and install Cogl as a standalone library.

Some notable things about this are:
A standalone installation of Cogl installs 3 pkg-config files;
cogl-1.0.pc, cogl-gl-1.0.pc and cogl-2.0.pc. The second is only for
compatibility with what clutter installed though I'm not sure that
anything uses it so maybe we could remove it. cogl-1.0.pc is what
Clutter would use if it were updated to build against a standalone cogl
library. cogl-2.0.pc is what you would use if you were writing a
standalone Cogl application.

A standalone installation results in two libraries currently, libcogl.so
and libcogl-pango.so. Notably we don't include a major number in the
sonames because libcogl supports two major API versions; 1.x as used by
Clutter and the experimental 2.x API for standalone applications.
Parallel installation of later versions e.g. 3.x and beyond will be
supportable either with new sonames or if we can maintain ABI then we'll
continue to share libcogl.so.

The headers are similarly not installed into a directory with a major
version number since the same headers are shared to export the 1.x and
2.x APIs (The only difference is that cogl-2.0.pc ensures that
-DCOGL_ENABLE_EXPERIMENTAL_2_0_API is used). Parallel installation of
later versions is not precluded though since we can either continue
sharing or later add a major version suffix.
2011-04-11 17:54:36 +01:00
Robert Bragg
d40cdfa3e1 Moves all GLX code down from Clutter to Cogl
This migrates all the GLX window system code down from the Clutter
backend code into a Cogl winsys. Moving OpenGL window system binding
code down from Clutter into Cogl is the biggest blocker to having Cogl
become a standalone 3D graphics library, so this is an important step in
that direction.
2011-04-11 17:54:36 +01:00
Robert Bragg
bcd97f35ea Adds renderer,display,onscreen-template and swap-chain stubs
As part of the process of splitting Cogl out as a standalone graphics
API we need to introduce some API concepts that will allow us to
initialize a new CoglContext when Clutter isn't there to handle that for
us...

The new objects roughly in the order that they are (optionally) involved
in constructing a context are: CoglRenderer, CoglOnscreenTemplate,
CoglSwapChain and CoglDisplay.

Conceptually a CoglRenderer represents a means for rendering.  Cogl
supports rendering via OpenGL or OpenGL ES 1/2.0 and those APIs are
accessed through a number of different windowing APIs such as GLX, EGL,
SDL or WGL and more. Potentially in the future Cogl could render using
D3D or even by using libdrm and directly banging the hardware. All these
choices are wrapped up in the configuration of a CoglRenderer.

Conceptually a CoglDisplay represents a display pipeline for a renderer.
Although Cogl doesn't aim to provide a detailed abstraction of display
hardware, on some platforms we can give control over multiple display
planes (On TV platforms for instance video content may be on one plane
and 3D would be on another so a CoglDisplay lets you select the plane
up-front.)

Another aspect of CoglDisplay is that it lets us negotiate a display
pipeline that best supports the type of CoglOnscreen framebuffers we are
planning to create. For instance if you want transparent CoglOnscreen
framebuffers then we have to be sure the display pipeline wont discard
the alpha component of your framebuffers. Or if you want to use
double/tripple buffering that requires support from the display
pipeline.

CoglOnscreenTemplate and CoglSwapChain are how we describe our default
CoglOnscreen framebuffer configuration which can affect the
configuration of the display pipeline.

The default/simple way we expect most CoglContexts to be constructed
will be via something like:

 if (!cogl_context_new (NULL, &error))
   g_error ("Failed to construct a CoglContext: %s", error->message);

Where that NULL is for an optional "display" parameter and NULL says to
Cogl "please just try to do something sensible".

If you want some more control though you can manually construct a
CoglDisplay something like:

 display = cogl_display_new (NULL, NULL);
 cogl_gdl_display_set_plane (display, plane);
 if (!cogl_display_setup (display, &error))
   g_error ("Failed to setup a CoglDisplay: %s", error->message);

And in a similar fashion to cogl_context_new() you can optionally pass
a NULL "renderer" and/or a NULL "onscreen template" so Cogl will try to
just do something sensible.

If you need to change the CoglOnscreen defaults you can provide a
template something like:
  chain = cogl_swap_chain_new ();
  cogl_swap_chain_set_has_alpha (chain, TRUE);
  cogl_swap_chain_set_length (chain, 3);

  onscreen_template = cogl_onscreen_template_new (chain);
  cogl_onscreen_template_set_pixel_format (onscreen_template,
                                           COGL_PIXEL_FORMAT_RGB565);

  display = cogl_display_new (NULL, onscreen_template);
  if (!cogl_display_setup (display, &error))
    g_error ("Failed to setup a CoglDisplay: %s", error->message);
2011-04-11 17:54:35 +01:00
Robert Bragg
e80a2b9b2f rename winsys files to be more consistent
This tries to make the naming style of files under cogl/winsys/
consistent with other cogl source files. In particular private header
files didn't have a '-private' infix.
2011-04-11 17:54:35 +01:00
Robert Bragg
9f19244971 Add temporary cogl-clutter.h to aid splitting out Cogl
This gives us a way to clearly track the internal Cogl API that Clutter
depends on. The aim is to split Cogl out from Clutter into a standalone
3D graphics API and eventually we want to get rid of any private
interfaces for Clutter so its useful to have a handle on that task.
Actually it's not as bad as I was expecting though.
2011-04-11 17:54:35 +01:00
Robert Bragg
0b45110302 framebuffer: expose experimental cogl_get_draw_framebuffer
This renames the two internal functions _cogl_get_draw/read_buffer
as cogl_get_draw_framebuffer and _cogl_get_read_framebuffer. The
former is now also exposed as experimental API.
2011-04-11 15:28:53 +01:00
Robert Bragg
aa1e45267b framebuffer: track context as CoglFramebuffer member
The long term goal with the Cogl API is that we will get rid of the
default global context. As a step towards this, this patch tracks a
reference back to the context in each CoglFramebuffer so in a lot of
cases we can avoid using the _COGL_GET_CONTEXT macro.
2011-04-11 15:28:47 +01:00
Robert Bragg
5c7ce809c1 remove unused _cogl_features_init prototype
There is no corresponding implementation of _cogl_features_init any more
so it was simply an oversight that the prototype wasn't removed when the
implementation was removed.
2011-04-11 15:26:25 +01:00
Robert Bragg
7fc6613fe9 Remove unused _cogl_swap_buffers_notify
Recently _cogl_swap_buffers_notify was added (in 142b229c5c) so that
Cogl would be notified when Clutter performs a swap buffers request for
a given onscreen framebuffer. It was expected this would be required for
the recent cogl_read_pixel optimization that was implemented (ref
1bdb0e6e98) but in the end it wasn't used.

Since it wasn't used in the end this patch removes the API.
2011-04-11 15:26:25 +01:00
Robert Bragg
c415818537 cogl: consolidate _create_context_driver + _features_init
This moves the functionality of _cogl_create_context_driver from
driver/{gl,gles}/cogl-context-driver-{gl,gles}.c into
driver/{gl,gles}/cogl-{gl,gles}.c as a static function called
initialize_context_driver.

cogl-context-driver-{gl,gles}.[ch] have now been removed.
2011-04-11 15:26:25 +01:00
Robert Bragg
e9b1ca0165 cogl: Adds experimental cogl_context_new() API
This adds a new experimental function (you need to define
COGL_ENABLE_EXPERIMENTAL_API to access it) which takes us towards being
able to have a standalone Cogl API. This is really a minor aesthetic
change for now since all the GL context creation code still lives in
Clutter but it's a step forward none the less.

Since our current designs introduce a CoglDisplay object as something
that would be passed to the context constructor this provides a stub
cogl-display.h with CoglDisplay typedef.

_cogl_context_get_default() which Clutter uses to access the Cogl
context has been modified to use cogl_context_new() to initialize
the default context.

There is one rather nasty hack used in this patch which is that the
implementation of cogl_context_new() has to forcibly make the allocated
context become the default context because currently all the code in
Cogl assumes it can access the context using _COGL_GET_CONTEXT including
code used to initialize the context.
2011-04-11 15:26:20 +01:00
Robert Bragg
fdbc741770 cogl: rename cogl-context.h cogl-context-private.h
Since we plan to add public cogl_context_* API we need to rename the
current cogl-context.h which contains private member details.
2011-04-11 15:18:12 +01:00
Neil Roberts
472e8e8f4e cogl-pipeline: Be careful not to take ownership of root layer
In _cogl_pipeline_prune_empty_layer_difference if the layer's parent
has no owner then it just takes ownership of it. However this could
theoretically end up taking ownership of the root layer because
according to the comment above in the same function that should never
have an owner. This patch just adds an extra check to ensure that the
unowned layer has a parent.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2588
2011-04-05 18:24:09 +01:00
Robert Bragg
7de3655298 pipeline: reclaim ownership if reverting to layer ancestor
In _cogl_pipeline_prune_empty_layer_difference if we are reverting to
the immediate parent of an empty/redundant layer then it is not enough
to simply add a reference to the pipeline's ->layer_differences list
without also updating parent_layer->owner to point back to its new
owner.

This oversight was leading us to break the invariable that all layers
referenced in layer_differences have an owner and was also causing us to
break another invariable whereby after calling
_cogl_pipeline_layer_pre_change_notify the returned layer must always be
owned by the given 'required_owner'.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2588
2011-04-05 18:24:09 +01:00
Emmanuele Bassi
12b622a320 offscreen: Plug a leak in an error path
When creating a CoglOffscreen we take a reference on the texture handle,
but in case of error we never release it.

We should take that reference only on success.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2620
2011-04-04 14:42:36 +01:00
Neil Roberts
f38b7a78fb cogl: Use GHookList instead of CoglCallbackList
glib already has a data type to manage a list of callbacks called a
GHookList so we might as well use it instead of maintaining Cogl's own
type. The glib version may be slightly more efficient because it
avoids using a GList and instead encodes the prev and next pointers
directly in the GHook structure. It also has more features than
CoglCallbackList.
2011-03-14 18:18:15 +00:00
Robert Bragg
034d273030 culling: Don't cull actors not being painted on the stage
Previously we were applying the culling optimization to any actor
painted without considering that we may be painting to an offscreen
framebuffer where the stage clip isn't applicable.

For now we simply expose a getter for the current draw framebuffer
and we can assume that a return value of NULL corresponds to the
stage.

Note: This will need to be updated as stages start to be backed by real
CoglFramebuffer objects and so we won't get NULL in those cases.
2011-03-10 21:02:29 +00:00
Jasper St. Pierre
30fa4e1a20 cogl-clip-state: Adapt to experimental cogl2 API.
The current clip state implementation couldn't be used in
conjunction with the CoglPath experimental API.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2594

Signed-off-by: Neil Roberts <neil@linux.intel.com>
2011-03-10 13:05:43 +00:00
Neil Roberts
cbe9d758d5 cogl-path: Optimise paths that are just a rectangle
Drawing and clipping to paths is generally quite expensive because the
geometry has to be tessellated into triangles in a single VBO which
breaks up the journal batching. If we can detect when the path
contains just a single rectangle then we can instead divert to calling
cogl_rectangle which will take advantage of the journal, or by pushing
a rectangle clip which usually ends up just using the scissor.

This patch adds a boolean to each path to mark when it is a
rectangle. It gets cleared whenever a node is added or gets set to
TRUE whenever cogl2_path_rectangle is called. This doesn't try to
catch cases where a rectangle is composed by cogl_path_line_to and
cogl_path_move_to commands.
2011-03-09 18:28:48 +00:00
Neil Roberts
9b7f362ea4 cogl-shader-boilerplate: Specify default precision earlier
In 9ff04e8a99 the builtin uniforms were moved to the common shader
boilerplate. However the common boilerplate is positioned before the
default precision specifier on GLES2 so it would fail to compile
because the uniforms end up with no precision in the fragment
shader. This patch just moves the precision specifier to above the
common boilerplate.
2011-03-08 13:21:24 +00:00
Robert Bragg
d4a5d70ee0 util: optimize _clutter_util_fully_transform_vertices
Instead of unconditionally combining the modelview and projection
matrices and then iterating each of the vertices to call
cogl_matrix_transform_point for each one in turn we now only combine the
matrices if there are more than 4 vertices (with less than 4 vertices
its less work to transform them separately) and we use the new
cogl_vertex_{transform,project}_points APIs which can hopefully
vectorize the transformations.

Finally the perspective divide and viewport scale is done in a separate
loop at the end and we don't do the spurious perspective divide and
viewport scale for the z component.
2011-03-07 13:26:20 +00:00
Robert Bragg
962b84ed56 matrix: adds 2d view transform conveniences
This adds two new experimental functions to cogl-matrix.c:
cogl_matrix_view_2d_in_perspective and cogl_matrix_view_2d_in_frustum
which can be used to setup a view transform that maps a 2D coordinate
system (0,0) top left and (width,height) bottom right to the current
viewport.

Toolkits such as Clutter that want to mix 2D and 3D drawing can use
these APIs to position a 2D coordinate system at an arbitrary depth
inside a 3D perspective projected viewing frustum.
2011-03-07 13:26:19 +00:00
Robert Bragg
bc372d2734 viewport: consistently use floats for viewports
OpenGL < 4.0 only supports integer based viewports and internally we
have a mixture of code using floats and integers for viewports. This
patch switches all viewports throughout clutter and cogl to be
represented using floats considering that in the future we may want to
take advantage of floating point viewports with modern hardware/drivers.
2011-03-07 13:26:19 +00:00
Robert Bragg
b3d9f313d4 util: tune point_in_poly test for polys in screen coords
This makes a change to the original point_in_poly algorithm from:
http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html

The aim was to tune the test so that tests against screen aligned
rectangles are more resilient to some in-precision in how we transformed
that rectangle into screen coordinates. In particular gnome-shell was
finding that for some stage sizes then row 0 of the stage would become a
dead zone when going through the software picking fast-path and this was
because the y position of screen aligned rectangles could end up as
something like 0.00024 and the way the algorithm works it doesn't have
any epsilon/fuz factor to consider that in-precision.

We've avoided introducing an epsilon factor to the comparisons since we
feel there's a risk of changing some semantics in ways that might not be
desirable. One of those is that if you transform two polygons which
share an edge and test a point close to that edge then this algorithm
will currently give a positive result for only one polygon.

Another concern is the way this algorithm resolves the corner case where
the horizontal ray being cast to count edge crossings may cross directly
through a vertex. The solution is based on the "idea of Simulation of
Simplicity" and "pretends to shift the ray infinitesimally down so that
it either clearly intersects, or clearly doesn't touch". I'm not
familiar with the idea myself so I expect a misplaced epsilon is likely
to break that aspect of the algorithm.

The simple solution this patch applies is to pixel align the polygon
vertices which should eradicate most noise due to in-precision.

https://bugzilla.gnome.org/show_bug.cgi?id=641197
2011-03-07 13:26:19 +00:00
Neil Roberts
25db8d0653 cogl-blit: Disable blending when using texture render
When using a pipeline and the journal to blit images between
framebuffers, it should disable blending. Otherwise it will end up
blending the source texture with uninitialised garbage in the
destination texture.
2011-02-24 20:45:19 +00:00
Emmanuele Bassi
c91f102232 cogl: Remove unused variables 2011-02-19 16:47:11 +00:00
Neil Roberts
8f8b05f0e5 cogl-atlas-texture: Don't let textures be destroyed during migration
If an atlas texture's last reference is held by the journal or by the
last flushed pipeline then if an atlas migration is started it can
cause a crash. This is because the atlas migration will cause a
journal flush and can sometimes change the current pipeline which
means that the texture would be destroyed during migration.

This patch adds an extra 'post_reorganize' callback to the existing
'reorganize' callback (which is now renamed to 'pre_reorganize'). The
pre_reorganize callback is now called before the atlas grabs a list of
the current textures instead of after so that it doesn't matter if the
journal flush destroys some of those textures. The pre_reorganize
callback for CoglAtlasTexture grabs a reference to all of the textures
so that they can not be destroyed when the migration changes the
pipeline. In the post_reorganize callback the reference is removed
again.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2538
2011-02-17 13:39:30 +00:00
Neil Roberts
b77276c99a cogl-atlas: Fix a compiler warning when Cogl debug is disabled
When Cogl debugging is disabled then the 'waste' variable is not used
so it throws a compiler warning. This patch removes the variable and
the value is calculated directly as the parameter to COGL_NOTE.
2011-02-15 14:26:18 +00:00
Neil Roberts
167c8aac1b cogl-debug: Don't define _cogl_debug_flags when debugging disabled
_cogl_debug_flags isn't used when COGL_DEBUG is not defined so there's
no need to declare it.

Based on a patch by Fan, Chun-wei

http://bugzilla.clutter-project.org/show_bug.cgi?id=2561
2011-02-15 14:26:17 +00:00
Neil Roberts
dd7b1326eb cogl: Avoid pointer arithmetic on void* pointers
Some code was doing pointer arithmetic on the return value from
cogl_buffer_map which is void* pointer. This is a GCC extension so we
should try to avoid it. This patch adds casts to guint8* where
appropriate.

Based on a patch by Fan, Chun-wei.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2561
2011-02-15 14:26:17 +00:00
Emmanuele Bassi
c4cfdd59d3 Fix ISO C90 compiler warnings in Cogl
Mixing declarations and statements and unused variables.
2011-02-15 12:40:11 +00:00
Neil Roberts
c8ddb3b55a cogl-atlas: Try 4 different approaches for migrating textures
Instead of directly banging GL to migrate textures the atlas now uses
the CoglFramebuffer API. It will use one of four approaches; it can
set up two FBOs and use _cogl_blit_framebuffer to copy between them;
it can use a single target fbo and then render the source texture to
the FBO using a Cogl draw call; it can use a single FBO and call
glCopyTexSubImage2D; or it can fallback to reading all of the texture
data back to system memory and uploading it again with a sub texture
update.

Previously GL calls were used directly because Cogl wasn't able to
create a framebuffer without a stencil and depth buffer. However there
is now an internal version of cogl_offscreen_new_to_texture which
takes a set of flags to disable the two buffers.

The code for blitting has now been moved into a separate file called
cogl-blit.c because it has become quite long and it may be useful
outside of the atlas at some point.

The 4 different methods have a fixed order of preference which is:

* Texture render between two FBOs
* glBlitFramebuffer
* glCopyTexSubImage2D
* glGetTexImage + glTexSubImage2D

Once a method is succesfully used it is tried first for all subsequent
blits. The default default can be overridden by setting the
environment variable COGL_ATLAS_DEFAULT_BLIT_MODE to one of the
following values:

* texture-render
* framebuffer
* copy-tex-sub-image
* get-tex-data
2011-02-15 12:10:54 +00:00
Neil Roberts
5ca053a3c1 cogl-texture-2d: Add _cogl_is_texture_2d to the private header
This adds a declaration for _cogl_is_texture_2d to the private header
so that it can be used in cogl-blit.c to determine if the target
texture is a simple 2D texture.
2011-02-15 12:10:54 +00:00
Neil Roberts
bc86db1057 cogl-texture-2d: Add an internal wrapper around glCopyTexSubImage2D
This adds a function called _cogl_texture_2d_copy_from_framebuffer
which is a simple wrapper around glCopyTexSubImage2D. It is currently
specific to the texture 2D backend.
2011-02-15 12:10:54 +00:00
Neil Roberts
9d242b62a9 cogl-framebuffer: Add _cogl_blit_framebuffer
This adds the _cogl_blit_framebuffer internal function which is a
wrapper around glBlitFramebuffer. The API is changed from the GL
version of the function to reflect the limitations provided by the
GL_ANGLE_framebuffer_blit extension (eg, no scaling or mirroring).
2011-02-15 12:10:54 +00:00
Neil Roberts
392cfb493a cogl-gles: Check for the GL_ANGLE_framebuffer_blit extension
This extension is the GLES equivalent of the GL_EXT_framebuffer_blit
extension except that it has some extra restrictions. We need to check
for some extension that provides glBlitFramebuffer so that we can
unconditionally use ctx->drv.pf_glBlitFramebuffer in both GL and GLES
code. Even with the restrictions, the extension provides enough
features for what Cogl needs.
2011-02-15 12:10:54 +00:00
Neil Roberts
50babfbc7a cogl-atlas-texture: Make copying a texture out more robust
Previously when _cogl_atlas_texture_migrate_out_of_atlas is called it
would unreference the atlas texture's sub-texture before calling
_cogl_atlas_copy_rectangle. This would leave the atlas texture in an
inconsistent state during the copy. This doesn't normally matter but
if the copy ends up doing a render then the atlas texture may end up
being referenced. In particular it would cause problems if the texture
is left in a texture unit because then Cogl may try to call
get_gl_texture even though the texture isn't actually being used for
rendering. To fix this the sub texture is now unrefed after the copy
call instead.
2011-02-15 12:10:54 +00:00
Neil Roberts
a067e7a16b cogl-framebuffer: Separate the draw and read buffer
The current framebuffer is now internally separated so that there can
be a different draw and read buffer. This is required to use the
GL_EXT_framebuffer_blit extension. The current draw and read buffers
are stored as a pair in a single stack so that pushing the draw and
read buffer is done simultaneously with the new
_cogl_push_framebuffers internal function. Calling
cogl_pop_framebuffer will restore both the draw and read buffer to the
previous state. The public cogl_push_framebuffer function is layered
on top of the new function so that it just pushes the same buffer for
both drawing and reading.

When flushing the framebuffer state, the cogl_framebuffer_flush_state
function now tackes a pointer to both the draw and the read
buffer. Anywhere that was just flushing the state for the current
framebuffer with _cogl_get_framebuffer now needs to call both
_cogl_get_draw_buffer and _cogl_get_read_buffer.
2011-02-15 12:10:54 +00:00
Neil Roberts
ef1b400042 cogl-framebuffer: Fix flushing the framebuffer on push
When pushing a framebuffer it would previously push
COGL_INVALID_HANDLE to the top of the framebuffer stack so that when
it later calls cogl_set_framebuffer it will recognise that the
framebuffer is different and replace the top with the new
pointer. This isn't ideal because it breaks the code to flush the
journal because _cogl_framebuffer_flush_journal is called with the
value of the old pointer which is NULL. That function was checking for
a NULL pointer so it wouldn't actually flush. It also would mean that
if you pushed the same framebuffer twice we would end up dirtying
state unnecessarily. To fix this cogl_push_framebuffer now pushes a
reference to the current framebuffer instead.
2011-02-10 20:19:01 +00:00
Neil Roberts
4d2878d4b2 cogl-framebuffer: Remove all dependencies after a flush
After a dependent framebuffer is added to a framebuffer it was never
getting removed. Once the journal for a framebuffer is flushed we no
longer depend on any framebuffers so the list should be cleared. This
was causing leaks of offscreens and textures.
2011-02-10 11:31:34 +00:00
Robert Bragg
df07edf83e docs: clarify cogl_vertex_buffer_adds docs
This adds a clarification that cogl_vertex_buffer_add can also be
used to replace a previously added attribute with the same name.
2011-02-09 19:12:12 +00:00
Robert Bragg
b351aa4af4 matrix: note that _matrix_multiply can multiply in-place
This adds a note to clarify that cogl_matrix_multiply allows you to
multiply the @a matrix in-place, so @a can equal @result but @b can't
equal @result.
2011-02-09 17:21:48 +00:00
Neil Roberts
b3a0bdf7f6 cogl: Set the layer matrix on the right layer instead of a random one
When uploading the layer matrix to GL it wasn't first calling
glActiveTextureMatrix to set the right texture unit for the
layer. This would end up setting the texture matrix on whatever layer
happened to be previously active. This happened to work for
test-cogl-multitexture presumably because it was coincidentally
setting the layer matrix on the last used layer.
2011-02-09 16:14:13 +00:00
Neil Roberts
94bcb4429b cogl-vertex-buffer: Use a ref count on the pipeline private data
The pipeline private data is accessed both from the private data set
on a CoglPipeline and the destroy notify function of a weak material
that the vertex buffer creates when it needs to override the wrap
mode. However when a CoglPipeline is destroyed, the CoglObject code
first removes all of the private data set on the object and then the
CoglPipeline code gets invoked to destroy all of the weak children. At
this point the vertex buffer's weak override destroy notify function
will get invoked and try to use the private data which has already
been freed causing a crash.

This patch instead adds a reference count to the pipeline private data
stuct so that we can avoid freeing it until both the private data on
the pipeline has been destroyed and all of the weak materials are
destroyed.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2544
2011-02-01 18:47:05 +00:00
Neil Roberts
a866f2f4f4 cogl-pipeline: Fix comparing the color in set_layer_combine_constant
In cogl_pipeline_set_layer_combine_constant it was comparing whether
the new color is the same as the old color using a memcmp on the
constant_color parameter. However the combine constant is stored in
the layer data as an array of four floats but the passed in color is a
CoglColor (which is currently an array of four guint8s). This was
causing valgrind errors and presumably also the check for setting the
same color twice would always fail.

This patch makes it do the conversion to a float array upfront before
the comparison.
2011-02-01 17:50:10 +00:00
Neil Roberts
fadd935891 cogl-matrix: Get rid of the *_packed variants
cogl_matrix_project_points and cogl_matrix_transform_points had an
optimization for the common case where the stride parameters exactly
match the size of the corresponding structures. The code for both when
generated by gcc with -O2 on x86-64 use two registers to hold the
addresses of the input and output arrays. In the strided version these
pointers are incremented by adding the value of a register and in the
packed version they are incremented by adding an immediate value. I
think the difference in cost here would be negligible and it may even
be faster to add a register.

Also GCC appears to retain the loop counter in a register for the
strided version but in the packed version it can optimize it out and
directly use the input pointer as the counter. I think it would be
possible to reorder the code a bit to explicitly use the input pointer
as the counter if this were a problem.

Getting rid of the packed versions tidies up the code a bit and it
could potentially be faster if the code differences are small and we
get to avoid an extra conditional in cogl_matrix_transform_points.
2011-02-01 13:18:43 +00:00
Robert Bragg
dc56d908ed pipeline: fix for _init_multi_property_sparse_state
When copying COMBINE state in
_cogl_pipeline_layer_init_multi_property_sparse_state we would read some
state from the destination layer (invalid data potentially), then
redundantly set the value back on the destination. This was picked up by
valgrind, and the code is now more careful about how it references the
src layer vs the destination layer.
2011-01-24 18:53:08 +00:00
Robert Bragg
325c620f81 framebuffer: flush journal when switching framebuffers
There is currently a problem with per-framebuffer journals in that it's
possible to create a framebuffer from a texture which then gets rendered
too but the framebuffer (and corresponding journal) can be freed before
the texture gets used to draw with.

Conceptually we want to make sure when freeing a framebuffer that - if
it is associated with a texture - we flush the journal as the last thing
before really freeing the framebuffer's meta data. Technically though
this is awkward to implement since the obvious mechanism for us to be
notified about the framebuffer's destruction (by setting some user data
internally with a callback) notifies when the framebuffer has a
ref-count of 0. This means we'd have to be careful what we do with the
framebuffer to consider e.g. recursive destruction; anything that would
set more user data on the framebuffer while it is being destroyed and
ensuring nothing else gets notified of the framebuffer's destruction
before the journal has been flushed.

For simplicity, for now, this patch provides another solution which is
to flush framebuffer journals whenever we switch away from a given
framebuffer via cogl_set_framebuffer or cogl_push/pop_framebuffer. The
disadvantage of this approach is that we can't batch all the geometry of
a scene that involves intermediate renders to offscreen framebufers.
Clutter is doing this more and more with applications that use the
ClutterEffect APIs so this is a shame. Hopefully this will only be a
stop-gap solution while we consider how to reliably support journal
logging across framebuffer changes.
2011-01-24 18:53:08 +00:00
Neil Roberts
2b812d3d04 cogl-clip-stack: Fix flushing multiple stencil rectangles
When flushing a clip stack that contains more than one rectangle which
needs to use the stencil buffer the code takes a different path so
that it can combine the new rectangle with the existing contents of
the stencil buffer. However it was not correctly flushing the
modelview and projection matrices so that rectangle would be in the
wrong place.
2011-01-24 17:40:07 +00:00
Neil Roberts
2ddab50ae4 cogl-debug: Add a debug option for tracing clipping
This adds a COGL_DEBUG=clipping option that reports how the clip is
being flushed. This is needed to determine whether the scissor,
stencil clip planes or software clipping is being used.
2011-01-24 17:39:48 +00:00
Neil Roberts
c4a94439de cogl-debug: Split the flags to support more than 32
The CoglDebugFlags are now stored in an array of unsigned ints rather
than a single variable. The flags are accessed using macros instead of
directly peeking at the cogl_debug_flags variable. The index values
are stored in the enum rather than the actual mask values so that the
enum doesn't need to be more than 32 bits wide. The hope is that the
code to determine the index into the array can be optimized out by the
compiler so it should have exactly the same performance as the old
code.
2011-01-24 15:45:45 +00:00
Neil Roberts
4bb08ba00b cogl-pipeline: Flush the lighting params in common code not vertend
The lighting parameters such as the diffuse and ambient colors were
previously only flushed in the fixed vertend. This meant that if a
vertex shader was used then they would not be set. The lighting
parameters are uniforms which are just as useful in a fragment shader
so it doesn't really make sense to set them in the vertend. They are
now flushed in the common cogl-pipeline-opengl code but the code is
#ifdef'd for GLES2 because they need to be part of the progend in that
case.
2011-01-24 12:09:11 +00:00
Neil Roberts
242d9a5002 cogl-pipeline-progend-glsl: Generalize updating GLES2 uniforms
The uniforms for the alpha test reference value and point size on
GLES2 are updating using similar code. This generalizes the code so
that there is a static array of predefined builtin uniforms which
contains the uniform name, a pointer to a function to get the value
from the pipeline, a pointer to a function to update the uniform and a
flag representing which CoglPipelineState change affects the
uniform. The uniforms are then updated in a loop. This should simplify
adding more builtin uniforms.
2011-01-24 12:09:11 +00:00
Neil Roberts
b2285058a4 cogl-shader-boilerplate: Move the uniforms to the common code
The builtin uniforms are accessible from either the vertex shader or
the fragment shader so we should define them in the common
section. This doesn't really matter for the current list of uniforms
because it's pretty unlikely that you'd want to access the matrices
from the fragment shader, but for other builtins such as the lighting
material properties it makes sense.
2011-01-24 12:09:11 +00:00
Robert Bragg
d6a150bb6e cogl: call _cogl_texture_init for x11 tfp
When we added the texture->framebuffers member a _cogl_texture_init
funciton was added to initialize the list of framebuffers associated
with a texture to NULL. All the backends were updated except the
x11 tfp backend. This was causing crashes in test-pixmap.
2011-01-21 18:58:58 +00:00
Robert Bragg
4758ed2cf2 journal: start uprof flush timer after flushing fb deps
This avoids us recursively starting the _cogl_journal_flush uprof timer
by only starting it after flushing the journals of dependency
framebuffers.
2011-01-21 17:38:14 +00:00
Robert Bragg
affce86924 cogl: make sure to init ctx->framebuffers
This makes sure to initialize ctx->framebuffers to NULL otherwise we can
get apps crashing when they create their first framebuffer.
2011-01-21 17:28:34 +00:00
Robert Bragg
9b0fd92527 cogl: rename CoglVertexAttribute CoglAttribute
This is part of a broader cleanup of some of the experimental Cogl API.
One of the reasons for this particular rename is to reduce the verbosity
of using the API. Another reason is that CoglVertexArray is going to be
renamed CoglAttributeBuffer and we want to help emphasize the
relationship between CoglAttributes and CoglAttributeBuffers.
2011-01-21 16:24:14 +00:00
Robert Bragg
87c990a29c cogl: s/Cogl*Vertex/CoglVertex*/
We have a bunch of experimental convenience functions like
cogl_primitive_p2/p2t2 that have corresponding vertex structures but it
seemed a bit odd to have the vertex annotation e.g. "P2T2" be an infix
of the type like CoglP2T2Vertex instead of be a postfix like
CoglVertexP2T2. This switches them all to follow the postfix naming
style.
2011-01-21 16:22:40 +00:00
Robert Bragg
5f6cb16e2b debug: Adds a COGL_DEBUG=disable-fast-read-pixel option
COGL_DEBUG=disable-fast-read-pixel can be used to disable the
optimization for reading a single pixel colour back by looking at the
geometry in the journal and not involving the GPU. With this disabled we
will always flush the journal, rendering to the framebuffer and then use
glReadPixels to get the result.
2011-01-21 16:18:11 +00:00
Robert Bragg
a8d6c3f686 cogl: Implements a software only read-pixel fast-path
This adds a transparent optimization to cogl_read_pixels for when a
single pixel is being read back and it happens that all the geometry of
the current frame is still available in the framebuffer's associated
journal.

The intention is to indirectly optimize Clutter's render based picking
mechanism in such a way that the 99% of cases where scenes are comprised
of trivial quad primitives that can easily be intersected we can avoid
the latency of kicking a GPU render and blocking for the result when we
know we can calculate the result manually on the CPU probably faster
than we could even kick a render.

A nice property of this solution is that it maintains all the
flexibility of the render based picking provided by Clutter and it can
gracefully fall back to GPU rendering if actors are drawn using anything
more complex than a quad for their geometry.

It seems worth noting that there is a limitation to the extensibility of
this approach in that it can only optimize picking a against geometry
that passes through Cogl's journal which isn't something Clutter
directly controls.  For now though this really doesn't matter since
basically all apps should end up hitting this fast-path. The current
idea to address this longer term would be a pick2 vfunc for ClutterActor
that can support geometry and render based input regions of actors and
move this optimization up into Clutter instead.

Note: currently we don't have a primitive count threshold to consider
that there could be scenes with enough geometry for us to compensate for
the cost of kicking a render and determine a result more efficiently by
utilizing the GPU. We don't currently expect this to be common though.

Note: in the future it could still be interesting to revive something
like the wip/async-pbo-picking branch to provide an asynchronous
read-pixels based optimization for Clutter picking in cases where more
complex input regions that necessitate rendering are in use or if we do
add a threshold for rendering as mentioned above.
2011-01-21 16:18:11 +00:00
Robert Bragg
3e42af2a00 matrix: fix transform/project_points() APIs
Both cogl_matrix_transform_points and _project_points take points_in and
points_out arguments and explicitly allow pointing to the same array
(i.e. to transform in-place) The implementation of the various internal
transform functions though were not handling this possability and so it
was possible the reference partially transformed vertex values as if
they were original input values leading to incorrect results. This patch
ensures we take a temporary copy of the current input point when
transforming.
2011-01-21 16:18:11 +00:00
Robert Bragg
1f0826543e cogl: Adds _cogl_util_point_in_polygon API
This adds a utility function that can determine if a given point
intersects an arbitrary polygon, by counting how many edges a
"semi-infinite" horizontal ray crosses from that point. The plan is to
use this for a software based read-pixel fast path that avoids using the
GPU to rasterize journaled primitives and can instead intersect a point
being read with quads in the journal to determine the correct color.
2011-01-21 16:18:11 +00:00
Robert Bragg
60fd6ab708 cogl: Adds _cogl_swap_buffers_notify for clutter backends
This adds a stop-gap mechanism for Cogl to know when the window system
is requested to present the current backbuffer to the frontbuffer by
adding a _cogl_swap_buffers_notify function that backends are now
expected to call right after issuing the equivalent request to OpenGL
vie the platforms OpenGL binding layer. This (blindly) updates all the
backends to call this new function.

For now Cogl doesn't do anything with the notification but the intention
is to use it as part of a planned read-pixel optimization which will
need to reset some state at the start of each new frame.
2011-01-21 16:18:10 +00:00
Robert Bragg
e1563436b1 clip: rename get_clip_stack + add framebuffer_get_stack
Instead of having _cogl_get/set_clip stack which reference the global
CoglContext this instead makes those into CoglClipState method functions
named _cogl_clip_state_get/set_stack that take an explicit pointer to a
CoglClipState.

This also adds _cogl_framebuffer_get/set_clip_stack convenience
functions that avoid having to first get the ClipState from a
framebuffer then the stack from that - so we can maintain the
convenience of _cogl_get_clip_stack.
2011-01-21 16:18:10 +00:00
Robert Bragg
cf92670fbb clip-stack: Adds _cogl_clip_stack_get_bounds API
This adds an internal function to be able to query the screen space
bounding box of the current clip entries contained in a given
CoglClipStack.

This bounding box which is cheap to determine can be useful to know the
largest extents that might be updated while drawing with this clip
stack.

For example the plan is to use this as part of an optimized read-pixel
path handled on the CPU which will need to track the currently valid
extents of the last call to cogl_clear()
2011-01-21 16:18:10 +00:00
Robert Bragg
1a5a4df326 journal: Support per-framebuffer journals
Instead of having a single journal per context, we now have a
CoglJournal object for each CoglFramebuffer. This means we now don't
have to flush the journal when switching/pushing/popping between
different framebuffers so for example a Clutter scene that involves some
ClutterEffect actors that transiently redirect to an FBO can still be
batched.

This also allows us to track state in the journal that relates to the
current frame of its associated framebuffer which we'll need for our
optimization for using the CPU to handle reading a single pixel back
from a framebuffer when we know the whole scene is currently comprised
of simple rectangles in a journal.
2011-01-21 16:18:10 +00:00
Robert Bragg
5f35bd7b67 cogl-object: Adds an internal _cogl_object_set_user_data
This adds an internal alternative to cogl_object_set_user_data that also
passes an instance pointer to destroy notify callbacks.

When setting private data on a CoglObject it's often desirable to know
the instance being destroyed when we are being notified to free the
private data due to the object being freed. The typical solution to this
is to track a pointer to the instance in the private data itself so it
can be identified but that usually requires an extra micro allocation
for the private data that could have been avoided if only the callback
were given an instance pointer.

The new internal _cogl_object_set_user_data passes the instance pointer
as a second argument which means it is ABI compatible for us to layer
the public version on top of this internal function.
2011-01-21 16:18:10 +00:00
Robert Bragg
a4e50b5ea5 framebuffer: Move clear code to cogl-framebuffer.c
This moves the implementation of cogl_clear into cogl-framebuffer.c as
two new internal functions _cogl_framebuffer_clear and
_cogl_framebuffer_clear4f. It's not clear if this is what the API will
look like as we make more of the CoglFramebuffer API public due to the
limitations of using flags to identify buffers when framebuffers may
contain any number of ancillary buffers but conceptually it makes some
sense to tie the operation of clearing a color buffer to a framebuffer.

The short term intention is to enable tracking the current clear color
as a property of the framebuffer as part of an optimization for reading
back single pixels when the geometry is simple enough that we can
compute the result quickly on the CPU. (If the point doesn't intersect
any geometry we'll need to return the last clear color.)
2011-01-21 16:18:09 +00:00
Neil Roberts
34ce527dca cogl-program: Don't use separate definitions on GLES 1.1
Previously most of the code for cogl-program and cogl-shader was
ifdef'd out for GLES 1.1 and alternate stub definitions were
defined. This patch removes those and instead puts #ifdef's directly
in the functions that need it. This should make it a little bit easier
to maintain.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2516
2011-01-17 12:56:58 +00:00
Neil Roberts
ed29d405b2 cogl-pipeline-opengl: #ifdef out set_glsl_program for GLES 1.1
glUseProgram is not available under GLES 1.1 so it was breaking the
build.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2516
2011-01-17 12:38:46 +00:00
Neil Roberts
d33f66303f cogl-pipeline: Fix the enum names for the constant combine source
When determining whether to hash the combine constant Cogl checks the
arguments to the combine funcs to determine whether the combine
constant is used. However is was using the GLenums GL_CONSTANT_COLOR
and GL_CONSTANT_ALPHA but these are not valid values for the
CoglPipelineCombineSource enum so presumably the constant would never
get hashed. This patch makes it use Cogl's enum of
COGL_PIPELINE_COMBINE_SOURCE_CONSTANT instead.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2516
2011-01-17 12:38:46 +00:00
Neil Roberts
4f08e3cf6e cogl-buffer: Support mapping buffers for write on GLES
GLES has an extension called GL_OES_mapbuffer to support mapping
buffer objects but only for writing. Cogl now has two new feature
flags to advertise whether mapping for reading and writing is
supported. Under OpenGL, these features are always set if the VBO
extension is advertised and under GLES only the write flag is set if
the GL_OES_mapbuffer extension is advertised.
2011-01-13 16:36:45 +00:00
Neil Roberts
36b996672c cogl: Enable the VBOs feature for GLES2
The GLES2 wrapper code has been removed so there are no longer any
problems with enabling VBOs.
2011-01-13 16:36:45 +00:00
Neil Roberts
a8216aff2f cogl: Fallback to set_data when mapping a buffer to fill it
In the journal code and when generating the stroke path the vertices
are generated on the fly and stored in a CoglBuffer using
cogl_buffer_map. However cogl_buffer_map is allowed to fail but it
wasn't checking for a NULL return value. In particular on GLES it will
always fail because glMapBuffer is only provided by an extension. This
adds a new pair of internal functions called
_cogl_buffer_{un,}map_for_fill_or_fallback which wrap
cogl_buffer_map. If the map fails then it will instead return a
pointer into a GByteArray attached to the context. When the buffer is
unmapped the array is copied into the buffer using
cogl_buffer_set_data.
2011-01-13 16:36:32 +00:00
Neil Roberts
ac81f3b936 cogl-context: Don't enable point sprites on GLES2
On GLES2 there's no builtin mechanism to replace texture coordinates
with point sprite coordinates so calling glEnable(GL_POINT_SPRITE)
isn't valid. Instead the point sprite coords are implemented by using
a special builtin varying variable in GLSL.
2011-01-13 14:26:03 +00:00
Robert Bragg
03dbf67ca4 pipeline: differentiate texture target and data state
There are several places where we need to compare the texture state of a
pipeline and sometimes we need to take into consideration if the
underlying texture has changed but other times we may only care to know
if the texture target has changed.

For example the fragends typically generate programs that they want to
share with all pipelines with equivalent fragment processing state, and
in this case when comparing pipelines we only care about the texture
targets since changes to the underlying texture won't affect the
programs generated.

Prior to this we had tried to handle this by passing around some special
flags to various functions that evaluate pipeline state to say when we
do/don't care about the texture data, but this wasn't working in all
cases and was more awkward to manage than the new approach.

Now we simply have two state bits:
COGL_PIPELINE_LAYER_STATE_TEXTURE_TARGET and
COGL_PIPELINE_LAYER_STATE_TEXTURE_DATA and CoglPipelineLayer has an
additional target member. Since all the appropriate code takes masks of
these state bits to determine what to evaluate we don't need any extra
magic flags.
2011-01-13 12:23:33 +00:00
Robert Bragg
a6628ca113 pipeline: optimize state init if changing property
When notifying that a pipeline property is going to change, then at
times a pipeline will take over being the authority of the corresponding
state group. Some state groups can contain multiple properties and so to
maintain the integrity of all of the properties we have to initialize
all the property values in the new authority. For state groups with only
one property we don't have to initialize anything during the
pre_change_notify() because we can assume the value will be initialized
as part of the change being notified.

This patch optimizes how we handle this initialization of state groups
in a couple of ways; firstly we no longer do anything to initialize
state-groups with only one property, secondly we no longer use
_cogl_pipeline_copy_differences - (we have a new
_cogl_pipeline_init_multi_property_sparse_state() func) so we can avoid
lots calls to handle_automatic_blend_enable() which is sometimes seen
high in sysprof profiles.
2011-01-13 12:23:33 +00:00
Neil Roberts
6e14b72284 cogl-atlas-texture: Don't disable atlas if can't read texture data
Previously atlasing would be disabled if the GL driver does not
support reading back texture data. This meant that atlasing would not
happen on GLES. However we also require that the driver support FBOs
and the texture data is only read back as a fallback if the FBO
fails. Therefore the atlas should be ok on GLES 2 which has FBO
support in core.
2011-01-13 11:50:09 +00:00
Robert Bragg
a74050554a pipeline: don't skip flush if skip_gl_color flag differs
We try and bail out of flushing pipeline state asap if we can see the
pipeline has already been flushed and hasn't changed but we weren't
checking to see if the skip_gl_color flag is the same as when it was
last flush too and so we'd sometimes bail out without updating the
glColor correctly.
2011-01-11 14:30:02 +00:00
Neil Roberts
3b3cfe1824 cogl-vertex-attribute: Optionally avoid applying the legacy state
When an item is added to the journal the current pipeline immediately
gets the legacy state applied to it and the modified pipeline is
logged instead of the original. However the actual drawing from the
journal is done using the vertex attribute API which was also applying
the legacy state. This meant that the legacy state used would be a
combination of the state set when the journal entry was added as well
as the state set when the journal is flushed. To fix this there is now
an extra CoglDrawFlag to avoid applying the legacy state when setting
up the GL state for the vertex attributes. The journal uses this flag
when flushing.
2011-01-11 14:06:09 +00:00
Neil Roberts
bbce77fcea cogl-journal: Avoid enabling blending if possible
The vertex attribute API assumes that if there is a color array
enabled then we can't determine if the colors are opaque so we have to
enable blending. The journal always uses a color array to avoid
switching color state between rectangles. Since the journal switched
to using vertex attributes this means we effectively always enable
blending from the journal. To fix this there is now a new flag for
_cogl_draw_vertex_attributes to specify that the color array is known
to only contain opaque colors which causes the draw function not to
copy the pipeline. If the pipeline has blending disabled then the
journal passes this flag.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2481
2011-01-10 17:11:42 +00:00
Neil Roberts
a847289850 cogl-vertex-attribute: Add flags to _cogl_draw_vertex_attributes_array
There is an internal version of cogl_draw_vertex_attributes_array
which previously just bypassed the framebuffer flushing, journal
flushing and pipeline validation so that it could be used to draw the
journal. This patch generalises the function so that it takes a set of
flags to specify which parts to flush. The public version of the
function now just calls the internal version with the flags set to
0. The '_real' version of the function has now been merged into the
internal version of the function because it was only called in one
place. This simplifies the code somewhat. The common code which
flushed the various state has been moved to a separate function. The
indexed versions of the functions have had a similar treatment.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2481
2011-01-10 17:11:41 +00:00
Neil Roberts
4a7dbc0e4e cogl: Don't assume that CoglBitmaps are allocated to height*rowstride
Cogl no longer has any code that assumes the buffer in a CoglBitmap is
allocated to the full size of height*rowstride. We should comment that
this is the case so that we remember to keep it that way. This is
important for cogl_texture_new_from_data because the application may
have created the data from a sub-region of a larger image and in that
case it's not safe to read the full rowstride of the last row when the
sub region contains the last row of the larger image.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2491
2011-01-10 16:55:01 +00:00
Neil Roberts
0f43e01cbc cogl-texture-driver-gles: Don't copy the bitmap if alignment matches
When uploading data for GLES we need to deal with cases where the
rowstride is too large to be described only by GL_UNPACK_ALIGNMENT
because there is no GL_UNPACK_ROW_LENGTH. Previously for the
sub-region uploading code it would always copy the bitmap and for the
code to upload the whole image it would copy the bitmap unless the
rowstride == bpp*width. Neither paths took into account that we don't
need to copy if the rowstride is just an alignment of bpp*width. This
moves the bitmap copying code to a separate function that is used by
both upload methods. It only copies the bitmap if the rowstride is not
just an alignment of bpp*width.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2491
2011-01-10 16:55:00 +00:00
Neil Roberts
14e94647bf cogl-util: Add an internal wrapper for the ffs function
The ffs function is defined in C99 so if we want to use it in Cogl we
need to provide a fallback for MSVC. This adds a configure check for
the function and then a fallback using a while loop if it is not
available.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2491
2011-01-10 16:55:00 +00:00
Neil Roberts
0b2dc74dbc cogl-texture: Don't use the source rowstride if we have to copy bitmap
If we have to copy the bitmap to do the premultiplication then we were
previously using the rowstride of the source image as the rowstride
for the new image. This is wasteful if the source image is a subregion
of a larger image which would make it use a large rowstride. If we
have to copy the data anyway we might as well compact it to the
smallest rowstride. This also prevents the copy from reading past the
end of the last row of pixels.

An internal function called _cogl_bitmap_copy has been added to do the
copy. It creates a new bitmap with the smallest possible rowstride
rounded up the nearest multiple of 4 bytes. There may be other places
in Cogl that are currently assuming we can read height*rowstride of
the source buffer so they may want to take advantage of this function
too.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2491
2011-01-10 16:54:58 +00:00
Neil Roberts
7ae61c3763 cogl-vertex-attribute: Fix the name of the cogl_normal_in attribute
The builtin vertex attribute for the normals was incorrectly checked
for as 'cogl_normal' however it is defined as cogl_normal_in in the
shader boilerplate and for the name generated by CoglVertexBuffer.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2499
2011-01-10 14:29:25 +00:00
Emmanuele Bassi
aa4f63338c docs: Fixes for the Cogl API reference 2010-12-22 09:52:35 +00:00
Neil Roberts
885942aec0 cogl-pipeline-fragend-arbfp: Generate ARBfp if user vertex shader
The ARBfp fragend was bypassing generating a shader if the pipeline
contains a user program. However it shouldn't do this if the pipeline
only contains a vertex shader. This was breaking
test-cogl-just-vertex-shader.
2010-12-14 13:12:28 +00:00
Neil Roberts
9aea72fab5 Allow multiple CoglAtlases for textures
Previously Cogl would only ever use one atlas for textures and if it
reached the maximum texture size then all other new textures would get
their own GL texture. This patch makes it so that we create as many
atlases as needed. This should avoid breaking up some batches and it
will be particularly good if we switch to always using multi-texturing
with a default shader that selects between multiple atlases using a
vertex attribute.

Whenever a new atlas is created it is stored in a GSList on the
context. A weak weference is taken on the atlas using
cogl_object_set_user_data so that it can be removed from the list when
the atlas is destroyed. The atlas textures themselves take a reference
to the atlas and this is the only thing that keeps the atlas
alive. This means that once the atlas becomes empty it will
automatically be destroyed.

All of the COGL_NOTEs pertaining to atlases are now prefixed with the
atlas pointer to make it clearer which atlas is changing.
2010-12-13 18:59:41 +00:00
Neil Roberts
0f0f763570 cogl-atlas: Convert to be a CoglObject subclass
To implement multiple atlases it will be useful to have ref-counting
on the CoglAtlas so it makes sense to convert it to be a CoglObject.
2010-12-13 18:59:41 +00:00
Neil Roberts
03d33a6f4d cogl-shader-boilerplate: Add the 3D texture extension on GLES2
To use the 3D texture extension on GLES2 it has to be enabled with the
following line in GLSL:

#extension GL_OES_texture_3D : enable
2010-12-13 17:29:14 +00:00
Neil Roberts
38971e4977 cogl2-path: Don't flush the enable flags
All of the drawing needed in _cogl_add_path_to_stencil_buffer is done
with the vertex attribute API so there should be no need to flush the
enable flags to enable the vertex array. This was causing problems on
GLES2 where the vertex array isn't available.
2010-12-13 17:29:14 +00:00
Neil Roberts
dc1f1949d0 Remove the GLES2 wrapper
The GLES2 wrapper is no longer needed because the shader generation is
done within the GLSL fragend and vertend and any functions that are
different for GLES2 are now guarded by #ifdefs.
2010-12-13 17:29:14 +00:00
Neil Roberts
2b32a9eb2a cogl-pipeline: Use enums for the layer combine values
Once the GLES2 wrapper is removed then we won't have the GLenums
needed for setting up the layer combine state. This adds Cogl enums
instead which have the same values as the corresponding GLenums. The
enums are:

CoglPipelineCombineFunc
CoglPipelineCombineSource
 and
CoglPipelineCombineOp
2010-12-13 17:29:14 +00:00
Neil Roberts
a05c701e6b cogl: upload matrices with uniforms on GLES2
Once the GLES2 wrapper is removed we won't be able to upload the
matrices with the fixed function API any more. The fixed function API
gives a global state for setting the matrix but if a custom shader
uniform is used for the matrices then the state is per
program. _cogl_matrix_stack_flush_to_gl is called in a few places and
it is assumed the current pipeline doesn't need to be flushed before
it is called. To allow these semantics to continue to work, on GLES2
the matrix flush now just stores a reference to the matrix stack in
the CoglContext. A pre_paint virtual is added to the progend which is
called whenever a pipeline is flushed, even if the same pipeline was
flushed already. This gives the GLSL progend a chance to upload the
matrices to the uniforms. The combined modelview/projection matrix is
only calculated if it is used. The generated programs end up never
using the modelview or projection matrix so it usually only has to
upload the combined matrix. When a matrix stack is flushed a reference
is taked to it by the pipeline progend and the age is stored so that
if the same state is used with the same program again then we don't
need to reupload the uniform.
2010-12-13 17:29:13 +00:00
Neil Roberts
35b07f6b83 cogl-matrix-stack: Add _cogl_matrix_stack_has_identity_flag
This adds an internal function to quickly determine whether the top of
the matrix stack is known to be the identity matrix.
2010-12-13 17:28:52 +00:00
Neil Roberts
c11f72fd6d cogl-matrix-stack: Convert to be a CoglObject
We will want to use ref-counting on the CoglMatrixStack so it might as
well be a CoglObject.
2010-12-13 17:28:29 +00:00
Robert Bragg
d678125dd4 matrix-stack: Make header style consistent
Cogl doesn't follow the Clutter/GTK+ columnized function prototype style
so this updates cogl-matrix-stack.h to match the other Cogl headers.
2010-12-13 17:28:29 +00:00
Robert Bragg
104961de6a matrix-stack: Adds a stack age counter
Sometimes it would be useful if we could efficiently track when a matrix
stack has been modified. For example on GLES2 we have to upload the
modelview as a uniform to our glsl programs but because the modelview
state is part of the framebuffer state it becomes a bit more tricky to
know when to re-sync the value of the uniform with the framebuffer
state. This adds an "age" counter to CoglMatrixStack which is
incremented for any operation that effectively modifies the top of the
stack so now we can save the age of the stack inside the pipeline
whenever we update modelview uniform and later compare that with the
stack to determine if it has changed.
2010-12-13 17:28:29 +00:00
Neil Roberts
566831de66 cogl-pipeline: Add internal API to get the layer matrix
This returns the layer matrix given a pipeline and a layer index. The
API is kept as internal because it directly returns a pointer into the
layer private data to avoid a copy into an out-param. We might also
want to add a public function which does the copy.
2010-12-13 17:28:29 +00:00