This adds COGL_PIPELINE_WRAP_MODE_MIRRORED_REPEAT enum so that mirrored
texture repeating can be used. This also adds support for emulating the
MIRRORED_REPEAT mode via the cogl-spans API so it can also be used with
meta textures such as sliced and atlas textures.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
CoglMetaTexture is an interface for dealing with high level textures
that may be comprised of one or more low-level textures internally. The
interface allows the development of primitive drawing APIs that can draw
with high-level textures (such as atlas textures) even though the
GPU doesn't natively understand these texture types.
There is currently just one function that's part of this interface:
cogl_meta_texture_foreach_in_region() which allows an application to
resolve the internal, low-level textures of a high-level texture.
cogl_rectangle() uses this API for example so that it can easily emulate
the _REPEAT wrap mode for textures that the hardware can't natively
handle repeating of.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Instead of using integers to represent spans we now use floats instead.
This means we are no longer forced to iterate using non-normalized
coordinates so we should hopefully be able to avoid numerous redundant
unnormalize/normalize steps when using the spans api.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Since we can assume that all slices are CoglTexture2D textures we don't
need to chain on our implementation of _foreach_sub_texture_in_region
by calling _cogl_texture_foreach_sub_texture_in_region() for each slice.
We now simply determine the normalized virtual coordinates for the
current span inline and call the given callback inline too.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Currently features are represented as bits in a 32bit mask so we
obviously can't have more than 32 features with that approach. The new
approach is to use the COGL_FLAGS_ macros which lets us handle bitmasks
without a size limit and we change the public api to accept individual
feature enums instead of a mask. This way there is no limit on the
number of features we can add to Cogl.
Instead of using cogl_features_available() there is a new
cogl_has_feature() function and for checking multiple features there is
cogl_has_features() which takes a zero terminated vararg list of
features.
In addition to being able to check for individual features this also
adds a way to query all the features currently available via
cogl_foreach_feature() which will call a callback for each feature.
Since the new functions take an explicit context pointer there is also
no longer any ambiguity over when users can first start to query
features.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Cogl provides a consistent public interface regardless of whether the
underlying GL driver supports VBOs so it doesn't make much sense to have
this feature as part of the public api. We can't break the api by
removing the enum but at least we no longer ever set the feature flag.
We now have a replacement private feature flag COGL_PRIVATE_FEATURE_VBOS
which cogl now checks for internally.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Cogl provides a consistent public interface regardless of whether the
underlying GL driver supports PBOs so it doesn't make much sense to have
this feature as part of the public api. We can't break the api by
removing the enum but at least we no longer ever set the feature flag.
We now have a replacement private feature flag COGL_PRIVATE_FEATURE_PBOS
which cogl now checks for internally.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Cogl doesn't currently expose public api for clip planes so it
doesn't make much sense to have this feature as part of the public api.
We can't break the api by removing the enum but at least we no longer
ever set the feature flag.
We now have a replacement private feature flag
COGL_PRIVATE_FEATURE_FOUR_CLIP_PLANES which cogl now checks for
internally.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Cogl doesn't expose public api for blitting between framebuffers so it
doesn't make much sense to have this feature as part of the public api
currently. We can't break the api by removing the enum but at least we
no longer ever set the feature flag.
We now have a replacement private feature flag
COGL_PRIVATE_FEATURE_OFFSCREEN_BLIT which cogl now checks for
internally.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Although we have to leave the COGL_FEATURE_STENCIL_BUFFER enum as part
of the public api we no longer ever set this feature flag.
Cogl doesn't currently expose the concept of a stencil buffer in the
public api (we only indirectly expose it via the clip stack api) so it
doesn't make much sense to have a stencil buffer feature flag.
We now have a COGL_PRIVATE_FEATURE_STENCIL_BUFFER flag instead which
we can check when we need to use the buffer for clipping.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Actual support for yuv textures isn't fully plumbed into Cogl currently
so the check for GL_MESA_ycbcr_texture is meaningless. For now we just
remove the check.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
make sure to #include "cogl-texture-private.h" in cogl-pipeline-layer.c
otherwise the build fails on win32.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
This fixes validate_first_layer_cb so that it update the override
pipeline not the user's original pipeline. It also makes the check
for when to override the wrap mode more robust by considering that
we might add more wrap modes in the future.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
To save users of the api having to manually check if each iterated span
intersects the region of interest we now guarantee that any span
iterated implicitly intersects the region of interest.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
This make the CoglTexture2DSliced type public and adds
cogl_texture_2d_sliced_new_with_size() as an experimental API that can
be used to construct a sliced texture without any initial data.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
This adds a new experimental function, cogl_clip_push_primitive, that
allows you to push a CoglPrimitive onto the clip stack. The primitive
should describe a flat 2D shape and the geometry shouldn't include any
self intersections. When pushing a primitive you also need to tell
Cogl what the bounding box of that shape is (in shape local coordinates)
so that Cogl is able to efficiently update the required region of the
stencil buffer.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
This adds an internal _cogl_primitive_draw API that takes CoglDrawFlags
like _cogl_draw_attributes does which allows us to draw a primitive but
skip things like flushing journals, flushing framebuffer state and avoid
validating the current pipeline. This allows us to draw primitives in
places that could otherwise cause recursion.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
The code that adds the silhouette of a path to the stencil buffer was
living in cogl2-path.c which seemed out of place when the bulk of the
work really related more to how the stencil buffer is managed and
basically only one line (a call to _cogl_path_fill_nodes) really related
to the path code directly.
This moves the code into cogl-clip-stack.c alone with similar code
that can add rectangle masks to the stencil buffer.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
If we are asked to fill a path using any sliced textures then we need
to fallback to adding a mask of the path to the stencil buffer
and then drawing a bounding rectangle with the source textures instead.
Previously we were sharing some of the clip-stack code for adding
the path mask to the stencil buffer and being careful to check
that the current clip stack has been flushed already. We then made
sure to dirty the clip stack to be sure the path mask would be cleared
from the stencil buffer later.
This patch aims to simplify how this fallback is dealt with by just
using the public clipping API instead of relying on more fiddly tricks
to modify the stencil buffer directly without conflicting with the clip
stack.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
This adds a new experimental function, cogl_framebuffer_finish(), which
can be used to explicitly synchronize the CPU with the GPU. It's rare
that this level of explicit synchronization is desirable but for example
it can be useful during performance analysys to make sure measurements
reflect the working time of the GPU not just the time to queue commands.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
This adds support for multisample rendering to offscreen framebuffers.
After an offscreen framebuffer is first instantiated using
cogl_offscreen_new_to_texture() it is then possible to use
cogl_framebuffer_set_samples_per_pixel() to request multisampling before
the framebuffer is allocated. This also adds
cogl_framebuffer_resolve_samples() for explicitly resolving point
samples into pixels. Even though we currently only support the
IMG_multisampled_render_to_texture extension which doesn't require an
explicit resolve, the plan is to also support the
EXT_framebuffer_multisample extension which uses the framebuffer_blit
extension to issue an explicit resolve.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
This adds support for multisample based rendering of onscreen windows
whereby multiple point samples per pixel can be requested and if the
hardware supports that it results in reduced aliasing (especially
considering the jagged edges of polygons)
Reviewed-by: Neil Roberts <neil@linux.intel.com>
When creating new onscreen framebuffers we need to take the
configuration in cogl terms and translate that into a configuration
applicable to any given winsys, e.g. an EGLConfig or a GLXFBConfig
or a PIXELFORMATDESCRIPTOR.
Also when we first create a context we typically have to do a very
similar thing because most OpenGL winsys APIs also associate a
framebuffer config with the context and all future configs need to be
compatible with that.
This patch introduces an internal CoglFramebufferConfig to wrap up some
of the configuration parameters that are common to CoglOnscreenTemplate
and to CoglFramebuffer so we aim to re-use code when dealing with the
above two problems.
This patch also aims to rework the winsys code so it can be more
naturally extended as we start adding more configureability to how
onscreen framebuffers are created.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
This adds cogl_framebuffer_discard_buffers API that allows applications
to explicitly discard depth and stencil buffers which really helps when
using a tile based GPU architexture by potentially avoiding the need to
save the results of depth and stencil buffer changes to system memory
between frames since these can usually be handled directly with on-chip
memory instead.
The semantics for cogl_framebuffer_swap_buffers and
cogl_framebuffer_swap_region are now documented to include an implicit
discard of all buffers, including the color buffer.
We now recommend that all rendering to a CoglOffscreen framebuffer
should be followed by a call like:
cogl_framebuffer_discard_buffers (fb,
COGL_BUFFER_BIT_DEPTH|
COGL_BUFFER_BIT_STENCIL);
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Both the GLSL and the ARBfp pipeline backends were using a variable
called last_used_for_pipeline to keep track of the last pipeline that
the shader or program state was used for. If this address is the same
as last time when the pipeline state is flushed then Cogl will only
flush the uniforms that have been modified, otherwise it will flush
all of them. The problem with this is that there was nothing to keep
that address alive so it could be destroyed and reused for a different
pipeline by the time the shader state is reused. This is quite likely
to happen in an application using legacy state because in that case
the shader state will always be used with a one-shot pipeline that
will likely be recycled in the next frame.
There is already a destroy callback to unref the shader state when the
pipeline is destroyed so this patch just makes that callback also
clear the last_used_for_pipeline pointer if it matches the pipeline
being destroyed.
https://bugzilla.gnome.org/show_bug.cgi?id=662542
Reviewed-by: Robert Bragg <robert@linux.intel.com>
This adds a description of the replacement Cogl names for the GLSL
builtins. It also updates some of the deprecation tags and corrects
some misinformation.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
Previously the EGL backend was directly prodding the width/height
members of the framebuffer structure when a configure notify event is
received. However this doesn't set the dirty flag for the viewport so
Cogl will continue using the wrong viewport y offset. The GLX backend
is already using an abstraction for updating the size which does set
the flag. This patch just makes the EGL backend also use that
abstraction.
When freeing a pipeline in _cogl_pipeline_free we weren't making sure to
free the layers_cache which was leading to a memory leak.
Thanks to Sunjin Yang for finding this.
https://bugzilla.gnome.org/show_bug.cgi?id=660986
Reviewed-by: Neil Roberts <neil@linux.intel.com>
If we failed to create a native texture from pixmap via EGL or GLX then
we shouldn't call the winsys's texture_pixmap_x11_damage_notify
function. By doing the validation in cogl-texture-pixmap-x11.c the
winsys code can continue to assume that it doesn't need to verify there
is a valid tex_pixmap->winsys pointer.
Thanks to Damien Leone <dleone@nvidia.com> for catching this issue.
https://bugzilla.gnome.org/show_bug.cgi?id=660184
The previous detection was based on color depth only to determine the
texture format to use in GLX. If that worked fine at depths 24 (RGB8)
and 32 (ARGB8), that would fail at depth 30 (BGR10) and fallback to
software instead of using the TFP extension.
This commit uses an efficient population count implementation to
compare the number of 1-bits in color masks against the color depth
requested by the X client. If they are not equal this means that an
alpha channel has been requested.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
G_DISABLE_DEPRECATED is only intended for developers of Cogl and it
sometimes breaks the build for people just trying to build a
release. This patch adds an option to enable deprecated Glib
features. By default it is enabled for non-git versions of Cogl.
The patch is based on similar code in Clutter except it adds the flags
to COGL_EXTRA_CFLAGS instead of having a separate variable.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
It seems that cogl-context-private.h needs to be included before including
any of the pipeline-related stuff to avoid build errors on C89 compilers.
This is due to the recent cogl-pipeline decoupling, seems like.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
During arbfp codegen we weren't checking for NULL textures and so we
would crash when trying to query a NULL texture's GL texture target.
Since NULL texture targets result in ctx->default_gl_texture_2d_tex
being bound we can assume that a NULL texture corresponds to a
GL_TEXTURE_2D target.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
This optimizes the layer and pipeline _compare_differences functions so
neither of them use the GArray api since building up the list of
ancestors by appending to a shared GArray was showing quite high on
profiles due to how frequently pipeline comparisons are made. Instead
we now build up a transient, singly linked list by allocating GList
nodes via alloca to build up the parallel lists of ancestors.
This tweaked approach actually ends up being a bit more concise than
before, we avoid the overhead of the GArray api and now avoid making any
function calls while comparing (assuming the _get_parent() calls always
inline), we avoiding needing to get the default cogl context.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
We only need a ctx pointer if we need to refer to the default_layer_x
layers to copy as templates so only call _cogl_context_get_default()
once we need to copy a template. _cogl_context_get_default() was
starting to show up in profiles and this was the main cause.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
This splits out the core CoglPipelineLayer support code from
cogl-pipeline.c into cogl-pipeline-layer.c; it splits out the debugging
code for dumping a pipeline to a .dot file into cogl-pipeline-debug.c
and it splits the CoglPipelineNode support which is shared between
CoglPipeline and CoglPipelineLayer into cogl-node.c.
Note: cogl-pipeline-layer.c only contains the layer code directly
relating to CoglPipelineLayer objects; it does not contain any
_cogl_pipeline API relating to how CoglPipeline tracks and manipulates
layers.
This avoids using sscanf to determine the texture_unit that a
tex_coord%d_in attribute name corresponds to since that was showing high
on profiles. Instead once we know we have a "tex_coord" name then we
can simply use strtoul which is much cheaper and use the returned endptr
we get to verify we have a "_in" suffix after the number.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
We've started seeing cases where we want to allocate lots of one-shot
primitives per-frame and the cost of allocating primitives becomes
important in this case since it can start being noticeable in profiles.
The main cost for allocating primitives was the GArray allocation
and appending the attributes to the array. This updates the code to
simply over allocate the primitive storage so we can embed the list
of attributes directly in that allocation.
If the user later sets new attributes and there isn't enough embedded
space then a separate slice allocation for the new attributes is made
but still this should be far less costly than using a GArray as before.
Most of the time we would expect when setting new attributes there will
still be the same number of attributes, so the embedded space can simple
be reused.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Calling g_strdup for attribute names was starting to show up in profiles
due to calling malloc for new string storage so frequently. This avoids
calling g_strdup and calls g_intern_string() instead. For the really
common case names we even avoid the cost of g_intern_string since we
can trivially relate our internal name_id to a static string.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
As part of the on going, incremental effort to purge the non type safe
CoglHandle type from the Cogl API this patch tackles most of the
CoglHandle uses relating to textures.
We'd postponed making this change for quite a while because we wanted to
have a clearer understanding of how we wanted to evolve the texture APIs
towards Cogl 2.0 before exposing type safety here which would be
difficult to change later since it would imply breaking APIs.
The basic idea that we are steering towards now is that CoglTexture
can be considered to be the most primitive interface we have for any
object representing a texture. The texture interface would provide
roughly these methods:
cogl_texture_get_width
cogl_texture_get_height
cogl_texture_can_repeat
cogl_texture_can_mipmap
cogl_texture_generate_mipmap;
cogl_texture_get_format
cogl_texture_set_region
cogl_texture_get_region
Besides the texture interface we will then start to expose types
corresponding to specific texture types: CoglTexture2D,
CoglTexture3D, CoglTexture2DSliced, CoglSubTexture, CoglAtlasTexture and
CoglTexturePixmapX11.
We will then also expose an interface for the high-level texture types
we have (such as CoglTexture2DSlice, CoglSubTexture and
CoglAtlasTexture) called CoglMetaTexture. CoglMetaTexture is an
additional interface that lets you iterate a virtual region of a meta
texture and get mappings of primitive textures to sub-regions of that
virtual region. Internally we already have this kind of abstraction for
dealing with sliced texture, sub-textures and atlas textures in a
consistent way, so this will just make that abstraction public. The aim
here is to clarify that there is a difference between primitive textures
(CoglTexture2D/3D) and some of the other high-level textures, and also
enable developers to implement primitives that can support meta textures
since they can only be used with the cogl_rectangle API currently.
The thing that's not so clean-cut with this are the texture constructors
we have currently; such as cogl_texture_new_from_file which no longer
make sense when CoglTexture is considered to be an interface. These
will basically just become convenient factory functions and it's just a
bit unusual that they are within the cogl_texture namespace. It's worth
noting here that all the texture type APIs will also have their own type
specific constructors so these functions will only be used for the
convenience of being able to create a texture without really wanting to
know the details of what type of texture you need. Longer term for 2.0
we may come up with replacement names for these factory functions or the
other thing we are considering is designing some asynchronous factory
functions instead since it's so often detrimental to application
performance to be blocked waiting for a texture to be uploaded to the
GPU.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
cogl_rectangle has some validation code to check whether the first
layer has a sliced texture. If so it will abandon the rest of the
layers and print a warning. However it was even doing this pruning and
displaying the warning if there is only one layer. This patch just
makes it check whether the pipeline actually has more than one layer
before pruning or displaying the warning but it will still fallback to
the multiple quads path.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
This adds an internal function to set the backface culling state on a
pipeline. This includes properties to set the culling mode (front,
back or both) and also to set which face is considered the front
(COGL_WINDING_CLOCKWISE or COGL_WINDING_COUNTER_CLOCKWISE). The actual
front face flushed to GL depends on whether we are rendering to an
offscreen buffer or not. This means that when changing between on- and
off- screen framebuffers it now checks whether the last flushed
pipeline has backface culling enabled and forces a reflush of the cull
face state if so.
The backface culling is now set on a pipeline as part of the legacy
state. This is important because some code in Cogl assumes it can
flush a temporary pipeline to revert to a known state, but previously
this wouldn't disable backface culling so things such as flushing the
clip stack could get confused.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
When changing between two framebuffers that have different color masks
it now forces the pipeline to flush the mask by setting
current_pipeline_changes_since_flush. For this to work there needs to
be a common bit of code that gets called when the framebuffers are
changed that has access to both the old framebuffer and the new
framebuffer. _cogl_set_framebuffers_real can't be used for this
because when it is called from cogl_pop_framebuffer the stack entries
have already changed so it can't know the old framebuffer. This patch
adds a new function called notify_buffers_changed which should get
called whenever the buffers are changed and it explicitly gets passed
pointers to the old and new buffers. cogl_pop_framebuffer now calls
this instead of trying to use _cogl_set_framebuffers_real to force a
flush.
This patch also fixes the ctx->window_buffer pointer. Previously this
was implemented by searching in the framebuffer stack for an onscreen
framebuffer whenever the current buffers are changed. However it does
this after the stack has already changed so it won't usually find the
right buffer.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
The ARBfp backend can't handle fog so it tries to check for when it's
enabled and bails out. However it was checking using the global legacy
state value on the CoglContext but this doesn't necessarily reflect
the state that will actually be used by the pipeline because Cogl may
have internally pushed a different pipeline.
This patch adds an internal _cogl_pipeline_get_fog_enabled which the
ARBfp backend now uses.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
Some code in Cogl such as when flushing a stencil clip assumes that it
can push a temporary simple pipeline to reset to a known state for
internal drawing operations. However this breaks down if the
application has set any legacy state because that is set globally so
it will also get applied to the internal pipeline.
_cogl_draw_attributes already had an internal flag to disable applying
the legacy state but I think this is quite awkward to use because not
all places that push a pipeline draw the attribute buffers directly so
it is difficult to pass the flag down through the layers.
Conceptually the legacy state is meant to be like a layer on top of
the purely pipeline-based state API so I think ideally we should have
an internal function to push the source without the applying the
legacy state. The legacy state can't be applied as the pipeline is
pushed because the global state can be modified even after it is
pushed. This patch adds a _cogl_push_source() function which takes an
extra boolean flag to mark whether to enable the legacy state. The
value of this flag is stored alongside the pipeline in the pipeline
stack. Another new internal function called
_cogl_get_enable_legacy_state queries whether the top entry in the
pipeline stack has legacy state enabled. cogl-primitives and the
vertex array drawing code now use this to determine whether to apply
the legacy state when drawing. The COGL_DRAW_SKIP_LEGACY_STATE flag is
now removed.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
Since 12b3d21aaa cogl is using the vertex attribute API to stroke a
path. However it was still manually appllying the legacy state to the
pipeline. cogl_vdraw_attributes also applies the legacy state so it
ends up getting applied twice. This patch just removes it from
_cogl_path_stroke_nodes.
Reviewed-by: Robert Bragg <robert@linux.intel.com>