PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB;
PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB;
PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB;
+PFNWGLBINDTEXIMAGEARBPROC wglBindTexImageARB;
+PFNWGLRELEASETEXIMAGEARBPROC wglReleaseTexImageARB;
/* ------------------------------------------------------------------------ */
PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB;
PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB;
PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB;
+ PFNWGLBINDTEXIMAGEARBPROC wglBindTexImageARB;
+ PFNWGLRELEASETEXIMAGEARBPROC wglReleaseTexImageARB;
wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC)wglGetProcAddress("wglGetPbufferDCARB");
wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetProcAddress("wglReleasePbufferDCARB");
wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC)wglGetProcAddress("wglCreatePbufferARB");
wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC)wglGetProcAddress("wglDestroyPbufferARB");
+ wglBindTexImageARB = (PFNWGLBINDTEXIMAGEARBPROC)wglGetProcAddress("wglBindTexImageARB");
+ wglReleaseTexImageARB = (PFNWGLRELEASETEXIMAGEARBPROC)wglGetProcAddress("wglReleaseTexImageARB");
+
if (!wglChoosePixelFormatARB ||
!wglGetPbufferDCARB ||
!wglReleasePbufferDCARB ||
return 1;
}
+ if ( !wglBindTexImageARB ||
+ !wglReleaseTexImageARB )
+ fprintf (stderr, "Warning: no [Bind|Release]TexImageARB extensions.\n");
+
glo_inited = 1;
return 0;
/* ------------------------------------------------------------------------ */
+/* 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[] = {
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};
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" );
/* 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));
*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
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);