Commit Graph

1295 Commits

Author SHA1 Message Date
Robert Bragg
39a7bcff67 matrix-stack: Avoid referencing the default CoglContext
This removes the use of _COGL_GET_CONTEXT() from cogl-matrix-stack.c
as part of the ongoing effort to evolve cogl to get rid of the need for
a default context.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-06 18:51:56 +00:00
Robert Bragg
5156365eae path: use cogl_framebuffer_push_path_clip in cogl2-path.c
_cogl_path_fill_nodes_with_clipped_rectangle() sometimes falls back to
pushing a framebuffer clip region and filling the region using
cogl_rectangle(). Since we aim to eventually deprecate
cogl_clip_push_from_path() as it relies on the default CoglContext we
would rather this internal code update a framebuffer's clip-state using
the cogl_framebuffer clip stack api instead.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-06 18:51:56 +00:00
Robert Bragg
36575502e8 docs: make cogl2-clip-state.h docs consistent
This updates some of the cogl2-clip-state.h cogl_clip_ API documentation
to make it consistent with the documentation for corresponding
framebuffer clip stack API in cogl-framebuffer.h

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-06 18:51:56 +00:00
Robert Bragg
de04a58f30 docs: make cogl.h clip stack docs consistent
This updates some of the cogl.h cogl_clip_ API documentation to make it
consistent with the documentation for corresponding framebuffer clip
stack API in cogl-framebuffer.h

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-06 18:51:56 +00:00
Robert Bragg
6bb409e996 framebuffer: Add CoglFramebuffer clip stack methods
This adds CoglFramebuffer methods for accessing the clip stack. We plan
on making some optimizations to how framebuffer state is flushed which
will require us to track when a framebuffer's clip state has changed.

This api also ties in to the longer term goal of removing the need for a
default global CoglContext since these methods are all implicitly
related to a specific context via their framebuffer argument.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-06 18:51:56 +00:00
Robert Bragg
652c8c31cf avoid touching fb matrix stack directly
This ensures we don't touch a framebuffer's matrix stack directly if we
are also relying on _cogl_framebuffer_flush_state(). We want to get to
the point where we can set dirty flags against framebuffer state at the
point it changes but that means we can't allow direct access to the
matrix stack. _cogl_texture_draw_and_read() has now been changed so it
uses cogl_framebuffer_ methods to update the matrix stacks including
adding new internal _cogl_framebuffer_push/pop_projection() functions
that allow us to set transient projections.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-06 18:51:56 +00:00
Robert Bragg
5ca78668af Adds cogl_framebuffer_identity_matrix
This adds a cogl_framebuffer_identity_matrix() method that can be used
to reset the current modelview matrix to the identity matrix.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-06 18:51:56 +00:00
Robert Bragg
a81458f5b9 docs: make cogl.h matrix stack documentation consistent
This updates the cogl.h matrix stack documentation consistent with the
corresponding documentation in cogl-framebuffer.h for the framebuffer
matrix stack methods.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-06 18:51:56 +00:00
Robert Bragg
ccde191191 framebuffer: Add CoglFramebuffer matrix stack methods
This adds cogl_framebuffer_ methods to update the modelview and
projection matrix stacks to replace functions like cogl_translate(),
cogl_rotate() and cogl_scale() etc.

This is part of the on-going effort to get rid of the global CoglContext
pointer since the existing methods don't take an explicit pointer to a
CoglContext. All the methods are now related to a context via the
framebuffer.

We added framebuffer methods instead of direct context methods because
the matrix stacks are per-framebuffer and as well as removing the global
CoglContext we would rather aim for a more direct state access API
design than, say, cairo or OpenGL, so we'd like to avoid needing the
cogl_push/pop_framebuffer(). We anticipate that Cogl will mostly be
consumed by middleware graphics layers such as toolkits or game engines
and feel that a more stateless model will avoid impedance mismatches if
higher levels want to expose a stateless model to their developers and
statefullness can still be added by higher levels if really desired.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-06 18:51:56 +00:00
Robert Bragg
595311ba55 cogl-matrix-stack: Adds _cogl_matrix_stack_equal
Adds a function for comparing the top matrix entries of two matrix
stacks.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-06 18:51:56 +00:00
Robert Bragg
a4f3d0d18b matrix: Add cogl_matrix_orthographic
This adds an experimental cogl_matrix_orthographic() function that is
more consistent with other Cogl api by taking x_1, y_1, x_2, y_2
arguments to define the top-left and bottom-right coordinates of the
orthographic coordinates instead of OpenGL style left, right, bottom and
top values.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-06 18:51:56 +00:00
Robert Bragg
ba02f70961 texture: assert set_region size <= src size
This improves the documentation for cogl_texture_set_region() and
cogl_texture_set_region_from_bitmap() to explain that the region can't
be larger than the source data and also adds runtime assertions that
such a request isn't made.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-06 18:51:56 +00:00
Robert Bragg
aa59dc5e8d docs: Fix a s/called/culled/ typo
The documentation for CoglPipelineCullFaceMode had a repeated typo with
"called" being used instead of "culled" which this fixes.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-06 18:51:56 +00:00
Tomeu Vizoso
1de6575ca2 build: Add missing include in cogl-winsys-egl-private.h
We were missing APIENTRY.
2011-12-06 19:49:00 +01:00
Rob Bradford
7f2a896351 kms: Avoid using struct member before it is set
When saving the CRTC we were trying to use a struct member for the encoder
that wasn't valid at that point in time - instead use the local variable.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-30 15:37:09 +00:00
Neil Roberts
da154b9a3b pipeline: Add a missing break for the uniforms state
_cogl_pipeline_init_multi_property_sparse_state was missing a break in
the case statement handling uniforms. This doesn't yet matter because
it is the last one handled anyway but it will bite someone later.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-29 13:03:25 +00:00
Robert Bragg
be40cbb8c3 build: include missing headers in cogl-winsys-egl-private.h
We were missing various platform header includes in
cogl-winsys-egl-private.h when building support for non KMS egl
platforms.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-28 23:19:45 +00:00
Robert Bragg
c2729e4ea8 build: don't inc egl headers for non EGL builds
For example when building on windows we don't want to require EGL
headers when compiling cogl-renderer.c or cogl-texture-2d.c so we make
sure not to include cogl-winsys-egl-private.h if we aren't supporting
EGL.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-28 23:19:35 +00:00
Robert Bragg
40b14c6084 kms: avoid using redundant g* and GL* types
A small, pedantic change to remove the use of redundant gint and GLuint
types instead of int and unsigned int.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-28 22:43:15 +00:00
Robert Bragg
056daad850 build: only include cogl-winsys-kms.h if KMS enabled
Only include cogl-winsys-kms.h in cogl-winsys-egl-private.h if KMS
support has been enabled.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-28 22:39:19 +00:00
Robert Bragg
aa6433d8c5 kms: Check for EGL_KHR_surfaceless_opengl extension
This adds a check for the EGL_KHR_surfaceless_opengl extension which we
depend on for being able to MakeCurrent (NO_SURFACE) as well as create a
context without and EGLConfig.

Reviewed-by: Rob Bradford <rob@linux.intel.com>
2011-11-28 17:38:17 +00:00
Robert Bragg
7a91c91994 kms: flatten setup_kms into _cogl_winsys_kms_display_setup
Since _cogl_winsys_kms_display_setup was basically just calling
setup_kms() it made sense to fold the code of setup_kms() back into the
_cogl_winsys_kms_display_setup() function.

Reviewed-by: Rob Bradford <rob@linux.intel.com>
2011-11-28 17:38:15 +00:00
Robert Bragg
607bfec48d kms: move Cogl*EGL typedefs to cogl-winsys-egl-private.h
So that the various internal Cogl*EGL typedefs can be available to
cogl-winsys-kms.c this moves them into cogl-winsys-egl-private.h

Reviewed-by: Rob Bradford <rob@linux.intel.com>
2011-11-28 17:37:31 +00:00
Rob Bradford
1b54c8023e kms: Add first version of "baremetal" backend for EGL on KMS
To start with this backend only supports creating a single CoglOnscreen
framebuffer and will automatically set is up to display fullscreen on
the first suitable crtc it can find.

To compile this backend - get some dribbly black candles, sacrifice a
goat and configure with: --enable-kms-egl-platform

Note: There is currently a problem with using GLES2 with this winsys
so you need to run with EGL_DRIVER=gl
Note: If you have problems with mesa crashing in XCB during
eglInitialize then you may need to explicitly run with EGL_PLATFORM=gbm

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-28 17:37:28 +00:00
Neil Roberts
d44e548715 cogl-debug: Mark _cogl_debug_flags with dllexport for MSVC
When building with MSVC, symbols to be exported that point to data
need to be marked with dllimport to be successfully imported. The
_cogl_debug_flags variable is currently exported because it is used
from cogl-pango. This patch adds a COGL_EXPORT macro to cogl-util.h
which is used in cogl-debug.h

Based on a patch by Chun-wei Fan

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-25 13:14:10 +00:00
Chun-wei Fan
2055f6ba91 VS 2008/2010 project files to build Cogl
These are the VS 2008/2010 project files to build Cogl, with a README.txt
to explain the process involved.

Note that the Cogl and Cogl-Pango projects (and filters for VS2010) are
expanded with the correct source file listings during "make dist", which
is done to simplify maintenance of these project files.

-added preconfigured config.h(.win32.in), which is expanded with the
 correct versioining info during autogen
-added preconfigued cogl/cogl-defines.h.win32
-added symbols files for cogl and cogl-pango
-Have configure.ac expand the config.h.win32.in into config.h.win32
 with the correct versioning info, etc, and to include the Visual C++
 project files for distribution
-Added rules in cogl/Makefile.am to expand the cogl VS 2008/2010 projects
 and filters from the templates with up-to-date source file listings, to
 distribute cogl-enum-types.c, cogl-enum-types.h to ease compilation and
 to avoid depending on PERL on Windows installations.
-Added rules in cogl-pango/Makefile.am to expand the cogl-pango VS2008/
 2010 projects and filters from the templates with up-to-date source file
 listings.
-Added/edited various Makefile.am's in build to distribute the VS2008/2010
 project files and associated items required for the build.
-Update .gitignore. There needs to be a pre-configured
 config.h(.win32) and its template, config.h.win32.in for Visual C++
 builds

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

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-25 13:12:45 +00:00
Neil Roberts
9e52b4d714 Fix comparing the uniforms state
When comparing uniform values, it was not correctly handling the case
where pipeline0 has the value set but pipeline1 does not (only the
other way around) so it would crash.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-24 13:23:00 +00:00
Chun-wei Fan
80a9c3bb32 Update cogl/winsys/cogl-winsys-stub.c
Deal with c99ism... I know it's not pretty, but it is the way
to go with non-c99 compilers.  That's life...

Reviewed-by: Neil Roberts <neil@linux.intel.com>
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-23 12:16:45 +00:00
Neil Roberts
61d71c0926 cogl-flags: Fix iterating flag when the most-significant bit is set
When the flags contain a value that only has the most-significant bit
set then ffsl will return the size of an unsigned long. According to
the C spec it is undefined what happens when shifting by a number
greater than or equal to the size of the left operand. On Intel (and
probably others) this seems to end up being a no-op so the iteration
breaks. To fix this we can split the shift into two separate
shifts. We always need to shift by at least one bit so we can put this
one bit shift into a separate operator.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-22 16:07:21 +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
4a7cd0d2ac cogl-pipeline: Store the uniform overrides in an array instead of list
Previously the uniform overrides were stored in a linked list. Now
they are stored in a g_malloc'd array. The values are still tightly
packed so that there is only a value for each uniform that has a
corresponding bit in override_mask. The allocated size of the array
always exactly corresponds to the number of bits set in the
override_mask. This means that when a new uniform value is set on a
pipeline it will have to grow the array and copy the old values
in. The assumption is that setting a value for a new uniform is much
less frequent then setting a value for an existing uniform so it makes
more sense to optimise the latter.

The advantage of using an array is that we can quickly jump to right
boxed value given a uniform location by doing a population count in
the bitmask for the number of bits less than the given uniform
location. This can be done in O(1) time whereas the old approach using
a list would scale by the number of bits set.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-16 16:32:11 +00:00
Neil Roberts
f23b12a886 cogl-bitmask: Add _cogl_bitmask_popcount
This returns a population count of all the bits that are set in the
bitmask.

There is now also a _cogl_bitmask_popcount_upto which counts the
number of bits set up to but not including the given bit index. This
will be useful to determine the number of uniform overrides to skip if
we tightly pack the values in an array.

The test-bitmask test has been modified to check these two functions.

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
4e760d51f1 cogl-bitmask: Add _cogl_bitmask_set_flags
This adds a _cogl_bitmask_set_flags function which can be used to copy
the values from a CoglBitmask to an array of unsigned longs which can
be used with the COGL_FLAGS_* macros. The values are or'd in so that
in can be used multiple times to combine multiple bitmasks.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-16 16:32:11 +00:00
Neil Roberts
d2fd168351 cogl-matrix: Add a public cogl_matrix_transpose()
This function takes a single matrix argument and replaces the matrix
with its transpose.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-16 16:32:11 +00:00
Neil Roberts
037c0aa88c Move POPCOUNTL to cogl-util
This moves the POPCOUNTL macro from cogl-winsys-glx to cogl-util and
renames it to _cogl_util_popcountl so that it can be used in more
places. The fallback function for when the GCC builtin is not
available has been replaced with an 8-bit lookup table because the
HAKMEM implementation doesn't look like it would work when longs are
64-bit so it's not suitable for a general purpose function on 64-bit
architectures. Some of the pages regarding population counts seem to
suggest that using a lookup table is the fastest method anyway.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-16 16:32:11 +00:00
Neil Roberts
436a7a45da cogl-boxed-value: Add _cogl_boxed_value_copy
This adds a function to copy one boxed value to another. It is assumed
that the destination boxed value is totally initialised (so it won't
try to free any memory in it).

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-16 16:32:11 +00:00
Neil Roberts
7068849ae6 cogl-boxed-value: Wrap the GL calls in the GE() macro
This wraps all of the calls to glUniform* in the GE() macro so that it
will detect GL errors in the right place.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-16 16:32:11 +00:00
Neil Roberts
256f5791fd cogl-program: Move the code for CoglBoxedValue to its own file
The code for manipulating CoglBoxedValues is now separated from
cogl-program.c into its own file. That way when we add support for
setting uniform values on a CoglPipeline the code for storing the
values can be shared.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-16 16:32:10 +00:00
Neil Roberts
d706991579 cogl-flags: Add some macros to help iterate the bits
This adds some macros to iterate over all the bits set in an array of
flags. The macros are a bit awkward because it tries to avoid using a
callback pointer so that the code is inlined.

cogl_bitmask is now using these macros as well so that the logic can
be shared.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-16 16:32:00 +00:00
Neil Roberts
dbc31b70cc cogl-bitmask: Add a return value for the foreach callback
The foreach callback can now return FALSE to stop the iteration.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-16 16:21:31 +00:00
Neil Roberts
f4c1ba9ed9 cogl-flags: Use longs instead of ints
Previously cogl-flags was using an array of ints to store the
flags. There was a comment saying that it would be nice to use longs
but this is awkward because g_parse_debug_flags can only work in
ints. This is a silly reason not to use longs because we can just
parse multiple sets of flags per long. This patch therefore changes
cogl-flags to use longs and tweaks the debug key parsing code.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-16 16:21:31 +00:00
Neil Roberts
2ba4fe417a cogl-bitmask: Use ffsl to speedup bitmask iteration
Instead of testing each bit when iterating a bitmask, we can use ffsl
to skip over unset bits in single instruction. That way it will scale
by the number of bits set, not the total number of bits.

ffsl is a non-standard function which glibc only provides by defining
GNUC_SOURCE. However if we are compiling with GCC we can avoid that
mess and just use the equivalent builtin. When not compiling for GCC
it will fall back to _cogl_util_ffs if the size of ints and longs are
the same (which is the case on i686). Otherwise it fallbacks to a slow
function implementation.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-16 16:21:31 +00:00
Neil Roberts
f0f9493f5c cogl-fixed: Move the GType defs from cogl-util.c to cogl-fixed.c
The boilerplate for defining a GType for CoglFixed lived in
cogl-util.c but this didn't seem to make much sense seeing as nothing
in the cogl-util.h header file relates to CoglFixed and there is
already a separate C file for CoglFixed code. This also removes some
redundant header includes from cogl-util.c

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-16 16:21:31 +00:00
Neil Roberts
93321d9b89 cogl-bitmask: Use longs instead of ints
Instead of storing only 31 bits in the pointer for a CoglBitmask, it
now assumes it can store a whole unsigned long minus the one bit used
to mark whether it has been converted to a GArray or not. This works
on the assumption that we can cast an unsigned long to a pointer and
back without losing information which I think should be true for any
platforms that Cogl is interested in. This has the advantage that on
64-bit architectures we can store 63 bits before we have to resort to
using a GArray at no extra cost. The values in the GArray are now
stored as unsigned longs as well on the assumption that it is more
efficient to load and store data in chunks of longs rather than ints.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-16 15:43:25 +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
5369b3c601 pipeline: Make the backface culling experimental public
This adds two new experimental public functions to replace the old
internal _cogl_pipeline_set_cull_face_state function:

void
cogl_pipeline_set_cull_face_mode (CoglPipeline *pipeline,
                                  CoglPipelineCullFaceMode cull_face_mode);

void
cogl_pipeline_set_front_face_winding (CoglPipeline *pipeline,
                                      CoglWinding front_winding);

There are also the corresponding getters.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-14 18:40:27 +00:00
Neil Roberts
8be44f9876 cogl-utils: Include cogl-defines.h
cogl-utils.h needs to include cogl-defines.h so that it knows whether
COGL_HAS_GLIB_SUPPORT is defined.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
Reviewed-by: Emmanuele Bassi <ebassi@linux.intel.com>
2011-11-14 18:40:27 +00:00
Chun-wei Fan
91f91dc678 cogl-renderer.c: Fix includes
Only include cogl-xlib-renderer.h when XLIB support is available

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-14 18:37:57 +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
Neil Roberts
c637324663 cogl-program: Don't ignore the transpose property of matrix uniforms
When setting a matrix uniform value the transpose property was getting
lost and left uninitialized.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 15:50:02 +00:00
Robert Bragg
89731d160e Skip clip flush in _texture_2d_copy_from_framebuffer
Although there was a comment in cogl_texture_2d_copy_from_framebuffer
explaining that we shouldn't flush the clip state, the comment was a bit
miss-leading implying we were going to explicitly set a NULL clip. Also
we weren't actually avoiding flushing the clip state since we were
passing 0 for the CoglDrawFlags.

We now pass COGL_FRAMEBUFFER_FLUSH_SKIP_CLIP_STATE in to the flags when
flushing the framebuffer state and the comment has be updated to explain
that clipping won't affect reading from the framebuffer so we don't need
to flush it.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-03 13:57:06 +00:00
Robert Bragg
e2c758c105 clip: make cogl_clip_ensure a NOP
This api is deprecated and documented to be a NOP which wasn't actually
true. This patch actually updates the function to be a NOP. Its nice
that this gets rid of a point where we flush framebuffer state because
we are looking to add a new VirtualFramebuffer interface which will need
special consideration at each of the points we flush framebuffer state.

It was a mistake that this API was ever published, we don't believe
anyone is using the api but until we break api we have to keep the
symbol. The documented semantics are vague enough that a NOP is ok since
we never explicitly documented how the state would be flushed to GL so
there would be no way to reliably use that state anyway.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-03 13:57:06 +00:00
Rob Bradford
11d38e7ce8 wayland: Port to current Wayland
This change is one logical update to update the Wayland support. This
comprises of the following parts:

* Binding to both the shell and compositor global objects - necessary since
the API for setting top level status moved to the wl_shell interface
* The Wayland visual API went away and instead you setup the EGL surface
appropriately
* The message handling was refined to reflect the current behaviour - now
obsolete comments were removed and new comments updated

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 13:57:01 +00:00
Rob Bradford
00ca539845 wayland: Remove unused function
The function force_roundtrip was unused and required API that was
removed from Wayland.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 13:52:37 +00:00
Robert Bragg
061ef6ed06 glx: remove miss leading comment
There was a comment implying that if a rgba config has been requested
but no suitable config was found then we would automatically fall back
to an rgb config instead. Actually if no rgba visual is found we simply
fail without any automatic fall back because Cogl is not in a good
position to judge if automatic fall backs are acceptable for higher
level apis such as clutter.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-03 13:52:30 +00:00
Neil Roberts
00f0a66ec9 Use the same number for n_tex_coord_attribs in all linked shaders
On GLES2, we need to specify an array size for the texture coord
varying array. Previously this size would be decided in one of the
following ways:

- For generated vertex shaders it is always the number of layers in
  the pipeline.

- For generated fragment shaders it is the highest sampled texture
  unit in the pipeline or the number of attributes supplied by the
  primitive, whichever is higher.

- For user shaders it is usually the number of attributes supplied by
  the primitive. However, if the application tries to compile the
  shader and query the result before using it, it will always be at
  least 4.

These shaders can quite easily end up with different values for the
declaration which makes it fail to link. This patch changes it so that
all of the shaders are generated with the maximum of the number of
texture attributes supplied by the primitive and the number of layers
in the pipeline. If this value changes then the shaders are
regenerated, including user shaders. That way all of the shaders will
always have the same value.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-02 13:50:28 +00:00
Robert Bragg
757916f17a doc: deprecate cogl_texture_get_rowstride()
This documents that cogl_texture_get_rowstride() is deprecated (or
rather it was a mistake that the api was ever published) and also
clarifies the rowstride argument documentation for
cogl_texture_get_data() to explain how it's automatically calculated
when 0 is passed to help avoid misleading people into thinking that
cogl_texture_get_rowstride() is an appropriate way to get a valid
rowstride for that.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-02 13:34:14 +00:00
Rico Tzschichholz
567661ccf3 build: add missing header to fix make dist 2011-11-02 07:34:26 -04:00
Zan Dobersek
d8c47e25f2 Remove inclusion of Xlib headers in Cogl headers
Xlib headers define many trivially named objects which can later cause
name collision problems when only cogl.h header is included in a program
or library. Xlib headers are now only included through including the
standalone header cogl-xlib.h.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-01 15:55:53 +00:00
Robert Bragg
e0344468d8 docs: Adds various missing 2.0 sections and symbols
This adds a number of missing sections and symbols to the experimental
2.0 reference manual.
2011-11-01 12:03:04 +00:00
Robert Bragg
e9075931e3 rectangles: rely on meta-texture api for clamping
Instead of emulating _CLAMP_TO_EDGE in cogl-primitives.c we now defer to
cogl_meta_texture_foreach_in_region() to support _CLAMP_TO_EDGE for us.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:03 +00:00
Robert Bragg
4c49f83056 meta-texture: Support CLAMP_TO_EDGE
cogl_meta_texture_foreach_in_region() now directly supports
CLAMP_TO_EDGE wrap modes. This means the cogl_rectangle code will be
able to build on this and makes the logic accessible to anyone
developing custom primitives that need to support meta textures.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:03 +00:00
Robert Bragg
8cf76ee36b primitive: Add n_indices arg to _set_indices function
When associating indices with a CoglPrimitive you are now forced to
specify the number of indices that should be read when drawing.

It's easy to forget to call cogl_primitive_set_n_vertices() after
associating indices with a primitive (and anyway you can see that someone
could be led to believe Cogl can determine that implicitly somewhow) so
this should avoid a lot of mistakes with using the API.

We'd expect that setting indices and updating the n_vertices property
would go hand in hand 99% of the time anyway so this change should
be more convenient as well as less error prone.

This patch adds some documentation for cogl_primitive_set_indices and
cogl_primitive_get/set_n_vertices. It also tries to clarify how the
CoglPrimitive:n_vertices property is updated and what that property
means in relation to other functions too.

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

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:03 +00:00
Robert Bragg
a8fbde4710 doc: Adds some documentation for CoglIndices
This adds just some basic documentation to try and explain what
CoglIndices are useful for.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:03 +00:00
Robert Bragg
98dc73a8f7 spans: avoid normalize with normalize_factor of 1
if a normalize factor of 1 is passed then we don't need to normalize the
starting point to find the closest point equivalent to 0.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:03 +00:00
Robert Bragg
18fb1ffab5 texture: Make CoglSubTexture experimental public api
This exposes cogl_sub_texture_new() and cogl_is_sub_texture() as
experimental public API. Previously sub-textures were only exposed via
cogl_texture_new_from_sub_texture() so there wasn't a corresponding
CoglSubTexture type. A CoglSubTexture is a high-level texture defined as
a sub-region of some other parent texture. CoglSubTextures are high
level textures that implement the CoglMetaTexture interface which can
be used to manually handle texture repeating.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:03 +00:00
Robert Bragg
1ee861a82c framebuffer: adds cogl_framebuffer_get_samples_per_pixel
It's useful to be able to query back the number of
point_samples_per_pixel that may have previously be chosen using
cogl_framebuffer_set_samples_per_pixel().

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:03 +00:00
Robert Bragg
90f106117f texture: Make CoglTextureRectangle experimentally public
This exposes CoglTextureRectangle in the experimental cogl 2.0 api. For
now we just expose a single constructor;
cogl_texture_rectangle_new_with_size() but we can add more later.

This is part of going work to improve our texture apis with more
emphasis on providing low-level access to the varying semantics of
different texture types understood by the gpu instead of only trying to
present a lowest common denominator api.

CoglTextureRectangle is notably useful for never being restricted to
power of two sizes and for being sampled with non-normalized texture
coordinates which can be convenient for use a lookup tables in glsl due
to not needing separate uniforms for mapping normalized coordinates to
texels. Unlike CoglTexture2D though rectangle textures can't have a
mipmap and they only support the _CLAMP_TO_EDGE wrap mode.

Applications wanting to use CoglTextureRectangle should first check
cogl_has_feature (COGL_FEATURE_ID_TEXTURE_RECTANGLE).

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:02 +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
fd67ddd56e matrix: check DIRTY_TYPE flag in _cogl_matrix_print
when printing a matrix we aim to print out the matrix type but we
weren't checking the flags first to see if the type is valid. We now
check for the DIRTY_TYPE flag and if not set we also validate the matrix
type isn't out of range.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:02 +00:00
Robert Bragg
a054b53891 matrix: init flags before tmp _translate in _look_at
In cogl_matrix_look_at we have a tmp CoglMatrix allocated on the stack
but we weren't initializing its flags before passing it to
cogl_matrix_translate which meant if we were using COGL_DEBUG=matrices
we would end up trying to print out an invalid matrix type resulting in
a crash when overrunning an array of type names.

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
1a30f4fb15 Adds support for a mirrored repeat wrap mode
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>
2011-11-01 12:03:02 +00:00
Robert Bragg
1d8fd64e1c meta-texture: This publicly exposes CoglMetaTexture
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>
2011-11-01 12:03:01 +00:00
Robert Bragg
c11036cd13 spans: Represent spans with floating point precision
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>
2011-11-01 12:03:01 +00:00
Robert Bragg
c7098e417d texture-2d-sliced: simplify _foreach_sub_texture_in_region
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>
2011-11-01 12:03:01 +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
d045bea70e make COGL_FEATURE_FOUR_CLIP_PLANES a private feature
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>
2011-11-01 12:03:00 +00:00
Robert Bragg
abbd28f484 make COGL_FEATURE_OFFSCREEN_BLIT a private feature
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>
2011-11-01 12:03:00 +00:00
Robert Bragg
b566170836 make COGL_FEATURE_STENCIL_BUFFER private
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>
2011-11-01 12:03:00 +00:00
Robert Bragg
6da3bff9b9 Remove beneign GL_MESA_ycbcr_texture check
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>
2011-11-01 12:03:00 +00:00
Robert Bragg
d3114b168a pipeline-layer: fix win32 build issue
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>
2011-11-01 12:03:00 +00:00
Robert Bragg
eef5013751 primitives: make validate_first_layer_cb update override pipeline
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>
2011-11-01 12:03:00 +00:00
Robert Bragg
583dc893be spans: remove unused intersect_start/end_local members
There were simply two unused members in CoglSpanIter which this patch
removes.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:00 +00:00
Robert Bragg
d92eaac3ec spans: only iterate spans within start-end range
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>
2011-11-01 12:03:00 +00:00
Robert Bragg
6253b09c69 texture-2d-sliced: make CoglTexture2DSliced public
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>
2011-11-01 12:02:59 +00:00
Robert Bragg
f6daed62e3 clip: Adds cogl_clip_push_primitive API
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>
2011-11-01 12:02:59 +00:00
Robert Bragg
7a834cf681 primitive: Adds _cogl_primitive_draw api taking flags
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>
2011-11-01 12:02:59 +00:00
Robert Bragg
fd2769f7e8 clip-stack: Move path flushing code to cogl-clip-stack.c
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>
2011-11-01 12:02:59 +00:00
Robert Bragg
a400aec51b path: handle slice tex fallback using clip stack
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>
2011-11-01 12:02:59 +00:00
Robert Bragg
a8efe6af06 framebuffer: Adds experimental _finish() API
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>
2011-11-01 12:02:55 +00:00
Robert Bragg
dd7b16faf2 offscreen: Adds support for offscreen multisampling
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>
2011-10-28 19:10:16 +01:00
Robert Bragg
a74c81ada3 onscreen: Support multisample based onscreen rendering
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>
2011-10-28 19:10:16 +01:00
Robert Bragg
98e5a9c777 Rework how we search for winsys configs
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>
2011-10-28 19:10:16 +01:00
Robert Bragg
63461c0f8b framebuffer: Add explicit buffer discard API
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>
2011-10-28 19:10:16 +01:00
Neil Roberts
49e733fcdc pipeline: Reset last_used_for_pipeline when the pipeline is destroyed
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>
2011-10-24 14:29:02 +01:00
Neil Roberts
b85f5e0198 cogl-shader: Update the gtk-doc
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>
2011-10-21 12:24:01 +01:00
Neil Roberts
1d67085e8a cogl-winsys-egl: Use the abstraction to update the window size
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.
2011-10-17 17:33:42 +01:00
Robert Bragg
8325ca00b8 build: removes unused variable i to avoid compiler warning
Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-10-17 13:57:29 +01:00
Neil Roberts
f628839771 Mark the debug options for translation
This adds the descriptions of the debug options to the list of
translatable strings.

https://bugzilla.gnome.org/show_bug.cgi?id=658700
2011-10-14 13:56:51 +01:00
Robert Bragg
5ab0b38657 pipeline: don't leak the layers_cache
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>
2011-10-12 15:29:07 +01:00
Robert Bragg
1f61868fed x11-tfp: don't call winsys x11_damage_notify without winsys
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
2011-10-12 14:24:44 +01:00
Damien Leone
895055c836 cogl-winsys-glx: fix texture format detection
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>
2011-10-01 16:44:55 +01:00
Neil Roberts
5aab8a2310 Add an option to avoid defining G_DISABLE_DEPRECATED
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>
2011-09-27 10:27:19 +01:00
Chun-wei Fan
34181d34f5 Makefile.am: Update sources list
There is no cogl/cogl-pipeline-debug-private.h, so remove that from
Makefile.am

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-09-26 15:54:07 +01:00
Chun-wei Fan
98a9428967 cogl-pipeline/cogl-pango: Added forgotten includes
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>
2011-09-26 15:53:30 +01:00
Robert Bragg
dd5208b0ba arbfp: assume GL_TEXTURE_2D target for NULL texture
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>
2011-09-23 15:31:07 +01: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
f16d3756df pipeline: lazily get ctx in _get_layer
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>
2011-09-21 17:28:22 +01:00
Robert Bragg
d4459e2d42 pipeline: Split more code out from cogl-pipeline.c
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.
2011-09-21 17:03:10 +01:00
Robert Bragg
77a7add50e attributes: optimize validation of tex_coord%d_in names
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>
2011-09-21 15:50:13 +01:00
Robert Bragg
d739892a5c primitive: micro optimize primitive allocations
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>
2011-09-21 15:50:08 +01:00
Robert Bragg
791773987c attributes: avoid g_strdup in cogl_attribute_new
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>
2011-09-21 15:39:46 +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
1984fea4b1 cogl-primitives: Don't warn if using sliced textures without multi-tex
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>
2011-09-19 16:40:07 +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
Neil Roberts
f6ec6e2d0e pipeline-arbfp: Check for fog on the pipeline not the legacy state
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>
2011-09-19 16:40:06 +01:00
Neil Roberts
2059ae3ac8 Add internal _cogl_push_source to optionally disable legacy state
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>
2011-09-19 16:40:06 +01:00
Neil Roberts
acc7d25188 cogl-path: Don't apply legacy state twice when stroking
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>
2011-09-19 16:40:06 +01:00
Adel Gadllah
671a4dfb34 winsys-glx: Fix synchronisation behaviour in _cogl_winsys_onscreen_swap_region
This patch basically restores the logic from 1.6.  There we assumed that
glXCopySubBuffer won't tear and thus only needs to be throttled to the
framerate, while glBlitFramebuffer needs to always wait to avoid
tearing.

With Nvidia drivers specifically we have seen that glBlitFramebuffer is
not synchronized. Eventually the plan is that Cogl will actually take
into consideration the underlying driver/hw vendor and driver version
and we may want to only mark glBlitFramebuffer un-synchronized on
Nvidia.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-09-19 16:40:06 +01:00
Robert Bragg
3c82fd056c pipeline: mark all cogl-pipeline.h symbols experimental
All of the cogl_pipeline API is currently experimental so this makes
sure the API is surrounded by #ifdef COGL_ENABLE_EXPERIMENTAL_API
guards and all the symbols have a #define to give them an _EXP suffix as
we do for other experimental API.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-09-19 16:40:06 +01:00
Robert Bragg
db6c452aaa pipeline: split out all layer state apis
As part of an on-going effort to get cogl-pipeline.c into a more
maintainable state this splits out all the apis relating just to
layer state. This just leaves code relating to the core CoglPipeline
and CoglPipelineLayer design left in cogl-pipeline.c.

This splits out around 2k more lines from cogl-pipeline.c although we
are still left with nearly 4k lines so we still have some way to go!

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-09-19 16:40:00 +01:00
Robert Bragg
9b58b6f472 pipeline: split out all core state apis
Since cogl-pipeline.c has become very unwieldy this make a start at
trying to shape this code back into a manageable state. This patche
moves all the API relating to core pipeline state into
cogl-pipeline-state.c. This doesn't move code relating to layer state
out nor does it move any of the code supporting the core design
of CoglPipeline itself.

This change alone factors out 2k lines of code from cogl-pipeline.c
which is obviously a good start. The next step will be to factor
out the layer state and then probably look at breaking all of this
state code down into state-groups.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-09-19 16:35:59 +01:00
Neil Roberts
c7969a33af cogl: Bind the locale dir for the Cogl domain
dgettext (which Cogl is using) doesn't work unless you first tell
gettext where the locale dir is for the library's domain. This just
adds the necessary calls into _cogl_init.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-09-19 12:53:58 +01:00
Neil Roberts
e81c1f3e9a cogl-journal: Fix software clipping for non-intersecting rectangles
When the clip contains two rectangles which do not intersect it was
generating a clip bounds where the bottom-right corner was above or to
the left of the top-left corner. This would end up allowing the pixels
between the two rectangles instead of clipping everything like it
should. To fix this there is now an extra check which detects this
situation and just clears the clip bounds to all zeroes in a similar
way to what cogl-clip-stack does.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-09-14 16:30:16 +01:00
Neil Roberts
9082dd0d71 cogl-path: Clear the stroke attribute buffer when modifying the path
Commit 12b3d21a changed cogl-path so that it will use the vertex
attribute API to stroke the path in a similar way to how it was using
the API to fill the path. However it wasn't clearing the stroke buffer
when the path is modified so it would continue to use the unmodified
stroke.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-09-12 18:54:16 +01:00
Robert Bragg
f1c2d7e965 2.0: Add cogl2-experimental.h + don't pollute .pc CFLAGS
Instead of adding -DCOGL_ENABLE_EXPERIMENTAL_2_0_API to the
cogl-2.0-experimental.pc file we now install a cogl2-experimental.h
that #defines COGL_ENABLE_EXPERIMENTAL_2_0_API before including
cogl.h.

The problem with having the define in the .pc file is that you might
develop a library that depends on the experimental 2.0 api internally
and then you might want to use that library with Clutter which still
uses the 1.0 API but the .pc file for your library will indirectly,
automatically enable the 2.0 api which can cause conflicts.
2011-09-09 15:06:31 +01:00
Robert Bragg
d43505db22 arbfp: remove redundant unit_state re-initialization
When we are about to start arbfp codegen we call shader_state_new() to
allocate new state structures used to build up the code and that
function makes sure to zero the newly allocated structures.

Right after calling shader_state_new() we were then also explicitly
iterating though the newly allocated unit_state structures and zeroing
the .sampled and .dirty_combine_constant members as well as resetting
shader_state->next_constant_id = 0. This patch removes that redundant
re-initialization of state.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-09-09 14:40:48 +01:00
Robert Bragg
b6cea6bed6 arbfp: track which layers have combine constants
We weren't actually tracking which layers have been allocated param
space for combine constants; all layers just had a default constant_id
of 0 that indexes into the program.local[] params array and a dirty flag
to say when the constant needs updating. There are times though when we
say to update everything by-passing the dirty flag and because we
weren't actually tracking which layers needed constants we would always
write a constant to program.local[0] for every layer. The upshot was
that we could end up clobbering a real constant that was actually
allocated the constant_id = 0 slot.

This patch adds a new UnitState bitfield to track if the layer has a
corresponding constant that may need flushing and we only ever write the
constant with glProgramLocalParameter4fv if that's set.

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

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-09-09 14:40:48 +01:00
Robert Bragg
b5a7657076 Starts porting Cogl conformance tests from Clutter
This makes a start on porting the Cogl conformance tests that currently
still live in the Clutter repository to be standalone Cogl tests that no
longer require a ClutterStage.

The main thing is that this commit brings in is the basic testing
infrastructure we need, so now we can port more and more tests
incrementally.

Since the test suite wants a way to synchronize X requests/replies and
we can't simply call XSynchronize in the test-utils code before we know
if we are really running on X this adds a check for an environment
variable named "COGL_X11_SYNC" in cogl-xlib-renderer.c and if it's set
it forces XSynchronize (dpy, TRUE) to be called.

By default the conformance tests are run off screen. This makes the
tests run much faster and they also don't interfere with other work you
may want to do by constantly stealing focus. CoglOnscreen framebuffers
obviously don't get tested this way so it's important that the tests
also get run on screen every once in a while, especially if changes are
being made to CoglFramebuffer related code.  On screen testing can be
enabled by setting COGL_TEST_ONSCREEN=1 in your environment.
2011-09-08 15:48:07 +01:00
Chun-wei Fan
a1d869384e Fix typo in cogl/cogl-display.h
The line "#define cogl_display_get_rendrer cogl_display_get_rendrer_EXP"
should read
"#define cogl_display_get_renderer cogl_display_get_renderer_EXP"...

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

Reviewed-by: Emmanuele Bassi <ebassi@linux.intel.com>
2011-09-06 11:19:20 +01:00
Robert Bragg
191d915671 framebuffer: Add a getter for the framebuffer format
This adds a new function, cogl_framebuffer_get_color_format() to be able
to query the common pixel format for any color buffers attached to a
given CoglFramebuffer. For example an offscreen framebuffer created
using cogl_offscreen_new_to_texture() would have a format matching the
texture.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-09-05 19:02:05 +01:00
Robert Bragg
476ff37fa6 display: always ensure we have an onscreen_template
If the user doesn't explicitly pass an onscreen template then instead of
leaving display->onscreen_template as NULL we now instantiate a template
ourselves. This simplifies winsys code that might want to refer to the
template since it needn't first check for a NULL pointer.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-09-05 19:02:05 +01:00
Robert Bragg
21e87a9bf0 texture-2d: move #defines before gtk-doc
All our experimental Cogl symbols have a corresponding #define to add
"_EXP" to the end of the symbol name, but those defines are often
positioned right after the corresponding gtk-doc comment and before
the symbol definition which means the generated documentation ends up
refering to the define and not the real definition. This tidies up
cogl-texture-2d.h and moves all the defines to be be before the gtk-doc
comments.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-09-05 19:02:05 +01:00
Neil Roberts
e7f374d799 cogl-pipeline-fragend-glsl: Cache the results of texture lookups
Whenever a texture lookup is performed for a layer the result is now
stored in a variable and used repeatedly instead of generating the
code for the lookup every time it is accessed. This means for example
when using the INTERPOLATE function with a texture lookup for the
third parameter it will only generate one texture lookup instead of
two.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-09-05 19:02:04 +01:00
Neil Roberts
769c8472dd fragend-glsl: Don't generate code for ignored layers
This patch changes it so that code for each layer is generated on
demand instead of directly in the add_layer implementation. The
pipeline only explicitly generates code for the last layer. If this
layer references the result from any other layers, these will also be
recursively generated. This means that if a layer is using 'REPLACE'
then it won't redundantly generate the code for the previous
layers.

The result for each layer is generated into a variable called layer%i
where %i is the layer index (not the unit index). Therefore to get the
result from layer n we just have to refer to the varible layern.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-09-05 19:02:04 +01:00
Neil Roberts
503f138fb6 texture: Call _cogl_texture_prepare_for_upload in set_region impl
Instead of calling _cogl_texutre_prepare_for_upload in
cogl_texture_set_region_from_bitmap the call is now deferred to the
implementation of the virtual for set_region. This is needed if the
texture backend is using a different format for the actual GL texture
than what is reported by cogl_texture_get_format. This happens for
example with atlas textures which report the original internal format
specified when the texture was created but actually always store the
data in an RGBA texture.

Also when creating an atlas texture from a bitmap it was preparing the
bitmap to be uploaded to the original format instead of the format of
the actual texture used for the atlas. Then it was using
cogl_texture_set_region_from_bitmap to upload the 5 pieces to make the
copies of the edge pixels. This would end up converting the image to
the actual format 5 times. The atlas textures have now been changed to
prepare the bitmap for the right format.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-09-05 19:02:04 +01:00
Robert Bragg
9b56ce4d5b blend-strings: Make braces around blend factor optional
for a blend string like:
"RGBA=ADD(SRC_COLOR, SRC_COLOR * (DST_COLOR[A]))"
it was awkward that we were requiring developers to explicitly put
redundant brackets around the DST_COLOR[A] blend factor. The parser has
been updated so now braces are only required for factors like
"(1-SRC_COLOR[A])"

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-09-05 17:54:46 +01:00
Damien Lespiau
c36652a4c3 renderer: Add cogl_renderer_get_n_fragment_texture_units()
Add a method on the renderer to know how many texture image units are
accessible from fragment shaders.

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
6a2e21183c display: Add an accessor to get the renderer out of a display
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
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
Robert Bragg
f37d9bbb4d matrix: Add cogl_matrix_look_at
Similar to the widely used gluLookAt API, this adds a CoglMatrix utility
for setting up a view transform in terms of positioning a camera/eye
position that points to a given object position aligned to a given
world-up vector.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-12 15:28:44 +01:00
Robert Bragg
3a2f94045e framebuffer: make _swap_region coords top-left relative
Cogl aims to consistently put the origin of 2D objects at the top-left
instead of the bottom left as OpenGL does, but there was an oversight
and the experimental cogl_framebuffer_swap_region API was accepting
coordinates relative to the bottom left. Cogl will now flip the user's
given rectangles to be relative to the bottom of the framebufffer before
sending them to APIs like glXCopySubBuffer and glBlitFramebuffer.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-12 15:28:43 +01:00
Robert Bragg
8e8690a562 framebuffer: lazily allocate framebuffers as needed
If the user doesn't explicitly allocate a CoglFramebuffer then Cogl
should automatically allocate the framebuffer when the user starts to
draw to the framebuffer. So this way calling cogl_framebuffer_allocate
is only required if you are explicitly interested in checking for and
gracefully handling failures to allocate a framebuffer. If automatic
allocation fails then application behaviour becomes undefined.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-12 15:28:43 +01:00
Robert Bragg
a3ad808f57 framebuffer: Make framebuffer_clear APIs public experimental
This makes cogl_framebuffer_clear and cogl_framebuffer_clear4f public as
experimental API. Since these functions take explicit framebuffer
pointers you don't need to push/pop a framebuffer just to clear it. Also
these functions are implicitly tied to a specific CoglContext via the
framebuffer pointer unlike cogl_clear.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-12 15:28:43 +01:00
Robert Bragg
f7b1bab1ad framebuffer: don't reference default fb in _clear apis
Some of the functions we were calling in cogl_framebuffer_clear[4f] were
referring to the current framebuffer, which would result in a crash
if nothing had been pushed before trying to explicitly clear a given
framebuffer.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-12 15:28:43 +01:00
Robert Bragg
19d12e65e5 framebuffer: avoid redundant calls to _init_bits
There is no need to call _cogl_framebuffer_init_bits for the draw and
read buffers each time we flush the framebuffer state since we will
always re-sync with gl if necessary when the
cogl_framebuffer_get_red/green/blue/alpha_bits functions are called.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-12 15:28:43 +01:00
Robert Bragg
64b2bbab84 framebuffer: Adds a context getter for CoglFramebuffer
This adds a function to query what CoglContext a given framebuffer
belongs too. This can be useful if you pass framebuffer pointers around
and at some point you want to create another framebuffer as part of the
same context as a given framebuffer without assuming there is a single
default context.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-12 15:28:43 +01:00
Robert Bragg
f3a4d21187 buffer: make the COGL_BUFFER casting macro public
The CoglBuffer api is available as experimental 2.0 api but we forgot to
exposed the COGL_BUFFER casting macro.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-12 15:28:43 +01:00
Robert Bragg
dd6935f129 stb_image: use glib sized types
Instead of creating typedefs like uint8, uint16 and uint32 we now use
the glib sized typedefs in stb_image to avoid conflict with the uint8,
uint16 and uint32 typedefs on android.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-12 15:28:42 +01:00
Robert Bragg
b2964b6910 ext-functions: Don't assume GLchar typedef
We shouldn't assume the GLchar is a valid typedef with all GL headers
when declaring all the symbols in cogl-ext-functions.h to lookup. GLchar
may not be avilable with gles1 for example so we were seeing build
failures. The patch simply replaces occurrences of GLchar with char.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-12 15:28:42 +01:00
Robert Bragg
2ac4002084 cogl: Add support for reading a cogl.conf config file
When cogl initializes we now check for a cogl/cogl.conf in any of the
system config dirs (determined using $XDG_CONFIG_DIRS on linux) we then
also check the user's config directory (determined using XDG_CONFIG_HOME
on linux) for a cogl/cogl.conf file. Options specified in the user
config file have priority over the system config options.

The config file has an .ini style syntax with a mandatory [global]
section and we currently understand 3 keynames: COGL_DEBUG, COGL_DRIVER
and COGL_RENDERER which have the same semantics as the corresponding
environment variables.

Options set using the environment variables have priority over options
set in the config files. To allow users to undo the enabling of debug
options in config files this patch also adds a check for COGL_NO_DEBUG
environment variable which will disable the specified options which may
have been enabled in config files.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-12 15:28:42 +01:00
Neil Roberts
9270412495 cogl-blend-string: Fix TEXTURE_N sources
The parser couldn't cope with TEXTURE_N source arguments because the
sources are checked in turn to find one that matches the beginning of
the argument. The TEXTURE_N source was checked last so it would end up
matching the regular 'TEXTURE' source and then the parser would choke
when it tries to parse the trailing parts.

This patch just moves the check for TEXTURE_ to the top. It also also
changes it so that the argument only needs to be at least 8 characters
long instead of 9. This is necessary because the parser doesn't
consider the digits to be part of the name of the argument so while we
are parsing 'TEXTURE_0' the length is only 8.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-08-04 19:14:27 +01:00
Robert Bragg
89fd2edeb0 Flush the journal before changing the projection
Since the projection matrix isn't tracked in the journal and since our
software transform of vertices as we log into the journal doesn't
include the projective transform we need to make sure we flush all
primitives in the journal before ever changing the projection.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-02 12:05:37 +01:00
Damien Lespiau
ee01fd263a egl-gdl: Don't generate cogl-display.h
It's not necessary to generate cogl-display.h just for the GDL backend
and to change the inclusion of libgdl.h. We can just tweak the include
CFLAGS to put /usr/include/CE4100 in the search path when needed.

Previously this did not work because of a stay ',' at the end of the
COGL_EXTRA_CFLAGS int he configure.ac. This actually simplifies the
code, which is always good.

This also fixes out of tree builds.

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

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-01 16:36:52 +01:00
Damien Lespiau
89426a802f egl-gdl: Silence a gcc warning
gcc warns us that we should put some {} to make to which 'if's the
'else' belongs to very clear.

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

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-01 16:36:09 +01:00
Neil Roberts
bbbe6db284 cogl-primitives: Plug some leaks in cogl_polygon
cogl_polygon creates some temporary strings, CoglAttributeBuffers and
CoglAttributes but it was never freeing them.

Based on a patch by Florian Renaut

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-08-01 14:08:46 +01:00
Neil Roberts
38deb97478 cogl-winsys-wgl: Add a fallback for failed wglGetProcAddress
The documentation for wglGetProcAddress implies that it should only be
used for extension functions. The rest of Cogl assumes that it can
dynamically resolve all GL symbols so it would crash if this
happens. This patch makes it fallback to trying to resolve the symbol
using GModule to open the opengl32 library if wglGetProcAddress fails.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-08-01 14:08:42 +01:00
Neil Roberts
93e69387cc Add the missing check for COGL_FEATURE_POINT_SPRITE on the GL driver
The check for the point sprite feature got lost when the feature
functions header was combined for GL and GLES in dae02a99a.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-08-01 14:05:09 +01:00
Chun-wei Fan
f7bdc92d6c Include cogl-win32-renderer.h in cogl.h on Windows
Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-31 17:46:35 +01:00
Chun-wei Fan
3d92038237 Fix cogl/cogl-framebuffer.h (#define error)
The cogl_framebuffer_get_blue_bits was defined 2 times-fix to use the
correct define for cogl_framebuffer_get_alpha_bits

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-31 17:46:35 +01:00
Chun-wei Fan
6256ad8a7b Update vtable.id in cogl-winsys-wgl.c
Change EGL id to WGL id.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-31 17:46:35 +01:00
Damien Lespiau
d4dc51849e egl: Make sure to free the underlying egl objects when the display is freed
If the display has been setup up, we should destroy the underlying
objects that the winsys has created. This can be done by calling the
winsys->destroy_display() function in _free.

Then, in that function, and for the NULL and GDL EGL platform we can
destroy the surface we have created in the setup_display() function
(through create_context()).

This allows to have clutter create a "dummy" display in
cogl_renderer_check_onscreen_template(), then free it, then recreate the
context and the surface that will be the final ones.

https://bugzilla.gnome.org/show_bug.cgi?id=655355
2011-07-29 11:50:15 +01:00
Damien Lespiau
2c3827aced egl-gdl: Provide defaults to be able to initialize a "dummy" context
If we are being called without any GDL specific call (either the plane
we want to render to or the swap chain length) we can provide sane
defaults to still be able to create a context and a surface.

https://bugzilla.gnome.org/show_bug.cgi?id=655355
2011-07-29 11:50:15 +01:00
Damien Lespiau
ff5a3503af egl-gdl: Make the egl winsys know about the GDL platform
The egl winsys has a few code paths depending on the platform we are
compiling for. The GDL platform needs those defined as well.

A few tweaks were needed here and there to make it compile again.

https://bugzilla.gnome.org/show_bug.cgi?id=655355
2011-07-29 11:50:15 +01:00
Damien Lespiau
388abe2907 egl-gdl: struct gdl_plane never was a valid type
The enum for the planes is called gdl_plant_id_t.

https://bugzilla.gnome.org/show_bug.cgi?id=655355
2011-07-29 11:50:15 +01:00
Damien Lespiau
a53af153c3 egl-gdl: Correctly substitute COGL_CEX100_LIBGDL_PREFIX
We weren't defining CLUTTER_CEX100_LIBGDL_PREFIX in the configure.ac and
thus failing to compile when selecting the EGL/GDL winsys. Take the
opportunity to rename that to COGL_CEX100_LIBGDL_PREFIX

https://bugzilla.gnome.org/show_bug.cgi?id=655355
2011-07-29 11:50:15 +01:00
Damien Lespiau
9ca3308892 egl: Guard the feature discovery of eglCreateImage()
EGLImageKHR might not be defined, the rest of the code seems to guard it
with #ifdef EGL_KHR_image_base.

https://bugzilla.gnome.org/show_bug.cgi?id=655216
2011-07-29 11:44:55 +01:00
Robert Bragg
912d46817e glx: Bail from _renderer_connect if not GL driver
The GLX winsys is only compatible with GL drivers so we now bail out
from cogl-winsys-glx.c:_cogl_winsys_renderer_connect if a GLES driver
has been chosen.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-28 20:44:46 +01:00
Robert Bragg
6e6620e089 egl: pass EGL_NO_CONTEXT to eglCreateImage for tfp
When passing the EGL_NATIVE_PIXMAP_KHR target to eglCreateImage the
EGL_KHR_image_pixmap extension explicitly states that EGL_NO_CONTEXT
must also be passed so we are now careful to do this.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-28 20:44:32 +01:00
Robert Bragg
b8503418ff framebuffer: dec current_pipeline_age to force color_mask
When we need to guarantee that the glColorMask is re-asserted the next
time that a primitive is drawn it is not enough to just OR in the
LOGIC_OPS flag to ctx->current_pipeline_changes_since_flush because
_cogl_pipeline_flush_gl_state actually checks the age of the pipeline
before checking that. If the pipeline hasn't aged then we bail out
early. This makes sure we decrement
ctx->current_pipeline_changes_since_flush so the next time we come to
flush a pipeline we will see a differing age.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-28 20:44:21 +01:00
Philip Withnall
d51c3c423e Fix testing of undefined macro constants to check for definedness instead
Reviewed-By: Robert Bragg <robert@linux.intel.com>
2011-07-27 18:46:36 +01:00
Robert Bragg
b8b37f6c41 quaternion: fix init_from_array and get_rotation_axis
In cogl_quaternion_init_from_array we were passing the address of the x
component as the destination for memcpy, but that was wrong at least
because w is actually the first member in the structure.  Another
concern raised was whether it was safe to assume that there was no
padding within the CoglQuaternion struct with some compilers so we also
switch to explicitly indexing each element of the array we want to copy.
In practice I think it's pretty safe to assume that padding will only be
introduced to ensure members are naturally aligned, but being explicit
is readable and it can't hurt to be extra cautious.

Another good catch in bug #655228 was that in
cogl_quaternion_get_rotation_axis we had a copy and paste error at the
end where we finally extract the axis and we were repeatedly calculating
just the x component. Now we calculate the y and z components too.

Thanks to Bug #655228 for identifying these issues.

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

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-27 18:21:27 +01:00
Neil Roberts
d259a87602 Don't use the 'NULL' GModule to resolve GL symbols
Previously, _cogl_get_proc_address had a fallback to resolve the
symbol using g_module_open(NULL) to get the symbol from anywhere in
the address space. The EGL backend ends up using this on some drivers
because eglGetProcAddress isn't meant to return a pointer for core
functions. This causes problems if something in the process is linking
against a different GL library, for example Cairo may be linking
against libGL itself. In this case it may end up resolving symbols
from the GL library even if GLES is being used.

This patch removes the fallback. The EGL version now has its own
fallback instead which passes the existing libgl_module from the
renderer to g_module_symbol so that it should only get symbols from
that library or its dependency chain. The GLX and WGL winsys only call
glXGetProcAddress and wglGetProcAddress. The stub winsys does however
continue using the global symbol lookup.

The internal _cogl_get_proc_address function has been renamed to
_cogl_renderer_get_proc_address because it needs a connected renderer
to work so it could be considered to be a renderer method. The pointer
to the renderer is passed down to the winsys backends so that it can
use the data attached to the renderer to get the module pointers.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-07-27 16:10:02 +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
Neil Roberts
1287d26444 cogl-pipeline-fragend-arbfp: Initialise template_pipeline
The template_pipeline variable in _cogl_pipeline_fragend_arbfp_start
was not being initialised if the program caches are disabled with
COGL_DEBUG=disable-program-caches so it would crash. The other
backends have a similar variable but they already initialise it.

https://bugzilla.gnome.org/show_bug.cgi?id=655400
2011-07-27 10:55:47 +01:00
Robert Bragg
a9184d5cb7 Export API for uploading a tex subregion from a CoglBuffer
This exposes 2 experimental functions that make it possible to upload a
subregion of a texture from a CoglBuffer by first wrapping the buffer as
a CoglBitmap and then allowing uploading of a subregion from a
CoglBitmap. The new functions are:

cogl_bitmap_new_from_buffer() and
cogl_texture_set_region_from_bitmap()

Actually for now we are exporting this API for practical reasons since
we already had this API internally and it enables a specific feature
that was requested, but it is worth nothing that it's quite likely we
will replace these with functions that don't involve the CoglBitmap API
at some point.

For reference: The CoglBitmap API was actually removed from the 2.0
experimental API reference manual some time ago because the hope was
that we'd come up with a neater replacement. It doesn't seem entirely
clear what the scope of the CoglBitmap api is so it has became a bit of
a dumping ground.  CoglBitmap is used for image loading, as a means to
represent the layout of image data and also internally deals with format
conversions.

Note: Because we are avoiding including CoglBitmap as part of the 2.0
API these functions aren't currently included in the 2.0 reference
manual.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-25 22:45:24 +01:00
Robert Bragg
52a5fae136 gles: don't check for glClientActiveTexture
in cogl-ext-functions.h we had one multitexture feature that checked for
the ARB_multitexture extension and if found it then expected to find
glActiveTexture and glClientActiveTexture. The problem is that the
multitexture extension is part of the core GLES 1 and 2 APIs except that
for GLES2 there is no glClientActiveTexture function. By trying to
handle it as one feature that meant that Cogl would fail to check the
multitexture extension which is a hard requirement for Cogl.

The reason this went unnoticed is because Cogl can indirectly end up
linked to an OpenGL library via cairo and so we were finding a
glClientActiveTexture symbol there. This highlights that we should
probably stop using g_module_open (NULL) when checking features and
instead we should use the module we opened in cogl-renderer.c.
2011-07-20 16:43:29 +01:00
Robert Bragg
1144a05bfd x11: don't try and close a NULL display
If we failed to open an X display then don't later try and close a NULL
display resulting in a crash.
2011-07-20 16:43:29 +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
03c4b20931 Specify the full filename when g_module_open'ing the GL library
Instead of using g_module_build_path with the short name of the GL
library (eg, "GL") and relying on glib to add the suffix and prefix,
the configure script now directly encodes the full name including the
version number (eg, "libGL.so.1"). This is necessary because distros
don't always install the non-versioned suffix for the library.

The GLES libraries are left without the version suffix because it's
not clear what should be placed here and I can't find any
documentation from Khronos to clarify this. Mesa seems to install a
file called libGLESv2.so.2 but the IMG SDK doesn't install any
versioned library. There is an example of dynamically loading
libGLESv2 in the Chromium source code and that does not use the
version suffix even though it does use the version suffix for GL. This
implies that it's at least fairly normal to load the unversioned name
for GLES.

https://bugzilla.gnome.org/show_bug.cgi?id=654593
2011-07-19 15:12:10 +01:00
Robert Bragg
eb578e4e0c gles: Or in private features into ctx->private_feature_flags
When we moved all the GL function pointers to be part of CoglContext in
commit dae02a99a5 we made a mistake and started to OR in the private
COGL_PRIVATE_FEATURE_TEXTURE_2D_FROM_EGL_IMAGE feature flag into the non
private flags which would mean cogl would think the GL_OES_EGL_image
extension wasn't supported.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-19 14:40:29 +01:00
Robert Bragg
6d79657f76 egl: if texture_pixmap_x11_create fails free priv data
This makes sure the egl winsys frees the private egl_tex_pixmap state if
in _cogl_winsys_texture_pixmap_x11_create if there is a failure to
create an EGLImage.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-18 16:49:07 +01:00
Robert Bragg
02ba1a7345 texture-pixmap-x11: set ->winsys = NULL if _create fails
If _cogl_winsys_texture_pixmap_x11_create() fails then implicitly no
private state has been associated with the given tex_pixmap. Since that
winsys isn't associated with it we explicitly set tex_pixmap->winsys =
NULL.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-18 16:49:07 +01:00
Robert Bragg
c058b50ac0 texture-pixmap-x11: initialize ->use_winsys_texture
This ensures that tex_pixmap->use_winsys_texture is always initialized
during cogl_texture_pixmap_x11_new - either according to the result of
winsys->texture_pixmap_x11_create, or if the winsys doesn't support tfp
we explicitly initialize to FALSE.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-18 16:49:07 +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
Emmanuele Bassi
2fc069888f Compilation fixes for suncc
https://bugzilla.gnome.org/show_bug.cgi?id=654718

Reviewed-by: Neil Roberts <neil@linux.intel.com>
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-07-18 15:37:38 +01:00
Robert Bragg
6f79eb8a5a Use MESA_pack_invert to avoid read_pixels flip
cogl_read_pixels returns image data in a top-down memory order, but
because OpenGL normally returns pixel data in a bottom-up order we
have to flip the data before returning it to the user. If the OpenGL
driver supports the GL_MESA_pack_invert extension though we can ask the
driver to return the data in a top-down order in the first place.

Signed-off-by: Neil Roberts <neil@linux.intel.com>
2011-07-13 19:06:19 +01:00
Robert Bragg
1527b017c5 build: don't referencing wayland syms if not available
cogl-winsys-egl-feature-functions.h was unconditionally depending on the
struct wl_display type being defined. This guards the check for the
"WL_bind_wayland_display" extension with
 #ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT

Signed-off-by: Neil Roberts <neil@linux.intel.com>
2011-07-13 19:06:19 +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
f3b90d1717 cogl-pipeline: Use the pipeline cache for the GLSL backends
The CoglPipelineCache is now extended to store templates for state
affecting vertex shaders and combined programs. The GLSL fragend,
vertend and progend now uses this to get cached shaders and a program.

When a new pipeline is created it will now get hashed three times if
the GLSL backends are in use (once for the fragend, once for the
vertend and once for the progend). Ideally we should add some way for
the progend to check its cache before the fragends and vertends are
checked so that it can bypass them entirely if it can find a cached
combined program.
2011-07-13 12:30:07 +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
Neil Roberts
d69d49fada pipeline: Unify how the backends store private data
Previously the fragends had a separate private data pointer which was
used by the GLSL and ARBfp fragends to store a tiny struct containing
a single pointer to the ref-counted shader state. The space for the
private data pointer is reserved in all of the pipelines for all of
the potential backends. The vertends and progends however did this
differently by directly storing the pointer to the ref counted data
using cogl_object_set_user_data. This patch unifies the different
methods so that they all use cogl_object_set_user_data and the
fragends don't bother with the separate tiny allocation for the
private data. The private data pointer array has been removed from
CoglPipeline and the corresponding fragend virtual to free the private
data has also been removed because this can instead be done with the
destroy notify from the object user data.

The variable names used have been unified so that all of the vertends
and fragends name their data struct CoglPipelineShaderState and use a
variable called shader_state to refer to it. The progend uses
CoglPipelineProgramState and a variable called program_state.

This should also fix two potential bugs. the ARBfp fragend was
apprently leaking a reference to the private state when it creates the
private data because it was adding a reference before stroring the
pointer to the newly allocated data but the ref count is already set
to 1 on creation. The other potential bug is that the free function
for CoglPipeline was only calling the free_priv virtual for the
currently used fragend of the pipeline. The design of the fragends is
meant to allow a pipeline to have multiple fragend priv datas because
a child pipeline could be attaching its fragend data to the ancestor
and its allowed to pick a different fragend.
2011-07-13 12:30:07 +01:00
Damien Lespiau
221850eca9 pipeline: NULLify deprecated_get_layers_list on copy
That list is tracking the layers for get_layers_list() and needs to be
freed later on. However _copy() did not initialize it and we ended up
trying to free some garbage pointer.
2011-07-12 14:49:21 +01:00
Damien Lespiau
711a817d8c pipeline: Plug a leak of GLists
_cogl_pipeline_get_layers() allocates a list on the pipeline to be able
to get the pointer valid as long as possible and store that list in the
pipeline object.

You need to free that list when freeing the pipeline.

Signed-off-by: Robert Bragg <robert@linux.intel.com>
2011-07-12 10:52:12 +01:00