1
0
Fork 0
Commit graph

519 commits

Author SHA1 Message Date
Emmanuele Bassi
924780ce35 cogl: Avoid C99-isms
Do not declare variables after statements.
2009-10-23 16:44:28 +01:00
Emmanuele Bassi
b56b26cc62 cogl: Remove cogl-current-matrix.c
The cogl-current-matrix.c file is unused since commit
5e5d94dfbe and it's not compiled
or distributed anymore.
2009-10-23 15:46:25 +01:00
Emmanuele Bassi
24594bcde4 build: Make COGL pass distcheck
Some changes to make COGL pass distcheck with Automake 1.11 and
anal-retentiveness turned up to 11.

The "major" change is the flattening of the winsys/ part of COGL,
which is built directly inside libclutter-cogl.la instead of an
intermediate libclutter-cogl-winsys.la object.

Ideally, the whole COGL should be flattened out using a
quasi-non-recursive Automake layout; unfortunately, the driver/
sub-section ships with identical targets and Automake cannot
distinguish GL and GLES objects.
2009-10-23 13:38:40 +01:00
Neil Roberts
f028744706 Fix some compilation errors in cogl-gles2-wrapper.c
The changes in 74f2122b6 introduced some syntax errors which were
preventing the GLES2 backend from compiling.
2009-10-22 18:04:59 +01:00
Neil Roberts
b82f874b46 Remove cogl/{gl,gles}/Makefile.am
These are no longer used anywhere.
2009-10-22 15:39:30 +01:00
Robert Bragg
74f2122b68 [gles2] remove lots of redundant matrix stack code
Since we no longer depend on the GL matrix API in Cogl we can remove a lot
of wrapper code from the GLES 2 backend.  This is particularly nice given
that there was no code shared between the cogl-matrix-stack API and gles2
wrappers so we had a lot of duplicated logic.
2009-10-20 12:32:51 +01:00
Robert Bragg
5e5d94dfbe [cogl] Removes the cogl-current-matrix abstraction
The indirection through this API isn't necessary since we no longer
arbitrate between the OpenGL matrix API and Cogl's client side API.  Also it
doesn't help to maintain an OpenGL style matrix mode API for internal use
since it's awkward to keep restoring the MODELVIEW mode and easy enough to
directly work with the matrix stacks of interest.

This replaces use of the _cogl_current_matrix API with direct use of the
_cogl_matrix_stack API.  All the unused cogl_current_matrix API is removed
and the matrix utility code left in cogl-current-matrix.c was moved to
cogl.c.
2009-10-20 12:32:50 +01:00
Robert Bragg
9f7bf9fb4d [matrix-stack] Adds ctx->flushed_matrix_mode to cache the gl matrix mode
This cache of the gl matrix mode lets us avoid repeat calls to glMatrixMode
in _cogl_matrix_stack_flush_to_gl when we have lots of sequential modelview
matrix modifications.
2009-10-20 12:32:50 +01:00
Robert Bragg
b1f9f0a97d matrix-stack: more optimization for load_identity case
This goes a bit further than the previous patch, and as a special case
we now simply represent identity matrices using a boolean, and only
lazily initialize them when they need to be modified.
2009-10-20 12:32:50 +01:00
Robert Bragg
460025d603 [matrix-stack] avoid redundant clearing of matrix when using load_identity
The journal always uses an identity matrix since it uses software
transformation.  Currently it manually uses glLoadMatrix since previous
experimentation showed that the cogl-matrix-stack gave bad performance, but
it would be nice to fix performance so we only have to care about one path
for loading matrices.

For the common case where we do:
cogl_matrix_stack_push()
cogl_matrix_stack_load_identity()
we were effectively initializing the matrix 3 times. Once due to use of
g_slice_new0, then we had a cogl_matrix_init_identity in
_cogl_matrix_state_new for good measure, and then finally in
cogl_matrix_stack_load_identity we did another cogl_matrix_init_identity.

We don't use g_slice_new0 anymore, _cogl_matrix_state_new is documented as
not initializing the matrix (instead _cogl_matrix_stack_top_mutable now
takes a boolean to choose if new stack entries should be initialised) and so
we now only initialize once in cogl_matrix_stack_load_identity.
2009-10-20 12:32:49 +01:00
Robert Bragg
2656b569b9 [current-matrix] Adds texture matrix stacks + removes GL matrix API usage
This relates back to an earlier commitment to stop using the OpenGL matrix
API which is considered deprecated. (ref 54159f5a1d)

The new texture matrix stacks are hung from a list of (internal only)
CoglTextureUnit structures which the CoglMaterial code internally references
via _cogl_get_texure_unit ().

So we would be left with only the cogl-matrix-stack code being responsible
for glMatrixMode, glLoadMatrix and glLoadIdentity this commit updates the
journal code so it now uses the matrix-stack API instead of GL directly.
2009-10-20 12:32:45 +01:00
Robert Bragg
ef9ea9e237 [cogl-primitives] Split the journal out from cogl-primitives.c
The Journal can be considered a standalone component, so even though
it's currently only used to log quads, it seems better to split it
out into its own file.
2009-10-16 18:58:52 +01:00
Robert Bragg
2f628b1a8a [cogl-spans] split out cogl-spans code from cogl-texture-2d-sliced
When we implement atlas textures we will probably want to use the spans API
to handle texture repeating so it doesn't make sense to leave the code in
cogl-texture-2d-sliced.c.  Since it's a standalone set of data structures
and algorithms it also seems reasonable to split out from cogl-texture.
2009-10-16 18:58:52 +01:00
Vladimir Nadvornik
568d684187 [cogl-texture] Split CoglTexture into an abstract class + CoglTexture2dSliced
cogl-texture-2d-sliced provides an implementation of CoglTexture and this
seperation lays the foundation for potentially supporting atlas textures,
pixmap textures (as in GLX_EXT_texture_from_pixmap) and fast-path
GL_TEXTURE_{1D,2D,3D,RECTANGLE} textures in a maintainable fashion.
2009-10-16 18:58:51 +01:00
Robert Bragg
9da26fc1ca [cogl-texture] Seal CoglTexture internals from cogl-primitives.c
cogl-primitives.c was previously digging right into CoglTextures so it could
manually iterate the texture slices for texturing quads and polygons and
because we were missing some state getters we were lazily just poking into
the structures directly.

This adds some extra state getter functions, and adds a higher level
_cogl_texture_foreach_slice () API that hopefully simplifies the way in
which sliced textures may be used to render primitives.  This lets you
specify a rectangle in "virtual" texture coords and it will call a given
callback for each slice that intersects that rectangle giving the virtual
coords of the current slice and corresponding "real" texture coordinates for
the underlying gl texture.

At the same time a noteable bug in how we previously iterated sliced
textures was fixed, whereby we weren't correctly handling inverted texture
coordinates.  E.g.  with the previous code if you supplied texture coords of
tx1=100,ty1=0,tx2=0,ty2=100 (inverted along y axis) that would result in a
back-facing quad, which could be discarded if using back-face culling.
2009-10-16 18:58:51 +01:00
Robert Bragg
52cecd50ec [docs] switch gl_handle+gl_target docs for cogl_texture_new_from_foreign
The descriptions for gl_handle and gl_target were inverted.

Thanks to Young-Ho Cha for spotting that.

Signed-off-by: Robert Bragg <robert@linux.intel.com>
2009-10-16 18:58:51 +01:00
Robert Bragg
95a869dab1 [cogl] move clutter/pango to clutter/cogl/pango
As part of the re-organisation of Cogl; move clutter/pango to be part of the
cogl sub-project.
2009-10-16 18:58:51 +01:00
Robert Bragg
43efab46bc Intial Re-layout of the Cogl source code and introduction of a Cogl Winsys
As part of an incremental process to have Cogl be a standalone project we
want to re-consider how we organise the Cogl source code.

Currently this is the structure I'm aiming for:
cogl/
    cogl/
	<put common source here>
	winsys/
	   cogl-glx.c
	   cogl-wgl.c
	driver/
	    gl/
	    gles/
	os/ ?
    utils/
	cogl-fixed
	cogl-matrix-stack?
        cogl-journal?
        cogl-primitives?
    pango/

The new winsys component is a starting point for migrating window system
code (i.e.  x11,glx,wgl,osx,egl etc) from Clutter to Cogl.

The utils/ and pango/ directories aren't added by this commit, but they are
noted because I plan to add them soon.

Overview of the planned structure:

* The winsys/ API is the API that binds OpenGL to a specific window system,
  be that X11 or win32 etc.  Example are glx, wgl and egl. Much of the logic
  under clutter/{glx,osx,win32 etc} should migrate here.

* Note there is also the idea of a winsys-base that may represent a window
  system for which there are multiple winsys APIs.  An example of this is
  x11, since glx and egl may both be used with x11.  (currently only Clutter
  has the idea of a winsys-base)

* The driver/ represents a specific varient of OpenGL. Currently we have "gl"
  representing OpenGL 1.4-2.1 (mostly fixed function) and "gles" representing
  GLES 1.1 (fixed funciton) and 2.0 (fully shader based)

* Everything under cogl/ should fundamentally be supporting access to the
  GPU.  Essentially Cogl's most basic requirement is to provide a nice GPU
  Graphics API and drawing a line between this and the utility functionality
  we add to support Clutter should help keep this lean and maintainable.

* Code under utils/ as suggested builds on cogl/ adding more convenient
  APIs or mechanism to optimize special cases. Broadly speaking you can
  compare cogl/ to OpenGL and utils/ to GLU.

* clutter/pango will be moved to clutter/cogl/pango

How some of the internal configure.ac/pkg-config terminology has changed:
backendextra -> CLUTTER_WINSYS_BASE # e.g. "x11"
backendextralib -> CLUTTER_WINSYS_BASE_LIB # e.g. "x11/libclutter-x11.la"
clutterbackend -> {CLUTTER,COGL}_WINSYS # e.g. "glx"
CLUTTER_FLAVOUR -> {CLUTTER,COGL}_WINSYS
clutterbackendlib -> CLUTTER_WINSYS_LIB
CLUTTER_COGL -> COGL_DRIVER # e.g. "gl"

Note: The CLUTTER_FLAVOUR and CLUTTER_COGL defines are kept for apps

As the first thing to take advantage of the new winsys component in Cogl;
cogl_get_proc_address() has been moved from cogl/{gl,gles}/cogl.c into
cogl/common/cogl.c and this common implementation first trys
_cogl_winsys_get_proc_address() but if that fails then it falls back to
gmodule.
2009-10-16 18:58:50 +01:00
Robert Bragg
2eea83de75 Make the CoglContext structure a bit more maintainable
This moves most of cogl-context.{c.h} to cogl/common with some driver
specific members now living in a CoglContextDriver struct.  Driver specific
context initialization and typedefs now live in
cogl/{gl,gles}/cogl-context-driver.{c,h}

Driver specific members can be found under ctx->drv.stuff
2009-10-16 18:58:49 +01:00
Robert Bragg
157eb437ba Improve cogl-texture maintainability by moving 90% into cogl/common
This splits the limited components that differed between
cogl/{gl,gles}/cogl-texture.c into new {gl,gles}/cogl-texture-driver.c files
and the rest that can now be shared into cogl/common/cogl-texture.c
2009-10-16 18:58:49 +01:00
Robert Bragg
ab76d64df0 [cogl-debug] avoid warnings when using COGL_NOTE with unbraced else clauses
When not building a debug build the compiler was warning about empty
else clauses with no braces due to code like:
  if (blah)
	do_foo();
  else
	COGL_NOTE (DRAW, "a-wibble");

This simply ensures that even for non debug builds COGL_NOTE will expand to
a single statement.
2009-09-24 21:41:50 +01:00
Robert Bragg
904c495c6d [cogl-vertex-buffer] fix n_components validation for GL's builtin attributes
glVertexPointer expects positions with 2, 3 or 4 components, glColorPointer
expects colors with 3 or 4 components and glNormalPointer expects normals
with three components so when adding vertex buffer atributes with the names
"gl_Vertex", "gl_Color" or "gl_Normal" we assert these constraints and print
an explanation to the developer if not met.

This also fixes the previosly incorrect constraint that gl_Normal attributes
must have n_components == 1; thanks to Cat Sidhe for reporting this:

Bug: http://bugzilla.openedhand.com/show_bug.cgi?id=1819
2009-09-24 21:41:50 +01:00
Damien Lespiau
6e50e26c86 Add a few annotations on Cogl primitives functions
By default, float * is considered as an out argument by gobject
introspection which is wrong for quite a few Cogl symbols. Start adding
annotations to fix that for the ones in the "Primitives" gtk-doc
section.
2009-09-21 18:40:20 +01:00
Neil Roberts
1c3d5a0e87 [cogl] Remove CoglContext->journal_vbo{,_len}
The lifetime of the journal VBO is entirely within the scope of the
cogl_journal_flush function so there is no need to store it globally
in the Cogl context. Instead, upload_vertices_to_vbo just returns the
new VBO. cogl_journal_flush stores this in a local variable and
destroys it before returning.

This also fixes an assertion when using the GLES backend which was
caused by nothing initialising the journal_vbo variable.
2009-09-17 18:30:55 +01:00
Emmanuele Bassi
ecfa0c4f92 [build] Split out the custom silent rules
The silent rules we use for custom targets should be moved into a
separate Makefile.am that gets included from all the others.
2009-09-16 17:47:59 +01:00
Robert Bragg
0d08f6e070 [cogl-fbo] Disable mipmap filters before calling glCheckFramebufferStatusEXT
The framebuffer_object spec isn't clear in defining whether attaching a
texture as a renderbuffer with mipmap filtering enabled while the mipmaps
have not been uploaded should result in an incomplete framebuffer object.
(different drivers make different decisions)

To avoid an error with drivers that do consider this a problem we explicitly
set non mipmapped filters before calling glCheckFramebufferStatusEXT.  The
filters will later be reset when the texture is actually used for rendering
according to the filters set on the corresponding CoglMaterial.
2009-09-15 17:54:07 +01:00
Emmanuele Bassi
742cc4d95b [docs] Small annotation fixes 2009-09-08 10:21:46 +01:00
Samuel Degrande
763f5a9d01 DOT3_RGB[A] cannot be used in a Blend String
The blend string compiler checks that the syntax of a function name is
[A-Za-z_]*, preventing the use of DOT3_RGB[A].

Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
2009-09-02 16:27:22 +01:00
Neil Roberts
4ca375e8fe [cogl-texture] Set GL_PACK_ROW_LENGTH when downloading texture data
Otherwise the rowstride passed in from an application is not used
correctly so you can not download to an area with a much larger
rowstride.
2009-08-24 12:50:57 +01:00
Robert Bragg
56daae9d7b Revert "[cogl] Allow Cogl to create NPOT textures for GLES2"
This reverts commit 3c47a3beb5.

Of course I remembered just after pushing the patch why we hadn't done
this before :-) If you look in the glsl spec:
http://www.khronos.org/registry/gles/specs/2.0/es_full_spec_2.0.24.pdf
Section 3.7.10 Texture Completeness and Non-Power-Of-Two Textures
you can see GLES 2.0 doesn't support mipmaps for npot textures.

There is possibly some way we could support this in Cogl but at least
it's not as simple as or-ing in the feature flag, sadly.
2009-08-20 12:53:32 +01:00
Robert Bragg
3c47a3beb5 [cogl] Allow Cogl to create NPOT textures for GLES2
The core GLES2 API supports NPOT textures, i.e. there is no extension as for
OpenGL, so we now add COGL_FEATURE_TEXTURE_NPOT to the feature flags in
_cogl_features_init.

Thanks to Gordon Williams for spotting this.
2009-08-20 12:17:56 +01:00
Robert Bragg
a5fe4ae4ec [cogl] %.c: %.glsl codegen: use BUILT_SOURCES var + fix stringify.sh
Don't let stringify.sh write to the $srcdir + use the BUILT_SOURCES var in
Makefile.am so as to ensure all .c.  and .h files get generated from their
corresponding .glsl files before building other targets.
2009-08-19 15:43:20 +01:00
Emmanuele Bassi
373b165b3f Use AM_SILENT_RULES if automake >= 1.11 is installed
Fixes bug:

  http://bugzilla.openedhand.com/show_bug.cgi?id=1756

Based on a patch by: Javier Jardón <javierjc1982@gmail.com>
2009-08-19 13:42:36 +01:00
Robert Bragg
9befb055d0 [cogl-material] Fix some brackets in _layer_flush_gl_sampler_state
The wrong part of an expression was bracketed in the test to determine
when a new texture matrix needed to be loaded which resulted in the
first pass through _cogl_material_layer_flush_gl_sampler_state
not uploading any user matrix.
2009-08-18 16:57:38 +01:00
Emmanuele Bassi
366e0725ce [docs] texture_polygon() is called polygon()
Remove the mentions to the old name of cogl_polygon().
2009-08-18 11:11:29 +01:00
Götz Waschk
366e0f9cd7 Update Clutter to use G-I 0.6.4
Following bug #1762, the syntax of g-ir-scanner was changed in
gobject-introspection, so Clutter does not build anymore with 0.6.4.

See the bugzilla bug:

  http://bugzilla.gnome.org/show_bug.cgi?id=591669

GObject-Introspection now uses a different mechanism to extract the
SONAME when building the gir file and it needs the libtool archive as
option.

Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
2009-08-17 14:14:18 +01:00
zhou jiangwei
2ab9bef587 [cogl] Fix the GLES 2.0 backend
Update the GLES 2.0 backend to the new COGL API after the breakage
introduced by the journal.

Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
2009-08-11 14:19:24 +01:00
Robert Bragg
dbfd3f0f44 [cogl_clear] Also pass the alpha component of the CoglColor to glClearColor
Previously we were passing a constant of 0.0 for the alpha component which
wasn't as flexible.
2009-08-11 14:15:44 +01:00
Emmanuele Bassi
79288b46ed [docs] Fix a missing parameter 2009-08-04 11:38:48 +01:00
Emmanuele Bassi
f8a964b422 [cogl] Expose cogl_is_vertex_buffer()
The function is public and available in the shared object, but
it's not present in the header, so this is not an API/ABI change.
2009-08-04 11:15:05 +01:00
Emmanuele Bassi
77fdd7494e Fix compiler warnings when COGL debug level=minimum 2009-07-28 13:57:46 +01:00
Ole André Vadla Ravnås
a1cef026c5 Avoid near/far identifier names.
Leads to conflict with system headers on Windows, where macros named
"near" and "far" are defined.
2009-07-28 12:13:44 +01:00
Ole André Vadla Ravnås
0157851270 Call glClientActiveTexture() through COGL context.
Fixes build issues on systems with OpenGL header older than 1.3.
2009-07-28 12:13:43 +01:00
Ole André Vadla Ravnås
f61f66c6fe Avoid C99 to fix compilation with compilers like MSVC. 2009-07-28 12:13:43 +01:00
Haakon Sporsheim
e4eed92177 Reposition variable declarations to avoid C99. 2009-07-28 12:13:42 +01:00
Emmanuele Bassi
b1d98c25f4 [doc] Miscellaneous documentation fixes
Remove private symbols, and add missing public ones.
2009-07-20 12:49:35 +01:00
Emmanuele Bassi
cdb239756b [cogl] Make the blend string error domain public
The error domain and codes must present in a publicly installed header
otherwise they won't be usable to match a GError.
2009-07-20 12:47:53 +01:00
Robert Bragg
da37e1e27d [doc] Remove references to cogl_vertex_buffer_delete_indices
These referencese were left over from before indices got CoglHandles to
uniquely identify them.  cogl_handle_unref can be used to delete indices
now.
2009-07-19 10:23:00 +01:00
Emmanuele Bassi
dc0b1cddf5 [cogl/gles] Fix missing symbols in CoglContext
Keep the CoglContext in sync between GL and GLES backends. We ought
to find a way to have a generic context, though, and have backend
specific sections.

Fixes bug:

  http://bugzilla.openedhand.com/show_bug.cgi?id=1698
2009-07-18 16:59:54 +01:00
Owen W. Taylor
7654ef10ab Fix building introspection when dolt is not in use
On some platforms (anything but Linux, and on obscure Linux
architectures) dolt isn't used, so $(top_builddir)/doltlibtool
won't exist. $(top_builddir)/libtool will always be generated
even if dolt is used, so just use that unconditionally. We don't
need the extra speed when linking the single program for
introspection.

http://bugzilla.openedhand.com/show_bug.cgi?id=1699

Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
2009-07-18 16:52:57 +01:00
Evan Martin
ea56a5e7a8 [docs] Fix typos and remove mentions of SVN
Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
2009-07-12 01:38:40 +01:00
Robert Bragg
1920b03381 [cogl] Fix more brokeness with _cogl_material_equal
commit e2c4a2a9f8 fixed one thing but broke many others things :-/
hopfully this fixes that.

It turned out that the journal was mistakenly setting the OVERRIDE_LAYER0
flush option for all entries, but some other logic errors were also
uncovered in _cogl_material_equal.
2009-07-10 19:00:16 +01:00
Robert Bragg
e2c4a2a9f8 [cogl] Fix drawing with sliced textures using material layer0 overrides
To help us handle sliced textures; When flushing materials there is an
override option that can be given to replace the texture name for layer0
so we may iterate the slices without needing to modify the material
in use.

Since improving the journal's ability to batch state changes we added a
_cogl_material_equals function that is used by the journal to compare
materials and identify when a state change is required, but this wasn't
correctly considering the layer0 override resulting in false positives that
meant the journal wouldn't update the GL state and the first texture name
was used for all slices.
2009-07-07 10:34:37 +01:00
Robert Bragg
df4429462f [cogl matrix stack] Create a client side matrix stack for the projection matrix
The cost of glGetFloatv with Mesa is still representing a majority of our
time in OpenGL for some applications, and the last thing left using this is
the current-matrix API when getting the projection matrix.

This adds a matrix stack for the projection matrix, so all getting, setting
and modification of the projection matrix is now managed by Cogl and it's only
when we come to draw that we flush changes to the matrix to OpenGL.

This also brings us closer to being able to drop internal use of the
deprecated OpenGL matrix functions, re: commit 54159f5a1d
2009-07-07 10:32:56 +01:00
Emmanuele Bassi
0414daf0fb Split the typdef to avoid confusing scanners
Scanners like gtk-doc and g-ir-scanner get confused by:

  typedef struct _Foo {
    ...
  } Foo;

And expect instead:

  typedef struct _Foo Foo;

  struct _Foo {
    ...
  };

CoglMatrix definition should be changed to avoid the former type.
2009-07-01 15:30:21 +01:00
Emmanuele Bassi
3726213291 Add debug notes for calls to glViewport()
In order to validate the sequence of:

        XResizeWindow
        ConfigureNotify
        glViewport

that should happen on X11 we need to add debug annotations to the
calls to glViewport() done through COGL.
2009-07-01 15:30:18 +01:00
Robert Bragg
3bab787103 [cogl] cache the viewport width and height
This avoids some calls to glGetFloatv, which have at least proven to be very
in-efficient in mesa at this point in time, since it always updates all derived
state even when it may not relate to the state being requested.
2009-07-01 15:23:10 +01:00
Robert Bragg
358d7c30dc [cogl] Ensure well defined semantics for COGL_INVALID_HANDLE material layers
Fixes and adds a unit test for creating and drawing using materials with
COGL_INVALID_HANDLE texture layers.

This may be valid if for example the user has set a texture combine string
that only references a constant color.

_cogl_material_flush_layers_gl_state will bind the fallback texture for any
COGL_INVALID_HANDLE layer, later though we could explicitly check when the
current blend mode does't actually reference a texture source in which case
binding the fallback texture is redundant.

This tests drawing using cogl_rectangle, cogl_polygon and
cogl_vertex_buffer_draw.
2009-06-30 17:35:07 +01:00
Robert Bragg
33400c0aae [cogl] Improve ability to break out into raw OpenGL via begin/end mechanism
Although we wouldn't recommend developers try and interleve OpenGL drawing
with Cogl drawing - we would prefer patches that improve Cogl to avoid this
if possible - we are providing a simple mechanism that will at least give
developers a fighting chance if they find it necissary.

Note: we aren't helping developers change OpenGL state to modify the
behaviour of Cogl drawing functions - it's unlikley that can ever be
reliably supported - but if they are trying to do something like:

   - setup some OpenGL state.
   - draw using OpenGL (e.g. glDrawArrays() )
   - reset modified OpenGL state.
   - continue using Cogl to draw

They should surround their blocks of raw OpenGL with cogl_begin_gl() and
cogl_end_gl():

   cogl_begin_gl ();
   - setup some OpenGL state.
   - draw using OpenGL (e.g. glDrawArrays() )
   - reset modified OpenGL state.
   cogl_end_gl ();
   - continue using Cogl to draw

Again; we aren't supporting code like this:
   - setup some OpenGL state.
   - use Cogl to draw
   - reset modified OpenGL state.
When the internals of Cogl evolves, this is very liable to break.

cogl_begin_gl() will flush all internally batched Cogl primitives, and emit
all internal Cogl state to OpenGL as if it were going to draw something
itself.

The result is that the OpenGL modelview matrix will be setup; the state
corresponding to the current source material will be setup and other world
state such as backface culling, depth and fogging enabledness will be also
be sent to OpenGL.

Note: no special material state is flushed, so if developers want Cogl to setup
a simplified material state it is the their responsibility to set a simple
source material before calling cogl_begin_gl. E.g. by calling
cogl_set_source_color4ub().

Note: It is the developers responsibility to restore any OpenGL state that they
modify to how it was after calling cogl_begin_gl() if they don't do this then
the result of further Cogl calls is undefined.
2009-06-30 17:13:38 +01:00
Robert Bragg
6d9498da7c Adds a cogl_flush() to give developers breaking into raw GL a fighting chance
This function should only need to be called in exceptional circumstances
since Cogl can normally determine internally when a flush is necessary.

As an optimization Cogl drawing functions may batch up primitives
internally, so if you are trying to use raw GL outside of Cogl you stand a
better chance of being successful if you ask Cogl to flush any batched
geometry before making your state changes.

cogl_flush() ensures that the underlying driver is issued all the commands
necessary to draw the batched primitives.  It provides no guarantees about
when the driver will complete the rendering.

This provides no guarantees about the GL state upon returning and to avoid
confusing Cogl you should aim to restore any changes you make before
resuming use of Cogl.

If you are making state changes with the intention of affecting Cogl drawing
primitives you are 100% on your own since you stand a good chance of
conflicting with Cogl internals.  For example clutter-gst which currently
uses direct GL calls to bind ARBfp programs will very likely break when Cogl
starts to use ARBfb programs internally for the material API, but for now it
can use cogl_flush() to at least ensure that the ARBfp program isn't applied
to additional primitives.

This does not provide a robust generalized solution supporting safe use of
raw GL, its use is very much discouraged.
2009-06-30 17:13:38 +01:00
Robert Bragg
87f99e214a [cogl-material] Be more carefull about flushing in cogl_material_remove_layer
Previously we would call _cogl_material_pre_change_notify unconditionally, but
now we wait until we really know we are removing a layer before notifying the
change, which will require a journal flush.

Since the convenience functions cogl_set_source_color4ub and
cogl_set_source_texture share a single material, cogl_set_source_color4ub
always calls cogl_material_remove_layer.  Often this is a NOP though and
shouldn't require a journal flush.

This gets performance back to where it was before reverting the per-actor
material commits.
2009-06-30 17:13:38 +01:00
Robert Bragg
8b67916cc1 [cogl-vertex-buffer] Disable unused client tex coord arrays
Before any cogl vertex buffer drawing we call
enable_state_for_drawing_buffer which sets up the GL state, but we weren't
disabling unsed client texture coord arrays.
2009-06-30 17:13:37 +01:00
Robert Bragg
8873c6a11a [cogl] disable all client tex coord arrays in _cogl_add_path_to_stencil_buffer
After flushing the journal an unknown number of client side texture arrays
may be left enabled. Disable them all before using glDrawArrays.
2009-06-30 17:13:37 +01:00
Robert Bragg
ca0a0e9dac [cogl] flush matrices in _cogl_add_path_to_stencil_buffer
Before calling glRectf we need to ensure we flush the modelview and
projection matrices.
2009-06-30 17:13:37 +01:00
Robert Bragg
f386b1f002 [journal] Don't resize a singlton VBO; create and destroy a VBO each flush
This simplifies the vertex data uploading in the journal, and could improve
performance.  Modifying a VBO mid-scene could reqire synchronizing with the
GPU or some form of shadowing/copying to avoid modifying data that the GPU
is currently processing; the buffer was also being marked as GL_STATIC_DRAW
which could have made things worse.

Now we simply create a GL_STATIC_DRAW VBO for each flush and and delete it
when we are finished.
2009-06-30 17:13:37 +01:00
Robert Bragg
7b7787b050 [cogl] avoid using the journal in _cogl_add_path_to_stencil_buffer
Using cogl_rectangle (and thus the journal) in
_cogl_add_path_to_stencil_buffer means we have to consider all the state
that the journal may change in case it may interfer with the direct GL calls
used.  This has proven to be error prone and in this case the journal is an
unnecissary overhead.  We now simply call glRectf instead of using
cogl_rectangle.
2009-06-30 17:13:37 +01:00
Robert Bragg
6ac3b5a564 [material] _cogl_material_equal: catch the simplest case of matching handles
We were missing the simplest test of all: are the two CoglHandles equal and
are the flush option flags for each material equal?  This should improve
batching for some common cases.
2009-06-30 17:13:36 +01:00
Robert Bragg
9afa52f056 [material] avoid flushing the journal when just changing the color
Whenever we modify a material we call _cogl_material_pre_change_notify which
checks to see if the material is referenced by the journal and if so flushes
if before we modify the material.

Since the journal logs material colors directly into a vertex array (to
avoid us repeatedly calling glColor) then we know we never need to flush
the journal when material colors change.
2009-06-30 17:13:36 +01:00
Robert Bragg
efbf483d8c [cogl journal] Perform software modelview transform on logged quads.
Since most Clutter actors aren't much more than textured quads; flushing the
journal typically involves lots of 'change modelview; draw quad' sequences.

The amount of overhead involved in uploading a new modelview and queuing
that primitive is huge in comparison to simply transforming 4 vertices by
the current modelview when logging quads.  (Note if your GPU supports HW
vertex transform, then it still does the projective and viewport transforms)

At the same time a --cogl-debug=disable-software-transform option has been
added for comparison and debugging.

This change allows typical pick scenes to be batched into a single draw call
and I'm seeing test-pick run over 200% faster with this.  (i965 + Mesa
7.6-devel)
2009-06-30 17:13:36 +01:00
Robert Bragg
612a1e2dea [Cogl journal] use G_UNLIKLEY around runtime debugging conditions
May as well improve the branch prediction around runtime debugging code.
2009-06-30 17:13:36 +01:00
Robert Bragg
7d1876fd26 [cogl journal] Adds a --cogl-debug=batching option to trace batching
Enabling this option makes Cogl trace how the journal is managing to batch
your rectangles.  The journal staggers how it emmits state to the GL driver
and the batches will normally get smaller for each stage, but ideally you
don't want to be in a situation where Cogl is only able to draw one quad per
modelview change and draw call.

E.g. this is a fairly ideal example:
BATCHING: journal len = 101
BATCHING:  vbo offset batch len = 101
BATCHING:   material batch len = 101
BATCHING:    modelview batch len = 101

This isn't:
BATCHING: journal len = 1
BATCHING:  vbo offset batch len = 1
BATCHING:   material batch len = 1
BATCHING:    modelview batch len = 1
BATCHING: journal len = 1
BATCHING:  vbo offset batch len = 1
BATCHING:   material batch len = 1
BATCHING:    modelview batch len = 1
<repeat>
2009-06-30 17:13:36 +01:00
Robert Bragg
d03e6cfb2c [Cogl journal] Adds a --cogl-debug=journal option for tracing the journal
When this option is used Cogl will print a trace of all quads that get
logged into the journal, and a trace of quads as they get flushed.

If you are seeing a bug with the geometry being drawn by Cogl this may give
some clues by letting you sanity check the numbers being logged vs the
numbers being emitted.
2009-06-30 17:13:35 +01:00
Robert Bragg
3ea7816499 [cogl] Adds a debug option for disabling use of VBOs --cogl-debug=disable-vbos
For testing the VBO fallback paths it helps to be able to disable the
COGL_FEATURE_VBOS feature flag.  When VBOs aren't available Cogl should use
client side malloc()'d buffers instead.
2009-06-30 17:13:35 +01:00
Robert Bragg
54159f5a1d [cogl] Force Cogl to always use the client side matrix stack
Previously we only used the Cogl matrix stack API for indirect contexts, but
it's too costly to keep on requesting modelview matrices from GL (for
logging in the journal) even for direct rendering.

I also experimented with a patch for mesa to improve performance and
discussed this with upstream, but we agreed to consider the GL matrix API
essentially deprecated.  (For reference the GLES 2 and GL 3 specs have
removed the matrix APIs)
2009-06-30 17:13:35 +01:00
Robert Bragg
713af6535d [cogl-debug] Adds a "client-side-matrices" Cogl debug option
This allows us to force Cogl to use the client side matrix stack even when
direct rendering.
2009-06-30 17:13:35 +01:00
Robert Bragg
a8be68c83c [cogl-color] Adds a cogl_color_equal() function
CoglColors shouldn't be compared using memcmp since they may contain
uninitialized padding bytes.

The prototype is also suitable for passing to g_hash_table_new as the
key_equal_func.

_cogl_pango_display_list_add_texture now uses this instead of memcmp.
2009-06-30 17:13:35 +01:00
Robert Bragg
aca1bf4329 [cogl material] optimize logging of material colors in the journal
We now put the color of materials into the vertex array used by the journal
instead of calling glColor() but the number of requests for the material
color were quite expensive so we have changed the material color to
internally be byte components instead of floats to avoid repeat conversions
and added _cogl_material_get_colorubv as a fast-path for the journal to
copy data into the vertex array.
2009-06-30 17:13:35 +01:00
Robert Bragg
40cfaeaffc [journal] Always pad our vertex data as if at least 2 layers are enabled
The number of material layers enabled when logging a quad in the journal
determines the stride of the corresponding vertex data (since we need a set
of texture coordinates for each layer.) By padding data in the case where we
have only one layer we can avoid a change in stride if we are mixing single
and double layer primitives in a scene (e.g.  relevent for a composite
manager that may use 2 layers for all shaped windows) Avoiding stride
changes means we can minimize calls to gl{Vertex,Color}Pointer when flushing
the journal.

Since we need to update the texcoord pointers when the actual number of
layers changes, this adds another batch_and_call() stage to deal with
glTexCoordPointer and enabling/disabling the client arrays.
2009-06-30 17:13:34 +01:00
Robert Bragg
845ff67301 [cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e.  the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry.  In ideal circumstances we will only flush once per scene.

In summary the journal works like this:

When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal.  A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix.  Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:

- modifying materials mid-scene
    This is because each quad in the journal has an associated material
    reference (i.e. not copy), so if you try and modify a material that is
    already referenced in the journal we force a flush first)

    NOTE: For now this means you should avoid using cogl_set_source_color()
	      since that currently uses a single shared material. Later we
	  should change it to use a pool of materials that is recycled
	  when the journal is flushed.

- modifying any state that isn't currently logged, such as depth, fog and
  backface culling enables.

The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.

We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together.  This is
currently broken up into 3 levels so we can stagger the state changes:

1) we break the journal up according to changes in the number of material layers
   associated with logged quads. The number of layers in a material determines
   the stride of the associated vertices, so we have to update our vertex
   array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
   materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
   we update the modelview matrix and actually emit the actual draw command.

This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-30 17:13:34 +01:00
Robert Bragg
722360774c [clip-stack] Use signed integers while combining window space clip rectangles
Use signed integers while combining window space clip rectangles, so we avoid
arithmatic errors later resulting in glScissor getting negative width and
height arguments.
2009-06-30 10:16:29 +01:00
Robert Bragg
d63cda3b76 [cogl] Remove unused ctx->polygon_vertices array
This array used to be used by cogl_polygon but was changed to use
ctx->logged_vertices some time ago.
2009-06-29 23:49:07 +01:00
Robert Bragg
30f13cafc5 [cogl] Give the default (fallback) texture a format of RGBA_8888_PRE
Previously this was RGBA_8888. It souldn't really make a difference but for
consistency we expect almost all textures in use to have an internaly
premultiplied pixel format.
2009-06-29 23:49:07 +01:00
Robert Bragg
4680b34046 [cogl-texture] use the right format when downloading sliced textures from GL
_cogl_texture_download_from_gl needs to create transient CoglBitmaps when
downloading sliced textures from GL, and then copies these as subregions
into the final target_bitmap. _cogl_texture_download_from_gl also supports
target_bitmaps with a different format to the source CoglTexture being
downloaded.

The problem was that in the case of slice textures we were always looking
at the format of the CoglTexture, not of the target_bitmap when setting
up the transient slice bitmap.
2009-06-29 23:49:07 +01:00
Robert Bragg
24ca92951f [cogl] Adds cogl_read_pixels to replace direct use of glReadPixels
To allow for flushing of batched geometry within Cogl we can't support users
directly calling glReadPixels.  glReadPixels is also awkward, not least
because it returns upside down image data.

All the unit tests have been swithed over and clutter_stage_read_pixels now
sits on top of this too.
2009-06-29 23:49:06 +01:00
Robert Bragg
27fff12a6a [cogl matrix] Adds ability to dirty state cached by the client matrix apis
To be able to load matrices to GL manually within Cogl we need a way to
dirty the state cached by the client matrix stack API.
2009-06-29 23:49:06 +01:00
Robert Bragg
56bc54d242 [cogl_polygon] fixes a buffer overrun and color format bug
We were calculating our vertex stride and allocating our vertex array
differently depending on whether the user passed TRUE for use_color or not.
The problem was that we were always writting color data to the array
regardless of use_color.

There was also a bug with _cogl_texture_sliced_polygon in that it was
writing byte color components but we were expecting float components.  We
now use byte components in _cogl_multitexture_unsliced_polygon too and pass
GL_UNSIGNED_BYTE to glColorPointer.
2009-06-29 23:49:06 +01:00
Robert Bragg
8f734ccbb4 [vertex-buffer] Add cogl_vertex_buffer_indices_get_type API
cogl_vertex_buffer_indices lets you query back the data type used for the
given indices handle.
2009-06-29 23:49:05 +01:00
Robert Bragg
555159776b [vertex-buffer] Remove the COGL_INDICES_TYPE_UNSIGNED_INT indicies type
Since some embedded GPUs may not support 32bit integer indices we wont
include it until there is a particular need.
2009-06-29 23:49:05 +01:00
Damien Lespiau
a66f027c61 [cogl] Add COGL_HAS_GL and COGL_HAS_GLES
Cogl already add similar defines but with the CLUTTER namespace
(CLUTTER_COGL_HAS_GL and CLUTTER_COGL_HAS_GLES). Let's just add two
similar defines with the COGL namespace. Removing the CLUTTER_COGL ones
could break applications silently for no real good reason.
2009-06-29 21:37:02 +02:00
Damien Lespiau
3653a9a64d Public headers should not have #ifdefs relying on private defines
HAVE_COGL_GLES2 is defined in config.h through the configure script and
should not be used in public headers.

The patch makes configure generate the right define that can be used
later in the header.
2009-06-19 06:43:34 +01:00
Colin Walters
63c84c46f8 Plug minor memory leak in cogl_vertex_buffer_submit_real
Free a temporary list.
2009-06-16 15:46:51 +01:00
Emmanuele Bassi
0415d62d40 Disable single header inclusion for GLib
In order to be ready for the next major version of GLib we need to
disable single header inclusion by using the G_DISABLE_SINGLE_INCLUDES
define in the build process.
2009-06-15 11:29:37 +01:00
Robert Bragg
9d82995773 [_cogl_texture_bitmap_prepare] use bitmap format for FORMAT_ANY + no alpha
My patch to choose a premultiplied format when the user gives
COGL_PIXEL_FORMAT_ANY for the internal_format broke the case where the data
in question doesn't have and alpha channel.

This was accidentally missed when merging the premultiplication branch
since I merged a local version of the branch that missed this commit.
2009-06-11 18:49:30 +01:00
Robert Bragg
71b62e75d2 [cogl] Don't allow calling cogl_set_source_texture with an INVALID_HANDLE
Although the underlying materials should allow layers with INVALID_HANDLES
it shouldn't be necissary to expose that via cogl_set_source_texture() and
it's easier to resolve a warning/crash here than odd artefacts/crashes later
in the pipeline.
2009-06-11 16:28:01 +01:00
Robert Bragg
96827db740 Bug 1406 - Handling of premultiplication in clutter
Merge branch 'premultiplication'

[cogl-texture docs] Improves the documentation of the internal_format args
[test-premult] Adds a unit test for texture upload premultiplication semantics
[fog] Document that fogging only works with opaque or unmultipled colors
[test-blend-strings] Explicitly request RGBA_888 tex format for test textures
[premultiplication] Be more conservative with what data gets premultiplied
[bitmap] Fixes _cogl_bitmap_fallback_unpremult
[cogl-bitmap] Fix minor copy and paste error in _cogl_bitmap_fallback_premult
Avoid unnecesary unpremultiplication when saving to local data
Don't unpremultiply Cairo data
Default to a blend function that expects premultiplied colors
Implement premultiplication for CoglBitmap
Use correct texture format for pixmap textures and FBO's
Add cogl_color_premultiply()
2009-06-11 16:00:28 +01:00
Robert Bragg
ec77b91398 [cogl-texture docs] Improves the documentation of the internal_format args
Clarifies that if you give COGL_PIXEL_FORMAT_ANY as the internal format for
cogl_texture_new_from_file or cogl_texture_new_from_data then Cogl will
choose a premultiplied internal format.
2009-06-11 14:31:01 +01:00
Robert Bragg
70636b4815 [fog] Document that fogging only works with opaque or unmultipled colors
The fixed function fogging provided by OpenGL only works with unmultiplied
colors (or if the color has an alpha of 1.0) so since we now premultiply
textures and colors by default a note to this affect has been added to
clutter_stage_set_fog and cogl_set_fog.

test-depth.c no longer uses clutter_stage_set_fog for this reason.

In the future when we can depend on fragment shaders we should also be
able to support fogging of premultiplied primitives.
2009-06-11 14:17:53 +01:00
Robert Bragg
a9b011f3ed [premultiplication] Be more conservative with what data gets premultiplied
We don't want to force texture data to be premultipled if the user
explicitly specifies a non premultiplied internal_format such as
COGL_PIXEL_FORMAT_RGBA_8888.  So now Cogl will only automatically
premultiply data when COGL_PIXEL_FORMAT_ANY is given for the
internal_format, or a premultiplied internal format such as
COGL_PIXEL_FORMAT_RGBA_8888_PRE is requested but non-premultiplied source
data is given.

This approach is consistent with OpenVG image formats which have already
influenced Cogl's pixel format semantics.
2009-06-11 14:17:53 +01:00
Robert Bragg
9d3aa57604 [bitmap] Fixes _cogl_bitmap_fallback_unpremult
The _cogl_unpremult_alpha_{first,last} functions which
_cogl_bitmap_fallback_unpremult depends on were incorrectly casting each
of the byte components of a texel to a gulong and performing shifts as
if it were dealing with the whole texel.

It now just uses array indexing to access the byte components without
needing to cast or manually shift any bits around.

Even though we used to depend on unpremult whenever we used a
ClutterCairoTexture, clutter_cairo_texture_context_destroy had it's own
unpremult code which worked which is why this bug wouldn't have been noticed
before.
2009-06-11 14:17:52 +01:00
Robert Bragg
cb959ef457 [cogl-bitmap] Fix minor copy and paste error in _cogl_bitmap_fallback_premult
The returned bitmap format should include the COGL_PREMULT_BIT flag not
have it explicitly removed as for _cogl_bitmap_fallback_unpremult.
2009-06-11 14:17:52 +01:00