<br>
<div><br></div><div><br></div><div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Hi,</div><div style="background-color:rgb(255,255,255)"><font color="#222222" face="arial, sans-serif">I do not know if it's the right place for this, but </font><font color="#222222" face="arial, sans-serif">I sent an email to the Mesa-users mailing list explaining the problem, and I have no answers, so if anyone can help</font><span style="background-color:transparent"><font color="#222222" face="arial, sans-serif">, this is what happens:</font></span></div>
<div style="background-color:rgb(255,255,255)"><font color="#222222" face="arial, sans-serif"><br></font></div><div style="background-color:rgb(255,255,255)"><font color="#222222" face="arial, sans-serif"><br></font></div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">I'm using Mesa 9.1, EGL and xcb, to make texture from pixmap.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
Using EGL_KHR_image_pixmap, i get errors in textures.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">I have also checked texture_from_pixmap in the EGL demos, and the demo not work.</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
I have no errors with Mesa 9.0, my test code and demo work well.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<div><br></div><div><div style="color:rgb(0,0,0);font-family:arial;font-size:small"><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px">Linux: archlinux</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px">
Mesa: mesa-9.1-2, (mesa-demos from git)</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px">Drivers: intel-dri 9.1-2, xf86-video-intel 2.21.3-1</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px">
Kernel: 3.8.0-2-ARCH (same results with kernel 3.7.9)</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px">I've re-checked the test-code with mesa 9.0, and the only error is that the texture (texture_a) is upside down... </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px"><br></div></div></div><div><br></div><div>Test code:</div><div><br></div><div>// gcc -Wall -O3 egl-xcb-texture.c -o egl-xcb-texture -lEGL -lGLESv1_CM -lGLESv2 -lxcb -lxcb-util</div>
<div><br></div><div>#include <xcb/xcb.h></div><div>#include <xcb/xcb_util.h></div><div><br></div><div>#include <GLES/gl.h></div><div>#include <GLES/glext.h></div><div>#include <GLES2/gl2.h></div>
<div>#include <GLES2/gl2ext.h></div><div>//#include <GLES3/gl3.h></div><div>//#include <GLES3/gl3ext.h></div><div>#include <EGL/egl.h></div><div>#include <EGL/eglext.h></div><div><br></div><div>
#include <stdio.h></div><div>#include <stdlib.h></div><div>#include <string.h></div><div><br></div><div><br></div><div><br></div><div>float vert_tex_data[] = { 1.00f, 1.00f, 0.00f, // Position 0</div>
<div> 1.00f, 1.00f, // TexCoord 0 </div><div> -1.00f, 1.00f, 0.00f, // Position 1</div><div> 0.00f, 1.00f, // TexCoord 1</div>
<div> -1.00f, -1.00f, 0.00f, // Position 2</div><div> 0.00f, 0.00f, // TexCoord 2</div><div> 1.00f, -1.00f, 0.00f, // Position 3</div>
<div> 1.00f, 0.00f}; // TexCoord 3</div><div><br></div><div>const GLushort index_data[] = {0, 1, 2,</div><div> 2, 3, 0,};</div><div><br></div><div><br></div>
<div>struct ctx_t {</div><div><span style="white-space:pre-wrap"> </span>xcb_connection_t<span style="white-space:pre-wrap"> </span>*conn;</div><div><span style="white-space:pre-wrap"> </span>int <span style="white-space:pre-wrap"> </span>num_scr;</div>
<div><span style="white-space:pre-wrap"> </span>xcb_screen_t<span style="white-space:pre-wrap"> </span>*screen;</div><div><span style="white-space:pre-wrap"> </span>const xcb_setup_t<span style="white-space:pre-wrap"> </span>*setup;</div>
<div><span style="white-space:pre-wrap"> </span></div><div><span style="white-space:pre-wrap"> </span>xcb_generic_event_t<span style="white-space:pre-wrap"> </span>*xcb_event;</div><div><br></div><div><span style="white-space:pre-wrap"> </span>xcb_window_t <span style="white-space:pre-wrap"> </span>window;</div>
<div><span style="white-space:pre-wrap"> </span>xcb_pixmap_t<span style="white-space:pre-wrap"> </span>xpix;</div><div><span style="white-space:pre-wrap"> </span>GLuint texture_a;</div><div><span style="white-space:pre-wrap"> </span>GLuint texture_b;</div>
<div><br></div><div><span style="white-space:pre-wrap"> </span>EGLDisplay<span style="white-space:pre-wrap"> </span>egl_dpy;</div><div><span style="white-space:pre-wrap"> </span>EGLConfig <span style="white-space:pre-wrap"> </span>egl_cfg;</div>
<div><br></div><div><span style="white-space:pre-wrap"> </span>EGLContext egl_context;</div><div> EGLSurface egl_surface;</div><div> GLuint shader_program;</div><div>
<br></div><div> GLint loc_v_position;</div><div> GLint loc_tex_coord;</div><div> GLint loc_texture;</div><div><br></div><div> PFNEGLCREATEIMAGEKHRPROC <span style="white-space:pre-wrap"> </span>eglCreateImageKHR;</div>
<div> <span style="white-space:pre-wrap"> </span>PFNEGLDESTROYIMAGEKHRPROC <span style="white-space:pre-wrap"> </span>eglDestroyImageKHR;</div><div> <span style="white-space:pre-wrap"> </span>PFNGLEGLIMAGETARGETTEXTURE2DOESPROC <span style="white-space:pre-wrap"> </span>glEGLImageTargetTexture2DOES;</div>
<div>};</div><div><br></div><div><br></div><div>void new_xwindow(struct ctx_t *ctx)</div><div>{</div><div><span style="white-space:pre-wrap"> </span>uint32_t<span style="white-space:pre-wrap"> </span>values[5], mask;</div>
<div><span style="white-space:pre-wrap"> </span>xcb_colormap_t<span style="white-space:pre-wrap"> </span>colormap = 0;</div><div><span style="white-space:pre-wrap"> </span>xcb_visualtype_t *visual = NULL;</div><div><span style="white-space:pre-wrap"> </span>xcb_visualid_t<span style="white-space:pre-wrap"> </span>visual_id;<span style="white-space:pre-wrap"> </span></div>
<div><span style="white-space:pre-wrap"> </span></div><div><span style="white-space:pre-wrap"> </span>visual = xcb_aux_find_visual_by_attrs(ctx->screen, XCB_VISUAL_CLASS_TRUE_COLOR,<span style="white-space:pre-wrap"> </span>32);</div>
<div><span style="white-space:pre-wrap"> </span>visual_id = visual->visual_id;</div><div><br></div><div><span style="white-space:pre-wrap"> </span>colormap = xcb_generate_id(ctx->conn);</div><div><span style="white-space:pre-wrap"> </span>xcb_create_colormap(ctx->conn, XCB_COLORMAP_ALLOC_NONE, colormap, ctx->screen->root, visual_id);</div>
<div><br></div><div><span style="white-space:pre-wrap"> </span>mask = XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL | XCB_CW_BIT_GRAVITY | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP;</div><div><span style="white-space:pre-wrap"> </span>values[0] = 0;</div>
<div><span style="white-space:pre-wrap"> </span>values[1] = 0; </div><div><span style="white-space:pre-wrap"> </span>values[2] = XCB_GRAVITY_NORTH_WEST;</div><div><span style="white-space:pre-wrap"> </span>values[3] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS;</div>
<div><span style="white-space:pre-wrap"> </span>values[4] = colormap;</div><div><span style="white-space:pre-wrap"> </span></div><div><span style="white-space:pre-wrap"> </span>ctx->window = xcb_generate_id(ctx->conn);</div>
<div><span style="white-space:pre-wrap"> </span>xcb_create_window(ctx->conn,</div><div><span style="white-space:pre-wrap"> </span> 32,</div><div><span style="white-space:pre-wrap"> </span> ctx->window,</div><div>
<span style="white-space:pre-wrap"> </span> ctx->screen->root,</div><div><span style="white-space:pre-wrap"> </span> 0,</div><div><span style="white-space:pre-wrap"> </span> 0,</div><div><span style="white-space:pre-wrap"> </span> 800, </div>
<div><span style="white-space:pre-wrap"> </span> 600, </div><div><span style="white-space:pre-wrap"> </span> 0, //border </div><div><span style="white-space:pre-wrap"> </span> XCB_WINDOW_CLASS_INPUT_OUTPUT,</div>
<div><span style="white-space:pre-wrap"> </span> visual_id,</div><div><span style="white-space:pre-wrap"> </span> mask,</div><div><span style="white-space:pre-wrap"> </span> values);</div><div><span style="white-space:pre-wrap"> </span></div>
<div><span style="white-space:pre-wrap"> </span>xcb_free_colormap(ctx->conn, colormap);</div><div><span style="white-space:pre-wrap"> </span>xcb_flush(ctx->conn);</div><div>}</div><div><br></div><div>void make_pixmap(struct ctx_t *ctx, uint16_t w, uint16_t h, uint8_t depth)</div>
<div>{</div><div><span style="white-space:pre-wrap"> </span>xcb_gcontext_t gc = 0;</div><div><span style="white-space:pre-wrap"> </span>xcb_rectangle_t rec = {0, 0, w - 1, h - 1};</div><div><span style="white-space:pre-wrap"> </span>xcb_arc_t arc[] = {{0, 0, w - 1, h - 1, 0, 90 * 64}, {0, 0, w - 1, h - 1, 90 * 64, 90 * 64}, </div>
<div><span style="white-space:pre-wrap"> </span> {0, 0, w - 1, h - 1, 180 * 64, 90 * 64}, {0, 0, w - 1, h - 1, 270 * 64, 90 * 64}};</div><div><span style="white-space:pre-wrap"> </span>uint32_t red = 0xff0000, yellow = 0x808000, blue = 0x0000ff, green = 0x00ff00, violet = 0xff00ff;</div>
<div><br></div><div><span style="white-space:pre-wrap"> </span>ctx->xpix = xcb_generate_id(ctx->conn);</div><div> xcb_create_pixmap(ctx->conn, depth, ctx->xpix, ctx->screen->root, w, h);</div><div>
<br></div><div> gc = xcb_generate_id(ctx->conn);</div><div> xcb_create_gc(ctx->conn, gc, ctx->xpix, XCB_GC_FOREGROUND, &yellow);</div><div> xcb_poly_fill_rectangle(ctx->conn, ctx->xpix, gc, 1, &rec);</div>
<div><br></div><div> xcb_change_gc(ctx->conn, gc, XCB_GC_FOREGROUND, &blue);</div><div> xcb_poly_rectangle(ctx->conn, ctx->xpix, gc, 1, &rec);</div><div><br></div><div> xcb_change_gc(ctx->conn, gc, XCB_GC_FOREGROUND, &red);</div>
<div> xcb_poly_fill_arc(ctx->conn, ctx->xpix, gc, 1, &arc[0]);</div><div><br></div><div> xcb_change_gc(ctx->conn, gc, XCB_GC_FOREGROUND, &blue);</div><div> xcb_poly_fill_arc(ctx->conn, ctx->xpix, gc, 1, &arc[1]);</div>
<div><br></div><div> xcb_change_gc(ctx->conn, gc, XCB_GC_FOREGROUND, &green);</div><div> xcb_poly_fill_arc(ctx->conn, ctx->xpix, gc, 1, &arc[2]);</div><div> </div><div> xcb_change_gc(ctx->conn, gc, XCB_GC_FOREGROUND, &violet);</div>
<div> xcb_poly_fill_arc(ctx->conn, ctx->xpix, gc, 1, &arc[3]);</div><div><br></div><div> xcb_copy_area(ctx->conn, ctx->xpix, ctx->window, gc, 0, 0, 0, 0, w, h);</div><div> xcb_free_gc(ctx->conn, gc);</div>
<div>}</div><div><br></div><div>void mirror(uint8_t *src, int len, int stride, uint8_t *dst)</div><div>{</div><div><span style="white-space:pre-wrap"> </span>uint8_t *out = dst + len - stride;</div><div><span style="white-space:pre-wrap"> </span>uint8_t *in = NULL;</div>
<div><br></div><div><span style="white-space:pre-wrap"> </span>for (in = src; in < src + len; in += stride) {</div><div><span style="white-space:pre-wrap"> </span>memcpy(out, in, stride);</div><div><span style="white-space:pre-wrap"> </span>out -= stride;</div>
<div><span style="white-space:pre-wrap"> </span>}</div><div>} </div><div><br></div><div><br></div><div>//Esta textura anda ok. </div><div>//texture ok</div><div>int make_texture_b(struct ctx_t *ctx)</div><div>{<span style="white-space:pre-wrap"> </span></div>
<div><span style="white-space:pre-wrap"> </span>xcb_get_geometry_cookie_t g_cookie;</div><div><span style="white-space:pre-wrap"> </span>xcb_get_geometry_reply_t *g_reply = NULL;</div><div><span style="white-space:pre-wrap"> </span>uint16_t w, h;</div>
<div><span style="white-space:pre-wrap"> </span>xcb_get_image_cookie_t cookie;</div><div><span style="white-space:pre-wrap"> </span>xcb_get_image_reply_t *reply =NULL;</div><div><span style="white-space:pre-wrap"> </span>uint8_t *pixels = NULL;</div>
<div><span style="white-space:pre-wrap"> </span>uint8_t *buffer = NULL;</div><div><span style="white-space:pre-wrap"> </span>int len, stride;</div><div><span style="white-space:pre-wrap"> </span></div><div><span style="white-space:pre-wrap"> </span>g_cookie = xcb_get_geometry(ctx->conn, ctx->xpix);</div>
<div><span style="white-space:pre-wrap"> </span>g_reply = xcb_get_geometry_reply(ctx->conn, g_cookie, NULL);</div><div><span style="white-space:pre-wrap"> </span>if (!g_reply) return -1;</div><div><br></div><div><span style="white-space:pre-wrap"> </span>w = g_reply->width;</div>
<div><span style="white-space:pre-wrap"> </span>h = g_reply->height;</div><div><span style="white-space:pre-wrap"> </span>free(g_reply);</div><div><br></div><div><span style="white-space:pre-wrap"> </span>cookie = xcb_get_image(ctx->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, ctx->xpix, 0, 0, w, h, 0xffffffff);</div>
<div><span style="white-space:pre-wrap"> </span>reply = xcb_get_image_reply(ctx->conn, cookie, NULL);</div><div><span style="white-space:pre-wrap"> </span>if (!reply) return -1;</div><div><br></div><div><span style="white-space:pre-wrap"> </span>pixels = xcb_get_image_data(reply);</div>
<div><span style="white-space:pre-wrap"> </span>len = xcb_get_image_data_length(reply);</div><div><br></div><div><span style="white-space:pre-wrap"> </span>stride = w * 4;</div><div><span style="white-space:pre-wrap"> </span>buffer = malloc(len);</div>
<div><span style="white-space:pre-wrap"> </span>mirror(pixels, len, stride, buffer);</div><div><span style="white-space:pre-wrap"> </span>free(reply);</div><div><br></div><div><span style="white-space:pre-wrap"> </span>glGenTextures(1, &ctx->texture_b); </div>
<div> glBindTexture(GL_TEXTURE_2D, ctx->texture_b); </div><div> </div><div> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);</div><div> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);</div>
<div> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);</div><div> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);</div><div><br></div><div> glTexImage2D(GL_TEXTURE_2D, </div>
<div> 0, </div><div> GL_BGRA_EXT, </div><div> w,</div><div> h, </div><div> 0, </div><div> GL_BGRA_EXT, </div>
<div> GL_UNSIGNED_BYTE,</div><div> buffer);</div><div><br></div><div> free(buffer);</div><div> return 0;</div><div>}</div><div><br></div><div><br></div><div><div>//Esta textura anda mal. </div>
<div>//texture bad</div></div><div>void make_texture_a(struct ctx_t *ctx)</div><div>{</div><div><span style="white-space:pre-wrap"> </span>EGLImageKHR khrimg = NULL;</div><div><span style="white-space:pre-wrap"> </span>const EGLint attr[] = {<span style="white-space:pre-wrap"> </span>EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,</div>
<div><span style="white-space:pre-wrap"> </span>//EGL_GL_TEXTURE_LEVEL_KHR, 0, // mip map level to reference</div><div><span style="white-space:pre-wrap"> </span>EGL_NONE};</div><div><br></div><div><span style="white-space:pre-wrap"> </span>khrimg = ctx->eglCreateImageKHR(ctx->egl_dpy, </div>
<div><span style="white-space:pre-wrap"> </span> EGL_NO_CONTEXT, </div><div><span style="white-space:pre-wrap"> </span> EGL_NATIVE_PIXMAP_KHR, </div><div><span style="white-space:pre-wrap"> </span> (EGLClientBuffer)(uintptr_t)ctx->xpix, </div>
<div><span style="white-space:pre-wrap"> </span> attr);</div><div><br></div><div><span style="white-space:pre-wrap"> </span>glGenTextures(1, &ctx->texture_a); </div><div> glBindTexture(GL_TEXTURE_2D, ctx->texture_a); </div>
<div> </div><div> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);</div><div> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);</div><div> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);</div>
<div> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);</div><div> </div><div> ctx->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)khrimg);</div><div> ctx->eglDestroyImageKHR(ctx->egl_dpy, khrimg);</div>
<div>}</div><div><br></div><div>void init_xcb(struct ctx_t *ctx)</div><div>{</div><div><span style="white-space:pre-wrap"> </span>ctx->conn = xcb_connect(NULL, &ctx->num_scr);</div><div><span style="white-space:pre-wrap"> </span>ctx->screen = xcb_aux_get_screen(ctx->conn, ctx->num_scr);</div>
<div><span style="white-space:pre-wrap"> </span>ctx->setup = xcb_get_setup(ctx->conn);</div><div><span style="white-space:pre-wrap"> </span>xcb_flush(ctx->conn);</div><div>}</div><div><br></div><div>void init_egl(struct ctx_t *ctx)</div>
<div>{</div><div><span style="white-space:pre-wrap"> </span>EGLint attr[] = {EGL_BUFFER_SIZE, 32,</div><div> <span style="white-space:pre-wrap"> </span> EGL_RED_SIZE, 8,</div><div> <span style="white-space:pre-wrap"> </span> EGL_GREEN_SIZE, 8,</div>
<div> <span style="white-space:pre-wrap"> </span> EGL_BLUE_SIZE, 8,</div><div> <span style="white-space:pre-wrap"> </span> EGL_ALPHA_SIZE, 8,</div><div> <span style="white-space:pre-wrap"> </span> EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT | EGL_OPENGL_BIT,</div>
<div> <span style="white-space:pre-wrap"> </span> EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PIXMAP_BIT,</div><div> <span style="white-space:pre-wrap"> </span> EGL_MATCH_NATIVE_PIXMAP, (GLint)ctx->screen->root,</div>
<div> <span style="white-space:pre-wrap"> </span> EGL_NONE};</div><div> </div><div> <span style="white-space:pre-wrap"> </span>//ctx->egl_dpy = eglGetDisplay((EGLNativeDisplayType)NULL);</div><div> <span style="white-space:pre-wrap"> </span>ctx->egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);</div>
<div> <span style="white-space:pre-wrap"> </span>eglInitialize(ctx->egl_dpy, NULL, NULL);</div><div><br></div><div> <span style="white-space:pre-wrap"> </span>EGLint num_config;</div><div> <span style="white-space:pre-wrap"> </span>eglChooseConfig(ctx->egl_dpy, attr, &ctx->egl_cfg, 1, &num_config);</div>
<div> </div><div> <span style="white-space:pre-wrap"> </span>ctx->egl_surface = eglCreateWindowSurface(ctx->egl_dpy, ctx->egl_cfg, ctx->window, NULL);</div><div> ctx->egl_context = eglCreateContext(ctx->egl_dpy, </div>
<div> ctx->egl_cfg, </div><div> EGL_NO_CONTEXT, </div><div> (EGLint[]){EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE});</div>
<div> </div><div> eglMakeCurrent(ctx->egl_dpy, ctx->egl_surface, ctx->egl_surface, ctx->egl_context);</div><div><br></div><div> eglBindAPI(EGL_OPENGL_ES_API);</div><div><br></div>
<div> ctx->eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress("eglCreateImageKHR");</div><div><span style="white-space:pre-wrap"> </span>ctx->eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress("eglDestroyImageKHR");</div>
<div><span style="white-space:pre-wrap"> </span>ctx->glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) eglGetProcAddress("glEGLImageTargetTexture2DOES");</div><div>}</div><div><br></div><div>
void init_shaders(struct ctx_t *ctx)</div><div>{</div><div><span style="white-space:pre-wrap"> </span>const char *vertx_src = "<span style="white-space:pre-wrap"> </span>\</div><div><span style="white-space:pre-wrap"> </span>attribute vec4 v_position; <span style="white-space:pre-wrap"> </span>\</div>
<div><span style="white-space:pre-wrap"> </span>attribute vec2 tex_coord; <span style="white-space:pre-wrap"> </span>\</div><div><span style="white-space:pre-wrap"> </span>varying mediump vec2 v_tex_coord;<span style="white-space:pre-wrap"> </span>\</div>
<div> <span style="white-space:pre-wrap"> </span>\</div><div><span style="white-space:pre-wrap"> </span>void main() <span style="white-space:pre-wrap"> </span>\</div><div><span style="white-space:pre-wrap"> </span>{ <span style="white-space:pre-wrap"> </span>\</div>
<div><span style="white-space:pre-wrap"> </span>gl_Position = v_position; <span style="white-space:pre-wrap"> </span>\</div><div> <span style="white-space:pre-wrap"> </span>v_tex_coord = tex_coord; <span style="white-space:pre-wrap"> </span>\</div>
<div><span style="white-space:pre-wrap"> </span>}";</div><div><br></div><div><span style="white-space:pre-wrap"> </span>const char *frag_src = "<span style="white-space:pre-wrap"> </span>\</div><div><span style="white-space:pre-wrap"> </span>varying mediump vec2 v_tex_coord; <span style="white-space:pre-wrap"> </span>\</div>
<div><span style="white-space:pre-wrap"> </span>uniform sampler2D texture;<span style="white-space:pre-wrap"> </span>\</div><div><span style="white-space:pre-wrap"> </span> <span style="white-space:pre-wrap"> </span>\</div>
<div><span style="white-space:pre-wrap"> </span>void main()<span style="white-space:pre-wrap"> </span>\</div><div><span style="white-space:pre-wrap"> </span>{<span style="white-space:pre-wrap"> </span>\</div>
<div><span style="white-space:pre-wrap"> </span>gl_FragColor = texture2D(texture, v_tex_coord);<span style="white-space:pre-wrap"> </span>\</div><div><span style="white-space:pre-wrap"> </span>}";</div><div><br></div>
<div><span style="white-space:pre-wrap"> </span>GLuint vertex_shader, fragment_shader; </div><div><br></div><div><span style="white-space:pre-wrap"> </span>ctx->shader_program = glCreateProgram();</div><div><br></div><div>
<span style="white-space:pre-wrap"> </span>vertex_shader = glCreateShader(GL_VERTEX_SHADER);</div><div> <span style="white-space:pre-wrap"> </span>glShaderSource(vertex_shader, 1, &vertx_src, NULL);</div><div> <span style="white-space:pre-wrap"> </span>glCompileShader(vertex_shader);</div>
<div><br></div><div> <span style="white-space:pre-wrap"> </span>fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);</div><div> <span style="white-space:pre-wrap"> </span>glShaderSource(fragment_shader, 1, &frag_src, NULL);</div>
<div> <span style="white-space:pre-wrap"> </span>glCompileShader(fragment_shader);</div><div><span style="white-space:pre-wrap"> </span></div><div><span style="white-space:pre-wrap"> </span>glAttachShader(ctx->shader_program, vertex_shader); </div>
<div> <span style="white-space:pre-wrap"> </span>glAttachShader(ctx->shader_program, fragment_shader); </div><div> </div><div> <span style="white-space:pre-wrap"> </span>glLinkProgram(ctx->shader_program);</div>
<div><br></div><div> <span style="white-space:pre-wrap"> </span>glDetachShader(ctx->shader_program, vertex_shader);</div><div><span style="white-space:pre-wrap"> </span>glDetachShader(ctx->shader_program, fragment_shader);</div>
<div><span style="white-space:pre-wrap"> </span>glDeleteShader(vertex_shader);</div><div><span style="white-space:pre-wrap"> </span>glDeleteShader(fragment_shader);</div><div>}</div><div><br></div><div><br></div><div>void render(struct ctx_t *ctx)</div>
<div>{</div><div><span style="white-space:pre-wrap"> </span>glClear(GL_COLOR_BUFFER_BIT);</div><div><span style="white-space:pre-wrap"> </span></div><div> glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, index_data);</div>
<div> eglSwapBuffers(ctx->egl_dpy, ctx->egl_surface);</div><div>}</div><div><br></div><div><br></div><div>int main()</div><div>{</div><div><span style="white-space:pre-wrap"> </span>struct ctx_t ctx;</div><div>
<br></div><div><span style="white-space:pre-wrap"> </span>init_xcb(&ctx);</div><div><span style="white-space:pre-wrap"> </span>new_xwindow(&ctx);</div><div><span style="white-space:pre-wrap"> </span>xcb_map_window(ctx.conn, ctx.window);</div>
<div><span style="white-space:pre-wrap"> </span>xcb_flush(ctx.conn);</div><div><br></div><div><span style="white-space:pre-wrap"> </span>make_pixmap(&ctx, 400, 200, 32);</div><div><span style="white-space:pre-wrap"> </span>xcb_flush(ctx.conn);</div>
<div><span style="white-space:pre-wrap"> </span></div><div><span style="white-space:pre-wrap"> </span>init_egl(&ctx);</div><div><span style="white-space:pre-wrap"> </span>make_texture_a(&ctx);</div><div><span style="white-space:pre-wrap"> </span>make_texture_b(&ctx);</div>
<div><br></div><div><span style="white-space:pre-wrap"> </span>init_shaders(&ctx);</div><div><br></div><div><span style="white-space:pre-wrap"> </span>glUseProgram(ctx.shader_program); </div><div><span style="white-space:pre-wrap"> </span>ctx.loc_v_position = glGetAttribLocation(ctx.shader_program, "v_position");</div>
<div> ctx.loc_texture = glGetUniformLocation(ctx.shader_program, "texture");</div><div> ctx.loc_tex_coord = glGetAttribLocation(ctx.shader_program, "tex_coord");</div><div><br></div><div>
glActiveTexture(GL_TEXTURE0); </div><div> glBindTexture(GL_TEXTURE_2D, ctx.texture_a); </div><div> // Set the sampler texture unit to 0</div><div> glUniform1i(ctx.loc_texture, 0); </div><div>
<br></div><div> glEnableVertexAttribArray(ctx.loc_v_position);</div><div> glVertexAttribPointer(ctx.loc_v_position, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), vert_tex_data);</div><div> // set the texture coords </div>
<div> glEnableVertexAttribArray(ctx.loc_tex_coord);</div><div> glVertexAttribPointer(ctx.loc_tex_coord, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &vert_tex_data[3]);</div><div><br></div><div> glViewport(0, 0, 800, 600);</div>
<div> </div><div> xcb_flush(ctx.conn);</div><div><span style="white-space:pre-wrap"> </span>for (;;) {</div><div><span style="white-space:pre-wrap"> </span>ctx.xcb_event = xcb_wait_for_event(ctx.conn);</div>
<div><span style="white-space:pre-wrap"> </span>if (xcb_connection_has_error(ctx.conn)) goto out;</div><div><span style="white-space:pre-wrap"> </span></div><div><span style="white-space:pre-wrap"> </span>uint8_t ev_type; <span style="white-space:pre-wrap"> </span></div>
<div><span style="white-space:pre-wrap"> </span>ev_type = ctx.xcb_event->response_type & ~0x80;</div><div><span style="white-space:pre-wrap"> </span>if (ev_type == XCB_KEY_PRESS) {</div><div><span style="white-space:pre-wrap"> </span>xcb_key_press_event_t *ev = (xcb_key_press_event_t *)ctx.xcb_event;</div>
<div><span style="white-space:pre-wrap"> </span>if (ev->detail == 9) { //Esc</div><div><span style="white-space:pre-wrap"> </span>goto out;</div><div><span style="white-space:pre-wrap"> </span>} </div><div> </div>
<div> //key a ---> show bad texture</div><div><span style="white-space:pre-wrap"> </span>if (ev->detail == 38) { //key a </div><div><span style="white-space:pre-wrap"> </span>glBindTexture(GL_TEXTURE_2D, ctx.texture_a); </div>
<div><span style="white-space:pre-wrap"> </span>render(&ctx);</div><div><span style="white-space:pre-wrap"> </span>}</div><div><br></div><div> //key b ---> show texture ok</div><div><span style="white-space:pre-wrap"> </span>if (ev->detail == 56) { //key b</div>
<div><span style="white-space:pre-wrap"> </span>glBindTexture(GL_TEXTURE_2D, ctx.texture_b); </div><div><span style="white-space:pre-wrap"> </span>render(&ctx);</div><div><span style="white-space:pre-wrap"> </span>}</div>
<div><span style="white-space:pre-wrap"> </span>}</div><div><br></div><div><span style="white-space:pre-wrap"> </span>free(ctx.xcb_event);</div><div><span style="white-space:pre-wrap"> </span>ctx.xcb_event = NULL;</div>
<div><span style="white-space:pre-wrap"> </span>xcb_flush(ctx.conn);</div><div><span style="white-space:pre-wrap"> </span>}</div><div>out:</div><div><span style="white-space:pre-wrap"> </span>glDisableVertexAttribArray(ctx.loc_v_position);</div>
<div> glDisableVertexAttribArray(ctx.loc_tex_coord);</div><div> glDeleteTextures(1, &ctx.texture_a);</div><div> glDeleteTextures(1, &ctx.texture_b);</div><div><span style="white-space:pre-wrap"> </span>glDeleteProgram(ctx.shader_program);</div>
<div> eglDestroySurface(ctx.egl_dpy, ctx.egl_surface);</div><div> eglMakeCurrent(ctx.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);</div><div> <span style="white-space:pre-wrap"> </span>eglDestroyContext(ctx.egl_dpy, ctx.egl_context);</div>
<div> <span style="white-space:pre-wrap"> </span>eglTerminate(ctx.egl_dpy);</div><div> <span style="white-space:pre-wrap"> </span>eglReleaseThread();</div><div> <span style="white-space:pre-wrap"> </span></div><div>
<span style="white-space:pre-wrap"> </span>if (ctx.xcb_event) free(ctx.xcb_event);</div><div><br></div><div> <span style="white-space:pre-wrap"> </span>xcb_free_pixmap(ctx.conn, ctx.xpix);</div><div> <span style="white-space:pre-wrap"> </span>xcb_destroy_window(ctx.conn, ctx.window);</div>
<div> <span style="white-space:pre-wrap"> </span>xcb_disconnect(ctx.conn);</div><div> <span style="white-space:pre-wrap"> </span>return 0;</div><div>}</div><div><br></div><div><br></div><div><br></div><div>original pixmap:</div>
<div><a href="http://www.freeimagehosting.net/33j4c" target="_blank" style="color:rgb(17,85,204)">http://www.freeimagehosting.net/33j4c</a></div><div><br></div><div>texture ok:</div><div><a href="http://www.freeimagehosting.net/dzh2d" target="_blank" style="color:rgb(17,85,204)">http://www.freeimagehosting.net/dzh2d</a></div>
<div><br></div><div>texture bad:</div><div><a href="http://www.freeimagehosting.net/pnd7r" target="_blank" style="color:rgb(17,85,204)">http://www.freeimagehosting.net/pnd7r</a></div><div><br></div><div><br></div><div><div>
I appreciate any help, thanks.</div><div>Gabriel.</div><div>(Sorry for my English, not my native language)</div></div><div><br></div><div><br></div><div><br></div><div><br></div></div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div>