Commit Graph

6 Commits

Author SHA1 Message Date
Robert Bragg
df21e20f65 Adds CoglError api
Although we use GLib internally in Cogl we would rather not leak GLib
api through Cogl's own api, except through explicitly namespaced
cogl_glib_ / cogl_gtype_ feature apis.

One of the benefits we see to not leaking GLib through Cogl's public API
is that documentation for Cogl won't need to first introduce the Glib
API to newcomers, thus hopefully lowering the barrier to learning Cogl.

This patch provides a Cogl specific typedef for reporting runtime errors
which by no coincidence matches the typedef for GError exactly.  If Cogl
is built with --enable-glib (default) then developers can even safely
assume that a CoglError is a GError under the hood.

This patch also enforces a consistent policy for when NULL is passed as
an error argument and an error is thrown. In this case we log the error
and abort the application, instead of silently ignoring it. In common
cases where nothing has been implemented to handle a particular error
and/or where applications are just printing the error and aborting
themselves then this saves some typing. This also seems more consistent
with language based exceptions which usually cause a program to abort if
they are not explicitly caught (which passing a non-NULL error signifies
in this case)

Since this policy for NULL error pointers is stricter than the standard
GError convention, there is a clear note in the documentation to warn
developers that are used to using the GError api.

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

(cherry picked from commit b068d5ea09ab32c37e8c965fc8582c85d1b2db46)

Note: Since we can't change the Cogl 1.x api the patch was changed to
not rename _error_quark() functions to be _error_domain() functions and
although it's a bit ugly, instead of providing our own CoglError type
that's compatible with GError we simply #define CoglError to GError
unless Cogl is built with glib disabled.

Note: this patch does technically introduce an API break since it drops
the cogl_error_get_type() symbol generated by glib-mkenum (Since the
CoglError enum was replaced by a CoglSystemError enum) but for now we
are assuming that this will not affect anyone currently using the Cogl
API. If this does turn out to be a problem in practice then we would be
able to fix this my manually copying an implementation of
cogl_error_get_type() generated by glib-mkenum into a compatibility
source file and we could also define the original COGL_ERROR_ enums for
compatibility too.

Note: another minor concern with cherry-picking this patch to the 1.14
branch is that an api scanner would be lead to believe that some APIs
have changed, and for example the gobject-introspection parser which
understands the semantics of GError will not understand the semantics of
CoglError. We expect most people that have tried to use
gobject-introspection with Cogl already understand though that it is not
well suited to generating bindings of the Cogl api anyway and we aren't
aware or anyone depending on such bindings for apis involving GErrors.
(GnomeShell only makes very-very minimal use of Cogl via the gjs
bindings for the cogl_rectangle and cogl_color apis.)

The main reason we have cherry-picked this patch to the 1.14 branch
even given the above concerns is that without it it would become very
awkward for us to cherry-pick other beneficial patches from master.
2013-01-22 17:47:39 +00:00
Neil Roberts
19ccb72b80 cogl-gles2-context: Wrap glCopyTex{Sub,}Image2D to flip the result
When the CoglGLES2Context is bound to read from a CoglOffscreen then
the result will be upside down from what GL expects if
glCopyTexImage2D is used directly. To fix that, this patch now wraps
glCopyTexImage2D and glCopyTexSubImage2D so that the copy is doing by
binding an FBO to the target texture and then rendering a quad
sampling from the texture in the offscreen framebuffer.

The rendering is done using the Cogl context rather than the GLES2
context because otherwise it would have to do a fair bit of work to
try and stash the old state on the context before setting up the state
to do the blit. The down side of this is that the contexts need to be
synchronized so that the rendering will be up-to-date. As far as I
understand from the GL spec, this requires a glFinish and then the
texture needs to be rebound in the new context because updates to
shared objects are guaranteed to be reflected until the object is
rebound.

GLES2 supports using glCopyTexImage2D for cube map textures. As Cogl
doesn't currently have support for cube maps, it is quite hard to get
that to work with this patch. For now attempts to copy to a cube map
texture will just be sliently ignored.

This patch also includes a test case which renders an image to the
framebuffer and then copies it to a texture. The texture is then
rendered back to the framebuffer and the contents are checked for the
correct orientation using glReadPixels.

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

(cherry picked from commit 30b6da8134bad95267265e26685c7475f6c351c9)
2012-08-15 13:46:20 +01:00
Neil Roberts
d12399b823 test-gles2-context: Add a test case for rendering to an FBO
This adds an extra test to test-gles2-context which renders to an FBO
and then checks that the orientation is correct once the texture is
rendered via Cogl. This should test the code path to flip the GLES2
rendering in Cogl.

The rendering is done in three different ways to test the various
state that needs flipping:

• Just renders two triangle strips, one at the top and one at the
  bottom.

• Renders two full screen triangle strips, but each with a different
  viewport to clip it to the top or the bottom.

• Clears the screen with two different colors and a scissor to either
  the top or the bottom.

• Renders both quads twice with two different colors and two different
  front face states.

Additionally the rendering is verified by calling glReadPixels to
check that the returned pixels are flipped correctly.

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

(cherry picked from commit 5b097f9bc4a3eb316c6bf0d9fe8db00ff93bfe73)
2012-08-15 13:44:16 +01:00
Neil Roberts
4c1b7c979d test-gles2-context: Fix error checking for cogl_gles2_context_new
The test was passing NULL as the error argument but then trying to use
the error object if it failed so it would just crash in that case.

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

(cherry picked from commit 61cbbb3000fb4001d51999fd05179c620b7e56bf)
2012-08-14 18:55:42 +01:00
Neil Roberts
06c3a7bc70 Fix a warning on test-gles2-context
test-gles2-context was giving a warning because printf was being used
without including stdio.h. This changes it to use g_print and to first
check for g_test_verbose().

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

(cherry picked from commit 9f4945e3daa693e1aa56fe4c1ce37fcc545f8558)
2012-08-06 14:27:43 +01:00
Robert Bragg
8d0b771cd3 conform: Adds a gles2 context test
This adds a conformance test that creates a GLES2 context via the cogl
api and verifies clearing an offscreen framebuffer via the gles2 api,
and switching back and forth between the Cogl and GLES2 apis.

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

(cherry picked from commit 9369c60a596c0cbc7a8bb9a45d7b8ffb6a848311)
2012-08-06 14:27:42 +01:00