From bc372d27346d22a31cf33edaa3f0c1ad91b989e3 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Tue, 1 Feb 2011 16:51:58 +0000 Subject: [PATCH] viewport: consistently use floats for viewports OpenGL < 4.0 only supports integer based viewports and internally we have a mixture of code using floats and integers for viewports. This patch switches all viewports throughout clutter and cogl to be represented using floats considering that in the future we may want to take advantage of floating point viewports with modern hardware/drivers. --- cogl/cogl-framebuffer-private.h | 26 +++++++++++++------------- cogl/cogl-framebuffer.c | 23 ++++++++++++----------- cogl/cogl-journal.c | 2 +- cogl/cogl-matrix-mesa.c | 8 +++++--- cogl/cogl-matrix-mesa.h | 2 +- cogl/cogl-texture.c | 12 ++++++------ cogl/cogl.c | 7 +------ cogl/cogl.h | 3 --- 8 files changed, 39 insertions(+), 44 deletions(-) diff --git a/cogl/cogl-framebuffer-private.h b/cogl/cogl-framebuffer-private.h index 27e137dc1..44fc84f37 100644 --- a/cogl/cogl-framebuffer-private.h +++ b/cogl/cogl-framebuffer-private.h @@ -46,10 +46,10 @@ struct _CoglFramebuffer CoglMatrixStack *modelview_stack; CoglMatrixStack *projection_stack; - int viewport_x; - int viewport_y; - int viewport_width; - int viewport_height; + float viewport_x; + float viewport_y; + float viewport_width; + float viewport_height; CoglClipState clip_state; @@ -173,25 +173,25 @@ _cogl_framebuffer_set_clip_stack (CoglFramebuffer *framebuffer, void _cogl_framebuffer_set_viewport (CoglFramebuffer *framebuffer, - int x, - int y, - int width, - int height); -int + float x, + float y, + float width, + float height); +float _cogl_framebuffer_get_viewport_x (CoglFramebuffer *framebuffer); -int +float _cogl_framebuffer_get_viewport_y (CoglFramebuffer *framebuffer); -int +float _cogl_framebuffer_get_viewport_width (CoglFramebuffer *framebuffer); -int +float _cogl_framebuffer_get_viewport_height (CoglFramebuffer *framebuffer); void _cogl_framebuffer_get_viewport4fv (CoglFramebuffer *framebuffer, - int *viewport); + float *viewport); CoglMatrixStack * _cogl_framebuffer_get_modelview_stack (CoglFramebuffer *framebuffer); diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c index fbe0b457d..f006407ce 100644 --- a/cogl/cogl-framebuffer.c +++ b/cogl/cogl-framebuffer.c @@ -499,10 +499,10 @@ _cogl_framebuffer_set_clip_stack (CoglFramebuffer *framebuffer, void _cogl_framebuffer_set_viewport (CoglFramebuffer *framebuffer, - int x, - int y, - int width, - int height) + float x, + float y, + float width, + float height) { _COGL_GET_CONTEXT (ctx, NO_RETVAL); @@ -523,32 +523,33 @@ _cogl_framebuffer_set_viewport (CoglFramebuffer *framebuffer, ctx->dirty_gl_viewport = TRUE; } -int +float _cogl_framebuffer_get_viewport_x (CoglFramebuffer *framebuffer) { return framebuffer->viewport_x; } -int +float _cogl_framebuffer_get_viewport_y (CoglFramebuffer *framebuffer) { return framebuffer->viewport_y; } -int +float _cogl_framebuffer_get_viewport_width (CoglFramebuffer *framebuffer) { return framebuffer->viewport_width; } -int +float _cogl_framebuffer_get_viewport_height (CoglFramebuffer *framebuffer) { return framebuffer->viewport_height; } void -_cogl_framebuffer_get_viewport4fv (CoglFramebuffer *framebuffer, int *viewport) +_cogl_framebuffer_get_viewport4fv (CoglFramebuffer *framebuffer, + float *viewport) { viewport[0] = framebuffer->viewport_x; viewport[1] = framebuffer->viewport_y; @@ -1290,7 +1291,7 @@ _cogl_framebuffer_flush_state (CoglFramebuffer *draw_buffer, if (ctx->dirty_gl_viewport) { - int gl_viewport_y; + float gl_viewport_y; /* Convert the Cogl viewport y offset to an OpenGL viewport y offset * NB: OpenGL defines its window and viewport origins to be bottom @@ -1303,7 +1304,7 @@ _cogl_framebuffer_flush_state (CoglFramebuffer *draw_buffer, gl_viewport_y = draw_buffer->height - (draw_buffer->viewport_y + draw_buffer->viewport_height); - COGL_NOTE (OPENGL, "Calling glViewport(%d, %d, %d, %d)", + COGL_NOTE (OPENGL, "Calling glViewport(%f, %f, %f, %f)", draw_buffer->viewport_x, gl_viewport_y, draw_buffer->viewport_width, diff --git a/cogl/cogl-journal.c b/cogl/cogl-journal.c index ea152f31e..88fbb9848 100644 --- a/cogl/cogl-journal.c +++ b/cogl/cogl-journal.c @@ -1552,7 +1552,7 @@ entry_to_screen_polygon (const CoglJournalEntry *entry, CoglMatrixStack *projection_stack; CoglMatrix projection; int i; - int viewport[4]; + float viewport[4]; poly[0] = vertices[0]; poly[1] = vertices[1]; diff --git a/cogl/cogl-matrix-mesa.c b/cogl/cogl-matrix-mesa.c index 59d9e6f4c..0356a1127 100644 --- a/cogl/cogl-matrix-mesa.c +++ b/cogl/cogl-matrix-mesa.c @@ -1251,13 +1251,15 @@ _math_matrix_translate (CoglMatrix *matrix, float x, float y, float z) * Transforms Normalized Device Coords to window/Z values. */ void -_math_matrix_viewport (CoglMatrix *matrix, int x, int y, int width, int height, +_math_matrix_viewport (CoglMatrix *matrix, + float x, float y, + float width, float height, float zNear, float zFar, float depthMax) { float *m = (float *)matrix; - m[MAT_SX] = (float)width / 2.0f; + m[MAT_SX] = width / 2.0f; m[MAT_TX] = m[MAT_SX] + x; - m[MAT_SY] = (float) height / 2.0f; + m[MAT_SY] = height / 2.0f; m[MAT_TY] = m[MAT_SY] + y; m[MAT_SZ] = depthMax * ((zFar - zNear) / 2.0f); m[MAT_TZ] = depthMax * ((zFar - zNear) / 2.0f + zNear); diff --git a/cogl/cogl-matrix-mesa.h b/cogl/cogl-matrix-mesa.h index 79f4558d4..72ac8650f 100644 --- a/cogl/cogl-matrix-mesa.h +++ b/cogl/cogl-matrix-mesa.h @@ -134,7 +134,7 @@ _math_matrix_frustum (CoglMatrix *matrix, void _math_matrix_viewport (CoglMatrix *matrix, - int x, int y, int width, int height, + float x, float y, float width, float height, float z_near, float z_far, float depth_max); void diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c index 2b4c09762..3348f483d 100644 --- a/cogl/cogl-texture.c +++ b/cogl/cogl-texture.c @@ -929,7 +929,7 @@ cogl_texture_set_region (CoglHandle handle, static void do_texture_draw_and_read (CoglHandle handle, CoglBitmap *target_bmp, - GLint *viewport) + float *viewport) { int bpp; float rx1, ry1; @@ -1036,7 +1036,7 @@ _cogl_texture_draw_and_read (CoglHandle handle, { int bpp; CoglFramebuffer *framebuffer; - int viewport[4]; + float viewport[4]; CoglBitmap *alpha_bmp; CoglMatrixStack *projection_stack; CoglMatrixStack *modelview_stack; @@ -1064,10 +1064,10 @@ _cogl_texture_draw_and_read (CoglHandle handle, _cogl_matrix_stack_push (projection_stack); _cogl_matrix_stack_load_identity (projection_stack); _cogl_matrix_stack_ortho (projection_stack, - 0, (float)(viewport[2]), - (float)(viewport[3]), 0, - (float)(0), - (float)(100)); + 0, viewport[2], + viewport[3], 0, + 0, + 100); modelview_stack = _cogl_framebuffer_get_modelview_stack (framebuffer); _cogl_matrix_stack_push (modelview_stack); diff --git a/cogl/cogl.c b/cogl/cogl.c index 515e4dd3c..b79452db3 100644 --- a/cogl/cogl.c +++ b/cogl/cogl.c @@ -407,19 +407,14 @@ _cogl_features_available_private (CoglFeatureFlagsPrivate features) * _cogl_framebuffer_get_viewport* functions public. */ void -cogl_get_viewport (float v[4]) +cogl_get_viewport (float viewport[4]) { CoglFramebuffer *framebuffer; - int viewport[4]; - int i; _COGL_GET_CONTEXT (ctx, NO_RETVAL); framebuffer = _cogl_get_draw_buffer (); _cogl_framebuffer_get_viewport4fv (framebuffer, viewport); - - for (i = 0; i < 4; i++) - v[i] = viewport[i]; } void diff --git a/cogl/cogl.h b/cogl/cogl.h index a55b4ed4e..f3a354361 100644 --- a/cogl/cogl.h +++ b/cogl/cogl.h @@ -1281,9 +1281,6 @@ _cogl_check_extension (const char *name, const char *ext); void _cogl_set_indirect_context (gboolean indirect); -void -_cogl_set_viewport (int x, int y, int width, int height); - gboolean _cogl_check_driver_valid (GError **error);