summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-03-24 09:18:41 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-03-24 10:53:59 +0100
commit0e5afa519a4ec5d3cd3dca699c965fa3ad73d74a (patch)
tree0d146b782c13f9e3c69b23b694690c077007579b
parent107dcbadef6e68cbcacb687c537f38f3bfca043c (diff)
downloadcv-0e5afa519a4ec5d3cd3dca699c965fa3ad73d74a.tar.gz
cv-0e5afa519a4ec5d3cd3dca699c965fa3ad73d74a.tar.bz2
cv-0e5afa519a4ec5d3cd3dca699c965fa3ad73d74a.zip
wimmel_gl: Use GL_BGRA_EXT in readpixels
That is the native format graphics cards use, so we reach a fastpath for the copy, which saves around 1s.
-rw-r--r--wimmel.frag2
-rw-r--r--wimmel_gl.c24
2 files changed, 21 insertions, 5 deletions
diff --git a/wimmel.frag b/wimmel.frag
index 22adcf9..58d633e 100644
--- a/wimmel.frag
+++ b/wimmel.frag
@@ -22,7 +22,7 @@ main()
}
}
- gl_FragColor = vec4(float(diff < barrier), 0.0, 0.0, 1.0);
+ gl_FragColor = vec4(0.0, 0.0, float(diff < barrier), 1.0);
}
// vim:ft=c:
diff --git a/wimmel_gl.c b/wimmel_gl.c
index 0f271af..64fdda3 100644
--- a/wimmel_gl.c
+++ b/wimmel_gl.c
@@ -1,4 +1,6 @@
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
@@ -8,6 +10,7 @@
#include <EGL/egl.h>
#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
#else
@@ -355,16 +358,29 @@ main(int argc, char **argv)
draw();
glPixelStorei(GL_PACK_ALIGNMENT, 1);
- stride = width * 4;
+ stride = width * sizeof(GLushort);
buffer = malloc(stride * height);
+
+#ifndef GLUT
+ if (!strstr((char *) glGetString(GL_EXTENSIONS),
+ "GL_EXT_read_format_bgra")) {
+ fprintf(stderr, "GL_EXT_read_format_bgra not available\n");
+ exit(EXIT_FAILURE);
+ }
+#endif
glReadPixels(0, 0, width, height,
- GL_RGBA, GL_UNSIGNED_BYTE,
+ GL_BGRA_EXT,
+#ifdef GL_EXT_read_format_bgra
+ GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT,
+#else
+ GL_UNSIGNED_SHORT_4_4_4_4_REV,
+#endif
buffer);
for (int j = 0; j < height; ++j) {
- guchar *row = buffer + (height - 1 - j) * stride;
+ GLushort *row = (GLushort *) (buffer + (height - 1 - j) * stride);
for (int i = 0; i < width; ++i) {
- if (*(row + i*4)) {
+ if (row[i] & 0x0f) {
color_t color = COLOR(255, 0, 0, 0);
for (int k = i; k < i+mwidth; k++) {
put_pixel(pixbuf, POINT(k, j), color);