[Title] Enable pixmap and the two extensions for windows.
authorSangjin Kim <sangjin3.kim@samsung.com>
Fri, 31 Aug 2012 02:04:29 +0000 (11:04 +0900)
committerSangjin Kim <sangjin3.kim@samsung.com>
Fri, 31 Aug 2012 02:04:29 +0000 (11:04 +0900)
[Type] feature
[Module] opengl
[Priority]
[CQ#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

package/pkginfo.manifest
tizen/src/hw/gloffscreen_glx.c
tizen/src/hw/gloffscreen_wgl.c
tizen/src/hw/gloffscreen_xcomposite.c
tizen/src/hw/opengl_exec.c

index 4db4d50..77bdd64 100644 (file)
@@ -1,4 +1,4 @@
-Version: 1.3.34
+Version: 1.3.35
 Maintainer: Yeong-Kyoon Lee<yeongkyoon.lee@samsung.com>
 Source: emulator
 
index a09da30..cc65d8c 100644 (file)
@@ -165,6 +165,10 @@ GloContext *glo_context_create(int formatFlags, GloContext *shareLists) {
 
   GloContext *context = __glo_context_create(formatFlags);
 
+  if (!context) {
+         return NULL;
+  }
+
   /* Create a GLX context for OpenGL rendering */
   context->context = glXCreateNewContext(glo.dpy, context->fbConfig,
                                          GLX_RGBA_TYPE,
index 6f94404..5f6df68 100644 (file)
@@ -82,6 +82,8 @@ PFNWGLGETPBUFFERDCARBPROC wglGetPbufferDCARB;
 PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB;
 PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB;
 PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB;
+PFNWGLBINDTEXIMAGEARBPROC wglBindTexImageARB;
+PFNWGLRELEASETEXIMAGEARBPROC wglReleaseTexImageARB;
 
 /* ------------------------------------------------------------------------ */
 
@@ -105,6 +107,8 @@ int glo_sanity_test (void) {
     PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB;
     PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB;
     PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB;
+       PFNWGLBINDTEXIMAGEARBPROC wglBindTexImageARB;
+       PFNWGLRELEASETEXIMAGEARBPROC wglReleaseTexImageARB;
 
     wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
     wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC)wglGetProcAddress("wglGetPbufferDCARB");
@@ -201,6 +205,9 @@ int glo_init(void) {
     wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetProcAddress("wglReleasePbufferDCARB");
     wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC)wglGetProcAddress("wglCreatePbufferARB");
     wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC)wglGetProcAddress("wglDestroyPbufferARB");
+    wglBindTexImageARB = (PFNWGLBINDTEXIMAGEARBPROC)wglGetProcAddress("wglBindTexImageARB");
+    wglReleaseTexImageARB = (PFNWGLRELEASETEXIMAGEARBPROC)wglGetProcAddress("wglReleaseTexImageARB");
+
     if (!wglChoosePixelFormatARB ||
         !wglGetPbufferDCARB ||
         !wglReleasePbufferDCARB ||
@@ -211,6 +218,10 @@ int glo_init(void) {
                return 1;
     }
 
+    if ( !wglBindTexImageARB ||
+         !wglReleaseTexImageARB )
+        fprintf (stderr, "Warning: no [Bind|Release]TexImageARB extensions.\n");
+
     glo_inited = 1;
 
        return 0;
@@ -671,13 +682,8 @@ void glo_surface_updatecontents(GloSurface *surface) {
 
 /* ------------------------------------------------------------------------ */
 
+/* Create a light-weight context just for creating surface */
 GloContext *__glo_context_create(int formatFlags) {
-       /* NOT IMPLEMENTED YET. */
-       printf("__glo_context_create() is not implemented for windows. \n");
-}
-
-/* Create an OpenGL context for a certain pixel format. formatflags are from the GLO_ constants */
-GloContext *glo_context_create(int formatFlags, GloContext *shareLists) {
     GloContext *context;
     // pixel format attributes
     int          pf_attri[] = {
@@ -690,6 +696,9 @@ GloContext *glo_context_create(int formatFlags, GloContext *shareLists) {
         WGL_DEPTH_BITS_ARB, 0,
         WGL_STENCIL_BITS_ARB, 0,
         WGL_DOUBLE_BUFFER_ARB, FALSE,      
+        /* Need following 2 to suport surface as texture */
+        WGL_DRAW_TO_PBUFFER_ARB, TRUE,
+        WGL_BIND_TO_TEXTURE_RGBA_ARB, TRUE,
         0                                
     };
     float        pf_attrf[] = {0, 0};
@@ -737,6 +746,18 @@ GloContext *glo_context_create(int formatFlags, GloContext *shareLists) {
                return NULL;
     }
 
+       return context;
+}
+
+/* Create an OpenGL context for a certain pixel format. formatflags are from the GLO_ constants */
+GloContext *glo_context_create(int formatFlags, GloContext *shareLists) {
+
+    GloContext *context = __glo_context_create(formatFlags);
+
+       if (!context) {
+               return NULL;
+       }
+
     context->hContext = wglCreateContext(context->hDC);
     if (context->hContext == NULL) {
         printf( "Unable to create GL context\n" );
@@ -775,19 +796,21 @@ void glo_context_destroy(GloContext *context) {
 /* Update the context in surface and free previous light-weight context */
 void glo_surface_update_context(GloSurface *surface, GloContext *context)
 {
-       /* NOT IMPLEMENTED YET. */
-    /*if ( surface->context )
+    if ( surface->context )
         g_free(surface->context);
     surface->context = context;
-       */
-       printf("glo_surface_update_context() is not implemented for windows. \n");
 }
 
 /* Create a surface with given width and height, formatflags are from the
  * GLO_ constants */
 GloSurface *glo_surface_create(int width, int height, GloContext *context) {
     GloSurface           *surface;
-    int                   pb_attr[] = { 0 };
+    int                   pb_attr[] = {
+        /* Need following 2 to support surface as texture */
+        WGL_TEXTURE_FORMAT_ARB,  WGL_TEXTURE_RGBA_ARB,
+        WGL_TEXTURE_TARGET_ARB,  WGL_TEXTURE_2D_ARB,
+        0
+    };
     
     // Create the p-buffer...
     surface = (GloSurface*)malloc(sizeof(GloSurface));
@@ -856,9 +879,43 @@ void glo_surface_get_size(GloSurface *surface, int *width, int *height) {
         *height = surface->height;
 }
 
-void glo_surface_as_texture(GloSurface *surface) {
-       /* NOT IMPLEMENTED YET. */
-       printf("glo_surface_as_texture() is not implemented for windows. \n");
+/* Bind the surface as texture */
+void glo_surface_as_texture(GloSurface *surface)
+{
+#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 (!wglBindTexImageARB)
+    {
+        fprintf (stderr, "wglBindTexImageEXT not supported! Can't emulate glEGLImageTargetTexture2DOES!\n");
+        return;
+    }
+
+    if ( !wglBindTexImageARB(surface->hPBuffer, WGL_FRONT_LEFT_ARB) )
+    {
+        fprintf(stderr, "wglBindTexImageARBr error=%d.\n", glGetError());
+    }
+
+#endif
+}
+void glo_surface_release_texture(GloSurface *surface)
+{
+    if (!wglReleaseTexImageARB)
+    {
+        fprintf (stderr, "wglReleaseTexImageARB not supported! Can't emulate glEGLImageTargetTexture2DOES!\n");
+        return;
+    }
+
+    if ( !wglReleaseTexImageARB(surface->hPBuffer, WGL_FRONT_LEFT_ARB) )
+    {
+        fprintf(stderr, "wglBindTexImageARBr error=%d.\n", glGetError());
+    }
+
 }
 
 #endif
index d8d38b0..4223675 100644 (file)
@@ -489,15 +489,21 @@ void glo_surface_as_texture(GloSurface *surface)
     ptr_func_glXBindTexImageEXT(glo.dpy, surface->glxPixmap, GLX_FRONT_LEFT_EXT, NULL);
     fprintf(stderr, "surface_as_texture:2:error=%d.\n", glGetError());
 #else
+       int glFormat, glType;
     glo_surface_updatecontents(surface);
     /*XXX: changet the fixed target: GL_TEXTURE_2D*/
-    fprintf(stderr, "surface_as_texture:teximage:width=%d,height=%d.\n", surface->width, surface->height);
+       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 use different RGB order than the contexts in the pixmap surface */
 /*    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->width, surface->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->image->data);*/
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->width, surface->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, surface->image->data);
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->width, surface->height, 0, glFormat, glType, surface->image->data);
 #endif
 }
 
+void glo_surface_release_texture(GloSurface *surface)
+{
+}
+
  /* Abstract glXQueryExtensionString() */
 const char *glo_glXQueryExtensionsString(void) {
     return glXQueryExtensionsString(glo.dpy, 0);
index 718ece0..f0582d4 100644 (file)
@@ -1644,6 +1644,7 @@ int do_function_call(ProcessState *process, int func_number, unsigned long *args
                     else {
 //                       DEBUGF( " --Client drawable found, using surface: %16x %16lx\n", (unsigned int)glstate->current_qsurface, (unsigned long int)client_drawable);
                     }
+#if 0
                     /*Test old surface contents */
                     int reset_texture = 0;
                     GLState *old_glstate = NULL;
@@ -1656,13 +1657,14 @@ int do_function_call(ProcessState *process, int func_number, unsigned long *args
                     }
                     fprintf(stderr, "edwin:MakeCurrent: drawable=0x%x,qsurface=%p.\n", client_drawable, glstate->current_qsurface);
 
-                    /* Switch to pixmap */
+#endif
+                    /* Switch in pixmap surface */
                     if (glstate->current_qsurface && SURFACE_PIXMAP == glstate->current_qsurface->type )
                     {
-                        /* get the windows contents */
-                        if ( process->current_state->current_qsurface )
-                        glo_surface_updatecontents(process->current_state->current_qsurface->surface);
+                        /* Release it if the surface is used as texture target */
+                        glo_surface_release_texture(glstate->current_qsurface);
                     }
+
                     process->current_state = glstate;
 
                     ret.i = glo_surface_makecurrent(glstate->current_qsurface->surface);
@@ -2021,7 +2023,7 @@ int do_function_call(ProcessState *process, int func_number, unsigned long *args
 
                 process->current_state->bindTexture2D = client_texture;
             }
-       break;
+                       break;
         }
 
     case glGenTextures_fake_func: