On windows, wgl backend, remove usage of wglBindTexImageARB.
authorFrédéric Dalleau <frederic.dalleau@linux.intel.com>
Wed, 12 Jun 2013 09:07:11 +0000 (11:07 +0200)
committerjinhyung.jo <jinhyung.jo@samsung.com>
Wed, 11 Sep 2013 09:03:39 +0000 (18:03 +0900)
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
tizen/src/hw/gloffscreen_common.c
tizen/src/hw/gloffscreen_glx.c
tizen/src/hw/gloffscreen_wgl.c
tizen/src/hw/gloffscreen_xcomposite.c

index 33e38c55ee15425f65034b7d731c84799008bb3a..5ae68c58fd6077dcaa0c4509555c3b1ad3c3ef70 100644 (file)
@@ -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);
     } 
 } 
   
index bd1285421c3aa671fea4776a62e64524918de42d..c8fd382c9bdd189be0c5295ba0aed89cf4b30243 100644 (file)
@@ -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);
 
index f649a0ff3e120aaa3ec11630a91ad25647337e07..a2ec3b2cc068dd3aa2302889268ae377a03ed68d 100644 (file)
@@ -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) {
index aa8d0ad0a1d6bd370d8b36a6a3ffc39a3ba33eaa..610a911f7efe55b64ece6e3c7a18266f07ef6a51 100644 (file)
 #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)
index 9887cc05726701a14d7ca9295c7b90b40bb4426d..e54e7cfb340d484a9bc4ea62be3f43b1d07754c5 100644 (file)
@@ -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 */