Commit Graph

26 Commits

Author SHA1 Message Date
Neil Roberts
d8df30cb9c cogl-pipeline-opengl: Don't use number of tex units on fixed-function
The CoglPipeline code uses a combination of GL_MAX_TEXTURE_COORDS,
GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS and GL_MAX_TEXTURE_UNITS to
determine the maximum number of layers to allow in a pipeline. However
on fixed function hardware that doesn't advertise either GLSL or ARBfp
it was still using the first two enums which will probably just return
0 and set a GLerror. This meant that we effectively didn't support
using any layers on purely fixed function hardware. This patch changes
it to only use those two enums if the appropriate extensions are
advertised and to always use GL_MAX_TEXTURE_UNITS except on GLES2
where there is no fixed function.

https://bugzilla.gnome.org/show_bug.cgi?id=650966
2011-05-27 11:59:17 +01:00
Robert Bragg
07c0b9f89f Add CoglDepthState API
Instead of simply extending the cogl_pipeline_ namespace to add api for
controlling the depth testing state we now break the api out. This adds
a CoglDepthState type that can be stack allocated. The members of the
structure are private but we have the following API to setup the state:

    cogl_depth_state_init
    cogl_depth_state_set_test_enabled
    cogl_depth_state_get_test_enabled
    cogl_depth_state_set_test_function
    cogl_depth_state_get_test_function
    cogl_depth_state_set_writing_enabled
    cogl_depth_state_get_writing_enabled
    cogl_depth_state_set_range
    cogl_depth_state_get_range

This removes the following experimental API which is now superseded:

    cogl_material_set_depth_test_enabled
    cogl_material_get_depth_test_enabled
    cogl_material_set_depth_test_function
    cogl_material_get_depth_test_function
    cogl_material_set_depth_writing_enabled
    cogl_material_get_depth_writing_enabled
    cogl_material_set_depth_range
    cogl_material_get_depth_range

Once a CoglDepthState structure is setup it can be set on a pipeline
using cogl_pipeline_set_depth_state().
2011-05-16 18:36:44 +01:00
Robert Bragg
fdbc741770 cogl: rename cogl-context.h cogl-context-private.h
Since we plan to add public cogl_context_* API we need to rename the
current cogl-context.h which contains private member details.
2011-04-11 15:18:12 +01:00
Neil Roberts
4bb08ba00b cogl-pipeline: Flush the lighting params in common code not vertend
The lighting parameters such as the diffuse and ambient colors were
previously only flushed in the fixed vertend. This meant that if a
vertex shader was used then they would not be set. The lighting
parameters are uniforms which are just as useful in a fragment shader
so it doesn't really make sense to set them in the vertend. They are
now flushed in the common cogl-pipeline-opengl code but the code is
#ifdef'd for GLES2 because they need to be part of the progend in that
case.
2011-01-24 12:09:11 +00:00
Neil Roberts
ed29d405b2 cogl-pipeline-opengl: #ifdef out set_glsl_program for GLES 1.1
glUseProgram is not available under GLES 1.1 so it was breaking the
build.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2516
2011-01-17 12:38:46 +00:00
Robert Bragg
03dbf67ca4 pipeline: differentiate texture target and data state
There are several places where we need to compare the texture state of a
pipeline and sometimes we need to take into consideration if the
underlying texture has changed but other times we may only care to know
if the texture target has changed.

For example the fragends typically generate programs that they want to
share with all pipelines with equivalent fragment processing state, and
in this case when comparing pipelines we only care about the texture
targets since changes to the underlying texture won't affect the
programs generated.

Prior to this we had tried to handle this by passing around some special
flags to various functions that evaluate pipeline state to say when we
do/don't care about the texture data, but this wasn't working in all
cases and was more awkward to manage than the new approach.

Now we simply have two state bits:
COGL_PIPELINE_LAYER_STATE_TEXTURE_TARGET and
COGL_PIPELINE_LAYER_STATE_TEXTURE_DATA and CoglPipelineLayer has an
additional target member. Since all the appropriate code takes masks of
these state bits to determine what to evaluate we don't need any extra
magic flags.
2011-01-13 12:23:33 +00:00
Robert Bragg
a74050554a pipeline: don't skip flush if skip_gl_color flag differs
We try and bail out of flushing pipeline state asap if we can see the
pipeline has already been flushed and hasn't changed but we weren't
checking to see if the skip_gl_color flag is the same as when it was
last flush too and so we'd sometimes bail out without updating the
glColor correctly.
2011-01-11 14:30:02 +00:00
Neil Roberts
dc1f1949d0 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
a05c701e6b 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
c11f72fd6d 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
Neil Roberts
e38e9e0355 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
fa13f6c107 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
3cf9159769 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
9b1ab9f0ec 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
6b7139b008 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
0098dc7acc 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
6ce210062d 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
Neil Roberts
f8449582c8 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
6607306a2d 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
7ea97b3eb7 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
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
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
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
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
Robert Bragg
353ea5299b cogl-shader: Prepend boilerplate for portable shaders
We now prepend a set of defines to any given GLSL shader so that we can
define builtin uniforms/attributes within the "cogl" namespace that we
can use to provide compatibility across a range of the earlier versions
of GLSL.

This updates test-cogl-shader-glsl.c and test-shader.c so they no longer
needs to special case GLES vs GL when splicing together its shaders as
well as the blur, colorize and desaturate effects.

To get a feel for the new, portable uniform/attribute names here are the
defines for OpenGL vertex shaders:

 #define cogl_position_in gl_Vertex
 #define cogl_color_in gl_Color
 #define cogl_tex_coord_in  gl_MultiTexCoord0
 #define cogl_tex_coord0_in gl_MultiTexCoord0
 #define cogl_tex_coord1_in gl_MultiTexCoord1
 #define cogl_tex_coord2_in gl_MultiTexCoord2
 #define cogl_tex_coord3_in gl_MultiTexCoord3
 #define cogl_tex_coord4_in gl_MultiTexCoord4
 #define cogl_tex_coord5_in gl_MultiTexCoord5
 #define cogl_tex_coord6_in gl_MultiTexCoord6
 #define cogl_tex_coord7_in gl_MultiTexCoord7
 #define cogl_normal_in gl_Normal

 #define cogl_position_out gl_Position
 #define cogl_point_size_out gl_PointSize
 #define cogl_color_out gl_FrontColor
 #define cogl_tex_coord_out gl_TexCoord

 #define cogl_modelview_matrix gl_ModelViewMatrix
 #define cogl_modelview_projection_matrix gl_ModelViewProjectionMatrix
 #define cogl_projection_matrix gl_ProjectionMatrix
 #define cogl_texture_matrix gl_TextureMatrix

And for fragment shaders we have:

 #define cogl_color_in gl_Color
 #define cogl_tex_coord_in gl_TexCoord

 #define cogl_color_out gl_FragColor
 #define cogl_depth_out gl_FragDepth

 #define cogl_front_facing gl_FrontFacing
2010-11-10 14:24:52 +00:00
Robert Bragg
f80cb197a9 cogl: rename CoglMaterial -> CoglPipeline
This applies an API naming change that's been deliberated over for a
while now which is to rename CoglMaterial to CoglPipeline.

For now the new pipeline API is marked as experimental and public
headers continue to talk about materials not pipelines. The CoglMaterial
API is now maintained in terms of the cogl_pipeline API internally.
Currently this API is targeting Cogl 2.0 so we will have time to
integrate it properly with other upcoming Cogl 2.0 work.

The basic reasons for the rename are:
- That the term "material" implies to many people that they are
  constrained to fragment processing; perhaps as some kind of high-level
  texture abstraction.
    - In Clutter they get exposed by ClutterTexture actors which may be
      re-inforcing this misconception.
- When comparing how other frameworks use the term material, a material
  sometimes describes a multi-pass fragment processing technique which
  isn't the case in Cogl.
- In code, "CoglPipeline" will hopefully be a much more self documenting
  summary of what these objects represent; a full GPU pipeline
  configuration including, for example, vertex processing, fragment
  processing and blending.
- When considering the API documentation story, at some point we need a
  document introducing developers to how the "GPU pipeline" works so it
  should become intuitive that CoglPipeline maps back to that
  description of the GPU pipeline.
- This is consistent in terminology and concept to OpenGL 4's new
  pipeline object which is a container for program objects.

Note: The cogl-material.[ch] files have been renamed to
cogl-material-compat.[ch] because otherwise git doesn't seem to treat
the change as a moving the old cogl-material.c->cogl-pipeline.c and so
we loose all our git-blame history.
2010-11-03 18:09:23 +00:00