<html>
<head>
<base href="https://bugs.freedesktop.org/">
</head>
<body>
<p>
<div>
<b><a class="bz_bug_link
bz_status_NEW "
title="NEW - Reading back an EGL Pbuffer using the OpenGL API returns garbled output"
href="https://bugs.freedesktop.org/show_bug.cgi?id=108977#c1">Comment # 1</a>
on <a class="bz_bug_link
bz_status_NEW "
title="NEW - Reading back an EGL Pbuffer using the OpenGL API returns garbled output"
href="https://bugs.freedesktop.org/show_bug.cgi?id=108977">bug 108977</a>
from <span class="vcard"><a class="email" href="mailto:matthieu.bouron@gmail.com" title="Matthieu Bouron <matthieu.bouron@gmail.com>"> <span class="fn">Matthieu Bouron</span></a>
</span></b>
<pre>Comment on <span class=""><a href="attachment.cgi?id=142750" name="attach_142750" title="EGL pbuffer test">attachment 142750</a> <a href="attachment.cgi?id=142750&action=edit" title="EGL pbuffer test">[details]</a></span>
EGL pbuffer test
<span class="quote">>#include <stdio.h>
>#include <stdint.h>
>#include <stdlib.h>
>#include <string.h>
>#include <EGL/egl.h></span >
>
<span class="quote">>#include <GL/gl.h></span >
>
<span class="quote">>#define WIDTH 4
>#define HEIGHT 4</span >
>
<span class="quote">>int main(int argc, char *argv[])
>{
> int gles = argc > 1 ? !strcmp(argv[1], "-es") : 0;</span >
>
<span class="quote">> EGLDisplay egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
> if (!egl_dpy)
> return -1;</span >
>
<span class="quote">> EGLint major, minor;
> int ret = eglInitialize(egl_dpy, &major, &minor);
> if (!ret)
> return -1;</span >
>
<span class="quote">> const EGLint attribs[] = {
> EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
> EGL_RENDERABLE_TYPE, gles ? EGL_OPENGL_ES_BIT : EGL_OPENGL_BIT,
> EGL_BLUE_SIZE, 8,
> EGL_GREEN_SIZE, 8,
> EGL_RED_SIZE, 8,
> EGL_NONE
> };
> EGLint nb_configs;
> EGLConfig egl_cfg;
> ret = eglChooseConfig(egl_dpy, attribs, &egl_cfg, 1, &nb_configs);
> if (!ret)
> return -1;</span >
>
<span class="quote">> eglBindAPI(gles ? EGL_OPENGL_ES_API : EGL_OPENGL_API);</span >
>
<span class="quote">> EGLContext egl_ctx = eglCreateContext(egl_dpy, egl_cfg, EGL_NO_CONTEXT, NULL);
> if (!egl_ctx)
> return -1;</span >
>
<span class="quote">> const EGLint pbuffer_attribs[] = {
> EGL_WIDTH, WIDTH,
> EGL_HEIGHT, HEIGHT,
> EGL_NONE,
> };
> EGLSurface egl_surface = eglCreatePbufferSurface(egl_dpy, egl_cfg, pbuffer_attribs);
> if (!egl_surface)
> return -1;</span >
>
<span class="quote">> ret = eglMakeCurrent(egl_dpy, egl_surface, egl_surface, egl_ctx);
> if (!ret)
> return -1;</span >
>
<span class="quote">> uint8_t *data = calloc(1, 4 * WIDTH * HEIGHT);
> if (!data)
> return -1;</span >
>
<span class="quote">> glClearColor(1.0, 0.0, 0.0, 1.0);
> glClear(GL_COLOR_BUFFER_BIT);
> glReadPixels(0, 0, WIDTH, HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, data);</span >
>
<span class="quote">> for(int y = 0; y < HEIGHT; y++) {
> for(int x = 0; x < WIDTH; x++) {
> int *color = (int *)data + x*y;</span >
Should be int *color = (int *)data + y*WIDTH + x;
<span class="quote">> printf("0x%8x ", *color);
> }
> printf("\n");
> }
> free(data);</span >
>
<span class="quote">> eglTerminate(egl_dpy);
> return 0;
>}</span ></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the QA Contact for the bug.</li>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>