Commit Graph

878 Commits

Author SHA1 Message Date
Neil Roberts
d99a8bf694 cogl: Add const to some pointer arguments
Some of the arguments to the material and path functions were taking a
pointer to a CoglColor or an array of floats that was not intended to
be written to but were not marked with const.
2010-06-28 15:25:19 +01:00
Robert Bragg
de1f4885dd material: Avoid possibly reading invalid memory
in _cogl_material_prune_empty_layer_difference we sometimes unref the
given layer before dereferencing it to get a pointer to its parent. This
defers the unref until after we have fetched the parent pointer.
2010-06-24 17:05:26 +01:00
Neil Roberts
e33a94bff4 cogl: Remove cogl-defines.h.in from the driver make files
Commit 7fae8ac051 changed cogl-defines.h.in so there is only a
single copy in clutter/cogl/ instead of one for each driver. However
the old files were still mentioned in the EXTRA_DIST of the
Makefile.am so make distcheck was failing.
2010-06-23 17:44:09 +01:00
Chris Lord
e8e5188484 cogl-path: Disable texture coord arrays before drawing
It was possible that the texture co-ord arrays were left enabled during
stroking, which could possibly cause a crash.
2010-06-23 16:07:00 +01:00
Robert Bragg
857aee2b91 texture-pixmap-x11: don't assume anything about the GLXFBConfig type
A pedantic change to get_fbconfig_for_depth() so that we don't need to
make any assumptions about the GLXFBConfig typedef or what values
we can overload to indicate an invalid config.

get_fbconfig_for_depth() now simply returns FALSE if it fails to find a
config.
2010-06-22 16:53:59 +01:00
Emmanuele Bassi
c0d42cb021 Silence another compiler warning 2010-06-22 14:43:36 +01:00
Neil Roberts
7d206ccdbb cogl-texture-pixmap-x11: Use NULL instead of None for invalid GLXFBConfig
GLXFBConfigs are opaque pointers not XIDs so it doesn't make sense to
return None from get_fbconfig_for_depth. Instead it now returns NULL.
2010-06-22 14:19:59 +01:00
Emmanuele Bassi
0244eccfe3 Silence some compiler warnings 2010-06-22 13:48:53 +01:00
Neil Roberts
8458fb7e20 Add a CoglTexturePixmapX11 texture backend
This is a publicly exposed texture backend to create a texture which
contains the contents of an X11 pixmap. The API is currently marked as
experimental.

The backend internally holds a handle to another texture. All of the
backend virtuals simply redirect to the internal texture.

The texture can optionally be automatically updated if the
automatic_updates parameter is TRUE. If set then Cogl will listen for
damage events on the pixmap and update the texture accordingly.
Alternatively a damage object can be created externally and passed
down to Cogl.

The updates can be performed with XGetImage, XShmGetImage or the
GLX_EXT_texture_pixmap extension. If the TFP extension is used it will
optionally try to create a rectangle texture if the driver does not
support NPOTs or it is forced through the
COGL_PIXMAP_TEXTURE_RECTANGLE or CLUTTER_PIXMAP_TEXTURE_RECTANGLE
environment variables.

If the GLXFBConfig does not support mipmapping then it will fallback
to using X{Shm,}GetImage. It keeps a separate texture around for this
so that it can later start using the TFP texture again if the texture
is later drawn with mipmaps disabled.
2010-06-22 12:22:48 +01:00
Neil Roberts
9c62265939 Add -DCOGL_ENABLE_EXPERIMENTAL_API to Makefiles for Cogl and x11/glx
Cogl and Clutter should be able to use the experimental API so this
adds the required define to the CPPFLAGS in the Makefiles.
2010-06-22 12:22:47 +01:00
Neil Roberts
9d0962098f cogl-defines.h: Add a COGL_HAS_X11 define
This will be defined in cogl-defines.h whenever Cogl is built using a
winsys that supports X11. This implies CoglTexturePixmapX11 will be
available.

To make this work the two separate cogl-defines.h.in files have been
merged into one. The configure script now makes a @COGL_DEFINES@
substitution variable which contains the #define lines to put in
rather than directly having them in the seperate files.
2010-06-22 12:22:47 +01:00
Neil Roberts
16c7d12e6c cogl: Add _cogl_xlib_{,un}trap_errors
This is similar to clutter_x11_{,un}trap_errors except that it stores
the previous trap state in a caller-allocated struct so that it can be
re-entrant.

Make _cogl_xlib_trap_errors re-entrant

(this will be squashed into an earlier commit)
2010-06-22 12:22:47 +01:00
Neil Roberts
6ad668c76b cogl-texture: Avoid premult conversion if the dst format has no alpha
The _cogl_texture_needs_premult_conversion function was already
checking whether the source format had an alpha channel before
returning TRUE, but it also doesn't make sense to do the premult
conversion if the destination format has no alpha. This patch adds
that check in too.
2010-06-22 12:22:47 +01:00
Neil Roberts
31b5beb2c0 cogl: Add the infrastructure for checking for winsys extensions
This adds the framework needed to check for winsys specific extensions
(such as GLX extensions) using a similar mechanism to the
cogl-feature-functions header. There is a separate
cogl-winsys-feature-functions header which will contain macros to list
the extensions and functions. cogl_create_context_winsys now calls
_cogl_feature_check for each of these functions. _cogl_feature_check
has had to be changed to accept the driver prefix as the first
parameter so that it can prepend "GLX" rather than "GL" in this case.
2010-06-22 12:22:43 +01:00
Neil Roberts
9646e85ba7 Pass all Xlib events through Cogl
The Clutter X11 backend now passes all events through
_cogl_xlib_handle_event. This function can now internally be hooked
with _cogl_xlib_add_filter. These are added to a list of callbacks
which are all called in turn by _cogl_xlib_handle_event. This is
intended to be used internally in Cogl by any parts that need to see
Xlib events.

Cogl now also has an internally exposed function to set a pointer to
the Xlib display. This is stored in a global variable. The Clutter X11
backend sets this.

_cogl_xlib_handle_event and _cogl_xlib_set_display can be removed once
Cogl gains a proper window system abstraction.
2010-06-22 12:20:59 +01:00
Neil Roberts
2e5b4a5b81 cogl: Add a struct for winsys-specific data to CoglContext
This creates a separate struct to store the fields of the context that
are specific to the winsys. This is all stored in one file but ideally
this could work more like the CoglContextDriver struct and have a
different header for each winsys.
2010-06-22 11:47:33 +01:00
Neil Roberts
9a1aa08fda cogl: Add an internal CoglTextureRectangle backend
This adds an internal rectangle texture backend which is mostly based
on the CoglTexture2D backend. It will throw assert failures if any
operations are attempted that rectangle textures don't support, such
as mipmapping or hardware repeating.
2010-06-22 11:47:33 +01:00
Neil Roberts
82e63a4753 cogl-texture: Replace the ensure_mipmaps virtual with pre_paint
Instead of the ensure_mipmaps virtual that is only called whenever the
texture is about to be rendered with a min filter that needs the
mipmap, there is now a pre_paint virtual that is always called when
the texture is about to be painted in any way. It has a flags
parameter which is used to specify whether the mipmap will be needed.

This is useful for CoglTexturePixmapX11 because it needs to do stuff
before painting that is unrelated to mipmapping.
2010-06-22 11:47:33 +01:00
Neil Roberts
ebb05bcb64 cogl-texture: List texture subclass types rather than hardcoding them
Instead of having a hardcoded series of if-statements in
cogl_is_texture to determine which types should appear as texture
subclasses, they are now stored in a GSList attached to the Cogl
context. The list is amended to using a new cogl_texture_register_type
function. There is a convenience macro called COGL_TEXTURE_DEFINE
which uses COGL_HANDLE_DEFINE_WITH_CODE to register the texture type
when the _get_type() function is first called.
2010-06-22 11:47:33 +01:00
Neil Roberts
2f286446af Add COGL_{OBJECT,HANDLE}_DEFINE_WITH_CODE
This macro is similar to COGL_HANDLE_DEFINE_WITH_CODE except that it
allows a snippet of code to be inserted into the _get_type()
function. This is similar to how G_DEFINE_TYPE_WITH_CODE
works. COGL_HANDLE_DEFINE is now just a wrapper around
COGL_HANDLE_DEFINE_WITH_CODE.
2010-06-22 11:47:33 +01:00
Neil Roberts
f9f2f6bc6c Add _cogl_texture_2d_externally_modified
_cogl_texture_2d_externally_modified is a function specific to the
CoglTexture2D texture backend that should be called whenever the
contents of the texture are modified without the backend knowing about
it. It simply marks the mipmap tree as invalid.
2010-06-22 11:47:32 +01:00
Neil Roberts
5a5b3914ba cogl: Fix the include path in driver/*/Makefile.am
The include path for the winsys and driver folder was given relative
to $(srcdir) so it would end up relative to the driver folder which is
wrong. It is now specified as $(srcdir)/../../winsys to get the right
location. The driver folder is removed because it is actually just
$(srcdir) and that is already included.
2010-06-22 11:47:32 +01:00
Robert Bragg
0e43647fed gles2: don't disable clip planes for GLES2
GLES2 doesn't provide user clip planes (you would have to use a vertex +
fragment shader to achieve the same kind of result) so we make sure not
to call glEnable/Disable with any of the GL_CLIP_PLANE0..3 defines.

http://bugzilla.o-hand.com/show_bug.cgi?id=2177
2010-06-22 11:35:22 +01:00
Robert Bragg
9234757c35 material: fix a typo in _cogl_material_journal_unref
The function had a line like:

CoglMaterial *material =
    material = _cogl_material_pointer_from_handle (material_handle);

where the duplicate "material =" wasn't intended, so this patch removes
it.
2010-06-22 11:21:09 +01:00
Robert Bragg
c8aae9a663 egl: Consolidates eglx and eglnative into one "egl" winsys
This remove quite a lot of redundant code by consolidating the eglx and
eglnative window system backends.
2010-06-18 17:38:41 +01:00
Neil Roberts
270e1e8188 cogl-context: Use the function pointer for glActiveUnit
Under WGL, any functions that were defined after GL 1.1 are not
directly exported in the DLL so we need to reference them via the
function pointers. A new call to glActiveUnit was missed in
cogl-context.c
2010-06-18 15:34:48 +01:00
Neil Roberts
f95cdfc11e cogl-material: Don't use the symbol 'near'
The window headers contain the line

 #define near

so it's not possible to use the symbol 'near' in code that's portable
to Windows. This replaces it with 'near_val'.

I think the define is meant to improve compatibility with code written
for Windows 3.1 where near would be a keyword to make it a smaller
pointer size.
2010-06-18 15:34:48 +01:00
Richard Hughes
7cd5908ef0 build: Fix a compiler warning when using make dist
Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
2010-06-16 10:43:55 +01:00
Emmanuele Bassi
d3b26f3f4d Set the initial value of a variable
Fixes a compiler warning.
2010-06-15 16:42:30 +01:00
Robert Bragg
c506b58ecf material: Adds arbfp compile counter
This adds a uprof counter to track how many ARBfp programs get compiled
by an application.
2010-06-15 15:26:28 +01:00
Robert Bragg
ba067c3da8 material: Support sparse ARBfp program generation
We don't need to generate a new ARBfp program for every material created
if we can find an ancestor whos state will result in the same program
being generated.

The more code we can have adopt the coding pattern of deriving their
materials from other similar materials using cogl_material_copy() the
more likely this metric will be good enough on its own to minimize the
set of arbfp programs necessary to support a given application.
2010-06-15 15:26:28 +01:00
Robert Bragg
a38e597aaa material: free any layer cache in material_set_parent
Previously in _cogl_material_pre_change_notify we manually freed the
layer caches of a material if we caused a reparent, but it makes more
sense to have _cogl_material_set_parent do this directly instead.
2010-06-15 15:26:28 +01:00
Robert Bragg
92e8fbfdc6 Adds an internal weak material mechanism
This adds a _cogl_material_weak_copy() function that can be used to
create materials that don't count as strong dependants on their parents.
This means the parent can be modified without worrying about how it will
affect weak materials. The material age of the parent can potentially be
queried to determine if a weak material might need to be re-created.
2010-06-15 15:26:28 +01:00
Robert Bragg
9689ec5aad material: Adds a simple material age getter
When we add support for weak materials it's expected that Clutter will
want to attach them as private data to other materials and it needs a
mechanism to determine when a weak material should be re-created because
its parent has changed somehow.

This adds the concept of a material age (internal only currently) which
increments whenever a material is modified. Clutter can then save the
age of the material which its weak materials are derived from and later
determine when the weak material may be invalid.
2010-06-15 15:26:28 +01:00
Robert Bragg
c9702be94e primitives: we were memsetting the wrong wrap mode overrides pointer
In _cogl_texture_quad_multiple_primitives we weren't memsetting the
CoglMaterialWrapModeOverrides structure we were memsetting
&state.wrap_mode_overrides where state.wrap_mode_overrides is just a
pointer that might potentially later point to the
CoglMaterialWrapModeOverrides structure.
2010-06-15 15:26:28 +01:00
Robert Bragg
20910a1215 material: generalize how we compare simple material properties
In _cogl_material_equal we were repeating the same code pattern to
compare several of the state groups so this just adds
simple_property_equal function that's now used instead.
2010-06-15 15:26:28 +01:00
Robert Bragg
dab4ddc718 material: Make CoglMaterial responsible for depth state
This redirects the legacy depth testing APIs through CoglMaterial and
adds a new experimental cogl_material_ API for handling the depth
testing state.

This adds the following new functions:
cogl_material_set_depth_test_enabled
cogl_material_get_depth_test_enabled
cogl_material_set_depth_writing_enabled
cogl_material_get_depth_writing_enabled
cogl_material_set_depth_test_function
cogl_material_get_depth_test_function
cogl_material_set_depth_range
cogl_material_get_depth_range

As with other experimental Cogl API you need to define
COGL_ENABLE_EXPERIMENTAL_API to access them and their stability isn't
yet guaranteed.
2010-06-15 15:26:28 +01:00
Robert Bragg
fca054e949 cogl docs: Improve documentation for cogl_ortho
cogl_ortho is one of those APIs whos style was, for better or worse,
copied from OpenGL and for some inexplicable reason the near and far
arguments are inconsistent with the left, right, top, bottom arguments
because they don't take z coordinates they take a "distance" which
should be negative for a plane behind the viewer.

This updates the documentation to explain this.
2010-06-15 15:26:28 +01:00
Robert Bragg
a5d6c02f7c primitives: no longer assume _get_layers list remains valid
The internal CoglMaterialLayer pointers associated with a material may
change whenever layer properties are modified so it's no longer ok to
assume that a list of layers returned by cogl_material_get_layers
remains valid if the layers have been changed.
2010-06-15 15:26:28 +01:00
Robert Bragg
b57f68245c material: Adds simple breadcrumb debugging mechanism
Since it can sometimes be awkward to figure out where a particular
material came from when debugging, this adds a breadcrumb mechanism that
lets you associate a const string with a material that may give a clue
about its origin.
2010-06-15 15:26:27 +01:00
Robert Bragg
6b5281401c material: remove override options from _cogl_material_equal
As a follow on to using cogl_material_copy instead of flush options this
patch now removes the ability to pass flush options to
_cogl_material_equal which is the final reference to the
CoglMaterialFlushOptions mechanism.
2010-06-15 15:26:27 +01:00
Robert Bragg
3979de6982 cogl: remove _cogl_material_flush_gl_state flush options
Since cogl_material_copy should now be cheap to use we can simplify
how we handle fallbacks and wrap mode overrides etc by simply copying
the original material and making our override changes on the new
material. This avoids the need for a sideband state structure that has
been growing in size and makes flushing material state more complex.

Note the plan is to eventually use weak materials for these override
materials and attach these as private data to the original materials so
we aren't making so many one-shot materials.
2010-06-15 15:26:27 +01:00
Robert Bragg
1cc3ae6944 CoglMaterial: Implements sparse materials design
This is a complete overhaul of the data structures used to manage
CoglMaterial state.

We have these requirements that were aiming to meet:
(Note: the references to "renderlists" correspond to the effort to
support scenegraph level shuffling of Clutter actor primitives so we can
minimize GPU state changes)

Sparse State:
We wanted a design that allows sparse descriptions of state so it scales
well as we make CoglMaterial responsible for more and more state. It
needs to scale well in terms of memory usage and the cost of operations
we need to apply to materials such as comparing, copying and flushing
their state. I.e. we would rather have these things scale by the number
of real changes a material represents not by how much overall state
CoglMaterial becomes responsible for.

Cheap Copies:
As we add support for renderlists in Clutter we will need to be able to
get an immutable handle for a given material's current state so that we
can retain a record of a primitive with its associated material without
worrying that changes to the original material will invalidate that
record.

No more flush override options:
We want to get rid of the flush overrides mechanism we currently use to
deal with texture fallbacks, wrap mode changes and to handle the use of
highlevel CoglTextures that need to be resolved into lowlevel textures
before flushing the material state.

The flush options structure has been expanding in size and the structure
is logged with every journal entry so it is not an approach that scales
well at all. It also makes flushing material state that much more
complex.

Weak Materials:
Again for renderlists we need a way to create materials derived from
other materials but without the strict requirement that modifications to
the original material wont affect the derived ("weak") material. The
only requirement is that its possible to later check if the original
material has been changed.

A summary of the new design:

A CoglMaterial now basically represents a diff against its parent.
Each material has a single parent and a mask of state that it changes.

Each group of state (such as the blending state) has an "authority"
which is found by walking up from a given material through its ancestors
checking the difference mask until a match for that group is found.

There is only one root node to the graph of all materials, which is the
default material first created when Cogl is being initialized.

All the groups of state are divided into two types, such that
infrequently changed state belongs in a separate "BigState" structure
that is only allocated and attached to a material when necessary.

CoglMaterialLayers are another sparse structure. Like CoglMaterials they
represent a diff against their parent and all the layers are part of
another graph with the "default_layer_0" layer being the root node that
Cogl creates during initialization.

Copying a material is now basically just a case of slice allocating a
CoglMaterial, setting the parent to be the source being copied and
zeroing the mask of changes.

Flush overrides should now be handled by simply relying on the cheapness
of copying a material and making changes to it. (This will be done in a
follow on commit)

Weak material support will be added in a follow on commit.
2010-06-15 15:26:27 +01:00
Robert Bragg
6c8b8cef9e material: fix #ifdef guard around use of _TEXTURE_RECTANGLE
We were incorrectly guarding the use of GL_TEXTURE_RECTANGLE_ARB with
ifdef ARB_texture_rectangle instead of ifdef GL_ARB_texture_rectangle
which broke test-cogl-texture-rectangle.
2010-06-15 15:26:27 +01:00
Robert Bragg
26628553ed blend-strings: removes the AUTO_COMPOSITE function enum
This was mistakenly added some time ago because at some point when we
were discussing how to handle premultiplied alpha in Clutter/Cogl we
were considering having a magic "just do the right thing" option which
was later abandoned.
2010-06-15 15:26:27 +01:00
Robert Bragg
99bef3116d cogl-color: add cogl_color_init_from_xyz funcs
This is to try and improve API consistency. Simple cogl structures that
don't derive from CoglObject and which can be allocated on the stack,
such as CoglColor and CoglMatrix should all have  "_init" or
"_init_from" functions to initialize all the structure members. (As
opposed to a cogl_xyz_new() function for CoglObjects). CoglColor
previously used the naming scheme "_set_from" for these initializers but
"_set" is typically reserved for setting individual properties of a
structure/object.

This adds three _init functions:
cogl_color_init_from_4ub
cogl_color_init_from_4f
cogl_color_init_from_4fv

The _set_from functions are now deprecated but only with a gtk-doc
annotation for now. This is because the cogl_color_set_from API is quite
widely used already and so were giving a grace period before enabling a
GCC deprecated warning just because otherwise the MX maintainers will
complain to me that I've made their build logs look messy.
2010-06-15 15:26:27 +01:00
Robert Bragg
49907d6267 cogl-color: add private _cogl_color_get_rgba_4ubv API
The journal logs colors as 4bytes into a vertex array and since we are
planning to make CoglMaterial track its color using a CoglColor instead
of a byte array this convenience will be useful for re-implementing
_cogl_material_get_colorubv.
2010-06-15 15:26:27 +01:00
Emmanuele Bassi
3af1dc18b8 Merge branch 'wip/deform-effect'
* wip/deform-effect:
  docs: Add DeformEffect and PageTurnEffect to the API reference
  effect: Add PageTurnEffect
  effect: Add DeformEffect
  offscreen-effect: Traslate the modelview with the offsets
  docs: Fix Effect subclassing section
2010-06-11 18:12:54 +01:00
Neil Roberts
fcfff3dd04 cogl/winsys/cogl-eglx: Use the right egl header on 1.1
Commit b0cc98fdce introduced a #include for the egl header in
cogl-eglx.c The header name is different under GLES 1.1 so it broke
compilation.
2010-06-11 16:06:31 +01:00
Neil Roberts
cc7722389c cogl-program: Add cogl_program_uniform_1i to GLES
The GLES 1.1 backend was missing a stub for cogl_program_uniform_1i.
2010-06-11 16:06:31 +01:00