1
0
Fork 0
Commit graph

1782 commits

Author SHA1 Message Date
Damien Lespiau
5912ee9997 doc: Fix the remaining broken internal cross-references
Symbols changed names, %1 makes gtk-doc sad and some referenced symbols
were missing in the -sections.txt file.

(cherry picked from commit c12919c321186ac7b223bc4f82c588ca2f199d67)
2013-01-22 17:48:16 +00:00
Damien Lespiau
4316c3c9e1 doc: Use Docbook's <constant> for external constants
For external (non gtk-doc even) constants, we can use <constant> to
correctly tag those without gtk-doc trying to cross-reference them.

(cherry picked from commit 78d22c6cd44a2279adcd2b94c3317292af861c70)
2013-01-22 17:48:16 +00:00
Damien Lespiau
ec6a713fcc doc: Add a missing '*' to the documentation of CoglFilterReturn
(cherry picked from commit 0b9bdd5aaf2616993c4c20c7d7317daf178b19fd)
2013-01-22 17:48:16 +00:00
Damien Lespiau
c0a024f81d doc: Put the opening '{' at the end of combined typedefs
gtk-doc is not smart enough to parse things like:

  typedef struct
  {
    ...
  } CoglFoo;

but needs the '{' at the end of the first line.

(cherry picked from commit d1187550ef547305fdeb8a22a7e39a95611a0e1d)
2013-01-22 17:48:15 +00:00
Damien Lespiau
bde1d2e661 doc: Fix FALSE documentation
Typo with the copy & paste from TRUE.

(cherry picked from commit c7d4a13889ee5681a237a0d2a0fbbdca79120f17)
2013-01-22 17:48:15 +00:00
Damien Lespiau
9401cb044e doc: Fixup type references
gtk-doc needs the types in -sections.txt to be able to do
cross-references. Add all those currently generating warnings.

(cherry picked from commit e57a21d2608f0885e6f2eb3a017feb7dffb7a63c)
2013-01-22 17:48:15 +00:00
Damien Lespiau
55d2a039c6 doc: Don't use '::' to denote an object property
That's actually for signals in gtk-doc and we're not dealing with
GObjects so it's not really appropriate. Used <structfield> as it's the
closest tag I could find to describe a 'property' of a CoglObject and
gives a generic style in the produced HTML.

(cherry picked from commit 8b485d57577cff227a0c7a2e6c06d8d277821374)
2013-01-22 17:48:15 +00:00
Damien Lespiau
780b01f1c8 doc: Populate cogl-types a bit more and move it to the general section
I just added the general types creating warnings in the current state of the
documentation (ie the ones references by already documented functions)
and moved the section from the 'Utility' section to the 'General'
section which I believe is a better fit as they are used by more than
one type and not really utilities.

(cherry picked from commit c51b147789763863ef32482d7ffa936160ed7c93)
2013-01-22 17:48:15 +00:00
Damien Lespiau
5c12c36c58 doc: Don't use the HTML <ul> but the DocBook equivalent
Of course, this confused gtk-doc.

(cherry picked from commit be512104784a9200a2e98a75d16a56e3897a8845)
2013-01-22 17:48:15 +00:00
Damien Lespiau
f1f1e876f1 doc: Fix the remaining warning around the depth state
Various changes have led to the current, separate from the pipeline,
depth state, this commit fixes the remaining waring around that.

(cherry picked from commit 111e687e722ad67a0e1c09f881c6282ccb06410b)
2013-01-22 17:48:15 +00:00
Damien Lespiau
9ae9602047 doc: Expose CoglDepthState
It wasn't included to the documention up to now.

(cherry picked from commit 826c0d5c8333ad31595d690d7c8753f84d12b2ad)
2013-01-22 17:48:14 +00:00
Damien Lespiau
17333d3f10 doc: Use <ulink> to make Gimbal Lock reactive
Instead of just having the reference at the end of the paragraph.
Usually seen as more usable.

(cherry picked from commit 6988d3ae61ab16fb298b34d2bd31860833f04186)
2013-01-22 17:48:14 +00:00
Damien Lespiau
61e1206d33 doc: Unhide cogl-matrix-stack.h
The documentation welcomes a new 2.0 API.

(cherry picked from commit 8d78957c8d29b89c7bf352131d84c9755083eed9)
2013-01-22 17:48:14 +00:00
Damien Lespiau
f2b0dac871 doc: Document CoglColor
(cherry picked from commit a0dfba1eb1c541490611a021799e656bf43a04fe)
2013-01-22 17:48:14 +00:00
Damien Lespiau
cfcb440d70 doc: Document the members of CoglPollFDEvent
(cherry picked from commit 7cc94c2a994a774f0d8db172c9e0bec506bd2287)
2013-01-22 17:48:14 +00:00
Damien Lespiau
864e5562df doc: Fix various mismatches between arguments and their documentation
Argument names and @$arg suffered from various little mismatches, fix
them in a batch commit.

(cherry picked from commit d2ac3c5a88d980e7519c98bd261111b93cf73a6e)
2013-01-22 17:48:13 +00:00
Damien Lespiau
6aadb4a0db doc: Make a pass on CoglRenderer argument documentation
Various arguments where missing, added them.

(cherry picked from commit 6e6ee4acb5524ced2f82d42d9c6a706f84f8184c)
2013-01-22 17:48:13 +00:00
Damien Lespiau
f63b4597f7 doc: Finish describing the arguments of cogl_error_matches()
(cherry picked from commit 8f429d9ce45e3df204db0bdc0d988fd07f103282)
2013-01-22 17:48:13 +00:00
Damien Lespiau
532cd9bf9f doc: Fix small typo of sequence
(cherry picked from commit 09706dc78178d022b4313572600a245112d23fd9)
2013-01-22 17:48:13 +00:00
Damien Lespiau
0142d027d7 doc: Update the section name and description of CoglIndices
cogl-index-range was the old API, update the section name to match what
is declared in the documentation. Also update the short description to
better match the new API.

(cherry picked from commit d73df38ff2a8ebe477e139e5ac20838c8f4364bb)
2013-01-22 17:48:13 +00:00
Damien Lespiau
e4ca3cb039 doc: s/Fuction/Function/
(cherry picked from commit 8e62a12cff9ba0a267d199c359fdc8e591f65264)
2013-01-22 17:48:12 +00:00
Damien Lespiau
8c1708ec93 doc: Fix argument syntax of existing commment blocks
Fixes:
  Parsing comment block file : parameter expecter

by correctly declaring parameters.

(cherry picked from commit 2fe9bc2017fa966ab445674a530aac0c17204040)
2013-01-22 17:48:12 +00:00
Damien Lespiau
388e589ac4 doc: Fix a typo in the description of cogl-bitmap
(cherry picked from commit 423b8f8c62b1f73d6b0e24a5689428821e154703)
2013-01-22 17:48:12 +00:00
Damien Lespiau
81a94a7849 doc: Expose the Cogl GLES 2.0 facilities in the documentation
(cherry picked from commit 0c2344b9aafe4afdf7782fd9badc451de79b7a63)
2013-01-22 17:48:12 +00:00
Damien Lespiau
37cc715269 doc: Add missing symbol in cogl_framebuffer_get_context() documentation
(cherry picked from commit 146a1bfc2655c7e7ed0a5a4fd64b490385159f49)
2013-01-22 17:48:12 +00:00
Damien Lespiau
7b43289ec9 doc: Use Returns: to annotate return values
gtk-doc complains that having a sentence starting by Return is a bit
ambiguous and it'd rather see 'Returns:' spelled out.

Fixes 2 warnings:

 warning: Free-form return value description in $symbol. Use `Returns:'
 to avoid ambiguities

(cherry picked from commit 9718f31717b3a0e01b7c4c69cea138f39d23c0e0)
2013-01-22 17:48:11 +00:00
Damien Lespiau
b8d9bbed1a Don't use #if with defines that are either defined or not
COGL_HAS_* and COGL_ENABLE_DEBUG are either defined in config.h or not.

So let's test against this, not against their truth value, this allow us
to use -Wundef to catch undefined macros in preprocessor directives.

(cherry picked from commit 73b62832f24711073b0876a6c0f5c61727842c1c)
2013-01-22 17:48:11 +00:00
Neil Roberts
1f0b432a25 sdl: Bind the default window when currently bound window is destroyed
Cogl always needs to have the context bound to something so that it
can freely create resources such as textures even if there is no
current window. When the currently bound SDLWindow is destroyed, SDL
apparently explicitly unbinds the GL context. If something then later
for example tries to create a texture Cogl would start getting GL
errors and fail. To fix this the SDL winsys now just binds the dummy
window before deiniting the currently bound onscreen.

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

(cherry picked from commit 2c0cfdefbb9d1ac5097d98887d3581b67a324fae)
2013-01-22 17:48:11 +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
3e33c00c84 matrix-stack: only maintain composite_gets in debug builds
At times there can be huge numbers of CoglMatrixEntry structures
allocated if they are being used to track the transform of many drawing
commands or objects in a scenegraph. Therefore the size of a
CoglMatrixEntry should be kept as small as possible both to help reduce
the memory usage of applications but also to improve cache usage since
matrix stack manipulations are performance critical at times.

This reduces the size of CoglMatrixEntry structures for non-debug builds
by removing the composite_gets counter used to sanity check how often
the transform for an entry is resolved.

(cherry picked from commit c400b86681a328b1e12b7e120e9c3f4f12c356e0)
2013-01-22 17:48:10 +00:00
Robert Bragg
f5b95e8087 matrix-stack: move pointer to top of CoglMatrixEntry
This moves the parent pointer member to the top of the CoglMatrixEntry
structure since it will lead to wasted padding when we build for 64bit
cpus.

(cherry picked from commit 42b4750070286a6404b103d8a827a46efb6b344c)
2013-01-22 17:48:10 +00:00
Robert Bragg
9eb816bc7e matrix-stack: getting parent ptr before freeing
When unrefing a CoglMatrixEntry we walk up the ancestry unrefing and
freeing entries until we find an entry that doesn't need to be freed.
The problem fixed by this patch was that we didn't dereference the
parent member of each entry until after the entry was freed and so there
was the potential for reading a junk parent pointer back.

(cherry picked from commit e5d836b84acb35a009854a0cc0892320023789d1)
2013-01-22 17:48:10 +00:00
Robert Bragg
5bc6121cbf journal: don't call cogl_attribute_buffer_new with NULL
It is considered an error to pass a NULL data pointer to
cogl_attribute_buffer_new so we now call
cogl_attribute_buffer_new_with_size instead.

(cherry picked from commit 8e201574b9c35847aa4e999a391741538a0b356b)
2013-01-22 17:48:10 +00:00
Damien Lespiau
5d796f0a4c x11: Replace all internal usage of cogl_xlib_get_display()
And use the renderer replacement, cogl_xlib_renderer_get_display()

(cherry picked from commit ea355792e88b09b0b0afa6fb5c5acc311d41688e)
2013-01-22 17:48:09 +00:00
Neil Roberts
6bcfc8342a Fix handling of binding errors when uploading a full texture
Both the texture drivers weren't handling errors correctly when a
CoglPixelBuffer was used to set the contents of an entire texture.
This was causing it to hit an assertion failure in the pixel buffer
tests.

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

(cherry picked from commit 888733d3c3b24080d2f136cedb3876a41312e4cf)
2013-01-22 17:48:09 +00:00
Robert Bragg
7011eb5db4 texture: expose mipmap level in set region apis
cogl_texture_set_region() and cogl_texture_set_region_from_bitmap() now
have a level argument so image data can be uploaded to a specific mipmap
level.

The prototype for cogl_texture_set_region was also updated to simplify
the arguments.

The arguments for cogl_texture_set_region_from_bitmap were reordered to
be consistent with cogl_texture_set_region with the source related
arguments listed first followed by the destination arguments.

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

(cherry picked from commit 3a336a8adcd406b53731a6de0e7d97ba7932c1a8)

Note: Public API changes were reverted in cherry-picking this patch
2013-01-22 17:48:09 +00:00
Robert Bragg
fa5a9c88fe atlas-texture: remove some use of _COGL_GET_CONTEXT
This removes several uses of _COGL_GET_CONTEXT in cogl-atlas-texture.c.
Notably this involved making CoglPangoGlyphCache track an associated
CoglContext pointer which cogl-pango can pass to
_cogl_atlas_texture_new_with_size().

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

(cherry picked from commit d66afbd0758539330490945c699a05c0749c76aa)
2013-01-22 17:48:09 +00:00
Robert Bragg
cd7b15b7df glx: avoid use of _COGL_GET_CONTEXT()
Removes some (not all) use of _COGL_GET_CONTEXT() from cogl-winsys-glx.c

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

(cherry picked from commit 698a131c4991e4393ce966b968637fba194f252c)
2013-01-22 17:48:09 +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
Robert Bragg
7941357e73 journal: don't reference global context
This removes all use of _COGL_GET_CONTEXT from cogl-journal.c

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

(cherry picked from commit b5c8ec5db52a6cb71f29b338a59fb3772506fef7)
2013-01-22 17:48:08 +00:00
Neil Roberts
ca5197a70c error: Don't allocate a new CoglError when propagating
The _cogl_propagate_error() function takes ownership of the incoming
error pointer so there's no need to allocate a new error when passing
it on. The errors can potentially be passed up from a number of layers
so it seems worthwhile to avoid the allocation.

The _cogl_propagate_gerror() function was previously using
_cogl_propagate_error(). Presumably this would not have worked because
that function would try to free the error from glib using
cogl_error_free but that would use the wrong free function and thus
the wrong slice allocator. The GError propagating function is only
used when gdk-pixbuf is enabled which now requires glib support anyway
so we can just avoid defining the function when compiling without
glib.

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

(cherry picked from commit 91266162bef9f89fb42c01be0f929d5079758096)
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
e8eb9793e6 moves some gl texture code too cogl-texture-gl.c
This adds a driver/gl/cogl-texture-gl.c file and moves some gl specific
bits from cogl-texture.c into it. The moved symbols were also given a
_gl_ infix and the calling code was updated accordingly.

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

(cherry picked from commit 2c9e81de70cc02d72b1ce9013c49e39300a05b6a)
2013-01-22 17:48:08 +00:00
Robert Bragg
6941ff2c71 matrix-stack: init cache->flipped
This ensures we initialize the value of cache->flipped in
_cogl_matrix_entry_cache_init()

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

(cherry picked from commit 507814d27298231c9ae50d74b386fb00f0909922)
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
07d47eadd3 texture: split out high-level texture constructors
This splits out the very high level texture constructors that may
internally construct one of several types of lower level texture due to
various constraints.

This also updates the prototypes for these constructors to take an
explicit context pointer and return a CoglError consistent with other
texture constructors.

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

(cherry picked from commit a1cabfae6ad50c51006c608cdde7d631b7832e71)
2013-01-22 17:48:07 +00:00
Robert Bragg
e439bdd12f atlas: catch _create_texture errors
Previously we were passing NULL to
cogl_texture_2d_new_{from_bitmap,with_size} so if there was an error the
application would be aborted. This ensures we pass an internal CoglError
so errors can be caught and suppressed instead.

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

(cherry picked from commit b8d1a1db482e1417979df9f88f92da47aa954bd0)
2013-01-22 17:48:07 +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
Robert Bragg
63db64f426 attribute: Only unref buffer for buffered attributes
constant attributes don't have a corresponding buffer so
_cogl_attribute_free shouldn't try to unref it. Also, for good measure,
in the case of constant attributes we should call
_cogl_boxed_value_destroy() (although currently we know there is no
dynamic data associated with the boxed values).

(cherry picked from commit 89d6dc90d10c59676e0deed87c2c15a0c9712737)
2013-01-22 17:48:07 +00:00
Robert Bragg
6e379fb54e attribute: Adds support for constant CoglAttributes
This makes it possible to create vertex attributes that efficiently
represent constant values without duplicating the constant for every
vertex. This adds the following new constructors for constant
attributes:

  cogl_attribute_new_const_1f
  cogl_attribute_new_const_2fv
  cogl_attribute_new_const_3fv
  cogl_attribute_new_const_4fv
  cogl_attribute_new_const_2f
  cogl_attribute_new_const_3f
  cogl_attribute_new_const_4f
  cogl_attribute_new_const_2x2fv
  cogl_attribute_new_const_3x3fv
  cogl_attribute_new_const_4x4fv

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

(cherry picked from commit 6507216f8030e84dcf2e63b8ecfe906ac47f2ca7)
2013-01-22 17:48:07 +00:00
Robert Bragg
56ae6f9afa progend-glsl: dirty prog for vertex state changes
_cogl_pipeline_progend_glsl_pre_change_notify and
_cogl_pipeline_progend_glsl_layer_pre_change_notify were only dirtying
the current program state for changes related to fragment processing.

This make both functions also check for changes that affect vertex
shader codegen.

This also fixes a mistake where
_cogl_pipeline_progend_glsl_layer_pre_change_notify was checking for
non-layer related changes which would never be seen, and instead it
should be checking for layer based changes only.
2013-01-22 17:48:07 +00:00
Robert Bragg
7fa04bb1a6 Adds back tex_coord array for CoglShader compatibility
This adds back compatibility for CoglShaders that reference the
cogl_tex_coord_in[] or cogl_tex_coord_out[] varyings. Unlike the
previous way this was done this patch maintains the use of layer numbers
for attributes and maintains forwards compatibility by letting shaders
alternatively access the per-layer tex_coord varyings via
cogl_tex_coord%i_in/out defines that index into the array.
2013-01-22 17:48:07 +00:00
Robert Bragg
1c449c67f6 Remove the varying array for tex_coords
This removes the need to maintain an array of tex_coord varyings and
instead we now just emit a varying per-layer uniquely named using a
layer_number infix like cogl_tex_coord0_out and cogl_tex_coord0_in.

Notable this patch also had to change the journal flushing code to use
pipeline layer numbers to determine the name of texture coordinate
attributes.

We now also break batches by using a deeper comparison of layers so
such that two pipelines with the same number of layers can now cause a
batch break if they use different layer numbers.

This adds an internal _cogl_pipeline_layer_numbers_equal() function that
takes two pipelines and returns TRUE if they have the same number of
layers and all the layer numbers are the same too, otherwise it returns
FALSE.

Where we used to break batches based on changes to the number of layers
we now break according to the status of
_cogl_pipeline_layer_numbers_equal

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

(cherry picked from commit e55b64a9cdc93285049d9b969bef67484c2d9fb3)

Note: this will cause a temporary regression for the Cogl 1.x CoglShader
api since it will break compatibility with existing shaders that
reference the texture varyings from the fragment shader.

The intention is to follow up with another patch to add back
CoglShader compatibility.
2013-01-22 17:48:06 +00:00
Robert Bragg
14d8ec7cca sync cogl-blit and cogl-texture with master
This synchronizes parts of cogl-blit.c and cogl-texture.c with the
master branch to help with cherry picking patches.
2013-01-22 17:48:06 +00:00
Robert Bragg
272431e102 Check for out-of-memory when allocating 3d textures
This makes Cogl explicitly check for out-of-memory errors reported by
the opengl driver in cogl_texture_3d_new_with_size() calls. This allows
us to throw a COGL_SYSTEM_ERROR_NO_MEMORY error and return NULL so
applications may gracefully handle this condition.

This patch only affects the cogl_texture_3d_new_with_size() api not
_new_from_data() or _new_from_bitmap().

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

(cherry picked from commit a602cae233b16d2ec9ad6fd238b169720467cf75)
2013-01-22 17:48:06 +00:00
Robert Bragg
31d105abd8 Check for out-of-memory when allocating 2d textures
This makes Cogl explicitly check for out-of-memory errors reported by
the opengl driver in cogl_texture_2d_new_with_size() calls. This allows
us to throw a COGL_SYSTEM_ERROR_NO_MEMORY error and return NULL so
applications may gracefully handle this condition.

This patch only affects the cogl_texture_2d_new_with_size() api not
_new_from_data() or _new_from_bitmap().

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

(cherry picked from commit 0283423dad59ba3d3e4cde400c29ac8e7803f888)
2013-01-22 17:48:06 +00:00
Neil Roberts
4f6fe6f0e2 Fixes for --disable-glib
This fixes some problems which were stopping --disable-glib from
working properly:

• A lot of the public headers were including glib.h. This shouldn't be
  necessary because the API doesn't expose any glib types. Otherwise
  any apps would require glib in order to get the header.

• The public headers were using G_BEGIN_DECLS. There is now a
  replacement macro called COGL_BEGIN_DECLS which is defined in
  cogl-types.h.

• A similar fix has been done for G_GNUC_NULL_TERMINATED and
  G_GNUC_DEPRECATED.

• The CFLAGS were not including $(builddir)/deps/glib which was
  preventing it finding the generated glibconfig.h when building out
  of tree.

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

(cherry picked from commit 4138b3141c2f39cddaea3d72bfc04342ed5092d0)
2013-01-22 17:48:05 +00:00
Neil Roberts
eec0f1cd65 Add cogl_sdl_onscreen_get_window()
This adds a function to get a pointer to the SDL_Window associated
with a CoglOnscreen when using the SDL2 winsys.

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

(cherry picked from commit 071f4b80daa8a2f967746a30b3acf014d74f781a)
2013-01-22 17:48:05 +00:00
Neil Roberts
ff11a2b207 Use GL_ARB_texture_swizzle to emulate GL_ALPHA textures
The core profile of GL3 has removed support for component-alpha
textures. Previously the GL3 driver would just ignore this and try to
create them anyway. This would generate a GL error on Mesa.

To fix this the GL texture driver will now create a GL_RED texture
when GL_ALPHA textures are not supported natively. It will then set a
texture swizzle using the GL_ARB_texture_swizzle extension so that the
alpha component will be taken from the red component of the texture.
The swizzle is part of the texture object state so it only needs to be
set once when the texture is created.

The ‘gen’ virtual function of the texture driver has been changed to
also take the internal format as a parameter. The GL driver will now
set the swizzle as appropriate here.

The GL3 driver now reports an error if the texture swizzle extension
is not available because Cogl can't really work properly without out
it. The extension is part of GL 3.3 so it is quite likely that it has
wide support from drivers. Eventually we could get rid of this
requirement if we have our own GLSL front-end and we could generate
the swizzle ourselves.

When uploading or downloading texture data to or from a
component-alpha texture, we can no longer rely on GL to do the
conversion. The swizzle doesn't have any effect on the texture data
functions. In these cases Cogl will now force an intermediate buffer
to be used and it will manually do the conversion as it does for the
GLES drivers.

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

(cherry picked from commit 32bacf81ebaa3be21a8f26af07d8f6eed6607652)
2013-01-22 17:48:04 +00:00
Neil Roberts
05ebbfdae7 sdl: Support setting resizable before allocate in SDL 1
The SDL 1 winsys now checks for the initial resizable state of the
onscreen framebuffer when it is allocated and updates the video flags
accordingly.

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

(cherry picked from commit f5fb9be70a92f751886a94da0b34e14252ed197e)
2013-01-22 17:48:04 +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
Neil Roberts
9f107ab3fb Support window resizing in the SDL 2 winsys
The SDL2 winsys will now set the SDL_WINDOW_RESIZABLE flag on the
window before creating it if the resizable property is set on the
onscreen. Note that there doesn't appear to be a way in SDL to change
the flag later so unlike the other winsyses it will only take affect
if it is set before allocating the framebuffer.

The winsys now registers a callback for SDL events so that it can
report window size changes back to the application.

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

(cherry picked from commit 0dea9aeb897faf029828379b120970477df3c7d5)
2013-01-22 17:48:04 +00:00
Adel Gadllah
41d59c0af7 cogl: Enable PBO path for all mesa versions when using intel
There seem to be other cases where the slow path is hit even with mesa 9.0.

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

(cherry picked from commit 6b14fa222bafb7e67c4845b26439322b34ac26a2)
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
362db1c445 Don't add the ARB suffix for the GL_ARB_map_buffer_range extension
The functions defined in the GL_ARB_map_buffer_range extension have no
suffix.

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

(cherry picked from commit f355d0a01af9015ffdcd574477090cdc69025280)
2013-01-22 17:48:04 +00:00
Neil Roberts
7654c7cffc Make cogl_color_init_from_4fv take a const array
The passed in array isn't written to so it's more convenient to use if
it is const.

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

(cherry picked from commit 87c02670107f00008611cbb0a8cfc97c8b6ea956)
2013-01-22 17:48:03 +00:00
Neil Roberts
6db9427e8a Use cogl_buffer_map_range from the journal
The journal maintains a cache of attribute buffers to upload the
vertices for the rectangles. The buffers are mapped to fill in the
data. However, if the previous journal was larger than the one being
flushed now then the buffers may be larger than is actually needed. In
that case we might as well only map the range that is actually used so
that the driver can potentially avoid having to set up a mapping for
the entire buffer. The COGL_BUFFER_MAP_HINT_DISCARD flag is still set
so that the driver is free to discard the entire buffer, not just the
subrange.

The _cogl_buffer_map_for_fill_or_fallback has been replaced with
_cogl_buffer_map_range_for_fill_or_fallback so that the range
parameters can be passed. The original function is now just a wrapper
around the latter.

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

(cherry picked from commit 27769e54806dcfc1a12fdc4b07b054b8f2f4215b)
2013-01-22 17:48:03 +00:00
Neil Roberts
ec03357e88 Add cogl_buffer_map_range()
This adds a buffer method to map a subregion of the buffer. This works
using the GL_ARB_map_buffer_range extension. If the extension is not
available then it will fallback to using glMapBuffer to map the entire
buffer and then just add the offset to the returned pointer.

cogl_buffer_map() is now just a wrapper which maps the entire range of
the buffer. The driver backend functions have been renamed to
map_range and they now all take the offset and size arguments.

When the COGL_BUFFER_MAP_HINT_DISCARD hint is used and the map range
extension is available instead of using glBufferData to invalidate the
buffer it will instead pass the new GL_MAP_HINT_INVALIDATE_BUFFER
flag. There is now additionally a COGL_BUFFER_MAP_HINT_DISCARD_REGION
hint which can be used if the application only wants to discard the
small region that is mapped. glMapBufferRange is always used if it is
available even if the entire buffer is being mapped because it seems
more robust to pass those flags then to call glBufferData.

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

(cherry picked from commit 55ca02b5ca9cafc750251ec974e0d6a536cb80b8)
2013-01-22 17:48:03 +00:00
Damien Lespiau
8a3fb7a10d context: Re-add /<* private *>/ for _COGL_N_FEATURE_IDS
Turns out gtk-doc really needs 'private' and glib-mkenums needs 'skip'.
So let's have both.

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

(cherry picked from commit e51206b2a9c9a582ac83fb71290524c99a8dbbb6)
2013-01-22 17:48:03 +00:00
Damien Lespiau
979a3d5517 error: Fix 'burden' typo
Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 9af7dda5d7de69522b152d853ed8921c00c15f4e)
2013-01-22 17:48:03 +00:00
Damien Lespiau
08205a40e1 context: glib-mkenums chokes on /*< private >*/ but supports /*< skip >*/
The private option is really part of gtk-doc, glib-mkenums does not
support it. Use skip instead.

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

(cherry picked from commit 015c36af27a8ce68d60f8aab6a10acdc48c5f38c)
2013-01-22 17:48:03 +00:00
Rico Tzschichholz
87e15d6693 build: fix make dist
(cherry picked from commit 6a78a8c6b6d368f2816f50e10cb9602f5c47de71)
2013-01-22 17:48:03 +00:00
Neil Roberts
76843fc529 sdl2: Fix GL3 context creation
The check to verify whether we've got the right GL context was
checking that the GL version was less than 3 whenever the non-GL3
driver is used. However it looks like the driver is free to return a
GL3 context that is compatible with GL2 if GL2 is requested so this
was breaking the GL2 driver.

This also adds the necessary SDL attributes to request a forward
compatible core context like the GLX and EGL winsys's do. I haven't
actually tested this because it looks like SDL will only create a GL
context with GLX and I haven't got a recent enough X server to handle
the glXCreateContextAttribs request.

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

(cherry picked from commit d46acafa3ea7ba2e6c4ac7a45f00a132df1b2872)
2013-01-22 17:48:02 +00:00
Neil Roberts
8039c2c779 Fix a warning when building the SDL2 winsys
The SDL2 winsys was using _cogl_set_error without including its header
so it was giving an annoying warning. This patch also fixes some
indentation issues.

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

(cherry picked from commit 9c8433087b7573f7606dfae2bae3045803ead115)
2013-01-22 17:48:02 +00:00
Damien Lespiau
2582fa1519 display: Fix 'arguments' typo
Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 1f30d200be65cd44dbd6f224532b9c4030d6c39c)
2013-01-22 17:48:02 +00:00
Damien Lespiau
f9c7e9d270 framebuffer: Annotate the output parameter of get_viewport4fv()
Annotate that the float* is an out parameter that points to a caller
allocated array of 4 floats.

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

(cherry picked from commit f40b0d03d796c16c62f4937e99e16de084fc6b9a)
2013-01-22 17:48:02 +00:00
Damien Lespiau
0866b90069 object: Move cogl_object_{ref,unref}() to cogl-object.h
Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit d2f07344a361c43ccdb85a0587812ca3a103078b)
2013-01-22 17:48:02 +00:00
Neil Roberts
2e77c039c9 Fix a warning when building without GLES2 support
Since commit 2701b93f cogl-pipeline-opengl.c always has code which
calls _cogl_pipeline_progend_glsl_get_attrib_location but the header
declaring this function was only included if GLES2 support was
enabled. This was making it give an annoying warning so let's just
unconditionally include it.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 34143bc6f1239c9cb22ba613521ba9ee7ec7059a)
2013-01-22 17:48:02 +00:00
Neil Roberts
bf8a1b1eda progend-glsl: Fix handling of the builtin uniforms on non-GLES2
The ‘builtin uniforms’ are added to the GLSL code generated for the
GLES2 driver to implement missing fixed functionality such as the
builtin point sprite size and the alpha test reference. Previously the
code that accessed these was #ifdef'd to be compiled only when GLES2
was enabled. However since 2701b93f part of this code is now always
used even for non-GLES2 drivers. The code that accessed the builtin
uniforms array was however no longer #ifdef'd which meant that it
wouldn't compile any more if GLES2 was not enabled. This was further
broken becase the GL3 driver actually should be using the alpha test
uniform because that also does not provide any fixed functionality for
alpha testing.

To fix this the builtin uniform array is now always compiled in and
the code to access it is always used. A new member has been added to
the array to mark which private feature the uniform is used to
replace. That is checked before updating the uniform so that under
GLES2 it will update both uniforms but under GL3 it will only update
the alpha test reference.

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

(cherry picked from commit 5469a25413883080df75a80153accf5d9124f716)
2013-01-22 17:48:02 +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
Neil Roberts
1abf0ed55e pipeline: Don't notify the undefined progend of layer changes
When a layer changes before the pipeline has decided which progend to
use it doesn't need to notify the progend of the change. This was
causing it to crash. This patch makes that change and also simplifies
the notification a bit by just making the calls directly instead of
having three separate functions.

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

(cherry picked from commit 2006ddd68ea6a5d53b5a810d8dbf39025d9ec04c)
2013-01-22 17:48:01 +00:00
Robert Bragg
de7416fd1d driver-gl: re-indent misleading if-else statement
There was a very, very, very misleading if else statement using no
braces for a single statement if block, followed by a blank line *and*
followed by a comment before the else which was aligned to the 'if'
column, all leading you to believe on first glance that there is no else
block. The fact that Neil and I were both separately mislead by this,
this week, is a pretty compelling reason to clarify this by deleting the
blank line, and moving the comment inside the else block.

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

(cherry picked from commit 96d9ea78eb56269c0de5283a5302ab095d8bdfce)
2013-01-22 17:48:01 +00:00
Robert Bragg
986ba3aa79 egl: remove special re-try without stencil code
The EGL winsys had a special case code path when trying to create a
context where if it failed it would try again except without requesting
a stencil buffer. Historically this code path was to allow Clutter to
run on PowerVR MBX hardware which doesn't support a stencil buffer. It
doesn't really make sense to keep this workaround in Cogl as it would
leave Cogl in a state where the clip stack doesn't work without
providing any feedback to the developer. If we need to support running
on MBX like hardware - probably not very likely these days - then we
should provide developer control over the stencil buffer so the
equivalent workaround could be implemented on top of Cogl.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit a7c391a985e82707b17f2fb1105de5d37822a390)
2013-01-22 17:48:01 +00:00
Robert Bragg
01937201e4 Unify a lot of gles2 vs gl glsl code
Since we used to support hybrid fixed-function + glsl pipelines when
running with OpenGL there were numerous differences in how we handled
codegen and uniform updates between GLES2 and full OpenGL. Now that we
only support end-to-end glsl pipelines this patch can largely unify how
we handle GLES2 and OpenGL.

Most notably we now never use the builtin attribute names. This should
also make it easy for us to support creating strict OpenGL 3.1 contexts
where the builtin names have been removed.

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

(cherry picked from commit 2701b93f159bf2d3387cedf2d06fe921ad5641f3)
2013-01-22 17:48:01 +00:00
Robert Bragg
62b472f4f5 add cogl-glsl-shader files to aid backporting patches
To aid with backporting patches from master made after the deprecated
CoglShader api was removed this patch adds the cogl-glsl- files that
have been added on master so we should get less conflicts when cherry
picking.
2013-01-22 17:48:01 +00:00
Robert Bragg
258aba3836 check the glsl version during init
This adds a check for the glsl version during driver init which gets
stored in ctx->glsl_major and ctx->glsl_minor.

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

(cherry picked from commit 9bde48bda6d602dd536c3536d56d2ff7545802c3)
2013-01-22 17:48:01 +00:00
Robert Bragg
2438d70b38 driver-gl: split out parse_gl_version function
This splits out the GL version parser code from
cogl-driver-gl.c:_cogl_get_gl_version() so it can also be used for
parsing other gl version strings.

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

(cherry picked from commit 66c2e74b9d61669fb5b93cf9a31cc8659a601fdd)
2013-01-22 17:48:00 +00:00
Neil Roberts
2bcf38d126 Fix a warning in the vtable for texture_2d_get_data
The function pointer for texture_2d_get_data in the driver vtable was
expecting an unsigned int for the rowstride but the definition in
cogl-texture-2d-gl.c took a size_t so it was giving an annoying
warning. This normalizes them both to just take an int. This seems to
better match the pattern used for cogl_bitmap_new_from_data and
cogl_texture_2d_new_from_data.

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

(cherry picked from commit 003f080531d5368835081568779b031ef4f09a77)
2013-01-22 17:48:00 +00:00
Robert Bragg
8f3380adc3 Clearly define 3 progends that own the frag+vertends
This adds a new "fixed-arbfp" progend so we now have 3 distinct ways of
setting up the state of a pipeline:

  » fixed; where the vertex and fragment processing are implemented
    using fixed function opengl apis.
  » fixed-arbfp; where vertex processing is implemented using fixed
    function opengl apis but fragment processing is implemented
    using the ARB Fragment Processing language.
  » glsl; there vertex and fragment processing are both implemented
    using glsl.

This means we avoid unusual, combinations such as glsl for vertex
processing and arbfp for fragment processing, and also avoid pairing
fixed-function vertex processing with glsl fragment processing which we
happen to know hits some awkward code paths in Mesa that lead to poor
performance.

As part of this change, the progend now implies specific vertend and
fragend choices so instead of associating a vertend and fragend with a
pipeline we now just associate a progend choice.

When flushing a pipeline and choosing what progend to use, we now call a
progend->start() method that is able to determine if the vertend and
fragend together will be able to handle the given pipeline so the
vertend and fragend ->start() methods no longer need to return a boolean
status.

Since we now don't need to support glsl used in conjunction with fixed
function this will allow us to avoid ever using OpenGL builtin attribute
names, though this patch doesn't change that yet.

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

(cherry picked from commit cec381f50c7a2f2186bd4a8c5f38fecd5f099075)
2013-01-22 17:48:00 +00:00
Robert Bragg
f05a1a62f4 pipeline: tidy up definition of *END defines
There is some fairly awkward #ifdefing to determine which vertends,
fragends and progends are available at build time. This patch
consolidates the #ifdefing of vertend, fragend and progend defines to
make for slightly easier reading.

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

(cherry picked from commit 098d6244bf7c8f2a4ca24206c6e8271d589ed4c9)
2013-01-22 17:48:00 +00:00
Robert Bragg
9fd201ffc6 pipeline: remove duplicate defines
There was a spurious duplication of the COGL_PIPELINE_VERTEND_DEFAULT
and COGL_PIPELINE_VERTEND_UNDEFINED defines which this patch removes.

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

(cherry picked from commit 1bcf34bd3eb0134b7ef1b30cba91d3e70a23e5ed)
2013-01-22 17:48:00 +00:00
Robert Bragg
d20c8e4a71 pipeline: remove unused _MASK defines
The COGL_PIPELINE_FRAGEND_XYZ_MASK and COGL_PIPELINE_VERTEND_XYZ_MASK
defines aren't used any more so this patch simply removes them.

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

(cherry picked from commit 119b0d771a4be2550ce1ca1e789db5b22776b066)
2013-01-22 17:48:00 +00:00
Robert Bragg
6712aaef45 pipeline: remove dubious optimization
This removes an optimization that I added at some point, which I'm
pretty certain I only added on a hunch. Reading the description I'm not
really convinced it makes sense to do this given that the fixed vertend
and fragend are currently listed before the glsl vertend and fragend in
the order that we look for a suitable backend. This means unless the
pipeline depends on glsl (e.g. due to an associated snippet) we would
reselect the fixed backend anyway, and if it really did depend on glsl
then we'd notice when we come to flush and switch backends there any way.

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

(cherry picked from commit 071698d2c017af33e41b838429d514f5df5e02a1)
2013-01-22 17:48:00 +00:00
Robert Bragg
b1ecfbf720 buffer: splits out GL specific code
As part of an on-going effort to be able to support non-opengl drivers
for Cogl this splits out the opengl specific code from cogl-buffer.c
into driver/gl/cogl-buffer-gl.c

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

(cherry picked from commit 4d7094a979ff2cbbe4054f4a44ca05fc41a9e447)
2013-01-22 17:47:59 +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
Robert Bragg
91a02e9107 buffer: move choice about using malloc closer to driver
This moves the decision about whether a buffer should be allocated using
malloc or not into cogl-buffer.c closer to the driver since it seem
there could be other driver specific factors that might also influence
this choice that we don't currently consider.

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

(cherry picked from commit 06d46f10bf755d3009c28904e616a0adb4586cf5)
2013-01-22 17:47:59 +00:00
Robert Bragg
ffd2cf8ef8 clip-stack: Splits out opengl specific code
As part of an on-going effort to enable non-opengl drivers for Cogl this
splits out the opengl specific code in cogl-clip-stack.c into
cogl/driver/cogl-clip-stack-gl.c

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

(cherry picked from commit acf989f1bb628282c53d1249b2e3fc6f6579f1e9)
2013-01-22 17:47:59 +00:00
Robert Bragg
ae713a32d0 Adds a NOP driver
This adds a new "nop" driver that does nothing. This can be selected at
runtime either with the COGL_DRIVER=nop environment variable or by
passing COGL_DRIVER_NOP to cogl_renderer_set_driver()

Adding the nop driver gives us a way to test workloads without any
driver and hardware overheads which can help us understand how Cogl's
state tracking performs in isolation.

Having a nop driver can also serve as an shell/outline for creating
other drivers later.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 90587418233b6438290741d80aedf193ae660cad)
2013-01-22 17:47:59 +00:00
Robert Bragg
4efcd4e6a6 attribute: Split out GL specific code
As part of an on-going effort to enable non-opengl drivers for Cogl this
splits out the GL specific code in cogl-attribute.c into
cogl/driver/gl/cogl-attribute-gl.c

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

(cherry picked from commit 7e20c39c47fa176aa5062867ff273bc2c41a2f22)
2013-01-22 17:47:59 +00:00
Robert Bragg
ae2b064fd7 blit: avoid using _COGL_GET_CONTEXT
As part of an on-going effort to avoid depending on a global Cogl
context cogl-blit.c now finds the context by looking at
data->src_text->context instead of using the _COGL_GET_CONTEXT macro.

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

(cherry picked from commit 3f2c99150494efc04487d0dbd17980bac20e4485)
2013-01-22 17:47:59 +00:00
Robert Bragg
4087e848c4 texture-2d: factor out all GL specific code
This factors out all of the OpenGL specific code in cogl-texture-2d.c
into cogl-texture-2d-gl.c and where necessary adds indirection through
the CoglDriver vtable so that we can eventually start to experiment with
non-OpenGL backends for Cogl.

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

(cherry picked from commit ec57588671696bbe7ce714bdfe7324236146c9c0)
2013-01-22 17:47:58 +00:00
Robert Bragg
8326c71b6b texture: rename texobj flush code as gl specific
This renames the set_filters and set_wrap_mode_parameters texture
virtual functions to gl_flush_legacy_texobj_filters and
gl_flush_legacy_texobj_wrap_modes respectively to clarify that they are
opengl driver specific and that they are only used to support the legacy
opengl apis for setting filters and wrap modes where the state is
associated with texture objects instead of being associated with sampler
objects.

This part of an effort to clearly delimit our abstraction over opengl so
that we can start to consider non-opengl backends for Cogl.

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

(cherry picked from commit 6f78b8a613340d7c6b736e51a16c625f52154430)
2013-01-22 17:47:58 +00:00
Robert Bragg
ab72a2275f build: don't include deps/glib headers if glib enabled
If we're using the system glib library then we need to make sure not to
include headers under deps/glib otherwise we end up with with
incompatible typedefs that break the build.

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

(cherry picked from commit 5d5fc97b59951ec56a4193b7ee7909ebd3cfbb94)
2013-01-22 17:47:58 +00:00
Damien Lespiau
d2c41502a4 build: Allow to build cogl without an external glib dependency
This commit pushes --disable-glib to the extreme of embedding the par of
glib cogl depends on in tree to be able to generate a DSO that does not
depend on an external glib.

To do so, it:
  - keeps a lot of glib's configure.ac in as-glibconfig.m4
  - pulls the code cogl depends on and the necessary dependencies

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2013-01-22 17:47:58 +00:00
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
Damien Lespiau
4a229cf708 config: Don't read a config file at startup when using --disable-glib
GKeyFile is a bit too much to import in a standalone build for my taste
as it depends on the encoding part of glib.

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

(cherry picked from commit 9af04f0d8813b7f6f7117e1cc2a38ae2b8d04cdd)
2013-01-22 17:47:24 +00:00
Damien Lespiau
eb92b512c6 core: Don't initialize the GType system with --disable-glib
--disable-glib also defines COGL_HAS_GTYPE_SUPPORT to #ifdef out GType
support in cogl. This also means we don't want to initialize glib's type
system in that case.

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

(cherry picked from commit 67ad777099d62bdbc8515f6ee58ed80429cc6496)
2013-01-22 17:47:24 +00:00
Robert Bragg
5d62185f1c Re-organize the source layout
As part of an effort towards being able to write non-opengl based
backends for Cogl this moves most of the opengl specific code under
drivers/gl. drivers/gl and drivers/gles have been moved to
drivers/gl/gl and drivers/gl/es respectively.

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

(cherry picked from commit 7dc482facb0a265c7f48660079e7e12dd7a2813e)
2013-01-22 17:47:19 +00:00
Damien Lespiau
024a143cb8 stb_image: Fix warnings that the original stb_image has
Clean compiler output is a must! that also means imported source code
from other projects. I can't be bothered to submit a patch upstream,
because last time it was totally ignored by the stb_image guy.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit b43b1eac77e2f13d126e2211e12dc0c6d152716e)
2013-01-18 17:28:25 +00:00
Damien Lespiau
24fa64bea2 core: Don't use g_once_*() API
As Cogl is not thread safe, we don't really need a thread safe
cogl_init() function.

This also reduces the amount of dependency cogl has on glib, handy when
we want to create a standalone version of cogl, some day.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 429e49e3028a425eb198d8969dfbf57790e2e72a)
2013-01-18 17:28:25 +00:00
Damien Lespiau
c9fe28c93b renderer: Remove unused error from CoglRendererError
This type is not documented and is experimental. We don't use
COGL_RENDERER_ERROR_NOT_FOUND and it's pretty vague anyway, just remove
it.

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

(cherry picked from commit ffa78534616547b9bd4cd5c0ade8fdc039a2b977)
2013-01-18 17:28:25 +00:00
Damien Lespiau
ab91bdf12b build: Remove spurious Makefile.am
These days cogl/ has a non-recursive Makefile.am and an old one was
still present in cogl/driver.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit e1db8e38be72f5372e9d7571a3faec5039e0e6d0)
2013-01-18 17:28:25 +00:00
Robert Bragg
1161870670 matrix: Add cogl_debug_matrix_print api
As a convenience for debugging this adds a cogl_debug_matrix_print
function that prints out the components of a matrix and any internal
flags associated with the given matrix.

(cherry picked from commit 3b33889ff1204f19347a9548320ba95baa54c18c)
2013-01-18 17:28:25 +00:00
Robert Bragg
0ffad6ba20 texture-rectangle: Make new_from_foreign api public
This adds a new public cogl_texture_rectangle_new_from_foreign()
function so that we can look at removing the generic
cogl_texture_new_from_foreign().

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

(cherry picked from commit af02792b336bb492c5bd11afc34a5dcd417503f6)
2013-01-18 17:28:19 +00:00
Robert Bragg
13f228fe69 Remove all remaining _EXP suffix defines
To delimit which symbols were considered experimental we used to use
some preprocessor defines to gives experimental symbols an _EXP suffix
so that anyone monitoring the ABI for changes would easily be able to
discount changes made to clearly experimental functions.

These days we simply rely on the gtk-doc "Stability: unstable"
annotation to serve this purpose because changing the actual symbol name
made it slightly more awkward to debug Cogl using GDB and was an extra
mechanical step we decided we could do without.

This patch removes the last remaining _EXP suffix defines in Cogl

(cherry picked from commit 5a1c4a979e00accd492097cfb8f6a8d0fd8331bc)
2013-01-18 10:53:29 +00:00
Robert Bragg
ce5d06afe1 framebuffer: split GL code out from cogl-framebuffer.c
This splits out most of the OpenGL specific code from cogl-framebuffer.c
into cogl-framebuffer-gl.c and extends the CoglDriverVtable interface
for cogl-framebuffer.c to use.

There are hopes to support several different backends for Cogl
eventually to hopefully get us closer to the metal so this makes some
progress in organizing which parts of Cogl are OpenGL specific so these
parts can potentially be switched out later.

The only remaining use of OpenGL still in cogl-framebuffer.c is to
handle cogl_framebuffer_read_pixels.
2013-01-18 10:53:29 +00:00
Damien Lespiau
87bc616d34 framebuffer: Support texture based depth buffers
This commit introduces some new framebuffer api to be able to
enable texture based depth buffers for a framebuffer (currently
only supported for offscreen framebuffers) and once allocated
to be able to retrieve the depth buffer as a texture for further
usage, say, to implement shadow mapping.

The API works as follow:
  * Before the framebuffer is allocated, you can request that a depth
    texture is created with
    cogl_framebuffer_set_depth_texture_enabled()
  * cogl_framebuffer_get_depth_texture() can then be used to grab a
    CoglTexture once the framebuffer has been allocated.
2013-01-18 10:53:29 +00:00
Tomeu Vizoso
5bce5f88d9 Use the correct type for GLintptr
On 32bit, intptr_t has a different type than khronos_intptr_t.

https://bugzilla.gnome.org/show_bug.cgi?id=691296
(cherry picked from commit a77222385812a696a999a871cde439f50b648f69)
2013-01-08 14:56:25 +01:00
Neil Roberts
f1baa4d60f Clear the scissor before calling glBlitFramebuffer in swap_region
glBlitFramebuffer is affected by the scissor so we need to ensure
there is an empty clip flushed before using it. This is similar to
what is done in _cogl_blit_framebuffer().

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
Tested-by: Aaron Plattner <aplattner@nvidia.com>

(cherry picked from commit 65da3f88af9c7b8d72758d116c2652aff68195c1)
2013-01-07 16:37:29 +00:00
Damien Lespiau
70f71e2627 doc: Generate a valid cogl-context.xml
The automagic paragraph support of gtk-doc is way too simple to support
things like multi-paragraphs <note>s. Let's trick gtk-doc and make it
generate a valid docbook snippet for cogl-context.

Without this, cogl-context remains absent of the reference
documentation, how sad is this?!

(cherry picked from commit 606b472d91450e3221da6631020f534892e866a9)
2013-01-04 17:02:02 +00:00
Adam Jackson
f326401094 opengl: Fix conditional call of BlendFuncSeparate
Checking whether src_rgb != src_alpha twice is pointless; not checking
whether dst_rgb != dst_alpha is clearly wrong.

Found by Coverity.

Signed-off-by: Adam Jackson <ajax@redhat.com>

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

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

(cherry picked from commit fc292c25db3004543e277d92693ab9cb388d2121)
2012-12-07 15:52:51 +00:00
Chun-wei Fan
491618a74c cogl-gles2-context: Cast func pointers to void* when filling
vtable

(Sorry, I had to re-apply Neil's patch as the original one somehow did
 not apply)

The function prototypes for the GL functions in CoglContext have the
GLAPIENTRY attribute which on Windows makes them use the stdcall
calling convention. The function pointers exposed from cogl-gles2.h
don't have GLAPIENTRY so they end up having a different calling
convention on Windows. When Cogl is compiled there it ends up giving a
lot of warnings because it assigns a pointer to an incompatible
function type.

We probably don't want to make the functions exposed in cogl-gles2.h
use the stdcall calling convention because we control that API so
there is no need to introduce a second calling convention. The GLES2
context support currently isn't going to work on Windows anyway
because there is no EGL or GLES2 implementation.

Eventually if we make the Cogl GLES2 context virtualized on top of
Cogl then we will provide our own implementations of all these
functions so we can easily keep the C calling convention even on
Windows.

Until then to avoid the warnings on Windows we can just cast the
function pointers temporarily to (void*) when filling in the vtable.

This will also fix the build on Windows using Visual Studio, as it is
more picky on calling convention mismatches.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-11-24 00:18:29 +08:00
Chun-wei Fan
fefa6bc929 cogl.symbols: Add symbols required for Clutter 1.12
Those symbols were missed and are needed for Clutter-1.12.x to build.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-11-24 00:01:40 +08:00
Neil Roberts
6a62e3077b sdl: Don't set SDL_GL_DOUBLEBUFFER when the swap chain has no pref
The ‘length’ for the swap chain is initially -1 which is supposed to
mean ‘no preference’. However, both of the SDL winsys's were
explicitly setting the SDL_GL_DOUBLEBUFFER attribute to zero in that
case which would try to disable double buffering.

On OS X, the equivalent to eglSwapBuffers (ie, [NSOpenGLContext
flushBuffer]) does nothing for a single buffer context. The
cogl-sdl-hello example does not specify the swap chain length so
presumably it would end up with a single buffer config. When
cogl_onscreen_swap_buffers is called it therefore does nothing and
nothing is painted.

I guess to make single-buffered contexts actually useful we should
expose some public equivalent to glFlush so that you can ensure the
rendering commands will actually hit the buffer. Alternatively we
could document that cogl_onscreen_swap_buffers performs this task on
single-buffered configs and then we could make the SDL winsys
explicitly call glFlush in that case.

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

(cherry picked from commit 71e57f99002d5dee79bbd44b3bc57712b99acb55)
2012-11-23 15:45:26 +00:00
Rob Bradford
0e33654efb wayland: Port to new Wayland protocol
Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit db50c3015c589375029a4c26c58db8295bb17bca)
2012-10-18 17:25:21 +01:00
Neil Roberts
0edb848850 Use the right context when pushing the GLES2 context to an onscreen
Previously when pushing the GLES2 context with an onscreen framebuffer
it would just call bind_onscreen. This actually binds it with Cogl's
context so presumably the context isolation wasn't working properly.
This patch splits out bind_onscreen to have a second function called
bind_onscreen_with_context that explicitly takes the EGL context to
use. Cogl now uses this when pushing the GLES2 context.

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

(cherry picked from commit 3653c5b10058a3f79900eb2644cb30f4cf1ca47e)
2012-10-01 15:05:22 +01:00
Neil Roberts
5e730568d4 Remove an out of date comment in the GLES2 context code
There was a FIXME comment about making glCopyTex{Sub,}Image2D work
with CoglOffscreen buffers. This has already been fixed so we should
remove the comment.

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

(cherry picked from commit 750e5668ee64a315c8090dd2223334b1e04bee54)
2012-10-01 15:05:16 +01:00
Neil Roberts
07a50012b9 egl: Only allow GLES2 context creation for the GLES2 driver
Previously, Cogl was advertising the GLES2 context feature whenever
the EGL winsys was used, even if the winsys was used with the GL
driver. This wasn't working because when the GL context is created the
API is set to GL with eglBindAPI and it is never changed back to GLES
when the GLES2 context is created. That meant that the created context
is actually GL not GLES2. Any rendering would then fail because the GL
context does not understand the precision statement.

It could be possible to fix it so that it will set the API correctly
before creating the context. It would then also need to reset the API
and unbind the previous context whenever switching between GLES2 and
GL contexts. If the context isn't unbound first then eglMakeCurrent
will actually try to bind both contexts at the same time and at least
Mesa detects this situation and reports that the two contexts
conflict. Presumably we would also need to do something more clever
when we retrieve the function pointers for the GLES2 context.
Currently we just copy them from the CoglContext but if the context is
using the GL driver then this would mean the functions came from libGL
not libGLESv2.

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

(cherry picked from commit 624dea207cf76ae9ccd7f57c4ebd15d3bd65bff0)
2012-10-01 15:05:11 +01:00
Neil Roberts
9563799655 Fix the terminator in one of the extension lists
The list of extension names in COGL_EXT_BEGIN should be a zero
separated list of strings which is terminated by an empty string. The
name for the GL_ARB_shader_objects extension was missing the zero
separator so presumably it was relying on the following byte to happen
to be a zero in order not to crash.

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

(cherry picked from commit f63381f23fa8b0b17e030561940b8a38efff221f)
2012-09-28 17:15:11 +01:00
Neil Roberts
f9e7f8df94 winsys-glx: Remove the vblank counter feature when indirect rendering
Previously when Cogl detects that the GLX context is indirect it
resets the function pointers for the VBLANK_COUNTER feature to NULL.
However it wasn't removing the VBLANK_COUNTER feature flag. Some other
parts of the winsys check for that feature flag rather than checking
whether the pointer is NULL so it would end up calling an invalid
function pointer and crashing. This just fixes it to also clear the
feature flag.

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

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

(cherry picked from commit e947c713a541086f80a308d22774229f0720196a)
2012-09-28 17:15:11 +01:00
Chun-wei Fan
b743d95e21 Bug 682071-cogl/cogl-sdl.h: MSVC: Link to SDL when apps are built
Link to SDL.lib and SDLmain.lib if Cogl was built with the SDL winsys.

Recent changes to the SDL winsys introduced a direct dependency to
SDLmain.lib (and hence SDL.lib) when programs are built, causing linker
errors to appear when any programs using cogl (with the SDL winsys built
in) are built.

Since we cannot determine whether a Cogl build is built with the SDL winsys
at build time easily, we could use #pragma comment (lib, ...) whenever
cogl-sdl.h is included by cogl.h so that SDLmain.lib and SDL.lib is linked
into the resulting binary, so that the program can link and run correctly.

This does not add any external dependencies as the Cogl DLL already depends
on SDL.dll when it is built with the SDL winsys.
2012-09-19 15:33:47 +08:00
Neil Roberts
1b3a7ac0ab gles2-context: Don't split the wrapper snippet into two
We don't need to split the wrapper snippet into two separate parts
because it should be ok to declare the flip uniform in the middle of
the shader as long as it is somewhere in the global scope. Therefore
we can just declare it right before the definition for the replacement
main function. This is important because we don't want to put anything
at the top of the application's shader in case it is using a
'#version' directive. In that case moving it to anything other than
the first line would break things.

This patch also adds a marker in a comment around the wrapper snippet
so that we can easily locate the snippet when glGetShaderSource is
called and remove it.

The wrapper for glGetAttachedShaders has been removed because there
are no longer any additional shaders attached to the program so we can
just let GL handle it directly.

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

(cherry picked from commit dbd92e24ae61dcbe7ef26f61c9117c5516a7fa87)
2012-09-17 23:06:21 +01:00
Robert Bragg
5f3768f086 gles2-context: only insert prelude + wrapper into strv once
In our wrapper for glShaderSource we special case when a vertex shader
is being specified so we can sneak in a wrapper for the main function to
potentially flip all rendering upside down for better integration with
Cogl.

Previously we were appending the wrapper to all the sub-strings passed
via the vector of strings to glShaderSource but we now grow the vector
instead and insert the prelude and wrapper strings into the beginning
and end of the vector respectively so we should only have one copy for a
single shader.

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

(cherry picked from commit d2904d518718e3fbf4441abe2c2bcfd63edfd64b)
2012-09-17 23:06:21 +01:00
Daniel Stone
a491789637 cogl-gles2-context: Append wrapper shader to user shaders
The SGX GLSL compiler refuses to accept shaders of the form:
    void foo();
    void bar() {
        foo();
    }
where foo is undefined at glShaderSource() time, left for definition at
link time.  To work around this, simply append the wrapper shader to
user shaders, rather than building a separate shader that's always
linked with user shaders.

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

(cherry picked from commit 96f02c445f763ace088be71dc32b3374b2cdbab2)
2012-09-17 23:06:21 +01:00
Robert Bragg
50ba5fa130 gpu-info: Match latest Mesa strings
Mesa now reports a vendor string of "Mesa Project" instead of "VMWare,
Inc." and the software rasterizer renderer string is now "Software
Rasterizer". This update cogl-gpu-info.c to recognize these new strings.

Thanks to Alexander Larsson for the original patch.

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

(cherry picked from commit dfacbbd96f3fbadaffa4a76dfd71c47ece6ed6a3)
2012-09-17 23:06:20 +01:00
Robert Bragg
0f0ee4a909 texture: Add a context pointer to each texture
As part of our on-going goal to remove our dependence on a global Cogl
context this patch adds a pointer to the context to each CoglTexture
so that the various texture apis no longer need to use
_COGL_GET_CONTEXT.

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

(cherry picked from commit 83131072eea395f18ab0525ea2446f443a6033b1)
2012-09-17 23:06:20 +01:00
Robert Bragg
ea3d8eca91 Don't take internal references on the context
We want applications to fully control the lifetime of a CoglContext
without having to worry that internal resources (such as the default
2d,3d and rectangle textures, or any caches we maintain) could result in
circular references that keep the context alive. We also want to avoid
making CoglContext into a special kind of object that isn't ref-counted
or that can't be used with object apis such as
cogl_object_set_user_data. Being able to reliably destroy the context is
important on platforms such as Android where you may be required
bring-up and tear-down a CoglContext numerous times throughout the
applications lifetime. A dissadvantage of this policy is that it is now
possible to leave other object such as framebuffers in an inconsistent
state if the context is unreferenced and destroyed. The documentation
states that all objects that directly or indirectly depend on a context
that has been destroyed will be left in an inconsistent state and must
not be accessed thereafter. Applications (such as Android applications)
that need to cleanly destroy and re-create Cogl resources should make
sure to manually unref these dependant objects before destroying the
context.

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

(cherry picked from commit 23ce51beba1bb739a224e47614a59327dfbb65af)
2012-09-17 23:06:20 +01:00
Robert Bragg
2942fd362d Avoid referencing file scope context in _context_new()
cogl_context_new() had a mixture of references to the file scope context
variable (_context) and the local (context) variable. This renames the
file scope variable to _cogl_context to catch unnecessary references to
the old name and fixes the code accordingly to reference the local
variable instead.

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

(cherry picked from commit 33a9397ee1ae1729200be2e5084cf43cebb64289)
2012-09-17 23:06:20 +01:00
Robert Bragg
66169276f4 texture-2d: improve new_from_foreign error handling
There were lots of places where cogl_texture_2d_new_from_foreign would
simply return NULL without returning a corresponding error. We now
return an error wherever we are returning NULL except in cases where the
user provided invalid data.

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

(cherry picked from commit a1efc9405a13ac8aaf692c5f631a3b8f95d2f259)
2012-09-17 23:06:20 +01:00
Robert Bragg
7b5b0bef83 framebuffer: drop _ALLOCATE_FLAG_DEPTH24_STENCIL8
There are two extensions, GL_OES_packed_depth_stencil and
GL_EXT_packed_depth_stencil, that inform us that the hardware supports
packing the depth and stencil values together into one format.

The OES extension is the GLES equivalent of the EXT extension and the
two extensions provide the same enums with basically the same semantics,
except that the EXT extension is a lot more wordy due to a larger number
of features in the full OpenGL api and the OES extension has some
asymmetric limitations on when the GL_DEPTH_STENCIL and
GL_DEPTH24_STENCIL8 enums can be used as internal formats.

GL_OES_packed_depth_stencil doesn't allow the GL_DEPTH_STENCIL enum
to be passed to glRenderbufferStorage (GL_DEPTH24_STENCIL8 should be
used instead) and GL_OES_packed_depth_stencil doesn't allow
GL_DEPTH24_STENCIL8 to be passed as an internal format to glTexImage2D.

We had been handling the two extensions differently in Cogl by calling
try_creating_fbo with different flags depending on whether the OES or
EXT extension was available and passing GL_DEPTH_STENCIL to
glRenderbufferStorage when we have the EXT extension or
GL_DEPTH24_STENCIL8 with the OES extension.

To localize the code that deals with the differences between the
extensions this patch does away with the need for separate flags
so we now just have COGL_OFFSCREEN_ALLOCATE_FLAG_DEPTH_DEPTH_STENCIL and
right before calling glRenderbufferStorage we check which extension we
are using to decide whether to use the GL_DEPTH_STENCIL or
GL_DEPTH24_STENCIL8 enums.

(cherry picked from commit 88a05fac6609f88c0f46d9df2611d9fbaf159939)
2012-09-17 23:06:19 +01:00
Alban Browaeys
8d09b93572 meta-texture: Fix textures[] index
textures[iter_y.index * n_y_spans + iter_x.index]
only works for vertical rectangles when n_x_spans > 0 (ie x != {0} )

is also wrong for horizontal rectangles ( x = {0, 1, 2, 3} , y = {0, 1}
-> second line will start at 2 = iter_y.index * n_y_spans + iter_x.index
-> iteration are 0, 1, 2, 3, \n 2, 3, 4, 5 instead of 0, 1, 2, 3 \n 4, 5, 6, 7

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

(cherry picked from commit bf0d187f1b5423b9ce1281aab1333fa2dfb9863f)
2012-09-17 11:47:04 +01:00
Neil Roberts
cb834c95e9 pipeline: Fix the layer index used when pruning layers
When pruning a pipeline to a set number of layers it records the index
of the first layer after the given number of layers have been found.
This is stored in a variable called 'first_index_to_prune' implying
that this layer should be included in the layers to be pruned. However
the subsequent if-statement was only pruning layers with an index
greater than the recorded index so it would presumably only prune the
following layers. This patch fixes it to use '>=' instead.

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

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

(cherry picked from commit d3063e8dea92a8f668acef6435cc68e0c901dc8d)
2012-09-07 11:44:41 +01:00
Neil Roberts
a18c97798f pipeline: Ensure the pipeline layer cache is freed when pruning layers
When pruning layers from a pipeline the pipeline cache would once be
freed due to the call to pre_change_notify but it would immediately be
recreated again when foreach_layer_internal is called. When n_layers
is later set to 0 it would end up with an invalid cache lying around.
This patch changes the order so that it will iterate the layers first
before triggering the pre-change notify so that the cache will be
cleared correctly.

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

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

(cherry picked from commit 1c8efdc838cc5ace380365cb54e0741645856edf)
2012-09-07 11:44:41 +01:00
Neil Roberts
27d74f09df kms: Fix the version check for GBM
The check for whether to use ‘stride’ instead of ‘pitch’ from the GBM
API tries to check whether the GBM version is >= 8.1.0. However it was
comparing the major and micro components independently so any version
with the minor part set to 0 would fail. The GBM version in Mesa
master is now 9.0.0 which breaks it. This patch changes it to check
the version using the COGL_VERSION_ENCODE macro instead.

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

(cherry picked from commit 38f1dc58b35023f9e6bbc0db746b1554bd0377fc)
2012-09-06 18:30:30 +01:00
Sjoerd Simons
cde0eb3e76 Make the default driver selectable at configure time
When building COGL with multiple backends it can be useful to force a
default driver to be selected. For example while for Debian we do want to
build the GL renderer on ARM, GLESv2 is much more suitable as the
default renderer on that platform.

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

(cherry picked from commit 8a43aa7167b56784f7b50c557391b990861d594f)
2012-09-03 15:51:45 +01:00
Robert Bragg
ac72d0685c profile: Print warning if "Mainloop" timer missing
As a helpful aid Cogl will now print a warning if no "Mainloop" UProf
timer was setup by the application that explains that either Clutter
should be built with --enable-profile or if Clutter isn't being used
then it shows how it can create its own Mainloop timer.

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

(cherry picked from commit 3d052dbca86bf36f30b2d60ff59b967d14665436)
2012-09-03 15:51:45 +01:00
Robert Bragg
85efcfac2a journal: Add a uprof timer around the _flush() discard
This adds a uprof timer around the _cogl_journal_discard() at the end of
_cogl_journal_flush() since this sometimes takes a significant
proportion of the time to flush the journal.

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

(cherry picked from commit 14ffc3a197100be814452af2d0f839970353b04d)
2012-09-03 15:51:45 +01:00
Robert Bragg
c477e9ce49 debug: define COGL_DEBUG_ macros for non-debug builds
Since we only want to disable the debug features that may impact
performance when building with --disable-debug this ensures that the
COGL_DEBUG_ macros aren't defined as NOPs for non-debug builds.

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

(cherry picked from commit c4b50040b5c033e370eb721d1d217eced8ebdaad)
2012-09-03 15:51:45 +01:00
Robert Bragg
fb22383993 pipeline: make _GET_LAYER_NO_CREATE enum a flag
_cogl_pipeline_get_layer_with_flags accepts a CoglPipelineGetLayerFlags
flags argument and understands one COGL_PIPELINE_GET_LAYER_NO_CREATE
flag. There was a mistake with the definition of this enum though so
COGL_PIPELINE_GET_LAYER_NO_CREATE had a value of 0 and so testing for
the flag using the bitwise & operator would never find the flag set.

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

(cherry picked from commit 5923f92f1428b3eb4977b5f21723f1b19a9d284a)
2012-09-03 15:51:45 +01:00
Robert Bragg
71f20064ab debug: ignore wireframe debug drawing for line primitives
If a primitive is already line based then we don't need to do anything
special to draw it in wireframe mode.

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

(cherry picked from commit fb575a42c308739a7185311a613b1a5f49dbfb39)
2012-09-03 15:51:44 +01:00
Robert Bragg
971b5cfae1 primitive: Don't leak indices
If a CoglPrimitive is associated with a set of indices then we must
unref those indices when freeing the primitive to avoid a leak.

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

(cherry picked from commit 45cac786b55c953e44f98b864add952b9e398b13)
2012-09-03 15:51:44 +01:00
Robert Bragg
74d749eca4 kms: Update to latest gbm api
gbm_bo_get_pitch was renamed to gbm_bo_get_stride to be consistent with
how the terms pitch and stride are used throughout mesa. This updates
the Cogl backend to use the new gbm_bo_get_stride name.

For compatibility with previous version of libgbm we now explicitly
check the version of libgbm in configure.ac and expose
COGL_GBM_{MAJOR,MINOR,MICRO} defines to the code so we can conditionally
use the older gbm_bo_get_pitch() name with older versions.

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

(cherry picked from commit 47c6247095e2f1f8725c4eb08d38c9de15e283cd)
2012-09-03 15:51:44 +01:00
Neil Roberts
ef73e6e3b9 cogl-version: Fix the 'since' tags in the documentation
The COGL_VERSION_* macros will also be in Cogl 1.12.0.

(cherry picked from commit e9473b58b80a06d3be34a4b518aade190ed9b666)
2012-09-03 15:48:05 +01:00
Neil Roberts
f13f6b9175 cogl-version: Fix the version number
The version number macros were using the @COGL_VERSION_*@
substitutions. These are always defined to 2.0.0 in the 1.x releases
so we need to use the Cogl @COGL_1_VERSION_*@ substitutions instead to
get the real version number.
2012-09-03 15:47:56 +01:00
Neil Roberts
b3f56ccb48 tex-driver-gles: Fix subregion uploads without GL_EXT_unpack_subimage
When the GL_EXT_unpack_subimage extension is not available and a
subregion of a texture is uploaded then it should first copy the
subregion to a newly allocated bitmap. However it was then later still
trying to prepare the upload using the original src_x and src_y values
which would cause an assertion failure. This patch fixes it to just
reset those to zero if the subregion is first copied.

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

(cherry picked from commit 6f9a62db6f846f1d76e3ca16d9d8cdadf82a7009)
2012-08-29 15:01:31 +01:00
Chun-wei Fan
55e4394780 Update/fix cogl.symbols for 1.12
Update the cogl.symbols file for the 1.12 series, where symbols
were added for the following commits:

010d16f6: Adds initial GLES2 integration support
6eb88648: Add a cogl_matrix_init_from_euler function
5e8ff248: Add functions to directly transform from a euler or a quaternion
1686e754: bitmap: Adds cogl_android_bitmap_new_from_asset()
df515741: onscreen: Adds support for resizable windows
e347135b: Move cogl_wayland_display_ proto to cogl-wayland-server.h

Plus, when we branched out for 1.12, some needed symbols were missing, so
we would need to make up for them, in particular those in cogl-shader.h
and cogl-path-functions.h.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-08-17 01:20:13 +08:00
Chun-wei Fan
8dbf7ffe05 cogl/Makefile.am: Correct the way gen-enums.bat is created
Don't use --symbol-prefix cogl_gtype as we are still using the old
namespace in cogl-1.12, so there will still be the various _get_type()'s
like before

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-08-17 01:20:02 +08:00
Tomeu Vizoso
04348bda0b cogl-gles2: Install headers in cogl/ instead of in cogl2/
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-08-16 16:36:34 +01:00
Neil Roberts
32fbd0ada6 kms: Use a dummy surface instead of the surfaceless extension
The surfaceless extension that Mesa advertises has been renamed to
EGL_KHR_surfaceless_context instead of a separate extension for the
GLES, GLES2 and GL APIs and the new extension has been ratified by
Khronos. Therefore the KMS backend no longer runs against Mesa master.
We could just rename the extension we check for, however Weston (the
sample Wayland compositor) has switched to just creating a dummy GBM
surface and not using the surfaceless extension at all. We should
probably do the same thing.

Using the surfaceless extension could be a good idea but we don't
really need to rely on it for KMS and we would want to do it for all
EGL backends, not just the KMS backend.

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

(cherry picked from commit d4f22f8cb013d417c99ba03924538924191c2fe6)
2012-08-15 17:29:16 +01:00
Neil Roberts
51d94769be framebuffer: Take const pointers for the matrix setters
cogl_framebuffer_set_{projection,modelview}_matrix don't need to read
from the matrix argument so they should probably take a const pointer.

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

(cherry picked from commit 710d6af053aca97935b54f9ff68858ef51f4482b)
2012-08-15 17:29:16 +01:00
Neil Roberts
41539dd7f0 bitmap: Use the 'copy' blend mode when loading images on Quartz
When loading images on Quartz, the image is rendered into a bitmap
context using a buffer allocated with
_cogl_bitmap_new_with_malloc_buffer. However this buffer is not
initialised and by default Quartz will blend the source image with the
destination so if there are transparent parts in the source image it
will leave garbage in the destination. This patch changes the blend
mode to 'copy' so that it won't try to blend.

Before 5b785dd4 the buffer was cleared because it was allocated with
g_malloc0 so it was working in that case. Presumably it should be more
efficient to disable blending and avoid the clear though.

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

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

(cherry picked from commit 5ba7f4e6837a539d92cbe45491f79a8926fd6828)
2012-08-15 17:14:25 +01:00
Sjoerd Simons
57f420e21e Remove one final user of cogl-handle and cogl-handle.h itself
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-08-15 13:46:25 +01: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
77edc1f204 cogl-gles2-context: Keep track of extra data per texture object
This patch adds a hash table mapping texture object IDs to a struct so
that we can keep track of some of the state for each texture object.
Currently it will just track the width and height of the texture 2D
target.

Additionally it will now try to delete any texture objects that have
data created for them by the GLES2 context so that it won't leak them.
It only tracks objects that get data set on them, not all objects that
are bound because it is possible to use the GLES2 context with foreign
textures via cogl_gles2_texture_get_handle() and we don't want to
delete those.

In order to keep track of the currently bound texture object it also
needs to track the active texture unit.

Note that this state tracking will probably go wrong if GL throws an
error for invalid state. For example if glActiveTexture is called with
an invalid texture unit then GL will ignore the binding but Cogl will
assume it is valid and the state tracking will get out of sync.
Perhaps it would be good if Cogl could detect the errors but this is
difficult to do without consuming them.

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

(cherry picked from commit d8c72bb56cf3598fc57d629edc618f1bfa79f125)
2012-08-15 13:44:22 +01:00
Neil Roberts
8e12e40da9 cogl-gles2-context: Flip the rendering when framebuffer is offscreen
Cogl has a different origin for texture coordinates than OpenGL so
that the results of rendering to a texture should leave the top of the
image at the texture coordinate 0,0 rather than the bottom. When a
GLES2 context is used to render to a Cogl texture via a CoglOffscreen
we don't really want the application to have to be aware of the
mismatch and flip the texture coordinates. To get that to work, this
patch now tracks all of the programs that the application generates
using the context and sneaks in an extra vertex shader with an
alternative main function. This main function multiplies the final
calculated gl_Position by a vector uniform which we can use to flip
the image. When the application uploads the source code for a vertex
shader we now replace any occurrences of the token 'main' with '_c31'
and this renamed function gets called from the replacement main
function. The token has a weird name so that it will be unlikely to
conflict with a variable name in the application's source but it also
needs to have the same number of characters as the original token so
that it won't affect column numbers in the error reporting.

We are also wrapping glGetShaderSource so that we can try to revert
the token name. The same goes for the error logs just in case the
error report mentions function names.

Both places that cause drawing to occur (glDrawElements and
glDrawArrays) are now also wrapped so that we can update the uniform
value whenever the program is used with a different type of
framebuffer from last time.

We additionally need to manually track the state for the viewport, the
stencil box and the front face because all of these will be affected
by whether we are flipping the image or not. Any attempts to change
these states will be queued and instead flushed at the last minute
before drawing.

There are still some known issues with this patch:

• glCopyTexImage2D and glCopyTexSubImage2D will do the wrong thing
  when copying data from a CoglOffscreen. This could be quite fiddly
  to solve.

• Point sprites won't flip correctly. To make this work we would need
  to flip the gl_PointSprite builtin variable somehow. This is done in
  the fragment shader not the vertex shader so flipping the calculated
  gl_Position doesn't help here.

• The patch doesn't attempt to flip rendering to framebuffers for
  textures created within the GLES2 context. This probably makes sense
  because those textures are likely to be used within the GLES2
  context in which case we want to leave the texture coordinates as
  they are. However, if the texture is shared back out to Cogl with
  cogl_gles2_texture_2d_new_from_handle then the texture will be
  upside-down.

• The application can discover our secret uniform that we added via
  glGetActiveUniform. It might be worth trying to disguise this by
  wrapping that function although that could be quite fiddly.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit d589bf19e51f22c3241b2a18db10f22131ac126a)
2012-08-14 18:55:42 +01:00
Neil Roberts
0c66431df3 Add a wrapper for 'memmem'
memmem is a GNU libc extension that works like strstr except that the
size of the needle and the haystack are passed into the function
instead of using null-terminated strings.

This patch adds a wrapper function called 'cogl_util_memmem' so that
we can use this function. There is a configure check and if the
function is not available then a fallback implementation will be used.
Otherwise cogl_util_memmem is just defined to memmem.

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

(cherry picked from commit 1dd1b0a67f6238e13f7f9253fb03addada0541b7)
2012-08-14 18:55:42 +01:00
Neil Roberts
12a1ef72c0 cogl-gles2-context: Keep some extra data for shaders and programs
All of the functions that create and destroy shaders are now wrapped
in the CoglGLES2Context so that we can track some extra data for them.
There are hash tables mapping object IDs to the corresponding data.
The data is currently not used for anything but will be in later
patches.

The glUseProgram, glAttachShader and glDetachShader functions
additionally need to be wrapped because GL does not delete shader
objects that are in use. Therefore we need to have a reference count
on the data so we can recognise when the last use has been removed.

The IDs are assumed to be specific to an individual CoglGLES2Context.
This is technically not the case because all of the CoglGLES2Contexts
are in the same share list. However we don't really want this to be
the case so currently we will assume sharing the object IDs between
contexts is undefined behaviour. Eventually we may want to actually
enforce this.

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

(cherry picked from commit 05dc1e34785ae5f5484cd398ecc5464bd8bd3dcd)
2012-08-14 18:55:42 +01:00
Neil Roberts
0cd88bd676 cogl-gles2-context: Fix the default viewport and scissor size
In GL, the default viewport and scissor should be set to the size of
the first surface that the context is bound to. If a CoglGLES2Context
is first used with an offscreen framebuffer then this surface will
actually be the dummy 1x1 window which will mess up the defaults. To
fix that, this patch makes it just always override the viewport and
scissor the first time the context is bound to something.

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

(cherry picked from commit 02567b3e6b64e6849b9f7c6aa2137401be7ece8d)
2012-08-14 18:55:42 +01:00
Robert Bragg
6a024acaa9 display: inc cogl-wayland-server.h if needed
Since 0773107deb9ede the prototype for
cogl_wayland_display_set_compositor_display() has moved into
cogl-wayland-server.h but cogl-display.c wasn't updated to include this
header.

(cherry picked from commit f6ccff9992fcfb9497ce91dd299460362476ba7a)
2012-08-06 18:51:34 +01:00
Robert Bragg
e347135b6a Move cogl_wayland_display_ proto to cogl-wayland-server.h
We need to avoid including wayland-server.h or wayland-client.h
indirectly when including cogl.h because there are overlapping typedef
names between the client and server wayland headers and we can't assume
whether Cogl is being used client or server side. This moves the
prototype for cogl_wayland_display_set_compositor_display() into
cogl-wayland-server.h which Cogl apps must include explicitly if the
want access to server side Cogl Wayland symbols.

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

(cherry picked from commit 0773107deb9eded408e2801f217462c5d551f15a)
2012-08-06 18:51:34 +01:00
Neil Roberts
0e168ed0aa Fix the header guards for cogl-texture-2d{,-private}.h
The header guard for cogl-texture-2d-private.h was
__COGL_TEXTURE_2D_H. This would conflict with the header guard for
cogl-texture-2d.h except there a small typo ('TEXURE') so that it
was subtly different. This fixes them both to make more sense.

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

(cherry picked from commit 222ec4d009973cb62020a9da05f72dea41460b33)
2012-08-06 18:51:33 +01:00
Neil Roberts
96b726b518 cogl-winsys-sdl: Fix the signature for the get_proc_address method
This function should take an extra third paramter to specify whether
the procedure is in core or not. The parameter is not used so this
patch just fixes an annoying warning.

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

(cherry picked from commit eed4ac80cd8c3fa1859493c9bb00547038be6095)
2012-08-06 18:51:33 +01:00
Neil Roberts
59ff396875 cogl-winsys-egl-kms: Remove some unused variables
This just gets rid of some annoying warnings.

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

(cherry picked from commit 3d0aea04d1f6a8094b749e20a59d8a9a95a6235e)
2012-08-06 18:51:33 +01:00
Neil Roberts
5fff83cd3c cogl-texture-2d-private: Include egl-defines.h
The cogl-texture-2d-private.h header checks for the presence of
EGL_KHR_image_base before declaring
_cogl_egl_texture_2d_new_from_image. This define will only be
available if the EGL headers are included so we should make sure that
happens. This was resulting in a warning complaining that the function
was not previously declared.

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

(cherry picked from commit bd4840d7858efcf30eb5cf5d6fd0d39bdd59d1c1)
2012-08-06 18:51:33 +01:00
Neil Roberts
74fd618df9 Add conf vars to trick Cogl to think extensions are disabled
This adds two new configuration environment variables:

COGL_DISABLE_GL_EXTENSIONS and
COGL_OVERRIDE_GL_VERSION

The variables can also be set in the cogl.conf file using the same
names.

The first one is a list of GL extension names separated by commas.
When set Cogl will assume any extension listed here is not available
by removing it from the string returned from
glGetString(GL_EXTENSIONS). If the string is set in both the config
file and the environment variable then the union of the two lists will
be used.

The second overrides the value returned from glGetString(GL_VERSION).
If the string is set in both places the version from the environment
variable will take priority.

These are sometimes useful for debugging Cogl to test the various
combinations of extensions. It could also be useful to work around
driver bugs where an extension is badly supported and it would be
better not to use it.

The variables in cogl-config that just set a global char * variable
have been put together in an array instead of having a separate blob
of code for each one in order to make it simpler to add new variables.

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

(cherry picked from commit ec69c2dc576c78664e0b73879365cb7414ecf441)
2012-08-06 18:51:33 +01:00
Damien Lespiau
e5fea8b734 egl-x11: Don't use GLXDrawable on EGL
Someone trying to compile cogl (ThijsNL on irc0 for the Rasberry Pi
stumbled into that one. GLXDrawable may not be defined in a pure EGL/X
environment.

Change it to Window, the type used for XConfigureEvent.window.

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

(cherry picked from commit f05d6923fff28b1d167a391d486e319743c49215)
2012-08-06 18:51:33 +01:00
Neil Roberts
cbad21f0f4 pipeline: Remove the CoglPipelineFlag enum
This doesn't appear to be used anywhere in the code since it was added
in 1cc3ae69. Dead code is confusing so let's remove it.

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

(cherry picked from commit 41928d0ac528acf4ba89b5b27d7ca7ac5501b194)
2012-08-06 18:51:33 +01:00
Tomeu Vizoso
bb258c1d42 Avoid including the EGL headers from the public Cogl headers
Otherwise, X11 identifiers may leak and cause havoc in big applications

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

(cherry picked from commit ed0cdca0eca815543619fe72fbd42d662d53f92d)
2012-08-06 18:51:32 +01:00
Robert Bragg
961832164b quaternions: Allow multiplication into 'a' arg
When multiplying two quaternions, we now implicitly copy the components
of the 'a' argument so that the result can be reliably written back to
the 'a' argument quaternion without conflicting with the multiplication
itself. This is consistent with the cogl_matrix_multiply() api which
allows the 'result' and 'a' arguments to point to the same matrix. In
debug builds Cogl will assert that the 'b' and 'result' arguments don't
point to the same quaternion.

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

(cherry picked from commit 207527313a8957789390069e84189254cf41e88f)
2012-08-06 18:51:32 +01:00
Robert Bragg
8f4dd4587e onscreen: Free swap notify callback state
When freeing a CoglOnscreen we weren't freeing the state associated with
swap notification callbacks.

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

(cherry picked from commit 70bc12fe20fa1be4eac58356861a730f18d6b59e)
2012-08-06 18:51:32 +01:00
Robert Bragg
56382435fa stack: don't deref freed mem in _cogl_memory_stack_free
This fixes _cogl_memory_stack_free to ensure we don't dereference freed
memory as we iterate the sub-stacks to free them.

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

(cherry picked from commit 1d27fedef9c599aa9976b809f18e0da1913cec26)
2012-08-06 18:51:32 +01:00
Robert Bragg
df51574116 onscreen: Adds support for resizable windows
This adds api to be able to request that the window system allows a
given onscreen framebuffer to be resizable, and api to add and remove
resize handlers to be called whenever the framebuffer does actually
change size.

The new functions are:
  cogl_onscreen_{get,set}_resizable()
  cogl_onscreen_{add,remove}_resize_handler()

The examples cogl-hello and cogl-x11-foreign have been updated to use
the new api. To smoke test how Cogl updates the viewport automatically
in response to window resizes the cogl-hello test doesn't explicitly
respond to resize events by setting the viewport and cogl-x11-foreign
responds by setting a viewport that is offset by a quarter of the
window's width/height and half the width and height of the window.

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

(cherry picked from commit a1a8cc00bfa2cecaf1007aec5f3dd95dc07b1786)
2012-08-06 18:51:32 +01:00
Neil Roberts
2ae352b0a6 Fix point sprite coordinates in shaders on GLES2
When using the GLES2 driver with a pipeline layer that has point
sprite coordinates enabled it extracts the texture coordinates from
the gl_PointCoord builtin instead of cogl_tex_coord_in[*].
gl_PointCoord is not quite the same as the regular texture coordinates
because it is only a vec2 instead of a vec4. This used to work ok
because either set of texture coordinates would always immediately be
accessed using a swizzle of '.st' so it would effectively be converted
to a vec2 anyway. However since the snippet hook for texture lookups
was added the texture coordinates are now passed to a function to
perform the actual lookup instead. This function always takes a vec4
so the shader would not compile. This patch fixes it to construct a
vec4 from gl_PointCoord by setting the third and fourth components to
0.0 and 1.0.

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

(cherry picked from commit cb3409b23caf324a548f82cfb88acc684cc71930)
2012-08-06 18:51:31 +01:00
Tomeu Vizoso
053845f796 framebuffer: Only remember offscreen allocate flags when !COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL
Otherwise, if a texture is created before all the other FBOs, a new
atlas will be created, with a FBO with COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL
causing last_offscreen_allocate_flags to be 0.

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

(cherry picked from commit 7d2156785da8196e129eb393efb0d09093c4783e)
2012-08-06 18:51:31 +01:00
Robert Bragg
1686e754a7 bitmap: Adds cogl_android_bitmap_new_from_asset()
This adds some android specific api for creating a CoglBitmap from an
Android asset.

As part of the work it also seemed like a good time to change the
internal bitmap constructors to take an explicit CoglContext argument
and so the public cogl_bitmap_new_from_file() api was also changed
accordingly to take a CoglContext pointer as the first argument.

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

(cherry picked from commit 099d6d1b505b55bbd09c50d081deb41ab5764e19)

  Since we aren't able to break APIs on the 1.12 branch this cherry-pick
  skips the change to cogl_bitmap_new_from_file()
2012-08-06 18:50:22 +01:00
Neil Roberts
d1dc4e1e0b Don't use the label 'ERROR' because it conflicts with windows.h
wingdi.h which gets included from windows.h #defines ERROR to 0 so we
can't use it as a label in Cogl. This patch changes it to be error in
lower case instead.

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

(cherry picked from commit e9bac2755c2cba84c82a856d369a30560d19a32e)
2012-08-06 14:27:45 +01:00
Neil Roberts
df77e8565e Don't use eglGetProcAddress to retrieve core functions
According to the EGL spec, eglGetProcAddress should only be used to
retrieve extension functions. It also says that returning non-NULL
does not mean the extension is available so you could interpret this
as saying that the function is allowed to return garbage for core
functions. This seems to happen at least for the Android
implementation of EGL.

To workaround this the winsys's are now passed down a flag to say
whether the function is from the core API. This information is already
in the gl-prototypes headers as the minimum core GL version and as a
pair of flags to specify whether it is available in core GLES1 and
GLES2. If the function is in core the EGL winsys will now avoid using
eglGetProcAddress and always fallback to querying the library directly
with the GModule API.

The GLX winsys is left alone because glXGetProcAddress apparently
supports querying core API and extension functions.

The WGL winsys could ideally be changed because wglGetProcAddress
should also only be used for extension functions but the situation is
slightly different because WGL considers anything from GL > 1.1 to be
an extension so it would need a bit more information to determine
whether to query the function directly from the library.

The SDL winsys is also left alone because it's not as easy to portably
determine which GL library SDL has chosen to load in order to resolve
the symbols directly.

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

(cherry picked from commit 72089730ad06ccdd38a344279a893965ae68cec1)

  Since we aren't able to break API on the 1.12 branch
  cogl_get_proc_address is still supported but isn't easily able to
  determine whether the given name corresponds to a core symbol or
  not.  For now we just assume the symbol being queried isn't part
  of the core GL api and update the documentation accordingly.
2012-08-06 14:27:45 +01:00
Neil Roberts
7cdaaf2bd5 Don't use the transpose argument of glUniformMatrix*
According to the GLES1/2 spec, the transpose argument of
glUniformMatrix* should always be FALSE. Cogl directly exposes the
transposedness of the uniform value in
cogl_pipeline_set_uniform_matrix and we were previously passing this
value on to GL. This patch makes it instead just always transpose the
matrix in Cogl itself when copying the value to the CoglBoxedValue. It
doesn't seem like there could be much advantage to letting GL
transpose the uniform value and at least Mesa just does a very similar
loop to handle the transpose.

Mesa has started being more pedantic about this which was making
test_pipeline_uniforms fail.

http://cgit.freedesktop.org/mesa/mesa/commit/?id=60e8a4944081b42127b3

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

(cherry picked from commit f42ee670ff663d03073d6b1038b21a0aa1b3ec2b)
2012-08-06 14:27:45 +01:00
Tomeu Vizoso
93d0de1d9a Mass rename CLUTTER_COMPILATION to COGL_COMPILATION
Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit a99512e5798e48ffa3a9a1a7eb98bc55647ee1b6)
2012-08-06 14:27:45 +01:00
Damien Lespiau
4ad1e9b83a Use <literal> not <pre> in the comments
Comments are interpreted as docbook snippets and <pre> is from html. The
closest maching tag for inline content seems to be <literal>.

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

(cherry picked from commit 66c9f26dfb3133f43d319128d6636f793a1ceb4a)
2012-08-06 14:27:45 +01:00
Damien Lespiau
829aafce98 Update the cogl_sdl_context_new() code snippet
The first argument has been removed from the function. Update the
example accordingly.

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

(cherry picked from commit 06e47af3144565bdf85abf8ae561c7ceeafa2cbc)
2012-08-06 14:27:45 +01:00
Damien Lespiau
ecc5c96aeb Initialize the inverse matrix in invert_matrix_3d()
Contrary to the other inversion functions, invert_matrix_3d() does not
initialize the inverse to the identity and then only touches the
elements it cares about. Problem is the ww component is left alone,
which makes everything go to a black hole when using an inverse matrix
as the transform matrix of a framebuffer.

This is how cameras are typically implemented, they have a transform
and the framebuffer matrix stack is initialized with the inverse
of that transform. A gdb session gives away what happens:

The camera model view matrix, slightly rotation around the X axis:
camera mv       1.000000 0.000000 0.000000 0.000000
camera mv       0.000000 0.984808 -0.173648 0.000000
camera mv       0.000000 0.173648 0.984808 10.000000
camera mv       0.000000 0.000000 0.000000 1.000000

Breakpoint 5, invert_matrix_3d (matrix=0x8056b58) at ./cogl-matrix.c:671
671       const float *in = (float *)matrix;
(gdb) p *matrix
$1 = {xx = 1, yx = 0, zx = 0, wx = 0, xy = 0, yy = 0.98480773,
  zy = 0.173648164, wy = 0, xz = 0, yz = -0.173648164, zz = 0.98480773,
  wz = 0, xw = 0, yw = 0, zw = 10, ww = 1, inv = {0 <repeats 16 times>},
  type = 6, flags = 1030, _padding3 = 0}
(gdb) finish
Run till exit from #0  invert_matrix_3d (matrix=0x8056b58)
    at ./cogl-matrix.c:671
0x00141ced in _cogl_matrix_update_inverse (matrix=0x8056b58)
    at ./cogl-matrix.c:1123
1123          if (inv_mat_tab[matrix->type](matrix))
Value returned is $2 = 1
(gdb) p *matrix
$3 = {xx = 1, yx = 0, zx = 0, wx = 0, xy = 0, yy = 0.98480773,
  zy = 0.173648164, wy = 0, xz = 0, yz = -0.173648164, zz = 0.98480773,
  wz = 0, xw = 0, yw = 0, zw = 10, ww = 1, inv = {1, 0, 0, 0, 0, 0.98480773,
    -0.173648164, 0, 0, 0.173648164, 0.98480773, 0, -0, -1.73648167,
    -9.84807777, 0}, type = 6, flags = 1030, _padding3 = 0}

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

(cherry picked from commit 9a19ea0147eb316247c45cbba6bb70dec5b9be4c)
2012-08-06 14:27:45 +01:00
Neil Roberts
763c1de2ab Use the old GLSL extensions if GL 2.0 is not available
Some drivers have good support for GLSL but don't have the complete
set of features needed to advertise GL 2.0 support. We should accept
the three old GLSL extensions (GL_ARB_shader_objects,
GL_ARB_vertex_shader and GL_ARB_fragment_shader) to support shaders on
these drivers.

This patch splits the shader functions into four sections :- those
that are provided only in GL 2.0, those that have the same name in the
shader objects extension, those that are provided by the vertex
shader extension (they all share the same name) and those that have a
different name in the shader objects extension.

If GL 2.0 is not supported but all three of the extensions are then
the pointers to the GL2-only functions will be replaced to point to
the equivalent functions from the extensions. That way the rest of the
Cogl source doesn't have to worry about the name differences.

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

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

(cherry picked from commit 71ecb51bd20dc3053b4221961b57e5a2b1029bdf)
2012-08-06 14:27:45 +01:00
Neil Roberts
a3989d035e Fix removing layers when the pipeline is not the owner
If cogl_pipeline_remove_layer is called on a copied pipeline to remove
a parent layer then it will still end up calling
_cogl_pipeline_remove_layer_difference on the layer. This function
was directly trying to remove the layer from the pipeline's list of
layer differences. However in the child pipeline the layer isn't in
the list because it is unchanged from its parent. The function had an
assertion to verify that this situation wasn't hit so in a debug build
it would just bail out.

This patch removes the assertion and changes it to only remove the
layer if it is owned by the pipeline. Otherwise it just sets the
COGL_PIPELINE_STATE_LAYERS difference as normal and decrements the
number of layers. This will cause it to successfully remove the layer
because either it is the last layer in which case it will be ignored
after n_layers is decreased or if it is in the middle of the list then
the subsequent layers will all be shifted down so there will be a
replacement layer difference.

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

(cherry picked from commit 88e73dd93fa09a158064a946ab229591a5888b97)
2012-08-06 14:27:45 +01:00
Neil Roberts
17c818a9a7 Add an SDL2 winsys
This adds an alternate version of the SDL winsys using the SDL 2 API.
The two versions are mutually exclusive and share the same
CoglWinsysID. Version 2 of SDL fits a little bit better with Cogl
because it supports multiple windows and the video subsystem can be
initialised entirely independently of the rest of the subsystems.

The SDL2 winsys creates an invisible dummy window in order to bind the
GL context after creating the Cogl display. This is similar to how the
X11 winsys's work.

SDL2 seems to support compiling with support for both GL and GLES.
However there doesn't seem to be a way to select between the two
backends outside of SDL. In fact if you do compile them both in it
seems to break down because it will always try to use the window
system functions from the GLES backend because those are filled in
second in the vtable. However when creating the window it will always
prefer to use the GL function to choose a visual. This function gets
confused because the GL backend has not been initialised at that
point. The Cogl backend therefore just leaves it up to SDL to pick a
sensible backend. It will then verify that it picked a GL library
which matches the Cogl driver by checking the string from
glGetString(GL_VERSION).

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

(cherry picked from commit 6cb5ab41355e7bfe28f367cf4afa39a7afcfeec2)
2012-08-06 14:27:44 +01:00
Tomeu Vizoso
9a1f0c4098 cogl-gles2: Add glTexParameterf to wrapper library
Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 06d6bdb73e3d2468cf3a8c355152cbdeb1b36d94)
2012-08-06 14:27:44 +01:00
Damien Lespiau
a87b657d73 Add a note about [0, 0, 0] and cogl_vector3_normalize()
When having the [0, 0, 0] vector, normalize() won't try to divide by 0
and thus it's always safe to use that funtion.

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

(cherry picked from commit 64370e7ddd32f25556a1792c00d14adc48a81d45)
2012-08-06 14:27:44 +01:00
Damien Lespiau
81bb87e037 Use the internal format to check if the texture size is supported
Until now, we hardcoded the internal format to GL_RGBA and used the
internal format returned by pixel_format_to_gl() as the format for
checking the texture size and format we're asked to create.

Let's use the proper internal format/format from now on.

This is needed as a later patch introduces DEPTH and DEPTH_STENCIL
textures.

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

(cherry picked from commit ec45f60ee2545f88302da314bcdbe1439c4ba9c9)
2012-08-06 14:27:44 +01:00
Rico Tzschichholz
5c16ad65c5 build: add newly introduced header to fix make dist
Missing bit of 4bb6eff3dbd50d8fef7d6bdbed55c5aaa70036a8

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

(cherry picked from commit 1674cf28f1f5b71bd25a1f253c99825d427dd243)
2012-08-06 14:27:44 +01:00