1
0
Fork 0

[cogl] cache the viewport width and height

This avoids some calls to glGetFloatv, which have at least proven to be very
in-efficient in mesa at this point in time, since it always updates all derived
state even when it may not relate to the state being requested.
This commit is contained in:
Robert Bragg 2009-07-01 12:57:30 +01:00
parent fdc048ddd0
commit 82ef6b51b9
4 changed files with 23 additions and 15 deletions

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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);