1
0
Fork 0
Commit graph

1219 commits

Author SHA1 Message Date
Neil Roberts
91c1602306 cogl-texture: Don't use the source rowstride if we have to copy bitmap
If we have to copy the bitmap to do the premultiplication then we were
previously using the rowstride of the source image as the rowstride
for the new image. This is wasteful if the source image is a subregion
of a larger image which would make it use a large rowstride. If we
have to copy the data anyway we might as well compact it to the
smallest rowstride. This also prevents the copy from reading past the
end of the last row of pixels.

An internal function called _cogl_bitmap_copy has been added to do the
copy. It creates a new bitmap with the smallest possible rowstride
rounded up the nearest multiple of 4 bytes. There may be other places
in Cogl that are currently assuming we can read height*rowstride of
the source buffer so they may want to take advantage of this function
too.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2491
2011-01-10 16:54:58 +00:00
Neil Roberts
c6fbc8c567 cogl-vertex-attribute: Fix the name of the cogl_normal_in attribute
The builtin vertex attribute for the normals was incorrectly checked
for as 'cogl_normal' however it is defined as cogl_normal_in in the
shader boilerplate and for the name generated by CoglVertexBuffer.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2499
2011-01-10 14:29:25 +00:00
Emmanuele Bassi
b6558c5a18 docs: Fixes for the Cogl API reference 2010-12-22 09:52:35 +00:00
Neil Roberts
f595433942 cogl-pipeline-fragend-arbfp: Generate ARBfp if user vertex shader
The ARBfp fragend was bypassing generating a shader if the pipeline
contains a user program. However it shouldn't do this if the pipeline
only contains a vertex shader. This was breaking
test-cogl-just-vertex-shader.
2010-12-14 13:12:28 +00:00
Neil Roberts
7b985f034f Allow multiple CoglAtlases for textures
Previously Cogl would only ever use one atlas for textures and if it
reached the maximum texture size then all other new textures would get
their own GL texture. This patch makes it so that we create as many
atlases as needed. This should avoid breaking up some batches and it
will be particularly good if we switch to always using multi-texturing
with a default shader that selects between multiple atlases using a
vertex attribute.

Whenever a new atlas is created it is stored in a GSList on the
context. A weak weference is taken on the atlas using
cogl_object_set_user_data so that it can be removed from the list when
the atlas is destroyed. The atlas textures themselves take a reference
to the atlas and this is the only thing that keeps the atlas
alive. This means that once the atlas becomes empty it will
automatically be destroyed.

All of the COGL_NOTEs pertaining to atlases are now prefixed with the
atlas pointer to make it clearer which atlas is changing.
2010-12-13 18:59:41 +00:00
Neil Roberts
d01a707623 cogl-atlas: Convert to be a CoglObject subclass
To implement multiple atlases it will be useful to have ref-counting
on the CoglAtlas so it makes sense to convert it to be a CoglObject.
2010-12-13 18:59:41 +00:00
Neil Roberts
d1ddca4eee cogl-shader-boilerplate: Add the 3D texture extension on GLES2
To use the 3D texture extension on GLES2 it has to be enabled with the
following line in GLSL:

#extension GL_OES_texture_3D : enable
2010-12-13 17:29:14 +00:00
Neil Roberts
bdeb555ae1 cogl2-path: Don't flush the enable flags
All of the drawing needed in _cogl_add_path_to_stencil_buffer is done
with the vertex attribute API so there should be no need to flush the
enable flags to enable the vertex array. This was causing problems on
GLES2 where the vertex array isn't available.
2010-12-13 17:29:14 +00:00
Neil Roberts
7dc4b3c894 Remove the GLES2 wrapper
The GLES2 wrapper is no longer needed because the shader generation is
done within the GLSL fragend and vertend and any functions that are
different for GLES2 are now guarded by #ifdefs.
2010-12-13 17:29:14 +00:00
Neil Roberts
1999bee5d2 cogl-pipeline: Use enums for the layer combine values
Once the GLES2 wrapper is removed then we won't have the GLenums
needed for setting up the layer combine state. This adds Cogl enums
instead which have the same values as the corresponding GLenums. The
enums are:

CoglPipelineCombineFunc
CoglPipelineCombineSource
 and
CoglPipelineCombineOp
2010-12-13 17:29:14 +00:00
Neil Roberts
271acaaae5 cogl: upload matrices with uniforms on GLES2
Once the GLES2 wrapper is removed we won't be able to upload the
matrices with the fixed function API any more. The fixed function API
gives a global state for setting the matrix but if a custom shader
uniform is used for the matrices then the state is per
program. _cogl_matrix_stack_flush_to_gl is called in a few places and
it is assumed the current pipeline doesn't need to be flushed before
it is called. To allow these semantics to continue to work, on GLES2
the matrix flush now just stores a reference to the matrix stack in
the CoglContext. A pre_paint virtual is added to the progend which is
called whenever a pipeline is flushed, even if the same pipeline was
flushed already. This gives the GLSL progend a chance to upload the
matrices to the uniforms. The combined modelview/projection matrix is
only calculated if it is used. The generated programs end up never
using the modelview or projection matrix so it usually only has to
upload the combined matrix. When a matrix stack is flushed a reference
is taked to it by the pipeline progend and the age is stored so that
if the same state is used with the same program again then we don't
need to reupload the uniform.
2010-12-13 17:29:13 +00:00
Neil Roberts
67847260bc cogl-matrix-stack: Add _cogl_matrix_stack_has_identity_flag
This adds an internal function to quickly determine whether the top of
the matrix stack is known to be the identity matrix.
2010-12-13 17:28:52 +00:00
Neil Roberts
016005591d cogl-matrix-stack: Convert to be a CoglObject
We will want to use ref-counting on the CoglMatrixStack so it might as
well be a CoglObject.
2010-12-13 17:28:29 +00:00
Robert Bragg
58a2261387 matrix-stack: Make header style consistent
Cogl doesn't follow the Clutter/GTK+ columnized function prototype style
so this updates cogl-matrix-stack.h to match the other Cogl headers.
2010-12-13 17:28:29 +00:00
Robert Bragg
4976d22940 matrix-stack: Adds a stack age counter
Sometimes it would be useful if we could efficiently track when a matrix
stack has been modified. For example on GLES2 we have to upload the
modelview as a uniform to our glsl programs but because the modelview
state is part of the framebuffer state it becomes a bit more tricky to
know when to re-sync the value of the uniform with the framebuffer
state. This adds an "age" counter to CoglMatrixStack which is
incremented for any operation that effectively modifies the top of the
stack so now we can save the age of the stack inside the pipeline
whenever we update modelview uniform and later compare that with the
stack to determine if it has changed.
2010-12-13 17:28:29 +00:00
Neil Roberts
856d43a27c cogl-pipeline: Add internal API to get the layer matrix
This returns the layer matrix given a pipeline and a layer index. The
API is kept as internal because it directly returns a pointer into the
layer private data to avoid a copy into an out-param. We might also
want to add a public function which does the copy.
2010-12-13 17:28:29 +00:00
Neil Roberts
4514d49dda cogl-vertex-attribute: Use glVertexAttribPointer on GLES2
When the GLES2 wrapper is removed we can't use the fixed function API
such as glColorPointer to set the builtin attributes. Instead the GLSL
progend now maintains a cache of attribute locations that are queried
with glGetAttribLocation. The code that previously maintained a cache
of the enabled texture coord arrays has been modified to also cache
the enabled vertex attributes under GLES2. The vertex attribute API is
now the only place that is using this cache so it has been moved into
cogl-vertex-attribute.c
2010-12-13 17:28:29 +00:00
Neil Roberts
1515a8d73a cogl-path: Stroke using the vertex attribute API
Previously when stroking a path it was flushing a pipeline and then
directly calling glDrawArrays to draw the line strip from the path
nodes array. This patch changes it to build a CoglVertexArray and a
series of attributes to paint with instead. The vertex array and
attributes are attached to the CoglPath so it can be reused later. The
old vertex array for filling has been renamed to fill_vbo.
2010-12-13 17:28:28 +00:00
Neil Roberts
3c5fa0cf90 cogl: Move COGL_DEBUG=show-source into cogl-shader.c
The code to display the source when the show-source debug option is
given has been moved to _cogl_shader_set_source_with_boilerplate so
that it will show both user shaders and generated shaders. It also
shows the code with the full boilerplate. To make it the same for
ARBfp, cogl_shader_compile_real now also dumps user ARBfp shaders.
2010-12-13 17:28:28 +00:00
Neil Roberts
8764a0d487 cogl: Add a vertend to generate GLSL
The GLSL vertend is mostly only useful for GLES2. The fixed function
vertend is kept at higher priority than the GLSL vertend so it is
unlikely to be used in any other circumstances.
2010-12-13 17:28:28 +00:00
Neil Roberts
6c34fb7232 cogl-shader-boilerplate: Don't put the color attrib in location 0
Due to Mesa bug 28585 calling glVertexAttrib with attrib location 0
doesn't appear to work. This patch just reorders the vertex and color
attributes in the shader in the hope that Mesa will assign the color
attribute to a different location.
2010-12-13 17:28:28 +00:00
Neil Roberts
cf0ded1361 cogl-shader-boilerplate: Add more builtins for GLES2
Some builtin attributes such as the matrix uniforms and some varyings
were missing from the boilerplate for GLES2. This also moves the
texture matrix and texture coord attribute declarations to
cogl-shader.c so that they can be dynamically defined depending on the
number of texture coord arrays enabled.
2010-12-13 17:22:57 +00:00
Neil Roberts
17d689f794 cogl-pipeline: Rename the fragment_{source,header}_buffer to codegen
We want to reuse the same buffers for vertends so calling them
fragment_* doesn't make sense.
2010-12-13 17:22:57 +00:00
Neil Roberts
a3e53dd029 cogl: Add a fixed function vertend
The vertends are intended to flush state that would be represented in
a vertex program. Code to handle the layer matrix, lighting and
point size has now been moved from the common cogl-pipeline-opengl
backend to the fixed vertend.
2010-12-13 17:22:57 +00:00
Neil Roberts
313adc7bdf cogl: Add a GLSL 'progend'
'progend' is short for 'program backend'. The progend is intended to
operate on combined state from a fragment backend and a vertex
backend. The progend has an 'end' function which is run whenever the
pipeline is flushed and the two pipeline change notification
functions. All of the progends are run whenever the pipeline is
flushed instead of selecting a single one because it is possible that
multiple progends may be in use for example if the vertends and
fragends are different. The GLSL progend will take the shaders
generated by the fragend and vertend and link them into a single
program. The fragend code has been changed to only generate the shader
and not the program. The idea is that pipelines can share fragment
shader objects even if their vertex state is different. The authority
for the progend needs to be the combined authority on the vertend and
fragend state.
2010-12-13 17:22:57 +00:00
Neil Roberts
1e3cdb60d6 cogl-program: Add private functions to check if have each shader type
This adds two internal functions:

gboolean
_cogl_program_has_fragment_shader (CoglHandle handle);

gboolean
_cogl_program_has_vertex_shader (CoglHandle handle);

They just check whether any of the contained shaders are of that type.
2010-12-13 17:22:57 +00:00
Neil Roberts
31f0eb4f71 cogl-pipeline: Make find codegen authority more general
The pipeline function _cogl_pipeline_find_codegen_authority has been
renamed to _cogl_pipeline_find_equivalent_parent and it now takes a
set of flags for the pipeline and layer state that affects the
authority. This is needed so that we can reuse the same code in the
vertend and progends.
2010-12-13 17:22:57 +00:00
Neil Roberts
a1996706a2 cogl-pipeline: Move texture enabling/disabling to fixed fragend
Previously enabling and disabling textures was done whatever the
backend in cogl-pipeline-opengl. However enabling and disabling
texture targets only has any meaning if no fragment shaders are being
used so this patch moves the code to cogl-pipeline-fragend-fixed.

The GLES2 wrapper has also been changed to ignore enabledness when
deciding whether to update texture coordinate attribute pointers.
2010-12-13 17:22:57 +00:00
Neil Roberts
952878aab1 Rename CoglPipelineBackend to CoglPipelineFragend
The current Cogl pipeline backends are entirely concerned with the
fragment processing state. We also want to eventually have separate
backends to generate shaders for the vertex processing state so we
need to rename the fragment backends. 'Fragend' is a somewhat weird
name but we wanted to avoid ending up with illegible symbols like
CoglPipelineFragmentBackendGlslPrivate.
2010-12-13 17:22:57 +00:00
Neil Roberts
dc61d58c0d cogl-pipeline-opengl: Remove the includes for the various backends
Nothing in cogl-pipeline-opengl needs to know about the actual backend
implementations, instead it just accesses then through the vtables.
2010-12-13 17:22:56 +00:00
Robert Bragg
cf1fced885 pipeline: don't dereference NULL program state
This avoid dereferencing a NULL arbfp program state in
_cogl_pipeline_backend_arbfp_layer_pre_change_notify for
_STATE_COMBINE_CONSTANT changes.
2010-12-08 18:57:42 +00:00
Robert Bragg
46295a0dd1 arbfp: Copy pipelines used as cache keys
We are currently using a pipeline as a key into our arbfp program cache
but because we weren't making a copy of the pipelines used as keys there
were times when doing a lookup in the cache would end up trying to
compare a lookup key with an entry key that would point to invalid
memory.

Note: the current approach isn't ideal from the pov that that key
pipeline may reference some arbitrarily large user textures will now be
kept alive indefinitely. The plan to improve on this is that we will
have a mechanism to create a special "key pipeline" which will derive
from the default Cogl pipeline (to avoid affecting the lifetime of
other pipelines) and only copy state from the original pipeline that
affects the arbfp program and will reference small dummy textures
instead of potentially large user textures.
2010-12-08 18:35:03 +00:00
Robert Bragg
87b2300f98 arbfp: initialize arbfp_program_state->next_constant_id
When allocating a new ArbfpProgramState struct when starting code
generation we weren't initializing arbfp_program_state->next_constant_id
to 0.
2010-12-08 18:35:02 +00:00
Robert Bragg
bac600b21b pipeline: Clarify stages for finding an arbfp program
In the arbfp backend there is a seqential approach to finding a suitable
arbfp program to use for a given pipeline; first we see if there's
already a program associated with the pipeline, 2nd we try and find a
program associated with the "arbfp-authority" 3rd we try and lookup a
program in a cache and finally we resort to starting code-generation for
a new program. This patch slightly reworks the code of these steps to
hopefully make them a bit clearer.
2010-12-08 18:35:02 +00:00
Neil Roberts
9606c42c55 cogl-pipeline: Fix the layer_has_alpha_cb
_cogl_pipeline_needs_blending_enabled tries to determine whether each
layer is using the default combine state. However it was using
argument 0 for both checks so the if-statement would never be true.
2010-12-08 18:35:02 +00:00
Robert Bragg
ab5f394e5a pipeline: remove unused HashState member
There was an unused pipeline_differences member as part of the HashState
struct which this patch remove to avoid confusion.
2010-12-08 18:35:02 +00:00
Robert Bragg
5fd8e9c608 pipeline: initialize HashState flags member
There are a set of "EvalFlags" that get passed to _cogl_pipeline_hash
that can tweak the semantics of what state is evaluated for hashing but
these flags weren't getting passed via the HashState state structure
so it would be undefined if you would get the correct semantics.
2010-12-08 18:35:02 +00:00
Robert Bragg
ea66156c83 pipeline: don't use near/far symbols
According to 9cc9033347 the windows headers #define near as nothing,
and presumable the same is true for 'far' too. Apparently this define is
to improve compatibility with code written for Windows 3.1, so it's good
that people will be able to incorporate such code into their Clutter
applications.
2010-12-08 18:35:01 +00:00
Robert Bragg
9d836d8ce5 context: only declare arbfp cache for GL
We were trying to declare and initializing an arbfp program cache for
GLES but since the prototypes for the _hash and _equal functions were
only available for GL this broke the GLES builds. By #ifdefing the code
to conditionally declare/initialize for GL only this should hopefully
fix GLES builds.
2010-12-07 16:47:02 +00:00
Robert Bragg
67c2a1b29f pipeline: remove spurious use of True instead of TRUE
The constant 'True' is defined by Xlib which isn't used for all clutter
builds so this replaces occurrences of True with TRUE which is defined
by glib. This should hopefully fix the win32 builds.
2010-12-07 16:36:44 +00:00
Robert Bragg
464ed7e6b7 arbfp: Adds an ARBfp program cache
This adds a cache (A GHashTable) of ARBfp programs and before ever
starting to code-generate a new program we will always first try and
find an existing program in the cache. This uses _cogl_pipeline_hash and
_cogl_pipeline_equal to hash and compare the keys for the cache.

There is a new COGL_DEBUG=disable-program-caches option that can disable
the cache for debugging purposes.
2010-12-07 16:00:32 +00:00
Robert Bragg
e87c3820ee pipeline: Implements _cogl_pipeline_hash function
This allows us to get a hash for a set of state groups for a given
pipeline. This can be used for example to get a hash of the fragment
processing state of a pipeline so we can implement a cache for compiled
arbfp/glsl programs.
2010-12-07 16:00:32 +00:00
Robert Bragg
cc36e49ec5 pipeline: generalize _cogl_pipeline_equal
_cogl_pipeline_equal now accepts a mask of pipeline differences and layer
differences to constrain what state will be compared. In addition a set
of flags are passed that can tweak the comparison semantics for some
state groups. For example when comparing layer textures we sometimes
only need to compare the texture target and can ignore the data itself.

In updating the code this patch also changes it so all required pipeline
authorities are resolved in one step up-front instead of resolving the
authority for each state group in turn and repeatedly having to traverse
the pipeline's ancestry. This adds two new functions
_cogl_pipeline_resolve_authorities and
_cogl_pipeline_layer_resolve_authorities to handle resolving a set of
authorities.
2010-12-07 16:00:32 +00:00
Robert Bragg
ff646b7fc3 pipeline: remove layer->backend_priv[] array
This removes the unused array of per-packend priv data pointers
associated with every CoglPipelineLayer. This reduces the size of all
layer allocations and avoids having to zero an array for each
_cogl_pipeline_layer_copy.
2010-12-07 12:16:51 +00:00
Robert Bragg
1180fd159e cogl-object: remove un-used cogl_object_get_type
A non-static function named cogl_object_get_type was inadvertently added
during the addition of the CoglObject base type, but there is no public
prototype in the headers and it's only referenced inside cogl-object.c
to implement cogl_handle_get_type() for compatibility. This removes the
function since we don't want to commit to CoglObject always simply being
a boxed type. In the future we may want to register hierarchical
GTypeInstance based types.
2010-12-07 12:16:50 +00:00
Robert Bragg
ef02cb7ff2 matrix gtype: registers a boxed type for CoglMatrix
To allow us to have gobject properties that accept a CoglMatrix value we
need to register a GType. This adds a cogl_gtype_matrix_get_type function
that will register a static boxed type called "CoglMatrix".

This adds a new section to the reference manual for GType integration
functions.
2010-12-07 12:16:50 +00:00
Robert Bragg
c29a7526c0 matrix: Adds matrix_copy and _free functions
As a pre-requisite for being able to register a boxed GType for
CoglMatrix (enabling us to define gobject properties that accept a
CoglMatrix) this adds cogl_matrix_copy and _free functions.
2010-12-07 12:16:50 +00:00
Robert Bragg
3edd02841b pipeline simple optimization for _needs_blending_enabled
In _cogl_pipeline_needs_blending_enabled after first checking whether
the property most recently changed requires blending we would then
resort to checking all other properties too in case some other state
also requires blending. We now avoid checking all other properties in
the case that blending was previously disabled and checking the property
recently changed doesn't require blending.

Note: the plan is to improve this further by explicitly keeping track
of the properties that currently cause blending to be enabled so that we
never have to resort to checking all other properties we can constrain
the checks to those masked properties.
2010-12-03 17:16:58 +00:00
Robert Bragg
9ff191bd3b pipeline: inline _get_parent and _get_authority
This moves _cogl_pipeline_get_parent and _cogl_pipeline_get_authority
into cogl-pipeline-private.h so they can be inlined since they have been
seen to get quite high in profiles. Given that they both contain such
small amounts of code the function call overhead is significant.
2010-12-03 17:16:58 +00:00
Neil Roberts
3fa91efea8 Add a COGL_DEBUG option to disable software clipping
This adds a debug option called disable-software-clipping which causes
the journal to always log the clip stack state rather than trying to
manually clip rectangles.
2010-12-03 17:16:58 +00:00
Neil Roberts
62c893feee cogl-journal: Attempt to clip manually to avoid breaking up batches
Before flushing the journal there is now a separate iteration that
will try to determine if the matrix of the clip stack and the matrix
of the rectangle in each entry are on the same plane. If they are it
can completely avoid the clip stack and instead manually modify the
vertex and texture coordinates to implement the clip. The has the
advantage that it won't break up batching if a single clipped
rectangle is used in a scene.

The software clip is only used if there is no user program and no
texture matrices. There is a threshold to the size of the batch where
it is assumed that it is worth the cost to break up a batch and
program the GPU to do the clipping. Currently this is set to 8
although this figure is plucked out of thin air.

To check whether the two matrices are on the same plane it tries to
determine if one of the matrices is just a simple translation of the
other. In the process of this it also works out what the translation
would be. These values can be used to translate the clip rectangle
into the coordinate space of the rectangle to be logged. Then we can
do the clip directly in the rectangle's coordinate space.
2010-12-03 17:16:58 +00:00
Neil Roberts
be63fcee7f cogl-clip-stack: Move the struct definitions to the header
It will be useful to be able to directly examine the contents of the
clip stack within the journal code.
2010-12-03 17:16:58 +00:00
Neil Roberts
dc0506a164 cogl-clip-stack: Don't convert rect clips to window clips
Previously in cogl-clip-state.c when it detected that the current
modelview matrix is screen-aligned it would convert the clip entry to
a window clip. Instead of doing this cogl-clip-stack.c now contains
the detection and keeps the entry as a rectangle clip but marks that
it is entirely described by its scissor rect. When flusing the clip
stack it doesn't do anything extra for entries that have this mark
(because the clip will already been setup by the scissor). This is
needed so that we can still track the original rectangle coordinates
and modelview matrix to help detect when it would be faster to modify
the rectangle when adding it to the journal rather than having to
break up the batch to set the clip state.
2010-12-03 17:16:57 +00:00
Neil Roberts
22be07c3b5 cogl-journal: Defer expanding the vertices until uploading
When logging a quad we now only store the 2 vertices representing the
top left and bottom right of the quad. The color is only stored once
per entry. Once we come to upload the data we expand the 2 vertices
into four and copy the color to each vertex. We do this by mapping the
buffer and directly expanding into it. We have to copy the data before
we can render it anyway so it doesn't make much sense to expand the
vertices before uploading and this way should save some space in the
size of the journal. It also makes it slightly easier if we later want
to do pre-processing on the journal entries before uploading such as
doing software clipping.

The modelview matrix is now always copied to the journal entry whereas
before it would only be copied if we aren't doing software
transform. The journal entry struct always has the space for the
modelview matrix so hopefully it's only a small cost to copy the
matrix.

The transform for the four entries is now done using
cogl_matrix_transform_points which may be slightly faster than
transforming them each individually with a call to
cogl_matrix_transfom.
2010-12-03 17:16:57 +00:00
Neil Roberts
a7d88e1527 Revert "cogl: Remove the generated array size for cogl_tex_coord_in"
This reverts commit 4cfe90bde2.

GLSL 1.00 on GLES doesn't support unsized arrays so the whole idea
can't work.

Conflicts:

	clutter/cogl/cogl/cogl-pipeline-glsl.c
2010-12-03 15:27:17 +00:00
Neil Roberts
dd5431ef38 cogl-pipeline-glsl: Fix reusing shaders for shared ancestors
The check for whether we can reuse a program we've already generated
was only being done if the pipeline already had a
glsl_program_state. When there is no glsl_program_state it then looks
for the nearest ancestor it can share the program with. It then
wasn't checking whether that ancestor already had a GL program so it
would start generating the source again. It wouldn't however compile
that source again because _cogl_pipeline_backend_glsl_end does check
whether there is already a program. This patch moves the check until
after it has found the glsl_program_state, whether or not it was found
from an ancestor or as its own state.
2010-12-02 16:36:00 +00:00
Neil Roberts
4cfe90bde2 cogl: Remove the generated array size for cogl_tex_coord_in
Under GLES2 we were defining the cogl_tex_coord_in varying as an array
with a size determined by the number of texture coordinate arrays
enabled whenever the program is used. This meant that we may have to
regenerate the shader with a different size if the shader is used with
more texture coord arrays later. However in OpenGL the equivalent
builtin varying gl_TexCoord is simply defined as:

varying vec4 gl_TexCoord[]; /* <-- no size */

GLSL is documented that if you declare an array with no size then you
can only access it with a constant index and the size of the array
will be determined by the highest index used. If you want to access it
with a non-constant expression you need to redeclare the array
yourself with a size.

We can replicate the same behaviour in our Cogl shaders by instead
declaring the cogl_tex_coord_in with no size. That way we don't have
to pass around the number of tex coord attributes enabled when we
flush a material. It also means that CoglShader can go back to
directly uploading the source string to GL when cogl_shader_source is
called so that we don't have to keep a copy of it around.

If the user wants to access cogl_tex_coord_in with a non-constant
index then they can simply redeclare the array themself. Hopefully
developers will expect to have to do this if they are accustomed to
the gl_TexCoord array.
2010-12-02 12:27:29 +00:00
Neil Roberts
87a72d188e cogl-pipeline: Fix comparing layer states for finding codgen authority
When compiling for GLES2, the codegen is affected by state other than
the layers. That means when we find an authority for the codegen state
we can't directly look at authority->n_layers to determine the number
of layers because it isn't necessarily the layer state authority. This
patch changes it to use cogl_pipeline_get_n_layers instead. Once we
have two authorities that differ in codegen state we then compare all
of the layers to decide if they would affect codegen. However it was
ignoring the fact that the authorities might also differ by the other
codegen state. This path also adds an extra check for whether
_cogl_pipeline_compare_differences contains any codegen bits other
than COGL_PIPELINE_STATE_LAYERS.
2010-12-01 15:48:37 +00:00
Neil Roberts
f620d53054 cogl-pipeline: Fix the codgen authority for texture target changes
When determining if a layer would require a different shader to be
generated it needs to check a certain set of state changes and it
needs to check whether the texture target is different. However it was
checking whether texture texture was different only if the other state
was also different which doesn't make any sense. It also only checked
the texture difference if that was the only state change which meant
that effectively the code was impossible to reach. Now it does the
texture target check indepent of the other state changes.
2010-12-01 14:39:28 +00:00
Neil Roberts
a38fa7a2df cogl-pipeline-fixed: Use the correct state flag for combine constant
The fixed pipeline backend wasn't correctly flushing the combine
constant because it was using the wrong flag to determine if the
combine constant has changed since the last flushed material.
2010-11-30 22:28:38 +00:00
Neil Roberts
499a370ee3 cogl-pipeline-opengl: Fix enabling previously disabled units
When enabling a unit that was disabled from a previous flush pipeline
it was forgetting to rebind the right texture unit so it wouldn't
work. This was causing the redhand to disappear when using the fixed
function backend in test-cogl-multitexture if anything else is added
to the scene.
2010-11-30 22:17:17 +00:00
Neil Roberts
17a98875d3 cogl-pipeline: Add more ignored state changes for program generation
For shader generation backends we don't need to worry about changes to
the texture object and changing the user matrix. The missing user
matrix flag was causing test-cogl-multitexture to regenerate the
shader every frame.
2010-11-30 22:15:40 +00:00
Damien Lespiau
1564418b3f cogl: Revert "build: Remove unused variable"
Having ctx here produces a warning on GLES. However it's needed for Big
GL as we have at the top of the file:

 #ifdef HAVE_COGL_GL
 #define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
 #endif

This reverts commit 27a3a2056a.
2010-11-30 16:39:00 +00:00
Damien Lespiau
bbbd91e581 cogl: Fix unused variable warning with GLES2
This shader variable is only used with big GL.
2010-11-30 16:03:26 +00:00
Damien Lespiau
27a3a2056a build: Remove unused variable
and be 100% warning free again.
2010-11-30 14:40:38 +00:00
Neil Roberts
d046df8e6f cogl-shader.c: Don't add the common boilerplate twice
In 6246c2bd6 I moved the code to add the boilerplate to a shader to a
separate function and also made it so that the common boilerplate is
added as a separate string to glShaderSource. However I didn't notice
that the #define for the vertex and fragment shaders already includes
the common part so it was being added twice. Mesa seems to accept this
but it was causing problems on the IMG driver because COGL_VERSION was
defined twice.
2010-11-29 13:43:09 +00:00
Neil Roberts
ae300dc8e0 cogl-pipeline-glsl: Use char* instead of GLchar*
It appears that some GLES2 headers don't define GLchar and it works
just as well to use a regular char.
2010-11-29 13:42:20 +00:00
Neil Roberts
21e47d4280 cogl_pipeline_equal: Fix the comparison for layer texture equality
Before commit 49898d43 CoglPipeline would compare whether a pipeline
layer's texture is equal by fetching the underlying GL handle. I
changed that so that it would only compare the CoglHandles because
that commit removes the GL handle texture overrides and sliced
textures instead log the underlying primitive texture. However I
forgot that the primitives don't always use
_cogl_texture_foreach_sub_texture_in_region when the quad fits within
the single texture so it won't use a texture override. This meant that
atlas textures and sub textures get logged with the atlas handle so
the comparison still needs to be done using the GL handles. It might
be nice to add a CoglTexture virtual to get the underlying primitive
texture instead to avoid having the pipeline poke around with GL
handles.
2010-11-26 15:49:31 +00:00
Robert Bragg
58a467c927 primitives: avoid leaking polygon override materials
If we have to make override changes to the user's source material to
handle cogl_polygon then we need to make sure we unref the override
material at the end.
2010-11-26 14:33:50 +00:00
Alexandre Quessy
01b93537ab Fixed "the the" repetitions in some doc strings
http://bugzilla.clutter-project.org/show_bug.cgi?id=2450
2010-11-25 18:18:51 +00:00
Robert Bragg
3729e47ef6 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
1b2a748d6c 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
b9176e8672 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
d19f6212ce 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
577d65c2c9 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
aa498072e0 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
289e880efd 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
a50010fb40 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
987e3c32dc 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
3504491b46 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
c3582b77df 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
959846326f 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
124441aade 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
3fa73735c0 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
6246c2bd6c 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
339fc68bcb 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
9bbb088a2a 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
e57a132f94 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
9b5c90f441 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
8b4034cd06 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
519b6fe6f2 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
08e1d7f574 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
2bd054f886 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
b4016f64fa 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
1b7c895a2d 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
01c6ccfa13 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
c68280556e 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
99f4832c28 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
2dba3e8cbf 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
4307e65f93 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