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)
‘Propagate’ was misspelled as ‘propogate’.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 5fb4a6178c3e64371c01510690d9de1e8a740bde)
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)
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)
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)
_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)
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)
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)
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.
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)
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)
_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.
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.
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.
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)
This adds a conformance test with an alpha-component texture. The
texture is rendered using a pipeline with the same layer combine mode
as cogl-pango.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 05190519bad4519e66cbdb5326943c832d15a841)
Previously when make test is run it would say ‘fail’ in lower case
letters for both tests that are known bugs we need to fix and for
drivers that can't run the test. This makes it too easy to lose track
of bugs.
To fix this, the ADD_TEST macro has now been changed to take two sets
of flags instead of just one. The first specifies the requirements for
the test to run at all. The second specifies the set of flags required
to run without any known failures. The table in the test report now
says ‘n/a’ instead of ‘fail’ for tests that don't match the feature
requirements.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 723f8d4402e7b2ef3a71f51bb29b10d1c0ec8d81)
The tests that were using GLSL or 3D textures were directly printing
“Skipped” and then reporting success. Instead of doing this they now
just try to continue without checking for the feature but the
appropriate test requirement flag is now set in test-conform-main so
the table of results will correctly display that is a failure.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit b8f918e44b243a5fa36d5f382a90bebb0de0728f)
This renames the global ctx and fb variables to test_ctx and test_fb
respectively in line with the names use on the master branch. This is to
make it easier to cherry pick patches from master.
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)
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)
The GDK pixbuf support requires being able to propagate errors from
GDKPixbuf as GErrors. This won't work if we are using the builtin
version of GLib because any attempt to call g_error_free from within
Cogl will use the internal version which will free the error using the
wrong slice allocator. It probably doesn't make much sense to build
without glib but with gdk-pixbuf so there's not much point in trying
to work around this situation.
Previously if you specified --enable-gdk-pixbuf but gdk-pixbuf was not
available it would silently disable it. This pach also fixes it so
that it will report an error in that case.
If --enable-gdk-pixbuf is not specified it will now default to
enabling it only if both glib is enabled and gdk-pixbuf is available.
This patch looks slightly longer than it ought to be because it moves
the check for glib up to above the descisions about the image backend.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 8b1eabdc08da89a57792f9eb666e893a6cbb4e26)
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)
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)
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)
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)
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)
This updates the npot-texture test to use Cogl directly instead of
relying on Clutter.
Note that this currently fails when Cogl ends up using sliced
textures. It looks like there is some bug with the meta texture
function to iterate the primitive textures. This happens when
COGL_DEBUG=disable-npot-textures is set.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 32f0e1e8fff56be3123dc4571f07bb5a314f6818)
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)
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)
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)
This adds a small test case which maps a sub region of a small
attribute buffer and replaces the texture coordinates of one of the
vertices. The vertices are then drawn and the correct colours are
checked.
There is now a new test requirement for the
COGL_FEATURE_ID_MAP_BUFFER_FOR_WRITE feature which this test requires.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 22183265b021dd038338b4398056c0a1eae77edb)
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)
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)
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)
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)
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)
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)
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)
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)
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)
This adds a simple test which sets an alpha test on a pipeline and
then renders a texture. It then verifies that the transparent parts of
the texture aren't drawn. This is currently failing with the GL3
driver because GL3 requires the alpha test to be implemented in GLSL
but the generated alpha test uniform is only updated for the GLES2
driver.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 4ec04507bfaf2d61707dccfb59ac7326962ee741)
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)
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)