From a6251ca710d978d803b52cc72995be9ba38993de Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Dalleau?= Date: Wed, 12 Jun 2013 11:07:11 +0200 Subject: [PATCH] On windows, wgl backend, remove usage of wglBindTexImageARB. This function is provided by extension WGL_ARB_render_texture. The extension is not supported by Intel hardware. So instead, use glReadPixels/glTexImage2D Additionnally do not flip pbuffer vertically when using them as textures. --- tizen/src/hw/gloffscreen_agl.c | 4 +-- tizen/src/hw/gloffscreen_common.c | 18 ++++++------ tizen/src/hw/gloffscreen_glx.c | 4 +-- tizen/src/hw/gloffscreen_wgl.c | 54 ++++++++++++++++++++--------------- tizen/src/hw/gloffscreen_xcomposite.c | 4 +-- 5 files changed, 47 insertions(+), 37 deletions(-) diff --git a/tizen/src/hw/gloffscreen_agl.c b/tizen/src/hw/gloffscreen_agl.c index 33e38c5..5ae68c5 100644 --- a/tizen/src/hw/gloffscreen_agl.c +++ b/tizen/src/hw/gloffscreen_agl.c @@ -57,7 +57,7 @@ struct _GloSurface extern void glo_surface_getcontents_readpixels(int formatFlags, int stride, int bpp, int width, int height, - void *data); + void *data, int noflip); @@ -316,7 +316,7 @@ void glo_surface_getcontents(GloSurface *surface, int stride, int bpp, { aglSwapBuffers(surface->context->context); aglSetInteger(surface->context->context, AGL_SWAP_INTERVAL, &swap_interval); - glo_surface_getcontents_readpixels(surface->context->formatFlags, stride, bpp, surface->width, surface->height, data); + glo_surface_getcontents_readpixels(surface->context->formatFlags, stride, bpp, surface->width, surface->height, data, 0); } } diff --git a/tizen/src/hw/gloffscreen_common.c b/tizen/src/hw/gloffscreen_common.c index bd12854..c8fd382 100644 --- a/tizen/src/hw/gloffscreen_common.c +++ b/tizen/src/hw/gloffscreen_common.c @@ -102,7 +102,7 @@ void g_free(void *ptr); // --------------------------------------------------- extern void glo_surface_getcontents_readpixels(int formatFlags, int stride, - int bpp, int width, int height, void *data); + int bpp, int width, int height, void *data, int noflip); // --------------------------------------------------- @@ -370,7 +370,7 @@ void glo_geometry_get_from_glx(const int* attrib_list, int* width, int* height) } void glo_surface_getcontents_readpixels(int formatFlags, int stride, int bpp, - int width, int height, void *data) { + int width, int height, void *data, int noflip) { int glFormat, glType, rl, pa; static int once; @@ -418,12 +418,14 @@ void glo_surface_getcontents_readpixels(int formatFlags, int stride, int bpp, glReadPixels(0, 0, width, height, glFormat, glType, data); - for(irow = 0; irow < height/2; irow++) { - memcpy(tmp, b, stride); - memcpy(b, c, stride); - memcpy(c, tmp, stride); - b += stride; - c -= stride; + if (noflip == 0) { + for(irow = 0; irow < height/2; irow++) { + memcpy(tmp, b, stride); + memcpy(b, c, stride); + memcpy(c, tmp, stride); + b += stride; + c -= stride; + } } g_free(tmp); diff --git a/tizen/src/hw/gloffscreen_glx.c b/tizen/src/hw/gloffscreen_glx.c index f649a0f..a2ec3b2 100644 --- a/tizen/src/hw/gloffscreen_glx.c +++ b/tizen/src/hw/gloffscreen_glx.c @@ -71,7 +71,7 @@ struct _GloSurface { }; extern void glo_surface_getcontents_readpixels(int formatFlags, int stride, - int bpp, int width, int height, void *data); + int bpp, int width, int height, void *data, int noflip); static void glo_test_readback_methods(void); /* ------------------------------------------------------------------------ */ @@ -371,7 +371,7 @@ void glo_surface_getcontents(GloSurface *surface, int stride, int bpp, void *dat // Compatible / fallback method. glo_surface_getcontents_readpixels(surface->context->formatFlags, stride, bpp, surface->width, - surface->height, data); + surface->height, data, 0); } // while(0) { diff --git a/tizen/src/hw/gloffscreen_wgl.c b/tizen/src/hw/gloffscreen_wgl.c index aa8d0ad..610a911 100644 --- a/tizen/src/hw/gloffscreen_wgl.c +++ b/tizen/src/hw/gloffscreen_wgl.c @@ -43,6 +43,12 @@ #include "gl_mangled.h" #endif +enum { + SURFACE_WINDOW, + SURFACE_PIXMAP, + SURFACE_PBUFFER +}; + /* In Windows, you must create a window *before* you can create a pbuffer or * get a context. So we create a hidden Window on startup (see glo_init/GloMain). * @@ -98,7 +104,7 @@ PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB; extern const char *glo_glXQueryExtensionsString(void); extern void glo_surface_getcontents_readpixels(int formatFlags, int stride, - int bpp, int width, int height, void *data); + int bpp, int width, int height, void *data, int noflip); /* ------------------------------------------------------------------------ */ @@ -946,7 +952,7 @@ void glo_surface_getcontents(GloSurface *surface, int stride, int bpp, void *dat // Compatible / fallback method. glo_surface_getcontents_readpixels(surface->context->formatFlags, stride, bpp, surface->width, - surface->height, data); + surface->height, data, 0); } /* Return the width and height of the given surface */ @@ -960,33 +966,35 @@ void glo_surface_get_size(GloSurface *surface, int *width, int *height) { /* Bind the surface as texture */ void glo_surface_as_texture(GloContext *ctxt, GloSurface *surface, int surface_type) { -#if 0 int glFormat, glType; - glo_surface_updatecontents(surface); - /*XXX: change the fixed target: GL_TEXTURE_2D*/ - glo_flags_get_readpixel_type(surface->context->formatFlags, &glFormat, &glType); - fprintf(stderr, "surface_as_texture:teximage:width=%d,height=%d,glFormat=0x%x,glType=0x%x.\n", surface->width, surface->height, glFormat, glType); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->width, surface->height, 0, glFormat, glType, surface->image->data); -#else - if(!Render_texture_support) - { - //fprintf(stderr, "Render to texture not supported on this machine, just return!\n"); - return ; - } + int bpp = 4; + int stride = surface->width * bpp; + char *data; + HGLRC oldCtx; + HDC oldDC; - if (!wglBindTexImageARB) - { - fprintf (stderr, "wglBindTexImageEXT not supported! Can't emulate glEGLImageTargetTexture2DOES!\n"); + data = malloc(surface->width * surface->height * bpp); + if (!data) return; - } - if ( !wglBindTexImageARB(surface->hPBuffer, WGL_FRONT_LEFT_ARB) ) - { - fprintf(stderr, "wglBindTexImageARBr error=%d.\n", glGetError()); - } + /* Read pixels from Speficied context */ + oldCtx = wglGetCurrentContext(); + oldDC = wglGetCurrentDC(); + glo_surface_makecurrent(surface); + glo_surface_updatecontents(surface); + glo_flags_get_readpixel_type(surface->context->formatFlags, &glFormat, &glType); + // Make sure we do not flip pbuffer surfaces on Windows + glo_surface_getcontents_readpixels(surface->context->formatFlags, + stride, bpp *8, surface->width, + surface->height, data, (surface_type == SURFACE_PBUFFER)); -#endif + /* Restore previous context for setting texture */ + wglMakeCurrent(oldDC, oldCtx); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->width, surface->height, 0, glFormat, glType, data); + free(data); } + void glo_surface_release_texture(GloSurface *surface) { if(!Render_texture_support) diff --git a/tizen/src/hw/gloffscreen_xcomposite.c b/tizen/src/hw/gloffscreen_xcomposite.c index 9887cc0..e54e7cf 100644 --- a/tizen/src/hw/gloffscreen_xcomposite.c +++ b/tizen/src/hw/gloffscreen_xcomposite.c @@ -83,7 +83,7 @@ struct _GloSurface { }; extern void glo_surface_getcontents_readpixels(int formatFlags, int stride, - int bpp, int width, int height, void *data); + int bpp, int width, int height, void *data, int noflip); static void glo_test_readback_methods(void); /* ------------------------------------------------------------------------ */ @@ -477,7 +477,7 @@ void glo_surface_getcontents(GloSurface *surface, int stride, int bpp, void *dat // Compatible / fallback method. glo_surface_getcontents_readpixels(surface->context->formatFlags, stride, bpp, surface->width, - surface->height, data); + surface->height, data, 0); } /* Return the width and height of the given surface */ -- 2.7.4