Commit Graph

132 Commits

Author SHA1 Message Date
Neil Roberts
d18b59d9e6 Add a public cogl_bitmap_new_for_data
This creates a CoglBitmap which points into an existing buffer in
system memory. That way it can be used to create a texture or to read
pixel data into. The function replaces the existing internal function
_cogl_bitmap_new_from_data but removes the destroy notify call back.
If the application wants notification of destruction it can just use
the cogl_object_set_user_data function as normal. Internally there is
now a convenience function to create a bitmap for system memory and
automatically free the buffer using that mechanism.

The name of the function is inspired by
cairo_image_surface_create_for_data which has similar semantics.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-03-14 12:19:56 +00:00
Neil Roberts
b8df3561f4 Remove the point size cache on the context
I don't think there's really any point in this cache because the
pipeline code completely owns the point size state. Pipelines are
already compared for whether their point size state is different
before setting it so it shouldn't result in any extra calls to
glPointSize apart from maybe when the first pipeline is initially
flushed.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-03-07 15:13:29 +00:00
Robert Bragg
785e6375eb Adds a context arg to cogl_pipeline_new()
As we move towards Cogl 2.0 we are aiming to remove the need for a
default global CoglContext and so everything should be explicitly
related to a context somehow. CoglPipelines are top level objects and
so this patch adds a context argument to cogl_pipeline_new().

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-02-21 12:38:24 +00:00
Robert Bragg
47868e1f3e texture-3d: remove _EXP defines + CoglHandle and pass context
We are in the process of removing all _EXP suffix mangling for
experimental APIs (Ref: c6528c4b6c) and adding missing gtk-doc
comments so that we can instead rely on the "Stability: unstable"
markers in the gtk-doc comments. This patch tackles the cogl-texture-3d
api symbols.

This patch also replaces use of CoglHandle with a CoglTexture3D type
instead.

Finally this patch also ensures the CoglTexture3D constructors take an
explicit CoglContext pointer but not a CoglTextureFlags argument,
consistent with other CoglTexture constructors.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-02-21 12:37:44 +00:00
Robert Bragg
680f63a48c Remove all internal includes of cogl.h
The cogl.h header is meant to be the public header for including the 1.x
api used by Clutter so we should stop using that as a convenient way to
include all likely prototypes and typedefs. Actually we already do a
good job of listing the specific headers we depend on in each of the .c
files we have so mostly this patch just strip out the redundant
includes for cogl.h with a few fixups where that broke the build.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-02-20 23:12:45 +00:00
Robert Bragg
ee940a3d0d Move all types/prototypes from cogl.h -> cogl[1]-context.h
So we can get to the point where cogl.h is merely an aggregation of
header includes for the 1.x api this moves all the function prototypes
and type definitions into a cogl-context.h and a new cogl1-context.h.

Ideally no code internally should ever need to include cogl.h as it just
represents the public facing header for accessing the 1.x api which
should only be used by Clutter.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-02-20 23:12:44 +00:00
Neil Roberts
b96e6900f5 cogl-pipeline-layer: Use CoglTextureType instead of GL target enum
Instead of storing the GLenum for the target of the last used texture
for a layer it now stores the CoglTextureType instead. The state name
has been renamed to 'texture type' instead of 'texture target'.
Previously the default pipeline layer would store 0 here to represent
that there is no texture. This has been changed to store
COGL_TEXTURE_TYPE_2D instead which means that all pipeline layers
always have a valid value for the texture type. Any places that were
previously fetching the texture from a layer to determine the target
(for example when generating shaders or when enabling a particular
texture target) now use the texture type instead. This means they will
work even for layers that don't have a texture.

This also changes it so that when binding a fallback texture instead
of always using a 2D texture it will now use the default texture
corresponding to the texture type of the layer. That way when the
generated shader tries to do a texture lookup for that type of texture
it will get a valid texture object. To make this work the patch adds a
default texture for 3D textures to the context and also makes the
default rectangle texture actually be a rectangle texture instead of
using a 2D texture.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-02-13 17:09:34 +00:00
Neil Roberts
f005f517fe Flush matrices in the progend and flip with a vector
Previously flushing the matrices was performed as part of the
framebuffer state. When on GLES2 this matrix flushing is actually
diverted so that it only keeps a reference to the intended matrix
stack. This is necessary because on GLES2 there are no builtin
uniforms so it can't actually flush the matrices until the program for
the pipeline is generated. When the matrices are flushed it would
store the age of modifications on the matrix stack so that it could
detect when the matrix hasn't changed and avoid flushing it.

This patch changes it so that the pipeline is responsible for flushing
the matrices even when we are using the GL builtins. The same
mechanism for detecting unmodified matrix stacks is used in all
cases. There is a new CoglMatrixStackCache type which is used to store
a reference to the intended matrix stack along with its last flushed
age. There are now two of these attached to the CoglContext to track
the flushed state for the global matrix builtins and also two for each
glsl progend program state to track the flushed state for a
program. The framebuffer matrix flush now just updates the intended
matrix stacks without actually trying to flush.

When a vertex snippet is attached to the pipeline, the GLSL vertend
will now avoid using the projection matrix to flip the rendering. This
is necessary because any vertex snippet may cause the projection
matrix not to be used. Instead the flip is done as a forced final step
by multiplying cogl_position_out by a vec4 uniform. This uniform is
updated as part of the progend pre_paint depending on whether the
framebuffer is offscreen or not.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-06 19:02:06 +00:00
Robert Bragg
7283e0a49c rework enabling of attributes, removing _cogl_enable()
This removes the limited caching of enabled attributes done by
_cogl_enable() and replaces it with a more generalized set of bitmasks
associated with the context that allow us to efficiently compare the set
of attribute locations that are currently enabled vs the new locations
that need enabling so we only have to inform OpenGL of the changes in
which locations are enabled/disabled.

This also adds a per-context hash table for mapping attribute names to
global name-state structs which includes a unique name-index for any
name as well as pre-validated information about builtin "cogl_"
attribute names including whether the attribute is normalized and what
texture unit a texture attribute corresponds too.

The name-state hash table means that cogl_attribute_new() now only needs
to validate names the first time they are seen.

CoglAttributes now reference a name-state structure instead of just the
attribute name, so now we can efficiently get the name-index for any
attribute and we can use that to index into a per-glsl-program cache
that maps name indices to real GL attribute locations so when we get
asked to draw a set of attributes we can very quickly determine what GL
attributes need to be setup and enabled. If we don't have a cached
location though we can still quickly access the string name so we can
query OpenGL.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-06 18:51:57 +00:00
Robert Bragg
042dc7c8cd framebuffer: Optimize _cogl_framebuffer_flush_state()
Previously the cost of _cogl_framebuffer_state_flush() would always
scale by the total amount of state tracked by CoglFramebuffer even in
cases where we knew up-front that we only wanted to flush a subset of
the state or in cases where we requested to flush the same framebuffer
multiple times with no changes being made to the framebuffer.

We now track a set of state changed flags with each framebuffer and
track the current read/draw buffers as part of the CoglContext so that
we can quickly bail out when asked to flush the same framebuffer
multiple times with no changes.

_cogl_framebuffer_flush_state() now takes a mask of the state that we
want to flush and the implementation has been redesigned so that the
cost of checking what needs to be flushed and flushing those changes
now scales by how much state we actually plan to update.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-06 18:51:57 +00:00
Neil Roberts
c269817edd cogl-pipeline: Use a hash table for faster uniform name lookup
The uniform names are now stored in a GPtrArray instead of a linked
list. There is also a hash table to speed up converting names to
locations.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-16 16:32:11 +00:00
Neil Roberts
4553ca0695 cogl-pipeline: Add support for setting uniform values
This adds the following new public experimental functions to set
uniform values on a CoglPipeline:

void
cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline,
                              int uniform_location,
                              float value);
void
cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline,
                              int uniform_location,
                              int value);
void
cogl_pipeline_set_uniform_float (CoglPipeline *pipeline,
                                 int uniform_location,
                                 int n_components,
                                 int count,
                                 const float *value);
void
cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
                               int uniform_location,
                               int n_components,
                               int count,
                               const int *value);
void
cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline,
                                  int uniform_location,
                                  int dimensions,
                                  int count,
                                  gboolean transpose,
                                  const float *value);

These are similar to the old functions used to set uniforms on a
CoglProgram. To get a value to pass in as the uniform_location there
is also:

int
cogl_pipeline_get_uniform_location (CoglPipeline *pipeline,
                                    const char *uniform_name);

Conceptually the uniform locations are tied to the pipeline so that
whenever setting a value for a new pipeline the application is
expected to call this function. However in practice the uniform
locations are global to the CoglContext. The names are stored in a
linked list where the position in the list is the uniform location.

The global indices are used so that each pipeline can store a mask of
which uniforms it overrides. That way it is quicker to detect which
uniforms are different from the last pipeline that used the same
CoglProgramState so it can avoid flushing uniforms that haven't
changed. Currently the values are not actually compared which means
that it will only avoid flushing a uniform if there is a common
ancestor that sets the value (or if the same pipeline is being flushed
again - in which case the pipeline and its common ancestor are the
same thing).

The uniform values are stored in the big state of the pipeline as a
sparse linked list. A bitmask stores which values have been overridden
and only overridden values are stored in the linked list.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-16 16:32:11 +00:00
Neil Roberts
39ca3e51df Don't take a reference to the last used onscreen framebuffer
Cogl keeps a pointer to the last used onscreen framebuffer from the
context to implement the deprecated cogl_set_draw_buffer function
which can take COGL_WINDOW_BUFFER as the target to use the last
onscreen buffer. Previously this would also take a reference to that
pointer. However that was causing a circular reference between the
framebuffer and the context which makes it impossible to clean up
resources properly when onscreen buffers are used. This patch instead
changes it to just store the pointer and then clear the pointer during
_cogl_onscreen_free as a kind of cheap weak reference.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-14 18:40:28 +00:00
Neil Roberts
1566941c2f cogl-context: Destroy texture units later on
This patch moves the call to _cogl_destroy_texture_units() from
_cogl_context_free() to later on. When destroying a GL texture the
texture units are checked. This would end up accessing invalid memory
so we need to try to destroy the texture units only after everything
that might be referencing a texture has been destroyed.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-04 13:03:01 +00:00
Robert Bragg
b72f255c0a Start to reduce dependence on glib
Since we've had several developers from admirable projects say they
would like to use Cogl but would really prefer not to pull in
gobject,gmodule and glib as extra dependencies we are investigating if
we can get to the point where glib is only an optional dependency.
Actually we feel like we only make minimal use of glib anyway, so it may
well be quite straightforward to achieve this.

This adds a --disable-glib configure option that can be used to disable
features that depend on glib.

Actually --disable-glib doesn't strictly disable glib at this point
because it's more helpful if cogl continues to build as we make
incremental progress towards this.

The first use of glib that this patch tackles is the use of
g_return_val_if_fail and g_return_if_fail which have been replaced with
equivalent _COGL_RETURN_VAL_IF_FAIL and _COGL_RETURN_IF_FAIL macros.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:02 +00:00
Robert Bragg
79719347c8 framebuffer: split out CoglOnscreen code
This factors out the CoglOnscreen code from cogl-framebuffer.c so we now
have cogl-onscreen.c, cogl-onscreen.h and cogl-onscreen-private.h.
Notably some of the functions pulled out are currently namespaced as
cogl_framebuffer but we know we are planning on renaming them to be in
the cogl_onscreen namespace; such as cogl_framebuffer_swap_buffers().

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:02 +00:00
Robert Bragg
426c8b8f41 features: Support more than 32 features!
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>
2011-11-01 12:03:01 +00:00
Robert Bragg
c86f698eb9 make COGL_FEATURE_VBOS a private feature
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>
2011-11-01 12:03:01 +00:00
Robert Bragg
69b44ac86d make COGL_FEATURE_PBOS a private feature
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>
2011-11-01 12:03:01 +00:00
Robert Bragg
30f8521790 pipeline: optimize _compare_differences functions
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>
2011-09-21 17:28:32 +01:00
Robert Bragg
4c3dadd35e Add a strong CoglTexture type to replace CoglHandle
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>
2011-09-21 15:27:03 +01:00
Neil Roberts
dbff3a357e Make backface culling be part of the legacy state
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>
2011-09-19 16:40:07 +01:00
Neil Roberts
879ce7301a cogl-framebuffer: Force flushing the color mask when changing fbs
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>
2011-09-19 16:40:07 +01:00
Damien Lespiau
6584c183f0 context: Add an accessor to get display associated with the context
https://bugzilla.gnome.org/show_bug.cgi?id=657347

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-09-05 17:54:46 +01:00
Damien Lespiau
4e1d08d59e pipeline: Remove unsused get_max_texture_image_units()
This function was not used in the opengl pipeline, probably because of
the more precise get_max_activable_texture_units().

Remove it then.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-09-05 17:54:46 +01:00
Kirk A. Baker
76c88958b7 Fixed uninitialized data (current_clip_stack_valid) in context creation
Reviewed-By: Robert Bragg <robert@linux.intel.com>
2011-07-27 15:55:27 +01:00
Robert Bragg
8b34a39319 Adds ColorMask support to Cogl
This adds CoglPipeline and CoglFramebuffer support for setting a color
mask which is a bit mask defining which color channels should be written
to the current framebuffer.

The final color mask is the intersection of the framebuffer color mask
and the pipeline color mask. The framebuffer mask affects all rendering
to the framebuffer while the pipeline masks can be used to affect
individual primitives.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-19 19:27:09 +01:00
Neil Roberts
231be91fb0 Combine _cogl_context_check_gl_version and update_features into one
The _cogl_context_check_gl_version function is meant to be called once
Cogl has a GL context so that it can check whether the context found
is supported by Cogl. However, only the stub winsys was calling this
and it was doing it before Cogl had a chance to retrieve the function
pointer for glString so it would just crash. This patch combines the
two functions into one so that _cogl_context_update_features returns a
gboolean and a GError. Then it can just check the context itself.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-07-18 15:41:35 +01:00
Robert Bragg
3ed8c8d0ba framebuffer: Add dither_enabled getter/setters
This adds a getter and setter for requesting dithering to be enabled.

Dithering is a hardware dependent technique to increase the visible
color resolution beyond what the underlying hardware supports by playing
tricks with the colors placed into the framebuffer to give the illusion
of other colors. (For example this can be compared to half-toning used
by some news papers to show varying levels of grey even though their may
only be black and white are available).

The results of enabling dithering are platform dependent and may have no
effect.

Signed-off-by: Neil Roberts <neil@linux.intel.com>
2011-07-13 19:06:19 +01:00
Neil Roberts
461bff1867 fragend-arbfp: Move the pipeline cache to a separate file
The pipeline cache is now handled in CoglPipelineCache instead of
directly in the ARBfp fragend. The flags needed to hash a pipeline
should be exactly the same for the ARBfp and GLSL fragends so it's
convenient to share the code. The hash table now stores the actual
pipeline as the value instead of the private data so that the two
fragends can attach their data to it. That way it's possible to use
the same pipeline key with ancestors that are using different
fragends.

The hash table is created with g_hash_table_new_full to set a
destructor for the key and value and there is a destructor for
CoglPipelineCache that gets called when the CoglContext is
destroyed. That way we no longer leak the pipelines and shader state
when the context is desroyed.
2011-07-13 12:30:07 +01:00
Robert Bragg
c3b91da414 fix namespace for cogl_context_egl_get_egl_context
This renames cogl_context_egl_get_egl_context to
cogl_egl_context_get_egl_context to be consistent with other platform
specific APIs.

Signed-off-by: Neil Roberts <neil@linux.intel.com>
2011-07-11 14:07:02 +01:00
Robert Bragg
09e7174b1d Remove cogl_context_set_default API
For cogl 2.0 we don't want to have a default context. In the meantime
we can simply assume that calling cogl_context_new() implicitly
sets that context as the default context before returning.

Signed-off-by: Neil Roberts <neil@linux.intel.com>
2011-07-11 14:07:02 +01:00
Neil Roberts
b2e735ff7f Dynamically load the GL or GLES library
The GL or GLES library is now dynamically loaded by the CoglRenderer
so that it can choose between GL, GLES1 and GLES2 at runtime. The
library is loaded by the renderer because it needs to be done before
calling eglInitialize. There is a new environment variable called
COGL_DRIVER to choose between gl, gles1 or gles2.

The #ifdefs for HAVE_COGL_GL, HAVE_COGL_GLES and HAVE_COGL_GLES2 have
been changed so that they don't assume the ifdefs are mutually
exclusive. They haven't been removed entirely so that it's possible to
compile the GLES backends without the the enums from the GL headers.

When using GLX the winsys additionally dynamically loads libGL because
that also contains the GLX API. It can't be linked in directly because
that would probably conflict with the GLES API if the EGL is
selected. When compiling with EGL support the library links directly
to libEGL because it doesn't contain any GL API so it shouldn't have
any conflicts.

When building for WGL or OSX Cogl still directly links against the GL
API so there is a #define in config.h so that Cogl won't try to dlopen
the library.

Cogl-pango previously had a #ifdef to detect when the GL backend is
used so that it can sneakily pass GL_QUADS to
cogl_vertex_buffer_draw. This is now changed so that it queries the
CoglContext for the backend. However to get this to work Cogl now
needs to export the _cogl_context_get_default symbol and cogl-pango
needs some extra -I flags to so that it can include
cogl-context-private.h
2011-07-11 12:57:38 +01:00
Neil Roberts
5f181973a6 Move the cogl texture driver functions to a vtable
The texture driver functions are now accessed through a vtable pointed
to by a struct in the CoglContext so that eventually it will be
possible to compile both the GL and GLES texture drivers into a single
binary and then select between them at runtime.
2011-07-08 15:35:51 +01:00
Neil Roberts
2b119b07da Use all core GL functions through indirect pointers
cogl-ext-functions.h now contains definitions for all of the core GL
and GLES functions that we would normally link to directly. All of the
code has changed to access them through the cogl context pointer. The
GE macro now takes an extra parameter to specify the context because
the macro itself needs to make GL calls but various points in the Cogl
source use different names for the context variable.
2011-07-08 15:35:46 +01:00
Neil Roberts
dae02a99a5 Move all of the GL function pointers directly to CoglContext
Instead of storing all of the feature function pointers in the driver
specific data of the CoglContext they are now all stored directly in
CoglContext. There is a single header containing the description of
the functions which gets included by cogl-context.h. There is a single
function in cogl-feature-private.c to check for all of these
functions.

The name of the function pointer variables have been changed from
ctx->drv.pf_glWhatever to just ctx->glWhatever.

The feature flags that get set when an extension is available are now
separated from the table of extensions. This is necessary because
different extensions can mean different things on GLES and GL. For
example, having access to glMapBuffer implies read and write support
on GL but only write support on GLES. The flags are instead set in the
driver specific init function by checking whether the function
pointers were successfully resolved.

_cogl_feature_check has been changed to assume the feature is
supported if any of the listed extensions are available instead of
requiring all of them. This makes it more convenient to specify
alternate names for the extension. Nothing else had previously listed
more than one name for an extension so this shouldn't cause any
problems.
2011-07-07 02:05:42 +01:00
Robert Bragg
a1234ee8d1 Add internal _cogl_init() function
This adds a _cogl_init function for Cogl that we expect to be the first
thing called before anything else is done with Cogl. It's not a public
API so it's expected that all entry points for Cogl that might be the
first function used should call _cogl_init().

We currently call _cogl_init() in these functions:
  cogl_renderer_new
  cogl_display_new
  cogl_context_new
  cogl_android_set_native_window

_cogl_init() can be called multiple times, and only the first call has
any affect.

For example _cogl_init() gives us a place check and parse the COGL_DEBUG
environment variable.

Since we don't have any need to parse command line arguments (we can
always get user configuration options from the environment) our init
function doesn't require argc/argv pointers.

By saying up front that we aren't interested in command line arguments
that means we can avoid the mess that is GOption based library
initialization which is extremely fragile due to its lack of dependency
tracking between modules.

Signed-off-by: Neil Roberts <neil@linux.intel.com>
2011-06-30 14:33:11 +01:00
Robert Bragg
57d76e315f Fixes for make distcheck 2011-06-14 17:09:55 +01:00
Robert Bragg
800f5e6d6e profile: Adds a --enable-profile option
This adds a --enable-profile option which enables uprof based profiling.
It was also necessary to fixup a CLUTTER_ENABLE_PROFILING #ifdef in
cogl-context.c to renamed COGL_ENABLE_PROFILING instead. By default Cogl
doesn't output uprof reports directly, instead it assumes a higher level
toolkit will output a report. If you want a report from Cogl you can
export COGL_PROFILE_OUTPUT_REPORT=1 before running your app.

The latest version of uprof can be fetched from:
git://github.com/rib/UProf.git
2011-06-14 17:09:55 +01:00
Robert Bragg
60b25615fd Add _cogl_egl_texture_2d_new_from_image API
This adds an internal texture_2d constructor that can wrap an EGLImage
as a CoglTexture2D. The plan is to utilize this for texture-from-pixmap
support with EGL as well as creating textures from wayland buffers.
2011-06-01 20:44:42 +01:00
Robert Bragg
b380fed23d Make stub winsys into a proper winsys backend
Instead of the stub winsys being a special case set of #ifdef'd code
used when COGL_HAS_FULL_WINSYS wasn't defined, the stub winsys now
implements a CoglWinsysVtable like all other winsys backends (it's just
that everything is a NOP). This way we can get rid of the
COGL_HAS_FULL_WINSYS define and also the stub winsys can be runtime
selected whereas before it was incompatible with all other winsys
backends.
2011-06-01 20:44:41 +01:00
Neil Roberts
14d1303259 cogl-winsys: Explicitly comment which vfuncs are optional
Some of the virtual functions in CoglWinsysVtable only need to be
implemented for specific backends or when a specific feature is
advertised. This splits the vtable struct into two commented sections
marking which are optional and which are required. Wherever an
optional function is used there is now a g_return_if_fail to ensure
there is an implementation.
2011-05-10 17:15:22 +01:00
Neil Roberts
239614a375 cogl-atlas-texture: Add a callback for when any atlas reorganizes
This adds cogl_atlas_texture_* functions to register a callback that
will get invoked whenever any of the CoglAtlas's the textures use get
reorganized. The callback is global and is not tied to any particular
atlas texture.
2011-05-05 17:32:28 +01:00
Robert Bragg
dc7383b714 Add a vtable of indirection to the winsys code
So that we can dynamically select what winsys backend to use at runtime
we need to have some indirection to how code accesses the winsys instead
of simply calling _cogl_winsys* functions that would collide if we
wanted to compile more than one backend into Cogl.
2011-05-05 14:46:01 +01:00
Robert Bragg
d5d11f1878 Moves all EGL code down from Clutter to Cogl
As was recently done for the GLX window system code, this commit moves
the EGL window system code down from the Clutter backend code into a
Cogl winsys.

Note: currently the cogl/configure.ac is hard coded to only build the GLX
winsys so currently this is only available when building Cogl as part
of Clutter.
2011-05-05 14:46:01 +01:00
Neil Roberts
d832172988 cogl-context: Initialize context->stub_winsys
If Cogl is built using a full Winsys then it wasn't initialising
context->stub_winsys which sometimes made it crash later on.
2011-04-21 16:45:21 +01:00
Neil Roberts
4a7762d6d7 cogl-context: Store winsys features in an array of unsigned ints
Previously the mask of available winsys features was stored in a
CoglBitmask. That isn't the ideal type to use for this because it is
intended for a growable array of bits so it can allocate extra memory
if there are more than 31 flags set. For the winsys feature flags the
highest used bit is known at compile time so it makes sense to
allocate a fixed array instead. This is conceptually similar to the
CoglDebugFlags which are stored in an array of integers with macros to
test a bit in the array. This moves the macros used for CoglDebugFlags
to cogl-flags.h and makes them more generic so they can be shared with
CoglContext.
2011-04-20 18:20:10 +01:00
Robert Bragg
d40cdfa3e1 Moves all GLX code down from Clutter to Cogl
This migrates all the GLX window system code down from the Clutter
backend code into a Cogl winsys. Moving OpenGL window system binding
code down from Clutter into Cogl is the biggest blocker to having Cogl
become a standalone 3D graphics library, so this is an important step in
that direction.
2011-04-11 17:54:36 +01:00
Robert Bragg
bcd97f35ea Adds renderer,display,onscreen-template and swap-chain stubs
As part of the process of splitting Cogl out as a standalone graphics
API we need to introduce some API concepts that will allow us to
initialize a new CoglContext when Clutter isn't there to handle that for
us...

The new objects roughly in the order that they are (optionally) involved
in constructing a context are: CoglRenderer, CoglOnscreenTemplate,
CoglSwapChain and CoglDisplay.

Conceptually a CoglRenderer represents a means for rendering.  Cogl
supports rendering via OpenGL or OpenGL ES 1/2.0 and those APIs are
accessed through a number of different windowing APIs such as GLX, EGL,
SDL or WGL and more. Potentially in the future Cogl could render using
D3D or even by using libdrm and directly banging the hardware. All these
choices are wrapped up in the configuration of a CoglRenderer.

Conceptually a CoglDisplay represents a display pipeline for a renderer.
Although Cogl doesn't aim to provide a detailed abstraction of display
hardware, on some platforms we can give control over multiple display
planes (On TV platforms for instance video content may be on one plane
and 3D would be on another so a CoglDisplay lets you select the plane
up-front.)

Another aspect of CoglDisplay is that it lets us negotiate a display
pipeline that best supports the type of CoglOnscreen framebuffers we are
planning to create. For instance if you want transparent CoglOnscreen
framebuffers then we have to be sure the display pipeline wont discard
the alpha component of your framebuffers. Or if you want to use
double/tripple buffering that requires support from the display
pipeline.

CoglOnscreenTemplate and CoglSwapChain are how we describe our default
CoglOnscreen framebuffer configuration which can affect the
configuration of the display pipeline.

The default/simple way we expect most CoglContexts to be constructed
will be via something like:

 if (!cogl_context_new (NULL, &error))
   g_error ("Failed to construct a CoglContext: %s", error->message);

Where that NULL is for an optional "display" parameter and NULL says to
Cogl "please just try to do something sensible".

If you want some more control though you can manually construct a
CoglDisplay something like:

 display = cogl_display_new (NULL, NULL);
 cogl_gdl_display_set_plane (display, plane);
 if (!cogl_display_setup (display, &error))
   g_error ("Failed to setup a CoglDisplay: %s", error->message);

And in a similar fashion to cogl_context_new() you can optionally pass
a NULL "renderer" and/or a NULL "onscreen template" so Cogl will try to
just do something sensible.

If you need to change the CoglOnscreen defaults you can provide a
template something like:
  chain = cogl_swap_chain_new ();
  cogl_swap_chain_set_has_alpha (chain, TRUE);
  cogl_swap_chain_set_length (chain, 3);

  onscreen_template = cogl_onscreen_template_new (chain);
  cogl_onscreen_template_set_pixel_format (onscreen_template,
                                           COGL_PIXEL_FORMAT_RGB565);

  display = cogl_display_new (NULL, onscreen_template);
  if (!cogl_display_setup (display, &error))
    g_error ("Failed to setup a CoglDisplay: %s", error->message);
2011-04-11 17:54:35 +01:00
Robert Bragg
c415818537 cogl: consolidate _create_context_driver + _features_init
This moves the functionality of _cogl_create_context_driver from
driver/{gl,gles}/cogl-context-driver-{gl,gles}.c into
driver/{gl,gles}/cogl-{gl,gles}.c as a static function called
initialize_context_driver.

cogl-context-driver-{gl,gles}.[ch] have now been removed.
2011-04-11 15:26:25 +01:00