Commit Graph

1199 Commits

Author SHA1 Message Date
Robert Bragg
cf647e327f pipeline: Simplify layer change notifications to backend
Previously we used the layers->backend_priv[] members to determine when
to notify backends about layer changes, but it entirely up to the
backends if they want to associate private state with layers, even
though they may still be interested in layer change notifications (they
may associate layer related state with the owner pipeline).

We now make the observation that in
_cogl_pipeline_backend_layer_change_notify we should be able to assume
there can only be one backend currently associated with the layer
because we wouldn't allow changes to a layer with multiple dependants.
This means we can determine the backend to notify by looking at the
owner pipeline instead.
2010-11-25 14:41:25 +00:00
Neil Roberts
7474d320f6 cogl-context: Get rid of the features_cached member
The features_cached member of CoglContext is intended to mark when
we've calculated the features so that we know if they are ready in
cogl_get_features. However we always intialize the features while
creating the context so features_cached will never be FALSE so it's
not useful. We also had the odd behaviour that the COGL_DEBUG feature
overrides were only applied in the first call to
cogl_get_features. However there are other functions that use the
feature flags such as cogl_features_available that don't use this
function so in some cases the feature flags will be interpreted before
the overrides are applied. This patch makes it always initialize the
features and apply the overrides immediately while creating the
context. This fixes a problem with COGL_DEBUG=disable-arbfp where the
first material flushed is done before any call to cogl_get_features so
it may still use ARBfp.
2010-11-24 18:39:07 +00:00
Neil Roberts
bbf912b61d Lower the priority of the GLSL pipeline backend
Now that the GLSL backend can generate code it can effectively handle
any pipeline unless there is an ARBfp program. However with current
open source GL drivers the ARBfp compiler is more stable so it makes
sense to prefer ARBfp when possible. The GLSL backend is also lower
than the fixed function backend on the assumption that any driver that
supports GLSL will also support ARBfp so it's quicker to try the fixed
function backend next.
2010-11-24 18:06:44 +00:00
Neil Roberts
4d0b167be4 Add a COGL_DEBUG option to disable the fixed function pipeline backend
This adds COGL_DEBUG=disable-fixed to disable the fixed function
pipeline backend. This is needed to test the GLSL shader generation
because otherwise the fixed function backend would always override it.
2010-11-24 18:06:44 +00:00
Neil Roberts
54ac6b16bf Don't use the fixed function backend if there is a user program
The fixed function pipeline backend can't handle a user program so it
should bail out if one is given.
2010-11-24 18:06:44 +00:00
Neil Roberts
8083167be9 Add a warning message when no usable Cogl pipeline backend is found
If none of the pipeline backends can handle the state then it now
displays a warning so the developer has a chance to work out what's
going on.
2010-11-24 18:06:44 +00:00
Neil Roberts
cda5ea771b cogl-pipeline-glsl: Don't use gl_PointCoord on OpenGL
We don't want to use gl_PointCoord to implement point sprites on big
GL because in that case we already use glTexEnv(GL_COORD_REPLACE) to
replace the texture coords with the point sprite coords. Although GL
also supports the gl_PointCoord variable, it requires GLSL 1.2 which
would mean we would have to declare the GLSL version and check for
it. We continue to use gl_PointCoord for GLES2 because it has no
glTexEnv function.
2010-11-24 18:06:44 +00:00
Neil Roberts
c50cb72748 Remove the fragment shader generation from the GLES2 wrapper
The GLES2 wrapper no longer needs to generate any fragment shader
state because the GLSL pipeline backend will always give the wrapper a
custom fragment shader. This simplifies a lot of the state comparison
done by the wrapper. The fog generation is also removed even though
it's actually part of the vertex shader because only the fixed
function pipeline backend actually calls the fog functions so it would
be disabled when using any of the other backends anyway. We can fix
this when the two shader backends also start generating vertex
shaders.
2010-11-24 18:06:44 +00:00
Neil Roberts
9089d95b3f Disable the fixed function backend for GLES2
GLES2 doesn't really support fixed function so if we disable it we can
remove the fixed function wrappers from the GLES2 Cogl backend.
2010-11-24 18:06:44 +00:00
Neil Roberts
a86a1df372 cogl-pipeline-glsl: Generate the alpha test snippet under GLES2
GLES2 has no glAlphaFunc function so we need to simulate the behaviour
in the fragment shader. The alpha test function is simulated with an
if-statement and a discard statement. The reference value is stored as
a uniform.
2010-11-24 18:06:44 +00:00
Neil Roberts
0a314a752d cogl-pipeline: Add getters for the alpha test state
This adds two public functions:

 cogl_pipeline_get_alpha_test_function
   and
 cogl_pipeline_get_alpha_test_reference.
2010-11-24 18:06:44 +00:00
Neil Roberts
60000690e1 cogl: Separate out state flags for the alpha test func and ref
Previously the flag to mark the differences for the alpha test
function and reference value were conflated into one. However this is
awkward when generating shader code to simulate the alpha testing for
GLES 2 because in that case changing the function would need a
different program but changing the reference value just requires
updating a uniform. This patch makes the function and reference have
their own state flags.
2010-11-24 18:06:44 +00:00
Neil Roberts
38ad560b19 Remove the disabling of layer constants for GLES2
The GLSL shader generation supports layer combine constants so there's
no need to disable it for GLES2. It looks like there was also code for
it in the GLES2 wrapper so I'm not sure why it was disabled in the
first place.
2010-11-24 18:06:44 +00:00
Neil Roberts
7da3610e82 Generate GLSL in the CoglPipeline GLSL backend
The GLSL pipeline backend can now generate code to represent the
pipeline state in a similar way to the ARBfp backend. Most of the code
for this is taken from the GLES 2 wrapper.
2010-11-24 18:06:43 +00:00
Neil Roberts
46e59dc50f Move the cogl shader boilerplate setting code to a separate function
_cogl_shader_compile_real had some code to create a set of strings to
combine the boilerplate code with a shader before calling
glShaderSource. This has now been moved to its own internal function
so that it could be used from the GLSL pipeline backend as well.
2010-11-24 18:06:43 +00:00
Neil Roberts
0b28018873 Move need_texture_combine_separate to cogl-pipeline
need_texture_combine_separate is moved to cogl-pipeline.c and renamed
to _cogl_pipeline_need_texture_combine_separate. The function is
needed by both the ARBfp and GLSL codegen backends so it makes sense to
share it.
2010-11-24 18:06:43 +00:00
Neil Roberts
fac7338fdd Move find_arbfp_authority to cogl-pipeline.c
The code for finding the arbfp authority for a pipeline should be the
same as finding the GLSL authority. So that the code can be shared the
function has been moved to cogl-pipeline.c and renamed to
_cogl_pipeline_find_codegen_authority.
2010-11-24 18:06:43 +00:00
Neil Roberts
7379a5fc04 cogl: Rename arbfp_source_buffer to fragment_source_buffer
Only one of the material backends can be generating code at the same
time so it seems to make sense to share the same source buffer between
arbfp and glsl. The new name is fragment_source_buffer in case we
later want to create a new buffer for the vertex shader. That probably
couldn't share the same buffer because it will likely need to be
generated at the same time.
2010-11-24 18:06:43 +00:00
Evan Nemerson
3be05abf60 cogl: Include exported pacakges information in GIR
http://bugzilla.clutter-project.org/show_bug.cgi?id=2438
2010-11-24 17:18:17 +00:00
Owen W. Taylor
cda29a8011 Use FBOs and use cogl_read_pixels() to efficiently read partial textures
* cogl_texture_get_data() is converted to use
   _cogl_texture_foreach_sub_texture_in_region() to iterate
  through the underlying textures.

 * When we need to read only a portion of the underlying
   texture, we set up a FBO and use _cogl_read_pixels()
   to read the portion we need. This is enormously more
   efficient for reading a small portion of a large atlas
   texture.

 * The CoglAtlasTexture, CoglSubTexture, and CoglTexture2dSliced
   implementation of get_texture() are removed.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2414
2010-11-24 15:56:35 +00:00
Neil Roberts
47ccbf472e cogl-framebuffer: Try to track format of the framebuffer
Previously in cogl_read_pixels we assume the format of the framebuffer
is always premultiplied because that is the most likely format with
the default Cogl blend mode. However when the framebuffer is bound to
a texture we should be able to make a better guess at the format
because we know the texture keeps track of the premult status. This
patch adds an internal format member to CoglFramebuffer. For onscreen
framebuffers we still assume it is RGBA_8888_PRE but for offscreen to
textures we copy the texture format. cogl_read_pixels uses this to
determine whether the data returned by glReadPixels will be
premultiplied.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2414
2010-11-24 15:56:35 +00:00
Neil Roberts
8fd47276b7 cogl_read_pixels: Fix the format used in GLES2
When converting the data in cogl_read_pixels it was using bmp_format
instead of the format passed in to the function. bmp_format is the
same as the passed in format except that it always has the premult bit
set. Therefore the conversion would not handle premultiply correctly.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2414
2010-11-24 15:56:35 +00:00
Neil Roberts
e41e5efac0 Add an internal _cogl_read_pixels_with_rowstride
This is the same as _cogl_read_pixels except that it takes a rowstride
parameter for the destination buffer. Under OpenGL setting the
rowstride this will end up calling GL_ROW_LENGTH so that the buffer
region can be directly written to. Under GLES GL_ROW_LENGTH is not
supported so it will use an intermediate buffer as it does if the
format is not GL_RGBA.

cogl_read_pixels now just calls the full version of the function with
the rowstride set to width*bpp.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2414
2010-11-24 15:56:34 +00:00
Neil Roberts
05d8cc1223 Add an internal _cogl_offscreen_new_to_texture_full function
This function is the same as cogl_offscreen_new_to_texture but it
takes a level parameter and a set of flags so that FBOs can be used to
render to higher mipmap levels and to disable the depth and stencil
buffers. cogl_offscreen_new_to_texture now just calls the new function
with the level set to zero. This function could be useful in a few
places in Cogl where we want to use FBOs as an implementation detail
such as when copying between textures.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2414
2010-11-24 15:56:34 +00:00
Neil Roberts
38929d55c9 cogl-texture-driver-gles: Fix image height for uploading 3D textures
When uploading a 3D texture with an awkward rowstride, on GLES Cogl
will copy the images to an intermediate buffer to pass to GL. However
it was using the wrong height when copying the data so it would end up
overflowing the buffer and crashing.
2010-11-23 14:12:17 +00:00
Emmanuele Bassi
8e8f5d5748 pipeline: Use WrapModeInternal in the Layer struct
Since we're using CoglPipelineWrapModeInternal in the internal API
anyway, and the compiler complains loudly when comparing two enumeration
types without casting, the PipelineLayer struct should store the
wrap modes using the internal enumeration.
2010-11-23 13:08:25 +00:00
Robert Bragg
0ec9e406ea clip-stack: combine modelview-projection in set_clip_planes
When using clip planes and we we have to project some vertices into
screen coordinates we used to transform those by the modelview and then
the projection matrix separately. Now we combine the modelview and
projection matrix and then use that to transform the vertices in one
step instead.
2010-11-23 12:50:29 +00:00
Robert Bragg
649aaffbe9 journal: remove possability of fallback layers
When logging quads in the journal it used to be possible to specify a
mask of fallback layers (layers where a default white texture should be
used in-place of the corresponding texture in the current source
pipeline). Since we now handle fallbacks for cogl_rectangle* primitives
when validating the pipeline up-front before logging in the journal we
no longer need the ability for the journal to apply fallbacks too.
2010-11-23 12:50:29 +00:00
Robert Bragg
e9e824fd86 matrix: Adds experimental cogl_matrix_{transform,project}_points
This add two new function that allows us to transform or project an
array of points instead of only transforming one point at a time. Recent
benchmarking has shown cogl_matrix_transform_point to be a bottleneck
sometimes, so this should allow us to reduce the overhead when
transforming lots of vertices at the same time, and also reduce the cost
of 3 component, non-projective transforms.

For now they are marked as experimental (you have to define
COGL_ENABLE_EXPERIMENTAL_API) because there is some concern that it
introduces some inconsistent naming. cogl_matrix_transform_point would
have to be renamed cogl_matrix_project_point to be consistent, but that
would be an API break.
2010-11-23 12:50:29 +00:00
Robert Bragg
56f36cf9c2 primitives: validate with _cogl_pipeline_foreach_layer
Switch _cogl_rectangles_with_multitexture_coords to using
_cogl_pipeline_foreach_layer to iterate the layers of a pipeline when
validating instead of iterating the pipelines internal list, which is
risky since any modifications to pipelines (even to an override pipeline
derived from the original), could potentially corrupt the list as it is
being iterated.
2010-11-23 12:50:28 +00:00
Robert Bragg
1a3f946cc6 cogl: remove WrapModeOverrides from FlushOptions
This removes the possibility to specify wrap mode overrides within a
CoglPipelineFlushOptions struct since the right way to handle these
overrides is by copying the user's material and making the changes to
that copy before flushing. All primitives code has already switched away
from using these wrap mode overrides so this patch just removes unused
code and types. It also remove the wrap_mode_overrides argument for
_cogl_journal_log_quad.
2010-11-23 12:50:28 +00:00
Emmanuele Bassi
ebdf112732 build: Add missing cogl-shader-boilerplate.h 2010-11-20 10:47:22 +00:00
Emmanuele Bassi
13561e2e2d build: Add a missing file 2010-11-19 18:30:06 +00:00
Emmanuele Bassi
05f5ae1a97 build: Don't reference non-existing files 2010-11-19 18:15:49 +00:00
Owen W. Taylor
4e56eec366 Free state at the end of a journal flush
At the end of flushing the journal, we need to free the vertex
attributes and vertex array.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2423
2010-11-19 13:27:30 +00:00
Owen W. Taylor
fae591b168 Actually free buffer objects
With the refactoring to centralize code into CoglBuffer,
_cogl_buffer_fini() was never actually implemented, so all GL
vertex and index buffer objects were leaked.

The duplicate call to glDeleteBuffers() in CoglPixelArray is
removed (it wasn't paying attention to whether the buffer had been
allocated as a PBO or not.)

http://bugzilla.clutter-project.org/show_bug.cgi?id=2423
2010-11-19 13:27:30 +00:00
Robert Bragg
460e4b90d3 debug: Adds a COGL_DEBUG=wireframe option
This adds a COGL_DEBUG=wireframe option to visualize the underlying
geometry of the primitives being drawn via Cogl. This works for triangle
list, triangle fan, triangle strip and quad (internal only) primitives.
It also works for indexed vertex arrays.
2010-11-19 13:27:30 +00:00
Robert Bragg
20a1f87628 vertex-buffer: don't unref NULL object
In cogl_vertex_buffer_indices_get_for_quads() we sometimes have to
extend the length of an existing array, but when we came to unref the
previous array we didn't first check that it wasn't simply NULL.
2010-11-19 13:27:30 +00:00
Robert Bragg
982f1b4bd0 vertex-array: Adds data arg for _vertex_array_new()
This adds an optional data argument for cogl_vertex_array_new() since it
seems that mostly every case where we use this API we follow up with a
cogl_buffer_set_data() matching the size of the new array. This
simplifies all those cases and whenever we want to delay uploading of
data then NULL can simply be passed.
2010-11-19 13:27:30 +00:00
Robert Bragg
60daaff724 indices: Makes cogl_indices_get_array public
This makes the previously internal only _cogl_indices_get_array API
public as cogl_indices_get_array (Though marked as experimental)
2010-11-19 13:27:30 +00:00
Robert Bragg
fbc01d659c build: cogl-clip-state.h depends on cogl-clip-stack.h
This adds a #include "cogl-clip-stack.h" to cogl-clip-state.h which
depends on the CoglClipStack typedef.
2010-11-19 13:27:30 +00:00
Emmanuele Bassi
26f68b6f0e Merge remote branch 'elliot/cookbook-opacity-values-fix'
* elliot/cookbook-opacity-values-fix:
  cookbook: Fix opacity examples in recipe
  cookbook: Fix incorrect value for opacity
2010-11-15 15:41:46 +00:00
Emmanuele Bassi
dedceb2647 Merge remote branch 'elliot/cookbook-animations-looping'
* elliot/cookbook-animations-looping:
  cookbook: Recipe for "looping animations"
  cookbook: Clarify how signals are emitted during looped animation
  cookbook: First draft for looping animations recipe
  cookbook: Recipe skeleton for "looping animations"
  cookbook: Looping animation examples
2010-11-15 15:37:42 +00:00
Emmanuele Bassi
7e9a20960c Merge remote branch 'elliot/c90-fix' 2010-11-15 15:26:07 +00:00
Emmanuele Bassi
8c3bfaf8d9 Merge branch 'wip/static-colors'
* wip/static-colors:
  Move tests to static colors where possible
  color: Add named, global colors
2010-11-11 17:53:42 +00:00
Neil Roberts
081eb2d75d cogl-texture: Remove the gl_handle from CoglTextureSliceCallback
There's no longer any need to use the GL handle in the callback for
_cogl_texture_foreach_sub_texture_in_region because it can now work in
terms of primitive cogl textures so it has now been removed. This
would be helpful if we ever want to make the foreach function public
so that apps could implement their own primitives using sliced
textures.
2010-11-11 16:25:13 +00:00
Neil Roberts
22c61c5315 cogl-pipeline: Use layer overrides as CoglHandles instead of GLuint
Since d5634e37 the sliced texture backend now works in terms of
CoglTexture2Ds so there's no need to have special casing for
overriding the texture of a pipeline layer with a GL handle. Instead
we can just use cogl_pipeline_set_layer_texture with the
CoglHandle. The special _cogl_pipeline_set_layer_gl_texture_slice
function has now been removed and parts of the code for comparing
materials have been simplified.
2010-11-11 16:25:13 +00:00
Neil Roberts
9302d146d1 CoglTexture2DSliced: Pass slice tex to callback in foreach_sub_texture
The cogl_texture_foreach_sub_texture_in_region virtual for the sliced
texture backend was previously passing the CoglHandle of the sliced
texture to the callback. Since d5634e37 the slice texture backend now
works in terms of 2D textures so it's possible to pass the underlying
slice texture as a handle too. This makes all of the foreach callbacks
consistent in that they pass a CoglHandle of the primitive texture
type that matches the GL handle.
2010-11-11 16:25:13 +00:00
Robert Bragg
cce8645aba path 2.0: update path API for experimental 2.0 API
When COGL_ENABLE_EXPERIMENTAL_2_0_API is defined cogl.h will now include
cogl2-path.h which changes cogl_path_new() so it can directly return a
CoglPath pointer; it no longer exposes a prototype for
cogl_{get,set}_path and all the remaining cogl_path_ functions now take
an explicit path as their first argument.

The idea is that we want to encourage developers to retain path objects
for as long as possible so they can take advantage of us uploading the
path geometry to the GPU. Currently although it is possible to start a
new path and query the current path, it is not convenient.

The other thing is that we want to get Cogl to the point where nothing
depends on a global, current context variable. This will allow us to one
day define a sensible threading model if/when that is ever desired.
2010-11-11 13:17:26 +00:00
Robert Bragg
1b75ad9c80 cogl: Adds COGL_ENABLE_EXPERIMENTAL_2_0_API define
For now this new define is simply an alias for
COGL_ENABLE_EXPERIMENTAL_API but the intention is that we will also use
it to start experimenting with changes that need to break the existing
Cogl API in incompatible ways.
2010-11-11 13:17:26 +00:00