[Glamor] [PATCH 10/15] glamor_render: Add non-Map/Unmap vertex array for GLES.
zhigang.gong at linux.intel.com
zhigang.gong at linux.intel.com
Fri Jan 20 00:52:08 PST 2012
From: Zhigang Gong <zhigang.gong at linux.intel.com>
As some GLES implementations' glMapOES /glUnmapOES is
not so efficient, we implement the in memory vertex array
for them.
Signed-off-by: Zhigang Gong <zhigang.gong at linux.intel.com>
---
src/glamor_render.c | 83 ++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 65 insertions(+), 18 deletions(-)
diff --git a/src/glamor_render.c b/src/glamor_render.c
index 481438f..6c93f95 100644
--- a/src/glamor_render.c
+++ b/src/glamor_render.c
@@ -305,29 +305,64 @@ glamor_init_eb(unsigned short *eb, int vert_cnt)
}
}
-
void
glamor_init_composite_shaders(ScreenPtr screen)
{
glamor_screen_private *glamor_priv;
glamor_gl_dispatch *dispatch;
unsigned short *eb;
+ float *vb;
+ int eb_size;
+ int vb_size;
glamor_priv = glamor_get_screen_private(screen);
dispatch = &glamor_priv->dispatch;
dispatch->glGenBuffers(1, &glamor_priv->vbo);
dispatch->glGenBuffers(1, &glamor_priv->ebo);
dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ebo);
- dispatch->glBufferData(GL_ELEMENT_ARRAY_BUFFER,
- GLAMOR_COMPOSITE_VBO_VERT_CNT * sizeof(short) * 2,
- NULL, GL_DYNAMIC_DRAW);
- eb = dispatch->glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
- glamor_init_eb(eb, GLAMOR_COMPOSITE_VBO_VERT_CNT);
- dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
- dispatch->glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
-}
+ eb_size = GLAMOR_COMPOSITE_VBO_VERT_CNT * sizeof(short) * 2;
+ if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+ dispatch->glBufferData(GL_ELEMENT_ARRAY_BUFFER,
+ eb_size,
+ NULL, GL_DYNAMIC_DRAW);
+ eb = dispatch->glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
+ }
+ else {
+ vb = malloc(GLAMOR_COMPOSITE_VBO_VERT_CNT * sizeof(float) * 2);
+ if (vb == NULL) {
+ ErrorF("Failed to allocate vb memory.\n");
+ exit(1);
+ }
+ eb = malloc(eb_size);
+ }
+
+ if (eb == NULL) {
+ ErrorF("fatal error, fail to get eb.\n");
+ exit(1);
+ }
+ glamor_init_eb(eb, GLAMOR_COMPOSITE_VBO_VERT_CNT);
+
+ if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+ dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ dispatch->glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
+ } else {
+ dispatch->glBufferData(GL_ELEMENT_ARRAY_BUFFER,
+ eb_size,
+ eb, GL_DYNAMIC_DRAW);
+ dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+
+ dispatch->glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo);
+ dispatch->glBufferData(GL_ARRAY_BUFFER,
+ GLAMOR_COMPOSITE_VBO_VERT_CNT * sizeof(float) * 2,
+ NULL, GL_DYNAMIC_DRAW);
+ dispatch->glBindBuffer(GL_ARRAY_BUFFER, 0);
+
+ free(eb);
+ glamor_priv->vb = (char*)vb;
+ }
+}
void
glamor_fini_composite_shaders(ScreenPtr screen)
@@ -342,7 +377,6 @@ glamor_fini_composite_shaders(ScreenPtr screen)
dispatch->glDeleteBuffers(1, &glamor_priv->vbo);
dispatch->glDeleteBuffers(1, &glamor_priv->ebo);
-
for(i = 0; i < SHADER_SOURCE_COUNT; i++)
for(j = 0; j < SHADER_MASK_COUNT; j++)
for(k = 0; k < SHADER_IN_COUNT; k++)
@@ -351,7 +385,9 @@ glamor_fini_composite_shaders(ScreenPtr screen)
if (shader->prog)
dispatch->glDeleteProgram(shader->prog);
}
-
+ if (glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP
+ && glamor_priv->vb)
+ free(glamor_priv->vb);
}
@@ -616,12 +652,13 @@ glamor_setup_composite_vbo(ScreenPtr screen, int n_verts)
if (glamor_priv->has_mask_coords)
glamor_priv->vb_stride += 2 * sizeof(float);
- dispatch->glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo);
- dispatch->glBufferData(GL_ARRAY_BUFFER,
- n_verts * sizeof(float) * 2,
- NULL, GL_DYNAMIC_DRAW);
-
- glamor_priv->vb = dispatch->glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
+ dispatch->glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo);
+ if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+ dispatch->glBufferData(GL_ARRAY_BUFFER,
+ n_verts * sizeof(float) * 2,
+ NULL, GL_DYNAMIC_DRAW);
+ glamor_priv->vb = dispatch->glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
+ }
dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ebo);
dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
@@ -690,7 +727,16 @@ glamor_flush_composite_rects(ScreenPtr screen)
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
if (!glamor_priv->render_nr_verts)
return;
- dispatch->glUnmapBuffer(GL_ARRAY_BUFFER);
+ if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP)
+ dispatch->glUnmapBuffer(GL_ARRAY_BUFFER);
+ else {
+
+ dispatch->glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo);
+ dispatch->glBufferData(GL_ARRAY_BUFFER,
+ glamor_priv->vbo_offset,
+ glamor_priv->vb, GL_DYNAMIC_DRAW);
+ }
+
dispatch->glDrawElements(GL_TRIANGLES, (glamor_priv->render_nr_verts * 3) / 2,
GL_UNSIGNED_SHORT, NULL);
}
@@ -1014,6 +1060,7 @@ glamor_composite_with_shader(CARD8 op,
glamor_set_destination_pixmap_priv_nc(dest_pixmap_priv);
glamor_validate_pixmap(dest_pixmap);
+
if (!glamor_set_composite_op(screen, op, dest, mask)) {
goto fail;
}
--
1.7.4.4
More information about the Glamor
mailing list