summaryrefslogtreecommitdiff
path: root/wimmel_gl.c
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 /wimmel_gl.c
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.
Diffstat (limited to 'wimmel_gl.c')
-rw-r--r--wimmel_gl.c24
1 files changed, 20 insertions, 4 deletions
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);