1
0
Fork 0
Commit graph

1511 commits

Author SHA1 Message Date
Neil Roberts
0e168ed0aa Fix the header guards for cogl-texture-2d{,-private}.h
The header guard for cogl-texture-2d-private.h was
__COGL_TEXTURE_2D_H. This would conflict with the header guard for
cogl-texture-2d.h except there a small typo ('TEXURE') so that it
was subtly different. This fixes them both to make more sense.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 222ec4d009973cb62020a9da05f72dea41460b33)
2012-08-06 18:51:33 +01:00
Neil Roberts
96b726b518 cogl-winsys-sdl: Fix the signature for the get_proc_address method
This function should take an extra third paramter to specify whether
the procedure is in core or not. The parameter is not used so this
patch just fixes an annoying warning.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit eed4ac80cd8c3fa1859493c9bb00547038be6095)
2012-08-06 18:51:33 +01:00
Neil Roberts
59ff396875 cogl-winsys-egl-kms: Remove some unused variables
This just gets rid of some annoying warnings.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 3d0aea04d1f6a8094b749e20a59d8a9a95a6235e)
2012-08-06 18:51:33 +01:00
Neil Roberts
5fff83cd3c cogl-texture-2d-private: Include egl-defines.h
The cogl-texture-2d-private.h header checks for the presence of
EGL_KHR_image_base before declaring
_cogl_egl_texture_2d_new_from_image. This define will only be
available if the EGL headers are included so we should make sure that
happens. This was resulting in a warning complaining that the function
was not previously declared.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit bd4840d7858efcf30eb5cf5d6fd0d39bdd59d1c1)
2012-08-06 18:51:33 +01:00
Neil Roberts
74fd618df9 Add conf vars to trick Cogl to think extensions are disabled
This adds two new configuration environment variables:

COGL_DISABLE_GL_EXTENSIONS and
COGL_OVERRIDE_GL_VERSION

The variables can also be set in the cogl.conf file using the same
names.

The first one is a list of GL extension names separated by commas.
When set Cogl will assume any extension listed here is not available
by removing it from the string returned from
glGetString(GL_EXTENSIONS). If the string is set in both the config
file and the environment variable then the union of the two lists will
be used.

The second overrides the value returned from glGetString(GL_VERSION).
If the string is set in both places the version from the environment
variable will take priority.

These are sometimes useful for debugging Cogl to test the various
combinations of extensions. It could also be useful to work around
driver bugs where an extension is badly supported and it would be
better not to use it.

The variables in cogl-config that just set a global char * variable
have been put together in an array instead of having a separate blob
of code for each one in order to make it simpler to add new variables.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit ec69c2dc576c78664e0b73879365cb7414ecf441)
2012-08-06 18:51:33 +01:00
Damien Lespiau
e5fea8b734 egl-x11: Don't use GLXDrawable on EGL
Someone trying to compile cogl (ThijsNL on irc0 for the Rasberry Pi
stumbled into that one. GLXDrawable may not be defined in a pure EGL/X
environment.

Change it to Window, the type used for XConfigureEvent.window.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit f05d6923fff28b1d167a391d486e319743c49215)
2012-08-06 18:51:33 +01:00
Neil Roberts
cbad21f0f4 pipeline: Remove the CoglPipelineFlag enum
This doesn't appear to be used anywhere in the code since it was added
in 1cc3ae69. Dead code is confusing so let's remove it.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 41928d0ac528acf4ba89b5b27d7ca7ac5501b194)
2012-08-06 18:51:33 +01:00
Tomeu Vizoso
bb258c1d42 Avoid including the EGL headers from the public Cogl headers
Otherwise, X11 identifiers may leak and cause havoc in big applications

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit ed0cdca0eca815543619fe72fbd42d662d53f92d)
2012-08-06 18:51:32 +01:00
Robert Bragg
961832164b quaternions: Allow multiplication into 'a' arg
When multiplying two quaternions, we now implicitly copy the components
of the 'a' argument so that the result can be reliably written back to
the 'a' argument quaternion without conflicting with the multiplication
itself. This is consistent with the cogl_matrix_multiply() api which
allows the 'result' and 'a' arguments to point to the same matrix. In
debug builds Cogl will assert that the 'b' and 'result' arguments don't
point to the same quaternion.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 207527313a8957789390069e84189254cf41e88f)
2012-08-06 18:51:32 +01:00
Robert Bragg
8f4dd4587e onscreen: Free swap notify callback state
When freeing a CoglOnscreen we weren't freeing the state associated with
swap notification callbacks.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 70bc12fe20fa1be4eac58356861a730f18d6b59e)
2012-08-06 18:51:32 +01:00
Robert Bragg
56382435fa stack: don't deref freed mem in _cogl_memory_stack_free
This fixes _cogl_memory_stack_free to ensure we don't dereference freed
memory as we iterate the sub-stacks to free them.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 1d27fedef9c599aa9976b809f18e0da1913cec26)
2012-08-06 18:51:32 +01:00
Robert Bragg
df51574116 onscreen: Adds support for resizable windows
This adds api to be able to request that the window system allows a
given onscreen framebuffer to be resizable, and api to add and remove
resize handlers to be called whenever the framebuffer does actually
change size.

The new functions are:
  cogl_onscreen_{get,set}_resizable()
  cogl_onscreen_{add,remove}_resize_handler()

The examples cogl-hello and cogl-x11-foreign have been updated to use
the new api. To smoke test how Cogl updates the viewport automatically
in response to window resizes the cogl-hello test doesn't explicitly
respond to resize events by setting the viewport and cogl-x11-foreign
responds by setting a viewport that is offset by a quarter of the
window's width/height and half the width and height of the window.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit a1a8cc00bfa2cecaf1007aec5f3dd95dc07b1786)
2012-08-06 18:51:32 +01:00
Neil Roberts
2ae352b0a6 Fix point sprite coordinates in shaders on GLES2
When using the GLES2 driver with a pipeline layer that has point
sprite coordinates enabled it extracts the texture coordinates from
the gl_PointCoord builtin instead of cogl_tex_coord_in[*].
gl_PointCoord is not quite the same as the regular texture coordinates
because it is only a vec2 instead of a vec4. This used to work ok
because either set of texture coordinates would always immediately be
accessed using a swizzle of '.st' so it would effectively be converted
to a vec2 anyway. However since the snippet hook for texture lookups
was added the texture coordinates are now passed to a function to
perform the actual lookup instead. This function always takes a vec4
so the shader would not compile. This patch fixes it to construct a
vec4 from gl_PointCoord by setting the third and fourth components to
0.0 and 1.0.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit cb3409b23caf324a548f82cfb88acc684cc71930)
2012-08-06 18:51:31 +01:00
Tomeu Vizoso
053845f796 framebuffer: Only remember offscreen allocate flags when !COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL
Otherwise, if a texture is created before all the other FBOs, a new
atlas will be created, with a FBO with COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL
causing last_offscreen_allocate_flags to be 0.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 7d2156785da8196e129eb393efb0d09093c4783e)
2012-08-06 18:51:31 +01:00
Robert Bragg
1686e754a7 bitmap: Adds cogl_android_bitmap_new_from_asset()
This adds some android specific api for creating a CoglBitmap from an
Android asset.

As part of the work it also seemed like a good time to change the
internal bitmap constructors to take an explicit CoglContext argument
and so the public cogl_bitmap_new_from_file() api was also changed
accordingly to take a CoglContext pointer as the first argument.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 099d6d1b505b55bbd09c50d081deb41ab5764e19)

  Since we aren't able to break APIs on the 1.12 branch this cherry-pick
  skips the change to cogl_bitmap_new_from_file()
2012-08-06 18:50:22 +01:00
Neil Roberts
d1dc4e1e0b Don't use the label 'ERROR' because it conflicts with windows.h
wingdi.h which gets included from windows.h #defines ERROR to 0 so we
can't use it as a label in Cogl. This patch changes it to be error in
lower case instead.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit e9bac2755c2cba84c82a856d369a30560d19a32e)
2012-08-06 14:27:45 +01:00
Neil Roberts
df77e8565e Don't use eglGetProcAddress to retrieve core functions
According to the EGL spec, eglGetProcAddress should only be used to
retrieve extension functions. It also says that returning non-NULL
does not mean the extension is available so you could interpret this
as saying that the function is allowed to return garbage for core
functions. This seems to happen at least for the Android
implementation of EGL.

To workaround this the winsys's are now passed down a flag to say
whether the function is from the core API. This information is already
in the gl-prototypes headers as the minimum core GL version and as a
pair of flags to specify whether it is available in core GLES1 and
GLES2. If the function is in core the EGL winsys will now avoid using
eglGetProcAddress and always fallback to querying the library directly
with the GModule API.

The GLX winsys is left alone because glXGetProcAddress apparently
supports querying core API and extension functions.

The WGL winsys could ideally be changed because wglGetProcAddress
should also only be used for extension functions but the situation is
slightly different because WGL considers anything from GL > 1.1 to be
an extension so it would need a bit more information to determine
whether to query the function directly from the library.

The SDL winsys is also left alone because it's not as easy to portably
determine which GL library SDL has chosen to load in order to resolve
the symbols directly.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 72089730ad06ccdd38a344279a893965ae68cec1)

  Since we aren't able to break API on the 1.12 branch
  cogl_get_proc_address is still supported but isn't easily able to
  determine whether the given name corresponds to a core symbol or
  not.  For now we just assume the symbol being queried isn't part
  of the core GL api and update the documentation accordingly.
2012-08-06 14:27:45 +01:00
Neil Roberts
7cdaaf2bd5 Don't use the transpose argument of glUniformMatrix*
According to the GLES1/2 spec, the transpose argument of
glUniformMatrix* should always be FALSE. Cogl directly exposes the
transposedness of the uniform value in
cogl_pipeline_set_uniform_matrix and we were previously passing this
value on to GL. This patch makes it instead just always transpose the
matrix in Cogl itself when copying the value to the CoglBoxedValue. It
doesn't seem like there could be much advantage to letting GL
transpose the uniform value and at least Mesa just does a very similar
loop to handle the transpose.

Mesa has started being more pedantic about this which was making
test_pipeline_uniforms fail.

http://cgit.freedesktop.org/mesa/mesa/commit/?id=60e8a4944081b42127b3

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit f42ee670ff663d03073d6b1038b21a0aa1b3ec2b)
2012-08-06 14:27:45 +01:00
Tomeu Vizoso
93d0de1d9a Mass rename CLUTTER_COMPILATION to COGL_COMPILATION
Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit a99512e5798e48ffa3a9a1a7eb98bc55647ee1b6)
2012-08-06 14:27:45 +01:00
Damien Lespiau
4ad1e9b83a Use <literal> not <pre> in the comments
Comments are interpreted as docbook snippets and <pre> is from html. The
closest maching tag for inline content seems to be <literal>.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 66c9f26dfb3133f43d319128d6636f793a1ceb4a)
2012-08-06 14:27:45 +01:00
Damien Lespiau
829aafce98 Update the cogl_sdl_context_new() code snippet
The first argument has been removed from the function. Update the
example accordingly.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 06e47af3144565bdf85abf8ae561c7ceeafa2cbc)
2012-08-06 14:27:45 +01:00
Damien Lespiau
ecc5c96aeb Initialize the inverse matrix in invert_matrix_3d()
Contrary to the other inversion functions, invert_matrix_3d() does not
initialize the inverse to the identity and then only touches the
elements it cares about. Problem is the ww component is left alone,
which makes everything go to a black hole when using an inverse matrix
as the transform matrix of a framebuffer.

This is how cameras are typically implemented, they have a transform
and the framebuffer matrix stack is initialized with the inverse
of that transform. A gdb session gives away what happens:

The camera model view matrix, slightly rotation around the X axis:
camera mv       1.000000 0.000000 0.000000 0.000000
camera mv       0.000000 0.984808 -0.173648 0.000000
camera mv       0.000000 0.173648 0.984808 10.000000
camera mv       0.000000 0.000000 0.000000 1.000000

Breakpoint 5, invert_matrix_3d (matrix=0x8056b58) at ./cogl-matrix.c:671
671       const float *in = (float *)matrix;
(gdb) p *matrix
$1 = {xx = 1, yx = 0, zx = 0, wx = 0, xy = 0, yy = 0.98480773,
  zy = 0.173648164, wy = 0, xz = 0, yz = -0.173648164, zz = 0.98480773,
  wz = 0, xw = 0, yw = 0, zw = 10, ww = 1, inv = {0 <repeats 16 times>},
  type = 6, flags = 1030, _padding3 = 0}
(gdb) finish
Run till exit from #0  invert_matrix_3d (matrix=0x8056b58)
    at ./cogl-matrix.c:671
0x00141ced in _cogl_matrix_update_inverse (matrix=0x8056b58)
    at ./cogl-matrix.c:1123
1123          if (inv_mat_tab[matrix->type](matrix))
Value returned is $2 = 1
(gdb) p *matrix
$3 = {xx = 1, yx = 0, zx = 0, wx = 0, xy = 0, yy = 0.98480773,
  zy = 0.173648164, wy = 0, xz = 0, yz = -0.173648164, zz = 0.98480773,
  wz = 0, xw = 0, yw = 0, zw = 10, ww = 1, inv = {1, 0, 0, 0, 0, 0.98480773,
    -0.173648164, 0, 0, 0.173648164, 0.98480773, 0, -0, -1.73648167,
    -9.84807777, 0}, type = 6, flags = 1030, _padding3 = 0}

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 9a19ea0147eb316247c45cbba6bb70dec5b9be4c)
2012-08-06 14:27:45 +01:00
Neil Roberts
763c1de2ab Use the old GLSL extensions if GL 2.0 is not available
Some drivers have good support for GLSL but don't have the complete
set of features needed to advertise GL 2.0 support. We should accept
the three old GLSL extensions (GL_ARB_shader_objects,
GL_ARB_vertex_shader and GL_ARB_fragment_shader) to support shaders on
these drivers.

This patch splits the shader functions into four sections :- those
that are provided only in GL 2.0, those that have the same name in the
shader objects extension, those that are provided by the vertex
shader extension (they all share the same name) and those that have a
different name in the shader objects extension.

If GL 2.0 is not supported but all three of the extensions are then
the pointers to the GL2-only functions will be replaced to point to
the equivalent functions from the extensions. That way the rest of the
Cogl source doesn't have to worry about the name differences.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 71ecb51bd20dc3053b4221961b57e5a2b1029bdf)
2012-08-06 14:27:45 +01:00
Neil Roberts
a3989d035e Fix removing layers when the pipeline is not the owner
If cogl_pipeline_remove_layer is called on a copied pipeline to remove
a parent layer then it will still end up calling
_cogl_pipeline_remove_layer_difference on the layer. This function
was directly trying to remove the layer from the pipeline's list of
layer differences. However in the child pipeline the layer isn't in
the list because it is unchanged from its parent. The function had an
assertion to verify that this situation wasn't hit so in a debug build
it would just bail out.

This patch removes the assertion and changes it to only remove the
layer if it is owned by the pipeline. Otherwise it just sets the
COGL_PIPELINE_STATE_LAYERS difference as normal and decrements the
number of layers. This will cause it to successfully remove the layer
because either it is the last layer in which case it will be ignored
after n_layers is decreased or if it is in the middle of the list then
the subsequent layers will all be shifted down so there will be a
replacement layer difference.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 88e73dd93fa09a158064a946ab229591a5888b97)
2012-08-06 14:27:45 +01:00
Neil Roberts
17c818a9a7 Add an SDL2 winsys
This adds an alternate version of the SDL winsys using the SDL 2 API.
The two versions are mutually exclusive and share the same
CoglWinsysID. Version 2 of SDL fits a little bit better with Cogl
because it supports multiple windows and the video subsystem can be
initialised entirely independently of the rest of the subsystems.

The SDL2 winsys creates an invisible dummy window in order to bind the
GL context after creating the Cogl display. This is similar to how the
X11 winsys's work.

SDL2 seems to support compiling with support for both GL and GLES.
However there doesn't seem to be a way to select between the two
backends outside of SDL. In fact if you do compile them both in it
seems to break down because it will always try to use the window
system functions from the GLES backend because those are filled in
second in the vtable. However when creating the window it will always
prefer to use the GL function to choose a visual. This function gets
confused because the GL backend has not been initialised at that
point. The Cogl backend therefore just leaves it up to SDL to pick a
sensible backend. It will then verify that it picked a GL library
which matches the Cogl driver by checking the string from
glGetString(GL_VERSION).

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 6cb5ab41355e7bfe28f367cf4afa39a7afcfeec2)
2012-08-06 14:27:44 +01:00
Tomeu Vizoso
9a1f0c4098 cogl-gles2: Add glTexParameterf to wrapper library
Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 06d6bdb73e3d2468cf3a8c355152cbdeb1b36d94)
2012-08-06 14:27:44 +01:00
Damien Lespiau
a87b657d73 Add a note about [0, 0, 0] and cogl_vector3_normalize()
When having the [0, 0, 0] vector, normalize() won't try to divide by 0
and thus it's always safe to use that funtion.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 64370e7ddd32f25556a1792c00d14adc48a81d45)
2012-08-06 14:27:44 +01:00
Damien Lespiau
81bb87e037 Use the internal format to check if the texture size is supported
Until now, we hardcoded the internal format to GL_RGBA and used the
internal format returned by pixel_format_to_gl() as the format for
checking the texture size and format we're asked to create.

Let's use the proper internal format/format from now on.

This is needed as a later patch introduces DEPTH and DEPTH_STENCIL
textures.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit ec45f60ee2545f88302da314bcdbe1439c4ba9c9)
2012-08-06 14:27:44 +01:00
Rico Tzschichholz
5c16ad65c5 build: add newly introduced header to fix make dist
Missing bit of 4bb6eff3dbd50d8fef7d6bdbed55c5aaa70036a8

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 1674cf28f1f5b71bd25a1f253c99825d427dd243)
2012-08-06 14:27:44 +01:00
Neil Roberts
9a654d173e Fix a typo in _cogl_matrix_init_translation
The y translation was being initialised with the z value and the z
translation was being left as 0.0.

(cherry picked from commit b44feb617ecb9cbf7d53f0d745f686c17ef3246d)
2012-08-06 14:27:43 +01:00
Neil Roberts
67a095b9dd Cache the debug wireframe snippet
When rendering the debug wireframe Cogl generates a child pipeline of
the application's pipeline to replace the fragment processing.
Previously it was creating a new snippet every time something was
drawn. Cogl doesn't attempt to compare the contents of snippets when
looking in the program cache for a matching pipeline so this would
cause it to generate a new program for every primitive. It then quite
quickly ends printing the warning about there being more than 50
programs in the cache. To fix that this patch makes it cache the
snippet so that Cogl can successfully recognise that it already has a
program generated for the new pipeline.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit c4bb08ee8767b5320980dba10b20921393cb5613)
2012-08-06 14:27:43 +01:00
Neil Roberts
1357c4c6a6 Preserve the CoglDrawFlags when drawing a wireframe
Previously the CoglDrawFlags passed to
_cogl_framebuffer_draw_indexed_attributes when drawing is redirected
to draw a wireframe are overriden to avoid validating the pipeline,
flushing the framebuffer state and flushing the journal. This ends up
breaking scenes that only contain models drawn from attributes in the
application because nothing will flush the matrices. It seems to make
more sense to just use whatever draw flags were passed from the
original draw command so that it will flush the matrices if the caller
was expecting it.

One problem with this is that if the wireframe causes the journal to
be flushed then it will already have temporarily disabled the
wireframe debug flag so the journal will not be drawn with wireframes.
To fix this the patch adds a CoglDrawFlag to disable the wireframe and
uses that instead of disabling the debug flag.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 283f6733e63ba65d9921f45868edaabbd9420a61)
2012-08-06 14:27:43 +01:00
Neil Roberts
702873c199 matrix-stack: Prune stack entries when loading a replacement matrix
Previously if an application does not use the matrix stack as a stack
but instead just loads its own matrices for each frame using
cogl_framebuffer_set_modelview_matrix then it will continously push
OP_LOAD entries on the stack and the stack will grow forever. This
patch fixes that use case by resetting the top of the stack to the
last save entry whenever something is pushed that replaces the
previous matrix on the stack.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit d31ed33241a9e9e3bc25f01b2614678827a7a9aa)
2012-08-06 14:27:43 +01:00
Neil Roberts
5e8ff248d2 Add functions to directly transform from a euler or a quaternion
This adds the following new functions to apply a rotation described by
a euler or a quaternion to either a CoglMatrix or directly to the
modelview stack of a framebuffer:

cogl_matrix_rotate_quaternion
cogl_matrix_rotate_euler
cogl_framebuffer_rotate_quaternion
cogl_framebuffer_rotate_euler

The direct framebuffer functions have corresponding functions in the
CoglMatrixStack to store an entry describing the rotation.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 5064315678b496395e1d01f266f322d73e55e324)
2012-08-06 14:27:43 +01:00
Neil Roberts
aa749bb177 matrix-stack: Fix the _cogl_matrix_entry_equal function
The _cogl_matrix_entry_equal function has a large switch statement to
do the right kind of comparison for the entry. However most of the
entries have a return statement that is only conditionally reached.
There were no corresponding break statements to the case labels so
presumably if the comparison succeeded for the correct entry type it
would also flow through and try the comparison for the next type which
would be extremely unlikely to pass.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 339db0f9cc3ee2bee4c56f9cb05dcb4ddd6815ed)
2012-08-06 14:27:43 +01:00
Neil Roberts
6eb8864866 Add a cogl_matrix_init_from_euler function
This creates a matrix to represent the given euler rotation. This
should be more efficient than creating the matrix by doing three
separate rotations because no separate intermediate matrices are
created and no matrix multiplication is needed.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit e66d9965897999a4889063f6df9a20ea6abf97fe)
2012-08-06 14:27:43 +01:00
Neil Roberts
0210cc40f9 Make cogl_matrix_init_from_quaternion take a const quaternion
The quaternion is not modified so for consistency with the rest of the
API it should probably be const.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 7fa8c05c2ffb90cba03289a04e37866efc0890a5)
2012-08-06 14:27:43 +01:00
Neil Roberts
bdc8a12ea1 Fix the documentation for cogl_quaterinon_init_from_array
The documentation for cogl_quaternion_init_from_array contradicts
itself and says that the array is w,x,y,z in one part but x,y,z,w in
another. This fixes it to say w,x,y,z in both parts.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit b08a81e5dfb05fec867c08c689237fae937341ad)
2012-08-06 14:27:43 +01:00
Neil Roberts
b977d75059 Fix disabling debugging
When --disable-debug is passed to the configure script it was actually
still defining COGL_ENABLE_DEBUG so very little would end up being
disabled. If COGL_ENABLE_DEBUG actually got defined it would also fail
to compile because _cogl_debug_instances and COGL_DEBUG_N_LONGS from
cogl-debug.h were only defined if debugging is enabled but they are
used regardless.

This patch also makes it so that the _COGL_RETURN_IF_FAIL family of
macros that are used when glib support is disabled are now disabled if
debugging is disabled. When the glib macros are used they are already
disabled because we additionally define G_DISABLE_CHECKS.

'COGL_HANDLE_DEBUG' has been removed from the list of defines passed
when debugging is enabled because CoglHandle has already been removed
and it is not used anywhere in the code.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 9811a0101c9cbb4ab95c55a2b41fd10ff4c77d9f)
2012-08-06 14:27:43 +01:00
Robert Bragg
498937083e Adds gles2-context renderer constraint
This adds a new renderer constraint enum:
  COGL_RENDERER_CONSTRAINT_SUPPORTS_GLES2_CONTEXT
that can be used by applications to ensure the renderer they connect to
has support for creating a GLES2 context via cogl_gles2_context_new().

The cogl-gles2-context and cogl-gles2-gears examples and the conformance
tests have been updated to use this constraint.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit ed61463d7194354b26624e8014859f0fbfc06a12)
2012-08-06 14:27:43 +01:00
Robert Bragg
10340a5495 Adds libcogl-gles2 frontend GLES2 api
This adds a library that can be used instead of libGLESv2.so to provide
symbols for the GLES 2.0 api. This can be used for convenience when
using the cogl_gles2_context_ api since you don't need to manually go
through a CoglGLES2Vtable when calling the gles2 api so it should be
easier to port existing gles2 code to integrate with Cogl.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 80d7599a2acefca7d01d8d7de9df524278ef72c5)
2012-08-06 14:27:42 +01:00
Robert Bragg
010d16f647 Adds initial GLES2 integration support
This makes it possible to integrate existing GLES2 code with
applications using Cogl as the rendering api.

Currently all GLES2 usage is handled with separate GLES2 contexts to
ensure that GLES2 api usage doesn't interfere with Cogl's own use of
OpenGL[ES]. The api has been designed though so we can provide tighter
integration later.

The api would allow us to support GLES2 virtualized on top of an
OpenGL/GLX driver as well as GLES2 virtualized on the core rendering api
of Cogl itself. Virtualizing the GLES2 support on Cogl will allow us to
take advantage of Cogl debugging facilities as well as let us optimize
the cost of allocating multiple GLES2 contexts and switching between
them which can both be very expensive with many drivers.

As as a side effect of this patch Cogl can also now be used as a
portable window system binding API for GLES2 as an alternative to EGL.

Parts of this patch are based on work done by Tomeu Vizoso
<tomeu.vizoso@collabora.com> who did the first iteration of adding GLES2
API support to Cogl so that WebGL support could be added to
webkit-clutter.

This patch adds a very minimal cogl-gles2-context example that shows how
to create a gles2 context, clear the screen to a random color and also
draw a triangle with the cogl api.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 4bb6eff3dbd50d8fef7d6bdbed55c5aaa70036a8)
2012-08-06 14:27:42 +01:00
Robert Bragg
3f2cb89a76 Fix depth testing, write enable bug
This fixes a bug in _cogl_pipeline_flush_color_blend_alpha_depth_state
whereby we were only calling flush_depth_state if we knew that at least
depth testing was enabled. This didn't take into account that enabling
and disabling depth writing is a useful change to make even if depth
testing is disabled. It also seemed a bit messy to flush the
depth-testing enable separately from the other depth state.

_cogl_pipeline_flush_color_blend_alpha_depth_state now simply calls
flush_depth_state() if there is a _DEPTH_STATE difference and
flush_depth_state() also handles flushing the depth-testing enable
in along with all the other depth state.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 6a9dfc55b8f55d7023cb592e5bef2118d0f3d50c)
2012-08-06 14:27:42 +01:00
Robert Bragg
fb636008ad By default enable swap throttling
This ensures that when we initialize a CoglOnscreenTemplate that
->swap_throttled is set to TRUE so by default Cogl applications should
have their swap buffer requests throttled to the vblank frequency.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit bdac9ab56284fb84ec09af176c7e31c44dc1bfc6)
2012-08-06 14:27:42 +01:00
Robert Bragg
a945890de6 Workaround drisw bug where clipped redraws don't work
This detects when we are running on any of Mesa's software rasterizer
backends and disables use of glBlitFramebuffer and glXCopySubBuffer.
Both of these currently result in full-screen copies so there's little
point in using these to optimize how much of the screen we present.

To help ensure we re-evaluate this workaround periodically we have added
a comment marker of "ONGOING BUG" above the workaround and added a note
to our RELEASING document that says we should grep for this marker and
write a NEWS section about ongoing bug workarounds.

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

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 11f2f6ebb42398978ec8dd92b3c332ae8140a728)
2012-08-06 14:27:42 +01:00
Robert Bragg
b8e380edc3 gpu-info: Detect more info including architecture
The GPU info api previously told us a driver package name and a driver
vendor name, but now we have introduced detection for the gpu
architecture too and started to track architecture feature flags that
can tell us whether a gpu is a deferred or immediate mode renderer for
example or if a software rasterizer is being used.

This also adds support for checking more vendor names. We should now
detect the following cases:

Vendors: Intel, Imagination Technologies, ARM, Qualcomm, Nvidia, ATI
Architectures: Sandybridge, SGX, Mali
Architecture flags:
  - vertex tiled
  - vertex immediate mode
  - vertex software
  - fragment deferred
  - fragment immediate mode
  - fragment software

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit b3803a0a7c9e663ed219e83626841895c7d95ad7)
2012-08-06 14:27:42 +01:00
Chun-wei Fan
feaaaad6a0 Update cogl.symbols
There are numerous APIs added/removed in the following commits:
e7f15826 Add a CoglPrimitiveTexture interface
6197e3ab Add constructors which take a CoglBitmap to all primitive textures
bdb645e7 kms: defer setting crtc modes until first swap buffers
9a1f1df8 Rework sdl integration api
ac0c72ab Removed legacy cogl-fixed 1.x api
e8c4c80c Remove deprecated cogl_vertex_buffer api
06d522cb Remove the legacy CoglPath API
713a8f81 Replace cogl_path_{stroke,fill} with framebuffer API
6ed3aaf4 Removes all remaining use of CoglHandle
068b3b59 matrix: Add a init_translation() constructor

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 2625354b8accaebe33ee2747ff03f665aea07e4f)
2012-08-06 14:27:42 +01:00
Chun-wei Fan
23becf67a7 Fix Visual C++ build
-Create a pre-defined cogl/cogl-gl-header.h(.win32) that is to be used on
 any Windows builds, and adapt the MSVC build process to set up and use
 that file.
-Fix up glib-mkenums code generation .bat file that is generated during
 "make"/"make dist", like the autotools-based builds.
-Since cogl/cogl-defines.h now contain versionioning info, and it no longer
 directly includes the GL headers, update the pre-configured
 cogl-defines.h[.win32|.win32_SDL] and use autotools to fill in the
 versioning info during "make"/"make dist".
-Fix up cogl/cogl-pango.rc.in so that they reflect the cogl-2.x versioning
 stuff correctly and versioning info can be filled in correctly during
 "make"/"make dist"

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 7ff42bb1c5280b0f53370f8d94ef5f10c9f39e2f)
2012-08-06 14:27:42 +01:00
Damien Lespiau
e6b75b6cfc quaternion: Fix typo in the init_from_z_rotation documentation
Clearly from a copy and paste from init_from_y_rotation().

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 2f06f4d79e29bbf30a44edbf48e8eaa637e30930)
2012-08-06 14:27:42 +01:00
Damien Lespiau
542fdcd2b0 doc: Hide the private fields of CoglQuaternion
Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit a98a69017cdf8879816c1a341e4982b57ef1bc32)
2012-08-06 14:27:41 +01:00
Damien Lespiau
86a5259578 doc: Include the documentation for CoglEuler
Several little changes were needed to make the CoglEuler documentation
appear:

  • Fix the embeded docbook snippet in the CoglEuler section header
  • Add the xinclude directive to the main document
  • Add the missing <SECTION> in -sections.txt

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit c7f6e07f7b8ba0d7dc9604e888c8a46165ec3ed4)
2012-08-06 14:27:41 +01:00
Damien Lespiau
e172cac480 quaternion: Document init_from_quaternion()
Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 91c2a3580a6055fcb6902524d3e8354f27932e89)
2012-08-06 14:27:41 +01:00
Damien Lespiau
28655fd608 quaternion: Document init_from_euler()
Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 018703a8e83835e7ab522f5e011fdd4a039523a2)
2012-08-06 14:27:41 +01:00
Damien Lespiau
7ff0b52d78 matrix: Add a init_translation() constructor
This allows people to initialize a matrix with a translation
transformation. The options to do it at the moment were:

* init_from_array() but it give cogl no information about the type of
  matrix.
* init_indentity() and then translate() but it means doing a lot of
  computations for no reason.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 068b3b59221e405dc288d434b0008464684a7c12)
2012-08-06 14:27:41 +01:00
Neil Roberts
68a6e82828 Add support for the WebOS version of SDL
The stock 1.2.x version of SDL only supports regular OpenGL. The
version on WebOS is specially patched to add some extra API to request
a GLES1 or GLES2 context. This patch adds a configure check to detect
when Cogl is being built with the patched version of SDL. In that case
it will additionally allow the gles1 and gles2 drivers and set the
right video mode attributes to get the corresponding context.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 3726c60deab2bd94617a562abb63f735627a25e4)
2012-08-06 14:27:41 +01:00
Neil Roberts
1d3d1732bd Fixes for building with --disable-gl
This fixes a few problems that occur when only using a GLES2 header.

• The use of GL_CLAMP_TO_BORDER and GL_MIRRORED_REPEAT were moved from
  cogl-pipelinelayer-state.h to cogl-sampler-cache-private.h but the
  corresponding defines were not.

• cogl-sampler-cache.c was using GL_TEXTURE_WRAP_R but this is only
  defined as GL_TEXTURE_WRAP_R_OES from the GLES2 header so it needs a
  #define.

• cogl-framebuffer-private.h uses GLuint but it does not include
  cogl-gl-header.h. It gets away with this when GLX support is enabled
  because the GL header would be included via glx.h.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 9cdb87c864fc262c4b26c13963670d60d7c18058)
2012-08-06 14:27:41 +01:00
Neil Roberts
d57fcd952e buffer: Use GL_STREAM_DRAW on GLES2
The function to convert the CoglBufferUpdateHint to a GL enum was
previously ifdef'd to only use GL_STREAM_DRAW when Cogl is compiled
with big GL support. One problem with this is that it would end up
trying to use it on GLES1 if support for both is compiled. The other
problem is that GLES2 seems to actually support GL_STREAM_DRAW so we
might as well use it in that case.

This patch also changes it so that if the hint is stream with GLES1
then it will default to GL_DYNAMIC_DRAW instead of GL_STATIC_DRAW
because I think that is closer to the meaning of the stream hint.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 9e997476a7f9271bc000abdc82b1e343b92afb4c)
2012-08-06 14:27:41 +01:00
Neil Roberts
85efb7daba Don't typedef CoglMemoryStack twice
CoglMemoryStack was being typedef'd twice, once in the private header
as an incomplete struct and once in the C source with the actual
struct definition. This removes the second typedef so that it just
defines the struct.

This patch was written by Jack River.

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

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 75cd425a48e0fc403bf88eace212a6d37b65df11)
2012-08-06 14:27:41 +01:00
Robert Bragg
9cf7aac80f Allow npot Texture2D creation with only basic npot support
Cogl has feature flags for basic npot texture support and then separate
flags for npot + repeat and npot + mipmap. If those three features are
available then there is a feature for full-npot support too for
convenience. The cogl_texture_2d_new_ constructors were checking for
full npot support and failing if not available but since we expose the
fine grained features to the user the user should be able to check the
limitations of npot textures and still choose to allocate them.

_cogl_texture_2d_can_create() now only checks for basic npot support
when creating a npot texture.  Since this change also affects the
automagic cogl_texture_ constructors they now check for basic npot +
mipmap support before considering using a Texture2D.

Notably the cogl_texture_ constructors will try constructing a Texture2D
even if we don't have npot + repeat support since the alternative is a
sliced texture which will need manual repeating anyway. Accordingly the
Texture2D::can_hardware_repeat and ::transform_quad_coords_to_gl vfuncs
have been made aware of the npot + repeat feature flag.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 6f6c5734d076372d98d0ec331b177ef7d65aa67d)
2012-08-06 14:27:40 +01:00
Neil Roberts
b6b9ac0b85 Add a cogl-version header
This adds a version header which contains macros to define which
version of Cogl the application is being compiled against. This helps
applications that want to support multiple incompatible versions of
Cogl at compile time.

The macros are called COGL_VERSION_{MAJOR,MINOR,MICRO}. This does not
match Clutter which names them CLUTTER_{MAJOR,MINOR,MICRO}_VERSION but
I think the former is nicer and it at least matches Cairo and Pango.

The values of the macro are defined to COGL_VERSION_*_INTERNAL which
is generated by the configure script into cogl-defines.h.

There is also a macro for the entire version as a string called
COGL_VERSION_STRING.

The internal utility macros for encoding a 3 part version number into
a single integer have been moved into the new header so they can be
used publicly as a convenient way to check if the version is within a
particular range. There is also a COGL_VERSION_CHECK macro for the
very common case that a feature will be used since a particular
version of Cogl. There is a macro called COGL_VERSION which contains
the pre-encoded version of Cogl being compiled against for
convenience.

Unlike in Clutter this patch does not add any runtime version
identification mechanism.

A test case is also added which just contains static asserts to sanity
check the macros.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 3480cf140dc355fa87ab3fbcf0aeeb0124798a8f)
2012-08-06 14:27:40 +01:00
Robert Bragg
8b22b0da65 journal: avoiding some _cogl_matrix_entry_get()'s
When uploading the vertices the journal calls _cogl_matrix_entry_get()
to get a CoglMatrix for each journal entry so that it can so a software
transform. Since _cogl_matrix_entry_get() can be a performance hot-spot
and since it's trivial to keep track of the last CoglMatrixEntry seen we
now avoid repeatedly calling _cogl_matrix_entry_get() for sequential
entries with the same transform.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 70cad61533316e2303b8e188f2f361701dfb0c61)
2012-08-06 14:27:40 +01:00
Robert Bragg
e3d6bc36d3 Re-design the matrix stack using a graph of ops
This re-designs the matrix stack so we now keep track of each separate
operation such as rotating, scaling, translating and multiplying as
immutable, ref-counted nodes in a graph.

Being a "graph" here means that different transformations composed of
a sequence of linked operation nodes may share nodes.

The first node in a matrix-stack is always a LOAD_IDENTITY operation.

As an example consider if an application where to draw three rectangles
A, B and C something like this:

cogl_framebuffer_scale (fb, 2, 2, 2);
cogl_framebuffer_push_matrix(fb);

  cogl_framebuffer_translate (fb, 10, 0, 0);

  cogl_framebuffer_push_matrix(fb);

    cogl_framebuffer_rotate (fb, 45, 0, 0, 1);
    cogl_framebuffer_draw_rectangle (...); /* A */

  cogl_framebuffer_pop_matrix(fb);

  cogl_framebuffer_draw_rectangle (...); /* B */

cogl_framebuffer_pop_matrix(fb);

cogl_framebuffer_push_matrix(fb);
  cogl_framebuffer_set_modelview_matrix (fb, &mv);
  cogl_framebuffer_draw_rectangle (...); /* C */
cogl_framebuffer_pop_matrix(fb);

That would result in a graph of nodes like this:

LOAD_IDENTITY
      |
    SCALE
    /     \
SAVE       LOAD
  |           |
TRANSLATE    RECTANGLE(C)
  |     \
SAVE    RECTANGLE(B)
  |
ROTATE
  |
RECTANGLE(A)

Each push adds a SAVE operation which serves as a marker to rewind too
when a corresponding pop is issued and also each SAVE node may also
store a cached matrix representing the composition of all its ancestor
nodes. This means if we repeatedly need to resolve a real CoglMatrix
for a given node then we don't need to repeat the composition.

Some advantages of this design are:
- A single pointer to any node in the graph can now represent a
  complete, immutable transformation that can be logged for example
  into a journal. Previously we were storing a full CoglMatrix in
  each journal entry which is 16 floats for the matrix itself as well
  as space for flags and another 16 floats for possibly storing a
  cache of the inverse. This means that we significantly reduce
  the size of the journal when drawing lots of primitives and we also
  avoid copying over 128 bytes per entry.
- It becomes much cheaper to check for equality. In cases where some
  (unlikely) false negatives are allowed simply comparing the pointers
  of two matrix stack graph entries is enough. Previously we would use
  memcmp() to compare matrices.
- It becomes easier to do comparisons of transformations. By looking
  for the common ancestry between nodes we can determine the operations
  that differentiate the transforms and use those to gain a high level
  understanding of the differences. For example we use this in the
  journal to be able to efficiently determine when two rectangle
  transforms only differ by some translation so that we can perform
  software clipping.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit f75aee93f6b293ca7a7babbd8fcc326ee6bf7aef)
2012-08-06 14:27:40 +01:00
Robert Bragg
882ff5612b Adds a "magazine" allocator for chunks of fixed size
This adds a very minimal and fast allocator for chunks of memory of a
predetermined size. This has some similarities to the glib slice
allocator although notably it is not thread safe and instead of
internally tracking multiple magazines for various sized allocations the
api lets you explicitly allocate a single magazine for a single specific
size and a pointer to the magazine is passed explicitly to the allocate
and free functions.

This allocator builds on the CoglMemoryStack allocator as an underlying
heap allocator and just never rewinds the stack. This means the heap is
effectively a grow only linked list of malloc()'d blocks of memory.

A CoglMagazine tracks a singly linked list of chunks of a predetermined
size and _cogl_magazine_chunk_alloc() simply unlinks and returns the
head of the list. If the list is empty it falls back to allocating from
the underlying stack.

_cogl_magazine_chunk_free() links the chunk back into the singly linked
list for re-use.

The chunk size passed to _cogl_magazine_new() is automatically rounded
to a multiple of 8 bytes to ensure that all stack allocations end up
aligned to 8 bytes. This also ensures that when a chunk is freed then it
will be large enough to store a pointer to the next free chunk as part
of a singly linked list.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 17799c2f109a008d6cf767f501b81aa9b32bbda8)
2012-08-06 14:27:40 +01:00
Robert Bragg
97d5406aef Adds internal CoglMemoryStack utility API
This adds a very minimal internal allocator api that lets us create a
dynamically growable (grow only) stack.

Underlying the allocator is the idea of "sub stacks" which are simply
malloc()'d chunks of memory kept in a linked list. The stack itself
maintains a pointer to the current sub-stack and a current
sub-stack-offset. 99% of the time allocating from the stack is just a
case of returning a pointer to the current sub-stack + sub-stack-offset
and bumping the offset by the allocation size. If there isn't room in
the current sub-stack then we walk through the list of free sub-stacks
looking for one that's big enough for the allocation and if we reach the
end of the list then we allocate a new sub-stack twice as big as the
last (or twice as big as the requested allocation if that's bigger).

Since it's a stack model there is no api to free allocations, just a
function to rewind the stack to the beginning.

We expect this to be useful in multiple places in Cogl as an extremely
fast allocator in cases when we know we can scrap all the allocations
after we're done figuring something out or as a building block for
other allocators.

For example the tessellator used for CoglPath allocates lots of tiny
structures that can all be freed after tessellation.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 6ee4a7a1b7f695bdfeb10ffa4112e776beea0a9d)
2012-08-06 14:27:40 +01:00
Robert Bragg
e58c7da9a8 build: Include stdint.h
Since 5967dad2400d32c we have stopped using glib types such as guint16
and guint32 in favour of the equivalent c99 types such as uint16_t and
uint32_t. When that patch was tested we must have used a configuration
that just happened to include <stdint.h> because we have since seen that
builds can fail due to missing c99 typedefs. This patch explicitly
includes stdint.h in cogl-types.h.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit c1e2220a4314071482d2d5638688b6bcf83882a2)
2012-08-06 14:27:39 +01:00
Neil Roberts
8dd77de009 Replace cogl_path_{stroke,fill} with framebuffer API
The existing functions for stroking and filling a path depend on the
global framebuffer and source stacks. These are now replaced with
cogl_framebuffer_{stroke,fill}_path which get explicitly passed the
framebuffer and pipeline.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 713a8f8160bc5884b091c69eb7a84b069e0950e6)
2012-08-06 14:27:39 +01:00
Robert Bragg
54735dec84 Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.

Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.

Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.

So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.

Instead of gsize we now use size_t

For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-08-06 14:27:39 +01:00
Robert Bragg
09642a83b5 Removes all remaining use of CoglHandle
Removing CoglHandle has been an on going goal for quite a long time now
and finally this patch removes the last remaining uses of the CoglHandle
type and the cogl_handle_ apis.

Since the big remaining users of CoglHandle were the cogl_program_ and
cogl_shader_ apis which have replaced with the CoglSnippets api this
patch removes both of these apis.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 6ed3aaf4be21d605a1ed3176b3ea825933f85cf0)

  Since the original patch was done after removing deprecated API
  this back ported patch doesn't affect deprecated API and so
  actually this cherry-pick doesn't remove all remaining use of
  CoglHandle as it did for the master branch of Cogl.
2012-08-06 14:27:39 +01:00
Robert Bragg
097d282b32 Add _COGL_STATIC_ASSERT macro
This adds a _COGL_STATIC_ASSERT macro that can be used for compile time
assertions in C code. If supported by the compiler this macro uses
_Static_assert so that a message can be printed out if the assertion
fails.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 465b39a764f2720e77678cafa56acb0e69007ffd)
2012-08-06 14:27:39 +01:00
Neil Roberts
eaf29af7ee bitmap-pixbuf: Fix the bitmap loader on Quartz
The code for loading a CoglBitmap from a file was missed when
upgrading to the new cogl_bitmap_new_for_data function in commit
d18b59d9e6 so it wouldn't compile. This changes it to use
_cogl_bitmap_new_with_malloc_buffer to allocate the buffer.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 5b785dd441a83024333e0a2f2b83d067f891194f)
2012-08-06 14:27:39 +01:00
Neil Roberts
d2a5d6f361 Add a context member to CoglPath
cogl_path_new now takes a CoglContext pointer which it keeps a pointer
to instead of relying on the global context.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit afc63f8211c230f8fd1f7801f9085627c46a8661)

  Since we can't change the api on this branch this just applies
  the internal cleanups so we depend less on _COGL_GET_CONTEXT
2012-08-06 14:27:38 +01:00
Neil Roberts
6400b455b8 Don't include any GL header from the public GL headers
This splits the GL header inclusion from cogl-defines.h into a
separate headear called cogl-gl-header.h which we will only include
internally. That way we don't leak GL declarations out of our public
headers. The texture functions that were using GLenum and GLuint in
the public header have now changed to just use unsigned int. Note
however that if an EGL winsys is enabled then it will still publicly
include an EGL header. This is a bit more awkward to fix because we
have public API which returns an EGLDisplay and we can't determine
what type that is.

There is also a conformance test which just verifies that no GL header
has been included while compiling. The test isn't added to
test-conform-main because it doesn't actually test anything at
runtime.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit ef5680d3fda5df929dbd0b420c8f598ded58dfee)
2012-08-06 14:27:38 +01:00
Chun-wei Fan
e85a04f0ce Fix cogl.symbols
cogl_framebuffer_draw_multitextured_rectangles is not in the public
API list, it is instead _cogl_framebuffer_draw_multitextured_rectangles,
which is private.

(Sorry, I forgot to add the reviewed by line for the same patch in the
cogl-1.10 branch :P)

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 4fc6cf5e3c1478bc0a29dfaf2f6d9e84b9d29ccd)
2012-08-06 14:27:38 +01:00
Chun-wei Fan
fa88ed8d74 cogl/Makefile.am: Fix filters for MSVC projects
We need to filter out all the *-egl-* sources as well, as the original
filter did not filter out the Wayland EGL sources

(Sorry, I forgot to add the reviewed by line for the same patch in the
cogl-1.10 branch :P)

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 3d4cb887a28d3bc2cde9e4e7cdd20a71c34a2eaa)
2012-08-06 14:27:38 +01:00
Damien Lespiau
943afe5711 winsys-glx: Remove unused variable
Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 2cffcae81fd91d97bfa239e8c7c6a5b2cefb2653)
2012-08-06 14:27:38 +01:00
Robert Bragg
9a1f1df83f Rework sdl integration api
This re-works the SDL integration api to simplify the integration for
application developers and also allow Cogl to know when the application
is about to go idle waiting for events so it can perform idle
book-keeping work.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-04-12 12:31:46 +01:00
Robert Bragg
bdb645e7f5 kms: defer setting crtc modes until first swap buffers
Instead of creating a dummy framebuffer allocation just so we can setup
crtc modes during display_setup we now wait until the first swap_buffers
request before setting up the crtc modes.

This patch also adds a cogl_kms_display_queue_modes_reset() function
that allows developers to explicitly queue a reset of the crtc modes.
The idea is that applications that handle VT switching can use this for
VT enter events to explicitly ensure their mode is restored since modes
are often not automatically restored correctly.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-04-11 15:44:58 +01:00
Robert Bragg
125c31a70b kms: Add mirror support and env var configurability
This adds support for mirroring the display output on two KMS
connectors.

This patch also checks for a number of environment variables that can
influence how KMS is configured. The following variables can be set:

COGL_KMS_MIRROR: If this is set to anything then Cogl will try and setup
two connectors with the same resolution so that onscreen frame buffers
can be mirrored.

COGL_KMS_CONNECTOR0: This can be set to an integer identifier for a
specific KMS connector id to use for the first output.

COGL_KMS_CONNECTOR0_MODE: Can be set to a mode name like "1024x768"
explicitly select what mode should be used for the first output.

If COGL_KMS_MIRROR is set then COGL_KMS_CONNECTOR1 and
COGL_KMS_CONNECTOR1_MODE can optionally be set to specify a connector id
and mode name for the second output.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-04-11 15:44:58 +01:00
Neil Roberts
f9d3ea03ec kms: Implement the swap buffers notify feature
The KMS EGL platform now notifies when a swap is complete. The
notification is delayed until the application calls
cogl_context_dispatch. The GLX backend doesn't currently do this but I
think that is how it should behave to make it easier for the
application to handle locks and such.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-11 15:44:50 +01:00
Neil Roberts
cfefff1500 egl-kms: Use drmModePageFlip
The KMS platform now uses drmModePageFlip to present the buffer. The
main loop mechanism is used to poll for events on the DRM file
descriptor so that we notice when the page flip is complete. The
swap_buffers is throttled so that if there is a pending flip it will
block until it is complete before starting another flip.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-11 15:44:45 +01:00
Neil Roberts
d1d2120a91 kms: Use GBM surfaces
Instead of creating FBOs on the GL side, the KMS EGL platform uses the
latest changes to Mesa to create an EGL surface using a GBM surface as
the native surface type. This removes some of the special vtable hooks
that the KMS platform needed because it is now much more similar to
the other platforms.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-11 15:44:32 +01:00
Robert Bragg
cc4c578887 fix cogl_context_new crash if fail to connect renderer
If a NULL display is passed to cogl_context_new() then it has to
implicitly create a CoglRenderer and CoglDisplay and propagate any
resulting errors back to the user. Previously the implementation relied
on passing a NULL renderer to cogl_display_new() as the means for
implicitly connecting to a renderer. The problem with this though is
that cogl_display_new() isn't designed to ever return NULL but if it
failed to connect to a renderer automatically it would do and then
cogl_context_new would pass NULL to cogl_display_setup() leading to a
crash.

This patch changes the implementation of cogl_context_new() to now
explicitly create a CoglRenderer and connect to it if a NULL display is
given. This way we can easily propagate any errors. In addition
cogl_display_new has been changed to abort if it fails to implicitly
connect to a renderer due to a NULL renderer argument.

An application needing to gracefully handle problems connecting to a
renderer at runtime should manually instantiate and connect a renderer
passing a GError argument to cogl_renderer_connect.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-04-11 12:26:52 +01:00
Neil Roberts
f676785906 Fix including a non-existent header
cogl-sampler-cache-private.h was including a header which doesn't
exist so the build was broken. The header comes from a patch which
hasn't been pushed to master yet which splits including GL/gl.h out of
cogl-defines.h into a separate header. I added the inclusion to make
it pick up the GL defines but it doesn't need to do this yet because
cogl-context.h is still including the GL header. I didn't notice the
failure because I still had a cogl-gl-header.h lying around from a
previous build with the patch.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 15:35:01 +01:00
Neil Roberts
cb146dc515 Add a workaround for slow read pixels on Mesa
Mesa before version 8.0.2 has a slow read pixels path that gets used
with the Intel driver where it converts all of the pixels into a
floating point representation and back even if the data is being read
into exactly the same format. There is however a faster path using the
blitter when reading into a PBO with BGRA format. It works out faster
to read into a PBO and then memcpy back out into the application's
buffer even though it adds an extra memcpy. This patch adds a
workaround in cogl_framebuffer_read_pixels_into_bitmap when it detects
this situation. In that case it will create a temporary CoglBitmap
using cogl_bitmap_new_with_size, read into it and then memcpy the data
back out.

The main impetus for this patch is that Gnome Shell has implemented
this workaround directly using GL calls but it seems like the kind of
thing that would sit better at the Cogl layer.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 13:52:43 +01:00
Neil Roberts
2037e0f4f1 Add a mechanism for determining GPU driver details
This adds a CoglGpuInfo struct to the CoglContext which contains some
enums describing the GL driver in use. This currently includes the
driver package (ie, is it Mesa) the version number of the package and
the vendor of the GPU (ie, is it by Intel). There is also a bitmask
which will contain the workarounds that we should do for that
particular driver configuration. The struct is initialised on context
creation by using a series of string comparisons on the strings
returned from glGetString.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 13:52:43 +01:00
Neil Roberts
ec5009fa23 Use GL_PACK_ALIGNMENT of 1 whenever possible
The Intel driver currently has an optimisation when calling
glReadPixels into a PBO so that it will use a blit instead of the Mesa
fallback path. However this only works if the GL_PACK_ALIGNMENT is
exactly 1, even if this would be equivalent to a higher alignment
value because the bpp*width is already aligned. To make it more likely
to hit this fast path, we now detect this situation and explicitly use
an alignment of 1. To make this work the texture driver needs to be
passed down the bpp*width as well as the rowstride when configuring
the alignment.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 13:51:56 +01:00
Neil Roberts
d54111795f Use ffs to calculate the GL_{UN,}PACK_ALIGNMENT
Instead of having a series of if-statements this adds an inline
function to calculate the alignment directly using ffs which is
probably slightly faster. Admittedly this is a pointless
micro-optimisation but I think it makes the code looks a bit neater
anyway.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 13:51:56 +01:00
Neil Roberts
c33ce5fc6b Use GL_ARB_sampler_objects
GL_ARB_sampler_objects provides a GL object which overrides the
sampler state part of a texture object with different values. The
sampler state that Cogl currently exposes is the wrap modes and
filters. Cogl exposes the state as part of the pipeline layer state
but without this extension GL only exposes it as part of the texture
object state. This means that it won't work to use a single texture
multiple times in one primitive with different sampler states. It also
makes switching between different sampler states with a single texture
not terribly efficient because it has to change the texture object
state every time.

This patch adds a cache for sampler states in a shared hash table
attached to the CoglContext. The entire set of parameters for the
sampler state is used as the key for the hash table. When a unique
state is encountered the sampler cache will create a new entry,
otherwise it will return a const pointer to an existing entry. That
means we can have a single pointer to represent any combination of
sampler state.

Pipeline layers now just store this single pointer rather than storing
all of the sampler state. The two separate state flags for wrap modes
and filters have now been combined into one. It should be faster to
compare the sampler state now because instead of comparing each value
it can just compare the pointers to the cached sampler entries. The
hash table of cached sampler states should only need to perform its
more expensive hash on the state when a property is changed on a
pipeline, not every time it is flushed.

When the sampler objects extension is available each cached sampler
state will also get a sampler object to represent it. The common code
to flush the GL state will now simply bind this object to a unit
instead of flushing the state though the CoglTexture when possible.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 13:47:36 +01:00
Neil Roberts
4229d61d3b Fix places that ignore the COGL_TEXTURE_NO_AUTO_MIPMAP flag
Two of the meta texture constructors which take a flags parameter were
ignoring the COGL_TEXTURE_NO_AUTO_MIPMAP flag when creating an
underlying CoglTexture2D. These have now been fixed to call
cogl_primitive_texture_set_auto_mipmap after constructing the texture.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 13:47:36 +01:00
Neil Roberts
6197e3abf3 Add constructors which take a CoglBitmap to all primitive textures
This adds public constructors which take a CoglBitmap to all primitive
texture types. This constructor should be considered the canonical
constructor for initializing the texture with data because it should
be possible to wrap any type of data in a CoglBitmap. Having at least
this single constructor avoids the need to have an explosion of
constructors such as new_from_data, new_from_pixel_buffer and
new_from_file etc.

The already available internal bitmap constructor for CoglTexture2D
has had its flags parameter removed under the assumption that flags do
not make sense for primitive textures. The meta constructor
cogl_texture_new_from_bitmap now just explicitly calls set_auto_mipmap
after constructing the texture depending on the value of the
COGL_TEXTURE_NO_AUTO_MIPMAP flag.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 13:47:32 +01:00
Neil Roberts
e7f1582630 Add a CoglPrimitiveTexture interface
This interface represents any textures that are backed by a single
texture in GL and that can be used directly with the
cogl_framebuffer_draw_attributes family of functions. This currently
equates to CoglTexture2D, CoglTexture3D and CoglTextureRectangle.

The interface currently has only one method called
cogl_primitive_set_auto_mipmap. This replaces the
COGL_TEXTURE_NO_AUTO_MIPMAP flag from the CoglTextureFlags parameter
in the constructors. None of the other flags in CoglTextureFlags make
sense for primitive textures so it doesn't seem like a good idea to
need them for primitive constructors.

There is a boolean in the vtable to mark whether a texture type is
primitive which the new cogl_is_primitive function uses. There is also
a new texture virtual called set_auto_mipmap which is only required to
be implemented for primitive textures.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-04 17:02:23 +01:00
Neil Roberts
e7df2dbf79 bitmap: Store a pointer to the context
This adds a context member to CoglBitmap which stores the context it
was created with. That way it can be used in texture constructors
which use a bitmap. There is also an internal private function to get
the context out of the bitmap which all of the texture constructors
now use. _cogl_texture_3d_new_from_bitmap has had its context
parameter removed so that it more closely matches the other bitmap
constructors.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-04 14:24:01 +01:00
Neil Roberts
be9d5b34c6 pipeline: Use cogl_depth_state_init to init default depth state
The previous code to initialise the depth state on the default
pipeline wasn't initialising the magic number. If you later tried to
retrieve the depth state using cogl_pipeline_get_depth_state you would
end up with an invalid depth state struct and you would just get
warnings if you tried to use it for anything. This patch just replaces
the initialisation with a call to cogl_depth_state_init because it
uses the same values anyway.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-03 16:36:54 +01:00
Adel Gadllah
a000189c68 texture: Fix error handling in get_texture_bits_via_offscreen
get_texture_bits_via_offscreen does not check the return value of
cogl_framebuffer_read_pixels_into_bitmap which results into never
using the fallback path texture_get_cb.

cogl_framebuffer_read_pixels_into_bitmap does not check whether the framebuffer
is properly allocated though; so fix that as well.

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

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-04-02 23:32:53 +01:00
Neil Roberts
ae5f8323c1 gles2: Support the GL_EXT_unpack_subimage extension
This extension lets you upload texture data from a subregion of a
buffer by passing GL_UNPACK_ROW_LENGTH, GL_UNPACK_SKIP_PIXELS and
GL_UNPACK_SKIP_ROWS to glPixelStore. When this extension is available
the GLES texture driver will now avoid making a copy of the bitmap
when a subregion is used.

Note that Mesa doesn't currently advertise this extension but I've
made a patch to propose it:

http://lists.freedesktop.org/archives/mesa-dev/2012-March/020191.html
2012-03-23 13:51:08 +00:00
Neil Roberts
21e304b339 gles: Support the GL_EXT_texture_format_BGRA8888 extension
This extension allows an application to upload data in BGRA format. We
can use this to avoid a conversion in Cogl whenever it is given BGRA
data. This is quite useful when uploading data generated by Cairo
because at least on little-endian architectures that ends up as BGRA.

The patch just makes the pixel_format_to_gl implementation return
GL_BGRA_EXT for the data format and internal format whenever
COGL_PIXEL_FORMAT_BGRA_8888{,_PRE} is used.

A small caveat with this patch is that once a texture is created as
GL_BGRA, when later using glTexSubImage2D to update the texture it
must always be given data as GL_BGRA. Currently this just works out
because we store the internal format of a texture as a CoglPixelFormat
and we already swizzle the data if it does not match exactly on GLES.
However if we later switch to using a different enum for internal
formats then we might lose the ability to store the component ordering
so we'll have to think of another way to do this.
2012-03-23 13:51:08 +00:00
Neil Roberts
d6ca75fbec Add a context parameter to all of the texture driver virtuals
All of the texture driver virtual functions now take an explicit
CoglContext parameter as a step towards removing the global context.
2012-03-23 13:51:08 +00:00
Neil Roberts
60812e6a0e Add a vtable for the driver
Cogl already had a vtable for the texture driver. This ended up being
used for some things that are not strictly related to texturing such
as converting between pixel formats and GL enums. Some other functions
that are driver dependent such as updating the features were not
indirected through a vtable but instead switched directly by looking
at the ctx->driver enum value. This patch normalises to the two uses
by adding a separate vtable for driver functions not related to
texturing and moves the pixel format conversion functions to it from
the texture driver vtable. It also adds a context parameter to all of
the functions in the new driver vtable so that they won't have to rely
on the global context.
2012-03-23 13:51:08 +00:00
Chun-wei Fan
699a0bd74a Update cogl.symbols
...for the following added APIs:

cogl_bitmap_new_for_data
cogl_framebuffer_read_pixels
cogl_framebuffer_draw_multitextured_rectangles
cogl_framebuffer_draw_rectangle
cogl_framebuffer_draw_rectangles
cogl_framebuffer_draw_textured_rectangle
cogl_framebuffer_draw_textured_rectangles

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-03-21 22:15:34 +08:00
Robert Bragg
890a75ab06 Create standalone public wayland client/server headers
Because the wayland-client-protocol.h header defines symbols that
collide with the wayland-server-protocol.h header we allow applications
to explicitly ensure that they are only including one at a time by
exposing corresponding <cogl/cogl-wayland-client.h> and
<cogl/cogl-wayland-server.h> headers. This also adds a missing guard to
cogl-texture-2d.h that it isn't included directly.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-03-20 14:26:44 +00:00