Commit graph

64 commits

Author SHA1 Message Date
Martin Robinson
9741099093 gl: Remove the shader language version abstraction
Cairo only needs to support one version of the shader language API,
thanks to the dispatch table. This seems unlikely to change any time
soon. This makes the addition of new features, such as a uniform
location cache, simpler.
2012-08-22 10:42:18 -07:00
Alexandros Frantzis
6867383017 gl: Provide a shader implementation of repeat wrap modes
In OpenGL ES 2.0, repeat wrap modes (GL_REPEAT and GL_MIRRORED REPEAT) are
only available for NPOT textures if the GL_OES_texture_npot is supported.
This commit adds a shader implementation of these wrap modes for use by
devices that do not support GL_OES_texture_npot.
2012-05-12 11:09:26 +01:00
Chris Wilson
4163391322 gl: Include use-coverage in shader hash
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-10-11 11:39:27 +01:00
Chris Wilson
22c485017d gl: Declare coverage input for fragment shaders.
The most minor of oversights which prevented compilation of any spans
based compositors.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-10-09 19:54:15 +01:00
Chris Wilson
af9fbd176b Introduce a new compositor architecture
Having spent the last dev cycle looking at how we could specialize the
compositors for various backends, we once again look for the
commonalities in order to reduce the duplication. In part this is
motivated by the idea that spans is a good interface for both the
existent GL backend and pixman, and so they deserve a dedicated
compositor. xcb/xlib target an identical rendering system and so they
should be using the same compositor, and it should be possible to run
that same compositor locally against pixman to generate reference tests.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

P.S. This brings massive upheaval (read breakage) I've tried delaying in
order to fix as many things as possible but now this one patch does far,
far, far too much. Apologies in advance for breaking your favourite
backend, but trust me in that the end result will be much better. :)
2011-09-12 08:29:48 +01:00
Alexandros Frantzis
2001d20747 gl: Define the float precision in the fragment shader for GLES2
According to the GLSL ES standard, the precision of variables in the fragment
shader should be explicitly defined (although mesa's compiler is not that
strict).

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-05-10 08:35:53 +01:00
Alexandros Frantzis
7bfcf1deaf gl: Store gradients in 2D textures of height 1 instead of 1D textures
1D textures are not available in GLES2. We use 2D textures with height 1
instead, which are equivalent to 1D textures and exist across all GL flavors.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-05-10 08:20:54 +01:00
Alexandros Frantzis
d308eee918 gl: Provide a shader implementation of GL_CLAMP_TO_BORDER for GLES2
The GL_CLAMP_TO_BORDER wrapping method (used with CAIRO_EXTEND_NONE) is not
available in GLES2. We use shaders to implement similar functionality for
GLES2.

If bilinear filtering is used, the shader performs a linear fade to
transparency effect in the texel coordinate intervals [-1/2n, 1/2n]
and [1 - 1/2n, 1 + 1/2n] (n: texture size).

If nearest filtering is used, the shader ensures that a clear color is
used for all texel coordinate values outside [0, 1).

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-05-10 08:19:52 +01:00
Alexandros Frantzis
7185ce4ddb gl: Pass more information to the shader emitter functions
This makes the shader emitter functions more versatile. It allows them to use
all information provided by the operands and the context to decide what shader
to produce.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-05-10 08:19:16 +01:00
Eric Anholt
17169a1e51 gl: Bind samplers just once at program compile time.
We never bound any other value to the sampler uniforms, so why bother
resetting them all the time?

[  0]   before      firefox-talos-gfx   29.972   30.493   0.89%    3/3
[  0]   after       firefox-talos-gfx   29.397   29.599   1.27%    3/3

Signed-off-by: Eric Anholt <eric@anholt.net>
2011-02-26 14:09:54 -08:00
Alexandros Frantzis
e4fdd9a1cd gl: Replace built-in vertex attributes with custom attributes
Built-in vertex attributes like gl_Vertex and gl_Color, have been obsoleted
and removed in recent GL versions and they are not supported at all in GLES2.0.
Custom attributes are supported in all GL versions >= 2.0, in GL 1.x with
ARB shader extensions and in GLES2.0.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-02-10 14:54:35 +00:00
Alexandros Frantzis
80a92b6d79 gl: Use a custom shader uniform for the ModelViewProjection matrix
The built-in gl_ModelViewProjectionMatrix uniform (and others) has been
deprecated and removed in recent GLSL versions and is not supported
at all in GLSL ES. A custom uniform for the same purpose works across
all versions.

[ickle: base _gl_identity_ortho on the 2D variant of glOrtho i.e. with
        fixed near/far values of [-1, 1]]
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-02-10 14:53:59 +00:00
Alexandros Frantzis
d88ada384f gl: Replace ftransform() with manual coordinate calculation in shaders
The ftransform() shader function was deprecated and removed in recent
GLSL versions and is not included at all in GLSL ES.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-02-10 14:37:48 +00:00
Alexandros Frantzis
b13198348c gl: Add function to bind a 4x4 float matrix shader uniform
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-02-10 14:37:43 +00:00
Alexandros Frantzis
f6ca11694b gl: Remove unnecessary checks for NULL shader implementation
Due to the fact that we fail if the system doesn't support shaders, we
now always have a valid shader implementation.

Reviewed-by: Eric Anholt <eric@anholt.net>
2011-01-31 16:07:53 -08:00
Alexandros Frantzis
037c9ba7e2 gl: Fail if GL implementation doesn't support shaders
The non-shaders implementation was never tuned for fixed-function GL
implementation, the maintainers are not interested in supporting it,
and the hardware is rather rare at this point.  This lets us focus on
the implementation for modern hardware, which needs plenty of work
still.

Reviewed-by: Eric Anholt <eric@anholt.net>
2011-01-31 16:07:53 -08:00
Andrea Canciani
49171fb534 gl: Update radial gradient implementation
Cairo assumes that radial gradients are drawn as defined in ISO3200
since b661bc8712.

To implement them in GLSL, three different shaders are required:
 - tangent circles (a=0 in the parameter equation)
 - none-extended gradient (solutions outside [0,1] must be ignored)
 - extended gradient

Moreover, texcoords are used instead of gl_FragCoord, to fix the
flipping as per 31e116f084.

Fixes huge-radial, radial-gradient, radial-gradient-extend,
radial-gradient-mask, radial-gradient-source.
2011-01-18 15:10:55 +01:00
Alexandros Frantzis
7cf9893546 gl: Replace GLEW by using the facilities provided by cairo-gl-info 2010-12-15 15:32:20 +00:00
Alexandros Frantzis
6373db8441 gl: Remove GL 1.x ARB shader implementation
Shaders for GL 1.x ARB are served by the same implementation as GL 2.x and therefore
a dedicated ARB implementation is not needed any more.
2010-12-15 15:32:20 +00:00
Alexandros Frantzis
a6facced8d gl: Use the GL core 2.0 shader implementation for both GL 1.x ARB and GL 2.x
The GL core 2.0 shader implementation can be used by both GL 1.x and 2.x
thanks to the dispatch table.
2010-12-15 15:32:20 +00:00
Alexandros Frantzis
cf518b29e0 gl: Use the dispatch table for calling ARB/EXT functions
Use the dispatch table for calling GL functions that can have multiple name
variants. Also, always use the core variant names for GL constants.
2010-12-15 15:32:20 +00:00
Eric Anholt
31e116f084 gl: Avoid using gl_FragCoord for linear gradients.
The issue is that we store our data flipped based on whether we're
rendering to an FBO or to a window.  By not flipping our gl_FragCoord
usage based on that (either with math or ARB_frag_coord_conventions),
this caused linear gradients to be flipped when rendering either to a
window or to an FBO.  To avoid this, pass in appropriate texcoords.
And, if we're passing in texcoords, just do the projection to the
linear gradient factor on the CPU side per vertex instead of providing
a bunch of uniforms to do the math per fragment.

Fixes 18 testcases.
2010-11-15 15:26:50 +08:00
Markus Stange
b53084b7c5 Fix type of _cairo_memory_stream_destroy parameter
In 9b9952ab4f
_cairo_memory_stream_destroy was changed to take an unsigned long
instead of unsigned int, and the two callsites in cairo-gl-shaders.c
weren't updated.
2010-11-05 09:25:11 +01:00
Eric Anholt
06ffb7df71 gl: Only use a mat3 for the transformation for gradients coordinates.
No point in passing in a column of zeroes that we multiply by zero, or
the row that we drop on the floor.  We could do even better by just
passing in a 3x2, at the expense of adding a language version
dependency (or just pass in 2 vectors).

No significant performance difference.
2010-07-11 21:56:55 -07:00
Benjamin Otte
0fc6f08981 gl: Make _shader_by_type() a getter
And refactor code to do the current_shader assigning itself.
2010-06-07 13:37:48 +02:00
Benjamin Otte
2971ca0498 gl: bind all shader variables at the same place
Avoids the need to bind the shader when creating it.
2010-06-07 13:37:48 +02:00
Benjamin Otte
8062fb352e gl: Add an enum for tex units
Instead of hardcoding 0 for source and 1 for mask, use an enum. It's
also clearer when functions take a cairo_gl_tex_t argument instead of a
GLuint.
2010-06-07 13:37:47 +02:00
Chris Wilson
53f0861059 gl: Make _cairo_gl_shader_(init|compile) static
Only used within _cairo_gl_shaders.c, so remove the private symbol.
2010-05-27 18:28:52 +01:00
Benjamin Otte
2a0f34c6da gl: Allow NONE and SPANS sampler for source, too 2010-05-20 13:54:02 +02:00
Benjamin Otte
bb7ca71c1a gl: Don't store the shader in the composite_t anymore
Now that we have ctx->current_shader, there's no need to keep it in the
composite setup code.
2010-05-20 11:02:49 +02:00
Benjamin Otte
970c879dd8 gl: Binding variables only works for the current shader
So make the code reflect that.
2010-05-20 11:02:49 +02:00
Benjamin Otte
065969d78f gl: Separate binding to shaders from setting operands
That way we only need to bind to shaders when creating them, but not
everytime we switch shaders on text output.
2010-05-20 11:02:49 +02:00
Benjamin Otte
e4cb46b500 gl: Implement texture upload to window with composite()
Instead of custom code that does basically the same thing, use
a temporary surface and _cairo_gl_surface_composite() to upload images.
2010-05-20 11:02:49 +02:00
Benjamin Otte
7c8759e279 gl: cache the current shader in the context 2010-05-20 11:02:49 +02:00
Chris Wilson
1c18ab02c8 gl: Rename cairo_gl_shader_program_t to cairo_gl_shader_t
And complete the move of the shaders into the cairo_gl_shader namespace.
Of particular note, the bind_*_to_shader become
_cairo_gl_shader_bind_*() and have proper types.
2010-05-17 11:54:28 +01:00
Benjamin Otte
7ef1bd22de gl: Update copyright statements
- add 2010 Red Hat copyright for my code
- include myself as author
- update contributors list
2010-05-17 01:16:16 +02:00
Benjamin Otte
0b69e51b52 gl: Assert that binding values to shaders never fails
As that would  be a programming error, we can use an assert and get rid
of return values that we weren't checking anyway.
2010-05-17 01:16:16 +02:00
Benjamin Otte
c16edee26f gl: use glBlendFuncSeparate()
This way we can treat alpha-only textures correctly and don't have to
emit different shaders for it. Also gets rid of
GL_OPERAND_TEXTURE_ALPHA.
2010-05-17 01:13:46 +02:00
Benjamin Otte
3f63004449 gl: Put shaders into a cache
This allows to grow the complexity of the shaders without enlarging the
static array to unreasonable sizes.

The cache size of 64 is essentially random.
2010-05-17 01:13:46 +02:00
Benjamin Otte
a3ee0a7f11 gl: Programmatically generate fragment shaders 2010-05-17 01:13:46 +02:00
Benjamin Otte
fe43b13052 gl: Automatically generate the vertex shader source
The idea is being able to generate shaders from the given input
on-demand. This allows creating more advanced shaders, such as those
that include the destination (for self-painting and
unsupported-by-blending operator) or painting images in weird formats
(extra translation step in shader, think YUV).
2010-05-17 01:13:46 +02:00
Benjamin Otte
405eee07ad gl: Get rid of cairo_gl_shader_source/mask_t
Use the cairo_gl_operand_type_t instead. Those enums are pretty much
identical.
2010-05-17 01:13:46 +02:00
Benjamin Otte
9f34e403f3 gl: Share vertex shaders
Previously, we created a new vertex shader for every shader program we
used. Now the code shares identical vertex shaders between programs.
2010-05-17 01:13:46 +02:00
Benjamin Otte
d2a250ad33 gl: Make the shader implementation per-context, not global 2010-05-08 18:08:18 +02:00
Andrea Canciani
b8a7f8621a Update FSF address
I updated the Free Software Foundation address using the following script.

for i in $(git grep Temple | cut -d: -f1 )
do
  sed -e 's/59 Temple Place[, -]* Suite 330, Boston, MA *02111-1307[, ]* USA/51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA/' -i "$i"
done

Fixes http://bugs.freedesktop.org/show_bug.cgi?id=21356
2010-04-27 11:13:38 +02:00
Chris Wilson
668ac047e6 gl: Avoid attempting to create a program on GLSL-incapable h/w for spans 2010-02-22 14:57:01 +00:00
Chris Wilson
29df5c91d0 gl: Return unsupported for h/w that cannot handle shaders.
Remove the ASSERT_NOT_REACHED and propagate the unsupported status so
that we fallback to fixed-function gracefully.
2010-02-22 14:46:18 +00:00
Eric Anholt
f1e794956f gl: Stop trying to handle first/last stop offset in the gradient shaders.
Since moving to pixman for the gradient textures, first=0 and last=1,
so there's no need to rescale to 0,1 any more.  Shaves 6 Gen4 ISA
instructions, including 2 inverses, in the radial fragment shader.
2010-02-17 11:03:52 -08:00
Eric Anholt
f813a0243b gl: Remove the old unused radial/linear gradients shaders.
They're dynamically generated now for source/mask.
2010-02-17 10:58:16 -08:00
Eric Anholt
8da843e996 gl: Reduce complexity of radial fragment shaders.
This shaves 1 Mesa IR instruction, and 6 Gen4 ISA instructions.
2010-02-17 10:54:39 -08:00