summaryrefslogtreecommitdiff
path: root/cogl/cogl-framebuffer.c
diff options
context:
space:
mode:
authorRobert Bragg <robert@linux.intel.com>2012-03-16 19:54:13 +0000
committerRobert Bragg <robert@linux.intel.com>2012-03-20 12:33:40 +0000
commit3881fd32595c8748e61164320805910a02937db7 (patch)
tree2995becad76982cb8bdecdfbd2b4127c8b01f198 /cogl/cogl-framebuffer.c
parent596b508653377216531db22c22271ac1309ab50d (diff)
downloadcogl-3881fd32595c8748e61164320805910a02937db7.tar.gz
Adds cogl_framebuffer_draw_[*_]rectangle functions
This adds experimental 2.0 api replacements for the cogl_rectangle[_*] functions that don't depend on having a current pipeline set on the context via cogl_{set,push}_source() or having a current framebuffer set on the context via cogl_push_framebuffer(). The aim for 2.0 is to switch away from having a statefull context that affects drawing to having framebuffer drawing apis that are explicitly passed a framebuffer and pipeline. To test this change several of the conformance tests were updated to use this api instead of cogl_rectangle and cogl_rectangle_with_texture_coords. Since it's quite laborious going through all of the conformance tests the opportunity was taken to make other clean ups in the conformance tests to replace other uses of 1.x api with experimental 2.0 api so long as that didn't affect what was being tested.
Diffstat (limited to 'cogl/cogl-framebuffer.c')
-rw-r--r--cogl/cogl-framebuffer.c149
1 files changed, 149 insertions, 0 deletions
diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c
index 8cbee1d5..74d595f0 100644
--- a/cogl/cogl-framebuffer.c
+++ b/cogl/cogl-framebuffer.c
@@ -46,6 +46,7 @@
#include "cogl-offscreen.h"
#include "cogl1-context.h"
#include "cogl-private.h"
+#include "cogl-primitives-private.h"
#ifndef GL_FRAMEBUFFER
#define GL_FRAMEBUFFER 0x8D40
@@ -3244,3 +3245,151 @@ cogl_framebuffer_draw_primitive (CoglFramebuffer *framebuffer,
_cogl_framebuffer_draw_primitive (framebuffer, pipeline, primitive,
COGL_DRAW_SKIP_LEGACY_STATE);
}
+
+void
+cogl_framebuffer_draw_rectangle (CoglFramebuffer *framebuffer,
+ CoglPipeline *pipeline,
+ float x_1,
+ float y_1,
+ float x_2,
+ float y_2)
+{
+ const float position[4] = {x_1, y_1, x_2, y_2};
+ CoglMultiTexturedRect rect;
+
+ /* XXX: All the _*_rectangle* APIs normalize their input into an array of
+ * _CoglMultiTexturedRect rectangles and pass these on to our work horse;
+ * _cogl_framebuffer_draw_multitextured_rectangles.
+ */
+
+ rect.position = position;
+ rect.tex_coords = NULL;
+ rect.tex_coords_len = 0;
+
+ _cogl_framebuffer_draw_multitextured_rectangles (framebuffer,
+ pipeline,
+ &rect,
+ 1,
+ TRUE);
+}
+
+void
+cogl_framebuffer_draw_textured_rectangle (CoglFramebuffer *framebuffer,
+ CoglPipeline *pipeline,
+ float x_1,
+ float y_1,
+ float x_2,
+ float y_2,
+ float s_1,
+ float t_1,
+ float s_2,
+ float t_2)
+{
+ const float position[4] = {x_1, y_1, x_2, y_2};
+ const float tex_coords[4] = {s_1, t_1, s_2, t_2};
+ CoglMultiTexturedRect rect;
+
+ /* XXX: All the _*_rectangle* APIs normalize their input into an array of
+ * CoglMultiTexturedRect rectangles and pass these on to our work horse;
+ * _cogl_framebuffer_draw_multitextured_rectangles.
+ */
+
+ rect.position = position;
+ rect.tex_coords = tex_coords;
+ rect.tex_coords_len = 4;
+
+ _cogl_framebuffer_draw_multitextured_rectangles (framebuffer,
+ pipeline,
+ &rect,
+ 1,
+ TRUE);
+}
+
+void
+cogl_framebuffer_draw_multitextured_rectangle (CoglFramebuffer *framebuffer,
+ CoglPipeline *pipeline,
+ float x_1,
+ float y_1,
+ float x_2,
+ float y_2,
+ const float *tex_coords,
+ int tex_coords_len)
+{
+ const float position[4] = {x_1, y_1, x_2, y_2};
+ CoglMultiTexturedRect rect;
+
+ /* XXX: All the _*_rectangle* APIs normalize their input into an array of
+ * CoglMultiTexturedRect rectangles and pass these on to our work horse;
+ * _cogl_framebuffer_draw_multitextured_rectangles.
+ */
+
+ rect.position = position;
+ rect.tex_coords = tex_coords;
+ rect.tex_coords_len = tex_coords_len;
+
+ _cogl_framebuffer_draw_multitextured_rectangles (framebuffer,
+ pipeline,
+ &rect,
+ 1,
+ TRUE);
+}
+
+void
+cogl_framebuffer_draw_rectangles (CoglFramebuffer *framebuffer,
+ CoglPipeline *pipeline,
+ const float *coordinates,
+ unsigned int n_rectangles)
+{
+ CoglMultiTexturedRect *rects;
+ int i;
+
+ /* XXX: All the _*_rectangle* APIs normalize their input into an array of
+ * CoglMultiTexturedRect rectangles and pass these on to our work horse;
+ * _cogl_framebuffer_draw_multitextured_rectangles.
+ */
+
+ rects = g_alloca (n_rectangles * sizeof (CoglMultiTexturedRect));
+
+ for (i = 0; i < n_rectangles; i++)
+ {
+ rects[i].position = &coordinates[i * 4];
+ rects[i].tex_coords = NULL;
+ rects[i].tex_coords_len = 0;
+ }
+
+ _cogl_framebuffer_draw_multitextured_rectangles (framebuffer,
+ pipeline,
+ rects,
+ n_rectangles,
+ TRUE);
+}
+
+void
+cogl_framebuffer_draw_textured_rectangles (CoglFramebuffer *framebuffer,
+ CoglPipeline *pipeline,
+ const float *coordinates,
+ unsigned int n_rectangles)
+{
+ CoglMultiTexturedRect *rects;
+ int i;
+
+ /* XXX: All the _*_rectangle* APIs normalize their input into an array of
+ * _CoglMultiTexturedRect rectangles and pass these on to our work horse;
+ * _cogl_framebuffer_draw_multitextured_rectangles.
+ */
+
+ rects = g_alloca (n_rectangles * sizeof (CoglMultiTexturedRect));
+
+ for (i = 0; i < n_rectangles; i++)
+ {
+ rects[i].position = &coordinates[i * 8];
+ rects[i].tex_coords = &coordinates[i * 8 + 4];
+ rects[i].tex_coords_len = 4;
+ }
+
+ _cogl_framebuffer_draw_multitextured_rectangles (framebuffer,
+ pipeline,
+ rects,
+ n_rectangles,
+ TRUE);
+}