diff --git a/clutter/cogl/common/cogl.c b/clutter/cogl/common/cogl.c index 309e744d5..9b1cbf7f0 100644 --- a/clutter/cogl/common/cogl.c +++ b/clutter/cogl/common/cogl.c @@ -492,11 +492,18 @@ _cogl_disable_clip_planes (void) GE( glDisable (GL_CLIP_PLANE0) ); } +/* XXX: This should be deprecated and Cogl should be left to manage + * the glViewport automatically when switching draw buffers. */ void cogl_viewport (guint width, guint height) { + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + GE( glViewport (0, 0, width, height) ); + + ctx->viewport_width = width; + ctx->viewport_height = height; } void @@ -510,7 +517,7 @@ _cogl_setup_viewport (guint width, float z_camera; CoglMatrix projection_matrix; - GE( glViewport (0, 0, width, height) ); + cogl_viewport (width, height); /* For Ortho projection. * _cogl_current_matrix_ortho (0, width, 0, height, -1, 1); @@ -591,23 +598,18 @@ cogl_features_available (CoglFeatureFlags features) return (ctx->feature_flags & features) == features; } +/* XXX: This function should be deprecated, and replaced with a + * cogl_draw_buffer_get_size() API instead. We don't support offset + * viewports, and you can't have floating point viewport sizes. */ void cogl_get_viewport (float v[4]) { - /* FIXME: cogl_get_viewport should return a gint vec */ - /* FIXME: cogl_get_viewport should only return a width + height - * (I don't think we need to support offset viewports) */ -#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES) - GLint viewport[4]; - int i; + _COGL_GET_CONTEXT (ctx, NO_RETVAL); - glGetIntegerv (GL_VIEWPORT, viewport); - - for (i = 0; i < 4; i++) - v[i] = (float)(viewport[i]); -#else - glGetFloatv (GL_VIEWPORT, v); -#endif + v[0] = 0; + v[1] = 0; + v[2] = ctx->viewport_width; + v[3] = ctx->viewport_height; } void diff --git a/clutter/cogl/gl/cogl-context.c b/clutter/cogl/gl/cogl-context.c index f587f8cd1..745069ce8 100644 --- a/clutter/cogl/gl/cogl-context.c +++ b/clutter/cogl/gl/cogl-context.c @@ -92,6 +92,9 @@ cogl_create_context () _context->in_begin_gl_block = FALSE; + _context->viewport_width = 0; + _context->viewport_height = 0; + _context->pf_glGenRenderbuffersEXT = NULL; _context->pf_glBindRenderbufferEXT = NULL; _context->pf_glRenderbufferStorageEXT = NULL; diff --git a/clutter/cogl/gl/cogl-context.h b/clutter/cogl/gl/cogl-context.h index 81d17c4fa..57facfa2f 100644 --- a/clutter/cogl/gl/cogl-context.h +++ b/clutter/cogl/gl/cogl-context.h @@ -112,6 +112,9 @@ typedef struct gboolean in_begin_gl_block; + guint viewport_width; + guint viewport_height; + /* Relying on glext.h to define these */ COGL_PFNGLGENRENDERBUFFERSEXTPROC pf_glGenRenderbuffersEXT; COGL_PFNGLDELETERENDERBUFFERSEXTPROC pf_glDeleteRenderbuffersEXT; diff --git a/clutter/cogl/gl/cogl-fbo.c b/clutter/cogl/gl/cogl-fbo.c index f13340966..f6c622bc5 100644 --- a/clutter/cogl/gl/cogl-fbo.c +++ b/clutter/cogl/gl/cogl-fbo.c @@ -209,7 +209,7 @@ cogl_set_draw_buffer (CoglBufferTarget target, CoglHandle offscreen) } /* Setup new viewport and matrices */ - GE( glViewport (0, 0, fbo->width, fbo->height) ); + cogl_viewport (fbo->width, fbo->height); _cogl_current_matrix_translate (-1.0f, -1.0f, 0.0f); _cogl_current_matrix_scale (2.0f / fbo->width, 2.0f / fbo->height, 1.0f);