1
0
Fork 0
Commit graph

196 commits

Author SHA1 Message Date
Owen W. Taylor
d16df5a5aa Add support for setting up stereo CoglOnscreens
If we want to show quad-buffer stereo with Cogl, we need to pick an
appropriate fbconfig for creating the CoglOnscreen objects. Add
cogl_onscreen_template_set_stereo_enabled() to indicate whether
stereo support is needed.

Add cogl_framebuffer_get_stereo_mode() to see if a framebuffer was
created with stereo support.

Add cogl_framebuffer_get_stereo_mode() to pick whether to draw to
the left, right, or both buffers.

Reviewed-by: Robert Bragg <robert.bragg@intel.com>
2014-07-17 19:27:05 -04:00
Lionel Landwerlin
3aee3f63c4 cogl-gtype: add missing gtype macros in intermediate macros
Reviewed-by: Neil Roberts <neil@linux.intel.com>
2014-03-21 14:28:27 +00:00
Lionel Landwerlin
1b2dd815b4 Registers gtypes for all public objects and structs
This adds much more comprehensive support for gobject-introspection
based bindings by registering all objects as fundamental types that
inherit from CoglObject, and all structs as boxed types.

Co-Author: Robert Bragg <robert@linux.intel.com>

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2014-03-20 18:27:12 +00:00
Robert Bragg
a0441778ad This re-licenses Cogl 1.18 under the MIT license
Since the Cogl 1.18 branch is actively maintained in parallel with the
master branch; this is a counter part to commit 1b83ef938fc16b which
re-licensed the master branch to use the MIT license.

This re-licensing is a follow up to the proposal that was sent to the
Cogl mailing list:
http://lists.freedesktop.org/archives/cogl/2013-December/001465.html

Note: there was a copyright assignment policy in place for Clutter (and
therefore Cogl which was part of Clutter at the time) until the 11th of
June 2010 and so we only checked the details after that point (commit
0bbf50f905)

For each file, authors were identified via this Git command:
$ git blame -p -C -C -C20 -M -M10  0bbf50f905..HEAD

We received blanket approvals for re-licensing all Red Hat and Collabora
contributions which reduced how many people needed to be contacted
individually:
- http://lists.freedesktop.org/archives/cogl/2013-December/001470.html
- http://lists.freedesktop.org/archives/cogl/2014-January/001536.html

Individual approval requests were sent to all the other identified authors
who all confirmed the re-license on the Cogl mailinglist:
http://lists.freedesktop.org/archives/cogl/2014-January

As well as updating the copyright header in all sources files, the
COPYING file has been updated to reflect the license change and also
document the other licenses used in Cogl such as the SGI Free Software
License B, version 2.0 and the 3-clause BSD license.

This patch was not simply cherry-picked from master; but the same
methodology was used to check the source files.
2014-02-22 02:02:53 +00:00
Robert Bragg
1932892b98 framebuffer: move fb stack under cogl/deprecated/
This moves the framebuffer stack apis out of cogl-framebuffer.c into
cogl/deprecated/cogl-framebuffer-deprecated.c so cogl-framebuffer.c is
more in-line with the master branch to ease cherry picking patches.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2014-01-09 16:29:14 +00:00
Robert Bragg
3f780e2f3f get_texture_bits_via_offscreen(): use meta texture format
When reading a texture back by first wrapping it as an offscreen
framebuffer and using _read_pixels_into_bitmap() we now make sure the
offscreen framebuffer has an internal format that matches the
meta-texture being read not that of the current sub-texture being
iterated. In the case of atlas textures the subtexture is a shared
texture whose format doesn't reflect the premultipled alpha status of
individual atlas-textures, nor whether the alpha component is valid.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 6ee425d4f10acd8b008a2c17e5c701fc1d850f59)
2014-01-09 15:49:46 +00:00
Robert Bragg
99cdcc9e3c texture: make cogl_texture_get_format api private
CoglPixelFormat is not a good way of describing the internal
format of a texture because it's too specific given that we don't
actually have exact knowledge of the internal format used by the driver.

This makes cogl_texture_get_format private and in the future we'll
provide a better way of querying the channels and their precision.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit ffde82981f22bd0185a7f33e1e6e1479f4c295b8)

Note: Since we can't break API compatibility on the 1.x branch this adds
a cogl/deprecated/cogl-texture-deprecated.c file with a
cogl_texture_get_format() wrapper around the private api. This also
moves the cogl_texture_get_rowstride() and cogl_texture_ref/unref()
functions that were previously deprecated into cogl-texture-deprecated.c
2014-01-09 15:49:35 +00:00
Robert Bragg
96ed01cc18 framebuffer: defer calculating level size until allocation
The plan is to defer more of the work for creating a texture until
allocation time, but that means we won't be able to always assume
we can query the size of a texture when creating an offscreen
framebuffer from a texture (consider for example using
_texture_new_from_file() where the size isn't known until the file has
been loaded). This defers needing to know the size of the texture
underlying an offscreen framebuffer until calling
cogl_framebuffer_allocate().

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 9688e7dc1eeae3144729dfd4a4bf409620346bf4)
2014-01-09 15:29:30 +00:00
Robert Bragg
08ba5c64b9 framebuffer: if size unknown; allocate for size/vp queries
This ensures framebuffers are implicitly allocated when querying the
width, height or viewport width/height if the framebuffer's size is
currently unknown. The plan is to allow texture backends to defer
calculating the size of textures until they are allocated which in turn
means we won't know the size of offscreen framebuffers until the texture
has been allocated. Potentially we could be more specific about this in
the future and only ensure the texture is allocated, but for now it will
be simplest to just ensure the framebuffer is allocated.

Note: in the case of onscreen buffers which are always initialized with
a requested size we are careful to avoid triggering an allocation when
this is queried otherwise we will see recursion when the winsys code
queries the requested size during allocation.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit f4b612f1b75e043f1852b9a32368cc37ab89308b)
2014-01-09 15:29:30 +00:00
Robert Bragg
a07d26e9ae offscreen: allocate texture before querying slicing
Since we are planning on deferring more texture allocation work this
makes sure we don't query whether a texture is sliced until we know it
has been allocated.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit b742638a1ce581f5a2c9f15907361c3b0c1b178c)
2014-01-09 15:29:30 +00:00
Robert Bragg
2e61318914 framebuffer: make format internal
This removes cogl_framebuffer_get_color_format() since the actual
internal format isn't strictly controlled by us. CoglFramebuffer::format
has been renamed to ::internal_format to make it clearer that it only
really represents the premultiplication status.

The plan is to make most of the work involved in creating a texture
happen lazily when allocating so this patch also changes
_cogl_framebuffer_init() to not take a format argument anymore since we
won't know the format of offscreen framebuffers until the framebuffer is
allocated, after the corresponding texture has been allocated. In the
case of offscreen framebuffers we now update the framebuffer
internal_format during allocation.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 8cc9e1c8bd2fac8b2a95087249c23c952d5e379f)

Note: Since we can't break API compatibility on the 1.x branch this
actually keeps the cogl_framebuffer_get_color_format() api but moves it
into a new deprecated/cogl-framebuffer-deprecated.c file and it now
returns the newly name ::internal_format.
2014-01-09 15:29:30 +00:00
Jasper St. Pierre
1b0d0f3892 cogl-framebuffer: Don't mark the clear clip dirty from the journal
This means that we can't cache the journal read_pixels optimization.

https://bugzilla.gnome.org/show_bug.cgi?id=719582

Reviewed-by: Neil Roberts <neil@linux.intel.com>
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 550bae22d20c8d6d7cf1d090faa9c91619594077)
2013-12-04 18:38:44 +00:00
Neil Roberts
24412798dc Revert "Revert "Remove the framebuffer's stack of clip stacks""
This reverts commit bc41489336.

The reason this was causing problems for Clutter is that it defines
COGL_ENABLE_EXPERIMENTAL_2_0_API which is meant to cause the Cogl
headers not to declare the deprecated API. The reverted patch moved
some additional clipping API to a deprecated header which was
previously being used by Clutter. Clutter was still successfully
compiling but with some warnings for the missing function
declarations. However when the binary is run the clipping would get
completely messed up because it would assume all of the arguments to
the functions are integers instead of floats and the wrong values
would be passed.

Clutter now has commit to make it use the 2.0 API instead of the
deprecated functions so the revert is no longer necessary.

https://git.gnome.org/browse/clutter/commit?id=705640367a5c2ae21405806bfa

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2013-12-04 17:22:01 +00:00
Jasper St. Pierre
bc41489336 Revert "Remove the framebuffer's stack of clip stacks"
This reverts commit ae9cd7ca01.

Pushing this for now so we can get gnome-shell working again without
memory corruption. Let's push a proper fix later for everybody.
2013-12-02 23:32:48 -05:00
Neil Roberts
ae9cd7ca01 Remove the framebuffer's stack of clip stacks
There used to be a function called cogl_clip_stack_save in the public
API which was used when temporarily switching to an offscreen buffer
to save the clip state. This is no longer necessary because each
framebuffer has its own clip stack anyway so the function was removed
in master. However the code to maintain the stack of stacks was
retained. This patch removes it in an effort to simplify the code.

On the 1.18 branch this function is deprecated and the documentation
says that it does nothing. However that is incorrect because it does
actually the push clip stack. I think it would be safe to backport
this patch to the 1.18 branch and actually make it do nothing like it
is documented to do.

https://bugzilla.gnome.org/show_bug.cgi?id=719546
(cherry picked from commit 8655027fdcf03b02fcbbb02d179a0a88ed79c5b3)

This patch has some extra changes while backporting to the 1.18
branch. Here the cogl-clip-state file still contained some deprecated
functions. Instead of deleting the file completely it has been moved
to the deprecated folder. The declarations for this functions have
been moved from cogl1-context.h to a new deprecated/cogl-clip-state.h
header.

Conflicts:
	cogl/Makefile.am
	cogl/cogl-clip-state.c

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2013-11-29 16:35:58 +00:00
Neil Roberts
c5644723f8 Use COGL_FLAGS_* for the context's private feature flags
Previously the private feature flags were stored in an enum and we
already had 31 flags. Adding the 32nd flag would presumably make it
add -2³¹ as one of the values which might cause problems. To avoid
this we'll just use an fixed-size array of longs and use indices for
the enum values like we do for the public features.

A slight complication with this is in the CoglDriverDescription where
we were previously using a static intialised value to describe the set
of features that the driver supports. We can't easily do this with the
flags array so instead the features are stored in a fixed-size array
of indices.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit d94cb984e3c93630f3c2e6e3be9d189672aa20f3)

Conflicts:
	cogl/cogl-context-private.h
	cogl/cogl-context.c
	cogl/cogl-private.h
	cogl/cogl-renderer.c
	cogl/driver/gl/cogl-pipeline-opengl.c
	cogl/driver/gl/gl/cogl-driver-gl.c
	cogl/driver/gl/gl/cogl-pipeline-progend-fixed-arbfp.c
	cogl/driver/gl/gles/cogl-driver-gles.c
	cogl/driver/nop/cogl-driver-nop.c
2013-11-28 18:12:22 +00:00
Neil Roberts
d24f632d91 Revert "framebuffer: Don't mark the clip dirty at mid scene"
This patch doesn't look right because now nothing will ever set
clear_clip_dirty = TRUE. Presumably that would mean that if a
rectangle is drawn and then the journal is flushed before the
framebuffer is read, then it would think it could return the clear
color even though it shouldn't.

Perhaps a better approach would be to make a second version of
_cogl_framebuffer_mark_mid_scene that doesn't set the clear_clip_dirty
flag and call that from the journal instead. As this patch was pushed
without review and without first going into the master branch I think
it makes sense to just revert it and apply a new version to master.

This reverts commit 3eb63f67a3.
2013-11-21 12:12:21 +00:00
Jasper St. Pierre
08ee344fa5 Revert "framebuffer: Fix clip tracking in the unclipped case"
This broke gnome-shell's StScrollViewFade.

This reverts commit 5c5715f4da.
2013-11-19 18:09:55 -05:00
Jasper St. Pierre
5c5715f4da framebuffer: Fix clip tracking in the unclipped case
Leaving the clip bounds untouched means that it will retain the stale value
of whatever it was when we last had a clip; reset it so that it contains the
full framebuffer contents instead.

https://bugzilla.gnome.org/show_bug.cgi?id=712562
2013-11-18 00:43:51 -05:00
Jasper St. Pierre
3eb63f67a3 framebuffer: Don't mark the clip dirty at mid scene
https://bugzilla.gnome.org/show_bug.cgi?id=712562
2013-11-18 00:43:50 -05:00
Hans Petter Jansson
a8e04a7d6b Add API to control per-framebuffer depth writing
Add framebuffer methods cogl_framebuffer_[gs]et_depth_write_enabled()
and backend bits to pass the state on to glDepthMask().

This allows us to enable or disable depth writing per-framebuffer, which
if disabled saves us some work in glClear(). When rendering, the flag
is combined with the pipeline's depth writing flag using a logical AND.

Depth writing is enabled by default.

https://bugzilla.gnome.org/show_bug.cgi?id=709827

Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 71406438c5357eb4e0ef03e940c5456a536602a0)
2013-10-28 16:34:58 +00:00
Robert Bragg
c1724eff60 framebuffer: NOP _set_color_mask if mask isn't changing
This makes cogl_framebuffer_set_color_mask immediately bail out if the
given mask equals the framebuffer's current mask, since the cost of
flushing the journal and flushing the gl state will hugely outweigh the
cost of the check.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 925174d99df7f1f4b11098e748bcc23eaa396a21)
2013-10-28 16:34:57 +00:00
Robert Bragg
daa3a7d7b5 framebuffer: restore api to maintain ABI for release
This restores the cogl_framebufer_[v]draw_*_attributes APIs for the 1.16
branch so we can avoid changing the soname for the 1.15.6 release
2013-08-20 01:06:25 +01:00
Robert Bragg
1317a25a91 offscreen: rename _new_to_texture to _new_with_texture
This renames cogl_offscreen_new_to_texture to
cogl_offscreen_new_with_texture. The intention is to then cherry-pick
this back to the cogl-1.16 branch so we can maintain a parallel
cogl_offscreen_new_to_texture() function which keeps the synchronous
allocation semantics that some clutter applications are currently
relying on.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit ecc6d2f64481626992b2fe6cdfa7b999270b28f5)

Note: Since we can't break the 1.x api on this branch this keeps a
thin shim around cogl_offscreen_new_with_texture to implement
cogl_offscreen_new_to_texture with its synchronous allocation
semantics.
2013-08-19 22:44:44 +01:00
Adel Gadllah
64aa6092ce offscreen: Allocate the framebuffer in cogl_offscreen_new_to_texture_full
The API says that it should return NULL on failure but it does not do that
due to the lazy allocation.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

https://bugzilla.gnome.org/show_bug.cgi?id=703174
2013-08-19 22:44:44 +01:00
Robert Bragg
7365c3aa77 Separate out CoglPath api into sub-library
This splits out the cogl_path_ api into a separate cogl-path sub-library
like cogl-pango and cogl-gst. This enables developers to build Cogl with
this sub-library disabled if they don't need it which can be useful when
its important to keep the size of an application and its dependencies
down to a minimum. The functions cogl_framebuffer_{fill,stroke}_path
have been renamed to cogl_path_{fill,stroke}.

There were a few places in core cogl and cogl-gst that referenced the
CoglPath api and these have been decoupled by using the CoglPrimitive
api instead. In the case of cogl_framebuffer_push_path_clip() the core
clip stack no longer accepts path clips directly but it's now possible
to get a CoglPrimitive for the fill of a path and so the implementation
of cogl_framebuffer_push_path_clip() now lives in cogl-path and works as
a shim that first gets a CoglPrimitive and uses
cogl_framebuffer_push_primitive_clip instead.

We may want to consider renaming cogl_framebuffer_push_path_clip to
put it in the cogl_path_ namespace.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 8aadfd829239534fb4ec8255cdea813d698c5a3f)

So as to avoid breaking the 1.x API or even the ABI since we are quite
late in the 1.16 development cycle the patch was modified to build
cogl-path as a noinst_LTLIBRARY before building cogl and link the code
directly into libcogl.so as it was previously. This way we can wait
until the start of the 1.18 cycle before splitting the code into a
separate libcogl-path.so.

This also adds shims for cogl_framebuffer_fill/stroke_path() to avoid
breaking the 1.x API/ABI.
2013-08-19 22:44:35 +01:00
Robert Bragg
e4f24dba75 framebuffer: remove attribute drawing apis
Almost nothing draws attributes directly and for those things that do
it's trivial to adapt them to instead draw via the cogl_primitive api.
This simplifies the Cogl api a bit.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 7395925bcc01aad6c695fd0d9af78b784b3c64d4)

Conflicts:
	cogl/cogl-framebuffer.c
	cogl/cogl-framebuffer.h
2013-07-30 15:08:39 +01:00
Robert Bragg
e9f721216e Add _primitive_draw to replace _framebuffer_draw_primitive
When splitting out the CoglPath api we saw that we would be left with
inconsistent drawing apis if the drawing apis in core Cogl were lumped
into the cogl_framebuffer_ api considering other Cogl sub-libraries or
that others will want to create higher level drawing apis outside of
Cogl but can't use the same namespace.

So that we can aim for a more consistent style this adds a
cogl_primitive_draw() api, comparable to cogl_path_fill() or
cogl_pango_show_layout() that's intended to replace
cogl_framebuffer_draw_primitive()

Note: the attribute and rectangle drawing apis are still in the
cogl_framebuffer_ namespace and this might potentially change but in
these cases there is no single object representing the thing being drawn
so it seems a more reasonable they they live in the framebuffer
namespace for now.

Note: the cogl_framebuffer_draw_primitive() api isn't removed by this
patch so it can more conveniently be cherry picked to the 1.16 branch so
we can mark it deprecated for a short while. Even though it's marked as
experimental api we know that there are people using the api so we'd
like to give them a chance to switch to the new api.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 418912b93ff81a47f9b38114d05335ab76277c48)

Conflicts:
	cogl-pango/cogl-pango-display-list.c
	cogl/Makefile.am
	cogl/cogl-framebuffer.c
	cogl/cogl-pipeline-layer-state.h
	cogl/cogl2-path.c
	cogl/driver/gl/cogl-clip-stack-gl.c
2013-07-29 18:31:36 +01:00
Neil Roberts
d0944b8fbd Add a callback to get dirty events from a CoglOnscreen
This adds a callback that can be registered with
cogl_onscreen_add_dirty_callback which will get called whenever the
window system determines that the contents of the window is dirty and
needs to be redrawn. Under the two X-based winsys's, this is reported
off the back of the Expose events, under SDL it is reported from
SDL_VIDEOEXPOSE or SDL_WINDOWEVENT_EXPOSED and under Windows from the
WM_PAINT messages. The Wayland winsys doesn't really have the concept
of dirtying the buffer but in order to allow applications to work the
same way on all platforms it will emit the event when the surface is
first shown and whenever it is resized.

There is a private feature flag to specify whether dirty events are
supported. If the winsys does not set this then Cogl will simulate
dirty events by emitting one when the window is first allocated and
when it is resized. The only winsys's that don't set this flag are
things like KMS or the EGL null winsys where there is no windowing
system and showing and hiding the onscreen doesn't really make any
sense. In that case Cogl can assume the buffer will only become dirty
once when it is first allocated.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 85c5a9ba419b2247bd768284c79ee69164a0c098)

Conflicts:
	cogl/cogl-private.h
2013-05-30 13:42:56 +01:00
Neil Roberts
45e18e0fb7 wayland: Don't delay resize if nothing is drawn since last swap
After discussing with Kristian Høgsberg it seems that the semantics of
wl_egl_window_resize is meant to be that if nothing has been drawn to
the framebuffer since the last swap then the resize will take effect
immediately. Cogl was previously always delaying the call to
wl_egl_window_resize until the next swap. That meant that if you
wanted to resize the surface you would have to call
cogl_wayland_onscreen_resize and then redundantly draw a frame at the
old size so that you can swap to get the resize to occur before
drawing again at the right size. Typically an application would decide
to resize at the start of its paint sequence so it should be able to
just resize immediately.

In current Mesa master it seems that there is a bug which means that
it won't actually delay a resize that is done mid-scene and instead it
will just discard what came before. To get consistent behaviour in
Cogl, the code to delay the call to wl_egl_window_resize is still used
if it determines that the buffer is dirty. There is an existing
_cogl_framebuffer_mark_mid_scene call which was being used to track
when the framebuffer becomes dirty since the last clear. This function
is now also used to track a new flag to track whether something has
been drawn since the last swap. It is called ‘mid_scene’ under the
assumption that this may also be useful for other things later.

cogl_framebuffer_clear has been slightly altered to always call
_cogl_framebuffer_mark_mid_scene even if it determines that it doesn't
need to clear because the framebuffer should still be considered to be
in the middle of a scene. Adding a quad to the journal now also begins
the scene.

This also fixes a potential bug where it looks like pending_dx/dy were
never cleared so they would always be accumulated even after the
resize is flushed.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 945689a62903990a20abb87a85d2c96eb3985fe7)
2013-05-30 13:42:11 +01:00
Neil Roberts
2a42576fe7 Rename _cogl_framebuffer_dirty to _cogl_framebuffer_mark_mid_scene
In some later patches we want to be able to use the term ‘dirty’ as a
public facing concept which represents expose events from the window
system. In that case the internal concept of dirtying the framebuffer
is confusing, so this patch changes the name to instead mean that
we've doing something which causes the framebuffer to be in the middle
of a frame.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 88eed85b52c29f66659ea112038f3522c9bd864e)
2013-05-30 13:42:11 +01:00
Daniel Stone
ea7d3b8476 Add fence API
cogl_framebuffer_add_fence creates a synchronisation fence, which will
invoke a user-specified callback when the GPU has finished executing all
commands provided to it up to that point in time.

Support is currently provided for GL 3.x's GL_ARB_sync extension, and
EGL's EGL_KHR_fence_sync (when used with OpenGL ES).

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Reviewed-by: Robert Bragg <robert@linux.intel.com>

https://bugzilla.gnome.org/show_bug.cgi?id=691752

(cherry picked from commit e6d37470da9294adc1554c0a8c91aa2af560ed9f)
2013-05-28 21:36:03 +01:00
Robert Bragg
3c5ebb8752 framebuffer: vp change = clip change for gen6 workaround
This makes sure that a viewport change when comparing between separate
framebuffers also implies a clip change when we are applying the Intel
gen6 workaround for broken viewport clipping. Without this then
switching between different size framebuffers could leave a scissor
matching the size of a previous framebuffer.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit f23f2129c58550f819cff783f47039d7bd91391e)
2013-03-06 16:45:14 +00:00
Robert Bragg
1d31055ddb disable viewport scissor workaround for clear
We have a workaround in Cogl to fix viewport clipping with Mesa Intel
Gen 6 drivers but this was breaking the semantics of
cogl_framebuffer_clear() which should not be affected by viewport
clipping. This makes sure we disable and restore the workaround when
clearing the framebuffer. This fixes Clutter's test-cogl-viewport
conformance test.
2013-01-22 17:48:19 +00:00
Neil Roberts
520ccba49d Query the framebuffer stencil bits instead of assuming it's global
Previously when the context was initialised Cogl would query the
number of stencil bits and set a private feature flag to mark that it
can use the buffer for clipping if there was at least 3. The problem
with this is that the number of stencil bits returned by
GL_STENCIL_BITS depends on the currently bound framebuffer. This patch
adds an internal function to query the number of stencil bits in a
framebuffer and makes it use that instead when determining whether it
can push the clip using the stencil buffer.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit e928d21516a6c07798655341f4f0f8e3c1d1686c)
2013-01-22 17:48:18 +00:00
Neil Roberts
109e576b1f Add a public cogl_framebuffer_get_depth_bits() function
Cogl publicly exposes the depth buffer state so we might as well have
a function to query the number of depth bits of a framebuffer.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 853143eb10387f50f8d32cf09af31b8829dc1e01)
2013-01-22 17:48:18 +00:00
Neil Roberts
0b01c91fc5 framebuffer: Bind the framebuffer before querying the bits
The GL framebuffer driver now makes sure to bind the framebuffer
before counting the number of bits. Previously it would just query the
number of bits for whatever framebuffer happened to be used last.

In addition the virtual for querying the framebuffer bits has been
modified to take a pointer to a structure instead of a separate
pointer to each component. This should make it slightly more efficient
and easier to maintain.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit e9c58b2ba23a7cebcd4e633ea7c3191f02056fb5)
2013-01-22 17:48:18 +00:00
Robert Bragg
73e8a6d7ce Allow lazy texture storage allocation
Consistent with how we lazily allocate framebuffers this patch allows us
to instantiate textures but still specify constraints and requirements
before allocating storage so that we can be sure to allocate the most
appropriate/efficient storage.

This adds a cogl_texture_allocate() function that is analogous to
cogl_framebuffer_allocate() which can optionally be called to explicitly
allocate storage and catch any errors. If this function isn't used
explicitly then Cogl will implicitly ensure textures are allocated
before the storage is needed.

It is generally recommended to rely on lazy storage allocation or at
least perform explicit allocation as late as possible so Cogl can be
fully informed about the best way to allocate storage.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 1fa7c0f10a8a03043e3c75cb079a49625df098b7)

Note: This reverts the cogl_texture_rectangle_new_with_size API change
that dropped the CoglError argument and keeps the semantics of
allocating the texture immediately. This is because Mutter currently
uses this API so we will probably look at updating this later once
we have a corresponding Mutter patch prepared. The other API changes
were kept since they only affected experimental api.
2013-01-22 17:48:17 +00:00
Robert Bragg
a57195d16d framebuffer: split out GL read_pixels code
This moves the direct use of GL in cogl-framebuffer.c for handling
cogl_framebuffer_read_pixels_into_bitmap() into
driver/gl/cogl-framebuffer-gl.c and adds a
->framebuffer_read_pixels_into_bitmap vfunc to CoglDriverVtable.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 2f893054d6754e6bc7983f061b27c7858f1a593c)
2013-01-22 17:48:17 +00:00
Robert Bragg
36c85da3b8 Remove cogl-internal.h
This remove cogl-internal.h in favour of using cogl-private.h. Some
things in cogl-internal.h were moved to driver/gl/cogl-util-gl-private.h
and the _cogl_gl_error_to_string function whose prototype was moved from
cogl-internal.h to cogl-util-gl-private.h has had its implementation
moved from cogl.c to cogl-util-gl.c

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 01cc82ece091aa3bec4c07fdd6bc9e5135fca573)
2013-01-22 17:48:17 +00:00
Robert Bragg
cab4622eb3 matrix-stack: make CoglMatrixStack public
We have found several times now when writing code using Cogl that it
would really help if Cogl's matrix stack api was public as a utility
api. In Rig for example we want to avoid redundant arithmetic when
deriving the matrices of entities used to render and we aren't able
to simply use the framebuffer's matrix stack to achieve this. Also when
implementing cairo-cogl we found that it would be really useful if we
could have a matrix stack utility api.

(cherry picked from commit d17a01fd935d88fab96fe6cc0b906c84026c0067)
2013-01-22 17:48:11 +00:00
Robert Bragg
110a7d0ed7 framebuffer: remove use of _COGL_GET_CONTEXT
Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit b8755a98e4139b6a077ff329b9c5900292d3a1d3)
2013-01-22 17:48:08 +00:00
Neil Roberts
af0dc3431d Fix spelling of _cogl_propagate_error
‘Propagate’ was misspelled as ‘propogate’.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 5fb4a6178c3e64371c01510690d9de1e8a740bde)
2013-01-22 17:48:08 +00:00
Robert Bragg
38921701e5 blit: avoid referring to framebuffer stack
This make _cogl_framebuffer_blit take explicit src and dest framebuffer
pointers and updates all the texture blitting strategies in cogl-blit.c
to avoid pushing/popping to/from the the framebuffer stack.

The removes the last user of the framebuffer stack which we've been
aiming to remove before Cogl 2.0

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 598ca33950a93dd7a201045c4abccda2a855e936)
2013-01-22 17:48:08 +00:00
Robert Bragg
da9f5e6179 bitmap: ret CoglError from _new_with_malloc_buffer
_cogl_bitmap_new_with_malloc_buffer() now takes a CoglError for throwing
exceptional errors and all callers have been updated to pass through
any application error pointer as appropriate.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 67cad9c0eb5e2650b75aff16abde49f23aabd0cc)
2013-01-22 17:48:08 +00:00
Robert Bragg
f53fb5e2e0 Allow propogation of OOM errors to apps
This allows apps to catch out-of-memory errors when allocating textures.

Textures can be pretty huge at times and so it's quite possible for an
application to try and allocate more memory than is available. It's also
very possible that the application can take some action in response to
reduce memory pressure (such as freeing up texture caches perhaps) so
we shouldn't just automatically abort like we do for trivial heap
allocations.

These public functions now take a CoglError argument so applications can
catch out of memory errors:

cogl_buffer_map
cogl_buffer_map_range
cogl_buffer_set_data
cogl_framebuffer_read_pixels_into_bitmap
cogl_pixel_buffer_new
cogl_texture_new_from_data
cogl_texture_new_from_bitmap

Note: we've been quite conservative with how many apis we let throw OOM
CoglErrors since we don't really want to put a burdon on developers to
be checking for errors with every cogl api call. So long as there is
some lower level api for apps to use that let them catch OOM errors
for everything necessary that's enough and we don't have to make more
convenient apis more awkward to use.

The main focus is on bitmaps and texture allocations since they
can be particularly large and prone to failing.

A new cogl_attribute_buffer_new_with_size() function has been added in
case developers need to catch OOM errors when allocating attribute buffers
whereby they can first use _buffer_new_with_size() (which doesn't take a
CoglError) followed by cogl_buffer_set_data() which will lazily allocate
the buffer storage and report OOM errors.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit f7735e141ad537a253b02afa2a8238f96340b978)

Note: since we can't break the API for Cogl 1.x then actually the main
purpose of cherry picking this patch is to keep in-line with changes
on the master branch so that we can easily cherry-pick patches.

All the api changes relating stable apis released on the 1.12 branch
have been reverted as part of cherry-picking this patch so this most
just applies all the internal plumbing changes that enable us to
correctly propagate OOM errors.
2013-01-22 17:48:07 +00:00
Neil Roberts
982ee75319 Fix flushing the stencil viewport clipping workaround
There were two problems with the stencil viewport clip workaround
introduced in afc5daab8:

• When the viewport is changed the current clip state is not marked as
  dirty. That means that when the framebuffer state is next flushed it
  would continue to use the stencil from the previous viewport.

• When the viewport is automatically updated due to the window being
  resized the viewport age was not incremented so the clip state
  wouldn't be flushed.

I noticed the bugs by running cogl-sdl2-hello.

This patch makes it so that the clip state is dirtied in
cogl_framebuffer_set_viewport if the workaround is enabled.

The automatic viewport changing code now just calls
cogl_framebuffer_set_viewport instead of directly prodding the
viewport values. This has the side-effect that it will also cause the
journal to be flushed. This seems like the right thing to do anyway
and presumably there would have been a bug before where it wouldn't
have flushed the journal, although presumably this is extremely
unlikely because it would have to have done a resize in the middle of
painting the scene.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 0dca99ddf728c8d4e3003861a03e8a2beccf282d)
2013-01-22 17:48:04 +00:00
Robert Bragg
6cfc93f26f clip-stack: workaround intel gen6 viewport clip bug
The Intel Mesa gen6 driver doesn't currently handle scissoring offset
viewports correctly, so this implements a workaround to intersect the
current viewport bounds with the scissor rectangle.

(cherry picked from commit afc5daab85e5faca99d6d6866658cb82c3954830)
2013-01-22 17:48:04 +00:00
Neil Roberts
2616ae0fa9 Add a GL 3 driver
This adds a new CoglDriver for GL 3 called COGL_DRIVER_GL3. When
requested, the GLX, EGL and SDL2 winsyss will set the necessary
attributes to request a forward-compatible core profile 3.1 context.
That means it will have no deprecated features.

To simplify the explosion of checks for specific combinations of
context->driver, many of these conditionals have now been replaced
with private feature flags that are checked instead. The GL and GLES
drivers now initialise these private feature flags depending on which
driver is used.

The fixed function backends now explicitly check whether the fixed
function private feature is available which means the GL3 driver will
fall back to always using the GLSL progend. Since Rob's latest patches
the GLSL progend no longer uses any fixed function API anyway so it
should just work.

The driver is currently lower priority than COGL_DRIVER_GL so it will
not be used unless it is specificly requested. We may want to change
this priority at some point because apparently Mesa can make some
memory savings if a core profile context is used.

In GL 3, getting the combined extensions string with glGetString is
deprecated so this patch changes it to use glGetStringi to build up an
array of extensions instead. _cogl_context_get_gl_extensions now
returns this array instead of trying to return a const string. The
caller is expected to free the array.

Some issues with this patch:

• GL 3 does not support GL_ALPHA format textures. We should probably
  make this a feature flag or something. Cogl uses this to render text
  which currently just throws a GL error and breaks so it's pretty
  important to do something about this before considering the GL3
  driver to be stable.

• GL 3 doesn't support client side vertex buffers. This probably
  doesn't matter because CoglBuffer won't normally use malloc'd
  buffers if VBOs are available, but it might but worth making
  malloc'd buffers a private feature and forcing it not to use them.

• GL 3 doesn't support the default vertex array object. This patch
  just makes it create and bind a single non-default vertex array
  object which gets used just like the normal default object. Ideally
  it would be good to use vertex array objects properly and attach
  them to a CoglPrimitive to cache the state.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 66c9db993595b3a22e63f4c201ea468bc9b88cb6)
2013-01-22 17:48:01 +00:00
Robert Bragg
bcf6a61d0b Give buffer/bitmap bind functions gl infix
The buffer and bitmap _bind() functions are GL specific so to clarify
that, this patch adds a _gl infix to these functions, though it doesn't
yet move the implementations out into gl specific files.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 6371fbb9637d88ff187dfb6c4bcd18468ba44d19)
2013-01-22 17:47:59 +00:00