From patchwork Tue Feb 8 11:10:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 87 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:39:52 -0000 Delivered-To: patches@linaro.org Received: by 10.147.124.5 with SMTP id b5cs87032yan; Tue, 8 Feb 2011 03:10:28 -0800 (PST) Received: by 10.103.228.7 with SMTP id f7mr744092mur.48.1297163427917; Tue, 08 Feb 2011 03:10:27 -0800 (PST) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx.google.com with ESMTPS id o67si8391366wej.69.2011.02.08.03.10.27 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 08 Feb 2011 03:10:27 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.50 is neither permitted nor denied by best guess record for domain of alexandros.frantzis@linaro.org) client-ip=74.125.82.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.50 is neither permitted nor denied by best guess record for domain of alexandros.frantzis@linaro.org) smtp.mail=alexandros.frantzis@linaro.org Received: by mail-ww0-f50.google.com with SMTP id 26so5658906wwf.31 for ; Tue, 08 Feb 2011 03:10:27 -0800 (PST) Received: by 10.227.144.14 with SMTP id x14mr4043448wbu.180.1297163427487; Tue, 08 Feb 2011 03:10:27 -0800 (PST) Received: from localhost ([194.219.210.40]) by mx.google.com with ESMTPS id x1sm4299756wbh.14.2011.02.08.03.10.26 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 08 Feb 2011 03:10:27 -0800 (PST) From: alexandros.frantzis@linaro.org To: cairo@cairographics.org Subject: [PATCH 4/6] gl: Use a custom shader uniform for the ModelViewProjection matrix Date: Tue, 8 Feb 2011 13:10:13 +0200 Message-Id: <1297163415-31035-5-git-send-email-alexandros.frantzis@linaro.org> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1297163415-31035-1-git-send-email-alexandros.frantzis@linaro.org> References: <1297163415-31035-1-git-send-email-alexandros.frantzis@linaro.org> From: Alexandros Frantzis 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. --- src/cairo-gl-composite.c | 2 + src/cairo-gl-device.c | 53 +++++++++++++++++++++++++++++++++++++++------ src/cairo-gl-private.h | 1 + src/cairo-gl-shaders.c | 3 +- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c index a32e00d..7cbe894 100644 --- a/src/cairo-gl-composite.c +++ b/src/cairo-gl-composite.c @@ -414,6 +414,8 @@ static void _cairo_gl_composite_bind_to_shader (cairo_gl_context_t *ctx, cairo_gl_composite_t *setup) { + _cairo_gl_shader_bind_matrix4f(ctx, "ModelViewProjectionMatrix", + ctx->modelviewprojection_matrix); _cairo_gl_operand_bind_to_shader (ctx, &setup->src, CAIRO_GL_TEX_SOURCE); _cairo_gl_operand_bind_to_shader (ctx, &setup->mask, CAIRO_GL_TEX_MASK); } diff --git a/src/cairo-gl-device.c b/src/cairo-gl-device.c index 25423e0..32543ce 100644 --- a/src/cairo-gl-device.c +++ b/src/cairo-gl-device.c @@ -269,6 +269,48 @@ _cairo_gl_ensure_framebuffer (cairo_gl_context_t *ctx, } } +/* + * Stores a parallel projection transformation in matrix 'm', + * using column-major order. + * + * This is equivalent to: + * + * glLoadIdentity() + * glOrtho() + * + * The calculation for the ortho tranformation was taken from the + * mesa source code. + */ +static void +_gl_identity_ortho (GLfloat left, GLfloat right, + GLfloat bottom, GLfloat top, + GLfloat nearval, GLfloat farval, + GLfloat *m) +{ +#define M(row,col) m[col*4+row] + M(0,0) = 2.0F / (right - left); + M(0,1) = 0.0F; + M(0,2) = 0.0F; + M(0,3) = -(right + left) / (right - left); + + M(1,0) = 0.0F; + M(1,1) = 2.0F / (top - bottom); + M(1,2) = 0.0F; + M(1,3) = -(top + bottom) / (top - bottom); + + M(2,0) = 0.0F; + M(2,1) = 0.0F; + M(2,2) = -2.0F / (farval - nearval); + M(2,3) = -(farval + nearval) / (farval - nearval); + + M(3,0) = 0.0F; + M(3,1) = 0.0F; + M(3,2) = 0.0F; + M(3,3) = 1.0F; +#undef M +} + + void _cairo_gl_context_set_destination (cairo_gl_context_t *ctx, cairo_gl_surface_t *surface) @@ -295,13 +337,10 @@ _cairo_gl_context_set_destination (cairo_gl_context_t *ctx, glViewport (0, 0, surface->width, surface->height); - glMatrixMode (GL_PROJECTION); - glLoadIdentity (); if (_cairo_gl_surface_is_texture (surface)) - glOrtho (0, surface->width, 0, surface->height, -1.0, 1.0); + _gl_identity_ortho (0, surface->width, 0, surface->height, -1.0, 1.0, + ctx->modelviewprojection_matrix); else - glOrtho (0, surface->width, surface->height, 0, -1.0, 1.0); - - glMatrixMode (GL_MODELVIEW); - glLoadIdentity (); + _gl_identity_ortho (0, surface->width, surface->height, 0, -1.0, 1.0, + ctx->modelviewprojection_matrix); } diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h index 3dd75f8..61c382d 100644 --- a/src/cairo-gl-private.h +++ b/src/cairo-gl-private.h @@ -259,6 +259,7 @@ struct _cairo_gl_context { cairo_bool_t has_mesa_pack_invert; cairo_gl_dispatch_t dispatch; + GLfloat modelviewprojection_matrix[16]; void (*acquire) (void *ctx); void (*release) (void *ctx); diff --git a/src/cairo-gl-shaders.c b/src/cairo-gl-shaders.c index 13efccb..6a3a606 100644 --- a/src/cairo-gl-shaders.c +++ b/src/cairo-gl-shaders.c @@ -518,9 +518,10 @@ cairo_gl_shader_get_vertex_source (cairo_gl_var_type_t src, cairo_gl_shader_emit_variable (stream, mask, CAIRO_GL_TEX_MASK); _cairo_output_stream_printf (stream, + "uniform mat4 ModelViewProjectionMatrix;\n" "void main()\n" "{\n" - " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"); + " gl_Position = ModelViewProjectionMatrix * gl_Vertex;\n"); cairo_gl_shader_emit_vertex (stream, src, CAIRO_GL_TEX_SOURCE); cairo_gl_shader_emit_vertex (stream, mask, CAIRO_GL_TEX_MASK);