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)
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)
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)
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)
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.
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)
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)
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)
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)
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)
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)
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)
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)