2 * gstvaapiutils_glx.c - GLX utilties
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
5 * Copyright (C) 2011-2012 Intel Corporation
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; either version 2.1
10 * of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301 USA
23 #define _GNU_SOURCE 1 /* RTLD_DEFAULT */
28 #include "gstvaapiutils_glx.h"
29 #include "gstvaapiutils_x11.h"
32 #include "gstvaapidebug.h"
34 /** Lookup for substring NAME in string EXT using SEP as separators */
36 find_string(const char *name, const char *ext, const char *sep)
44 end = ext + strlen(ext);
45 name_len = strlen(name);
47 n = strcspn(ext, sep);
48 if (n == name_len && strncmp(name, ext, n) == 0)
56 * gl_get_error_string:
57 * @error: an OpenGL error enumeration
59 * Retrieves the string representation the OpenGL @error.
61 * Return error: the static string representing the OpenGL @error
64 gl_get_error_string(GLenum error)
67 #define MAP(id, str) \
68 case id: return str " (" #id ")"
69 MAP(GL_NO_ERROR, "no error");
70 MAP(GL_INVALID_ENUM, "invalid enumerant");
71 MAP(GL_INVALID_VALUE, "invalid value");
72 MAP(GL_INVALID_OPERATION, "invalid operation");
73 MAP(GL_STACK_OVERFLOW, "stack overflow");
74 MAP(GL_STACK_UNDERFLOW, "stack underflow");
75 MAP(GL_OUT_OF_MEMORY, "out of memory");
76 #ifdef GL_INVALID_FRAMEBUFFER_OPERATION_EXT
77 MAP(GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
78 "invalid framebuffer operation");
89 * Purges all OpenGL errors. This function is generally useful to
90 * clear up the pending errors prior to calling gl_check_error().
95 while (glGetError() != GL_NO_ERROR)
102 * Checks whether there is any OpenGL error pending.
104 * Return value: %TRUE if an error was encountered
110 gboolean has_errors = FALSE;
112 while ((error = glGetError()) != GL_NO_ERROR) {
113 GST_DEBUG("glError: %s caught", gl_get_error_string(error));
121 * @param: the parameter name
122 * @pval: return location for the value
124 * This function is a wrapper around glGetIntegerv() that does extra
127 * Return value: %TRUE on success
130 gl_get_param(GLenum param, guint *pval)
135 glGetIntegerv(param, &val);
136 if (gl_check_error())
145 * gl_get_texture_param:
146 * @target: the target to which the texture is bound
147 * @param: the parameter name
148 * @pval: return location for the value
150 * This function is a wrapper around glGetTexLevelParameteriv() that
151 * does extra error checking.
153 * Return value: %TRUE on success
156 gl_get_texture_param(GLenum target, GLenum param, guint *pval)
161 glGetTexLevelParameteriv(target, 0, param, &val);
162 if (gl_check_error())
171 * gl_get_texture_binding:
172 * @target: a texture target
174 * Determines the texture binding type for the specified target.
176 * Return value: texture binding type for @target
179 gl_get_texture_binding(GLenum target)
185 binding = GL_TEXTURE_BINDING_1D;
188 binding = GL_TEXTURE_BINDING_2D;
191 binding = GL_TEXTURE_BINDING_3D;
193 case GL_TEXTURE_RECTANGLE_ARB:
194 binding = GL_TEXTURE_BINDING_RECTANGLE_ARB;
205 * @color: the requested RGB color
207 * Sets background color to the RGB @color. This basically is a
208 * wrapper around glClearColor().
211 gl_set_bgcolor(guint32 color)
214 ((color >> 16) & 0xff) / 255.0f,
215 ((color >> 8) & 0xff) / 255.0f,
216 ( color & 0xff) / 255.0f,
223 * @fovy: the field of view angle, in degrees, in the y direction
224 * @aspect: the aspect ratio that determines the field of view in the
225 * x direction. The aspect ratio is the ratio of x (width) to y
227 * @zNear: the distance from the viewer to the near clipping plane
229 * @zFar: the distance from the viewer to the far clipping plane
232 * Specified a viewing frustum into the world coordinate system. This
233 * basically is the Mesa implementation of gluPerspective().
236 gl_perspective(GLdouble fovy, GLdouble aspect, GLdouble near_val, GLdouble far_val)
238 GLdouble left, right, top, bottom;
241 <http://www.opengl.org/resources/faq/technical/transformations.htm> */
242 top = tan(fovy * M_PI / 360.0) * near_val;
244 left = aspect * bottom;
245 right = aspect * top;
246 glFrustum(left, right, bottom, top, near_val, far_val);
251 * @width: the requested width, in pixels
252 * @height: the requested height, in pixels
254 * Resizes the OpenGL viewport to the specified dimensions, using an
255 * orthogonal projection. (0,0) represents the top-left corner of the
259 gl_resize(guint width, guint height)
265 #define Z_CAMERA 0.869f
267 glViewport(0, 0, width, height);
268 glMatrixMode(GL_PROJECTION);
270 gl_perspective(FOVY, ASPECT, Z_NEAR, Z_FAR);
271 glMatrixMode(GL_MODELVIEW);
274 glTranslatef(-0.5f, -0.5f, -Z_CAMERA);
275 glScalef(1.0f/width, -1.0f/height, 1.0f/width);
276 glTranslatef(0.0f, -1.0f*height, 0.0f);
281 * @dpy: an X11 #Display
282 * @screen: the associated screen of @dpy
283 * @parent: the parent #GLContextState, or %NULL if none is to be used
285 * Creates a GLX context sharing textures and displays lists with
286 * @parent, if not %NULL.
288 * Return value: the newly created GLX context
291 gl_create_context(Display *dpy, int screen, GLContextState *parent)
294 GLXFBConfig *fbconfigs = NULL;
295 int fbconfig_id, val, n, n_fbconfigs;
298 static GLint fbconfig_attrs[] = {
299 GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
300 GLX_RENDER_TYPE, GLX_RGBA_BIT,
301 GLX_DOUBLEBUFFER, True,
308 cs = malloc(sizeof(*cs));
313 cs->display = parent->display;
314 cs->window = parent->window;
315 screen = DefaultScreen(parent->display);
323 cs->swapped_buffers = FALSE;
325 if (parent && parent->context) {
326 status = glXQueryContext(
329 GLX_FBCONFIG_ID, &fbconfig_id
331 if (status != Success)
334 if (fbconfig_id == GLX_DONT_CARE)
335 goto choose_fbconfig;
337 fbconfigs = glXGetFBConfigs(parent->display, screen, &n_fbconfigs);
341 /* Find out a GLXFBConfig compatible with the parent context */
342 for (n = 0; n < n_fbconfigs; n++) {
343 status = glXGetFBConfigAttrib(
346 GLX_FBCONFIG_ID, &val
348 if (status == Success && val == fbconfig_id)
351 if (n == n_fbconfigs)
356 fbconfigs = glXChooseFBConfig(
359 fbconfig_attrs, &n_fbconfigs
364 /* Select the first one */
368 cs->visual = glXGetVisualFromFBConfig(cs->display, fbconfigs[n]);
369 cs->context = glXCreateNewContext(
373 parent ? parent->context : NULL,
380 gl_destroy_context(cs);
389 * gl_destroy_context:
390 * @cs: a #GLContextState
392 * Destroys the GLX context @cs
395 gl_destroy_context(GLContextState *cs)
405 if (cs->display && cs->context) {
406 if (glXGetCurrentContext() == cs->context) {
407 /* XXX: if buffers were never swapped, the application
408 will crash later with the NVIDIA driver */
409 if (!cs->swapped_buffers)
411 glXMakeCurrent(cs->display, None, NULL);
413 glXDestroyContext(cs->display, cs->context);
421 * gl_get_current_context:
422 * @cs: return location to the current #GLContextState
424 * Retrieves the current GLX context, display and drawable packed into
425 * the #GLContextState struct.
428 gl_get_current_context(GLContextState *cs)
430 cs->display = glXGetCurrentDisplay();
431 cs->window = glXGetCurrentDrawable();
432 cs->context = glXGetCurrentContext();
436 * gl_set_current_context:
437 * @new_cs: the requested new #GLContextState
438 * @old_cs: return location to the context that was previously current
440 * Makes the @new_cs GLX context the current GLX rendering context of
441 * the calling thread, replacing the previously current context if
444 * If @old_cs is non %NULL, the previously current GLX context and
445 * window are recorded.
447 * Return value: %TRUE on success
450 gl_set_current_context(GLContextState *new_cs, GLContextState *old_cs)
452 /* If display is NULL, this could be that new_cs was retrieved from
453 gl_get_current_context() with none set previously. If that case,
454 the other fields are also NULL and we don't return an error */
455 if (!new_cs->display)
456 return !new_cs->window && !new_cs->context;
459 if (old_cs == new_cs)
461 gl_get_current_context(old_cs);
462 if (old_cs->display == new_cs->display &&
463 old_cs->window == new_cs->window &&
464 old_cs->context == new_cs->context)
467 return glXMakeCurrent(new_cs->display, new_cs->window, new_cs->context);
472 * @cs: a #GLContextState
474 * Promotes the contents of the back buffer of the @win window to
475 * become the contents of the front buffer. This simply is wrapper
476 * around glXSwapBuffers().
479 gl_swap_buffers(GLContextState *cs)
481 glXSwapBuffers(cs->display, cs->window);
482 cs->swapped_buffers = TRUE;
487 * @ts: a #GLTextureState
488 * @target: the target to which the texture is bound
489 * @texture: the name of a texture
491 * Binds @texture to the specified @target, while recording the
492 * previous state in @ts.
494 * Return value: %TRUE on success
497 gl_bind_texture(GLTextureState *ts, GLenum target, GLuint texture)
503 if (glIsEnabled(target)) {
504 binding = gl_get_texture_binding(target);
507 if (!gl_get_param(binding, &ts->old_texture))
509 ts->was_enabled = TRUE;
510 ts->was_bound = texture == ts->old_texture;
517 ts->was_enabled = FALSE;
518 ts->was_bound = FALSE;
522 glBindTexture(target, texture);
523 if (gl_check_error())
530 * @ts: a #GLTextureState
532 * Rebinds the texture that was previously bound and recorded in @ts.
535 gl_unbind_texture(GLTextureState *ts)
537 if (!ts->was_bound && ts->old_texture)
538 glBindTexture(ts->target, ts->old_texture);
539 if (!ts->was_enabled)
540 glDisable(ts->target);
545 * @target: the target to which the texture is bound
546 * @format: the format of the pixel data
547 * @width: the requested width, in pixels
548 * @height: the requested height, in pixels
550 * Creates a texture with the specified dimensions and @format. The
551 * internal format will be automatically derived from @format.
553 * Return value: the newly created texture name
556 gl_create_texture(GLenum target, GLenum format, guint width, guint height)
558 GLenum internal_format;
561 guint bytes_per_component;
563 internal_format = format;
566 bytes_per_component = 1;
568 case GL_LUMINANCE_ALPHA:
569 bytes_per_component = 2;
573 internal_format = GL_RGBA;
574 bytes_per_component = 4;
577 bytes_per_component = 0;
580 g_assert(bytes_per_component > 0);
582 glGenTextures(1, &texture);
583 if (!gl_bind_texture(&ts, target, texture))
585 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
586 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
587 glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
588 glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
589 glPixelStorei(GL_UNPACK_ALIGNMENT, bytes_per_component);
600 gl_unbind_texture(&ts);
606 * @name: the name of the OpenGL extension function to lookup
608 * Returns the specified OpenGL extension function
610 * Return value: the OpenGL extension matching @name, or %NULL if none
613 typedef void (*GLFuncPtr)(void);
614 typedef GLFuncPtr (*GLXGetProcAddressProc)(const char *);
617 get_proc_address_default(const char *name)
622 static GLXGetProcAddressProc
623 get_proc_address_func(void)
625 GLXGetProcAddressProc get_proc_func;
628 *(void **)(&get_proc_func) = dlsym(RTLD_DEFAULT, "glXGetProcAddress");
630 return get_proc_func;
632 *(void **)(&get_proc_func) = dlsym(RTLD_DEFAULT, "glXGetProcAddressARB");
634 return get_proc_func;
636 return get_proc_address_default;
639 static inline GLFuncPtr
640 get_proc_address(const char *name)
642 static GLXGetProcAddressProc get_proc_func = NULL;
644 get_proc_func = get_proc_address_func();
645 return get_proc_func(name);
651 * Initializes the global #GLVTable.
653 * Return value: the #GLVTable filled in with OpenGL extensions, or
656 static GLVTable gl_vtable_static;
661 GLVTable * const gl_vtable = &gl_vtable_static;
662 const gchar *gl_extensions = (const gchar *)glGetString(GL_EXTENSIONS);
663 gboolean has_extension;
665 /* GLX_EXT_texture_from_pixmap */
666 gl_vtable->glx_create_pixmap = (PFNGLXCREATEPIXMAPPROC)
667 get_proc_address("glXCreatePixmap");
668 if (!gl_vtable->glx_create_pixmap)
670 gl_vtable->glx_destroy_pixmap = (PFNGLXDESTROYPIXMAPPROC)
671 get_proc_address("glXDestroyPixmap");
672 if (!gl_vtable->glx_destroy_pixmap)
674 gl_vtable->glx_bind_tex_image = (PFNGLXBINDTEXIMAGEEXTPROC)
675 get_proc_address("glXBindTexImageEXT");
676 if (!gl_vtable->glx_bind_tex_image)
678 gl_vtable->glx_release_tex_image = (PFNGLXRELEASETEXIMAGEEXTPROC)
679 get_proc_address("glXReleaseTexImageEXT");
680 if (!gl_vtable->glx_release_tex_image)
683 /* GL_ARB_framebuffer_object */
685 find_string("GL_ARB_framebuffer_object", gl_extensions, " ") ||
686 find_string("GL_EXT_framebuffer_object", gl_extensions, " ")
689 gl_vtable->gl_gen_framebuffers = (PFNGLGENFRAMEBUFFERSEXTPROC)
690 get_proc_address("glGenFramebuffersEXT");
691 if (!gl_vtable->gl_gen_framebuffers)
693 gl_vtable->gl_delete_framebuffers = (PFNGLDELETEFRAMEBUFFERSEXTPROC)
694 get_proc_address("glDeleteFramebuffersEXT");
695 if (!gl_vtable->gl_delete_framebuffers)
697 gl_vtable->gl_bind_framebuffer = (PFNGLBINDFRAMEBUFFEREXTPROC)
698 get_proc_address("glBindFramebufferEXT");
699 if (!gl_vtable->gl_bind_framebuffer)
701 gl_vtable->gl_gen_renderbuffers = (PFNGLGENRENDERBUFFERSEXTPROC)
702 get_proc_address("glGenRenderbuffersEXT");
703 if (!gl_vtable->gl_gen_renderbuffers)
705 gl_vtable->gl_delete_renderbuffers = (PFNGLDELETERENDERBUFFERSEXTPROC)
706 get_proc_address("glDeleteRenderbuffersEXT");
707 if (!gl_vtable->gl_delete_renderbuffers)
709 gl_vtable->gl_bind_renderbuffer = (PFNGLBINDRENDERBUFFEREXTPROC)
710 get_proc_address("glBindRenderbufferEXT");
711 if (!gl_vtable->gl_bind_renderbuffer)
713 gl_vtable->gl_renderbuffer_storage = (PFNGLRENDERBUFFERSTORAGEEXTPROC)
714 get_proc_address("glRenderbufferStorageEXT");
715 if (!gl_vtable->gl_renderbuffer_storage)
717 gl_vtable->gl_framebuffer_renderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC)
718 get_proc_address("glFramebufferRenderbufferEXT");
719 if (!gl_vtable->gl_framebuffer_renderbuffer)
721 gl_vtable->gl_framebuffer_texture_2d = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)
722 get_proc_address("glFramebufferTexture2DEXT");
723 if (!gl_vtable->gl_framebuffer_texture_2d)
725 gl_vtable->gl_check_framebuffer_status = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)
726 get_proc_address("glCheckFramebufferStatusEXT");
727 if (!gl_vtable->gl_check_framebuffer_status)
729 gl_vtable->has_framebuffer_object = TRUE;
737 * Retrieves a VTable for OpenGL extensions.
739 * Return value: VTable for OpenGL extensions
744 static gsize gl_vtable_init = FALSE;
745 static GLVTable *gl_vtable = NULL;
747 if (g_once_init_enter(&gl_vtable_init)) {
748 gl_vtable = gl_init_vtable();
749 g_once_init_leave(&gl_vtable_init, TRUE);
755 * gl_create_pixmap_object:
756 * @dpy: an X11 #Display
757 * @width: the request width, in pixels
758 * @height: the request height, in pixels
760 * Creates a #GLPixmapObject of the specified dimensions. This
761 * requires the GLX_EXT_texture_from_pixmap extension.
763 * Return value: the newly created #GLPixmapObject object
766 gl_create_pixmap_object(Display *dpy, guint width, guint height)
768 GLVTable * const gl_vtable = gl_get_vtable();
769 GLPixmapObject *pixo;
770 GLXFBConfig *fbconfig;
773 XWindowAttributes wattr;
775 int n_fbconfig_attrs;
777 int fbconfig_attrs[32] = {
778 GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
779 GLX_DOUBLEBUFFER, GL_FALSE,
780 GLX_RENDER_TYPE, GLX_RGBA_BIT,
781 GLX_X_RENDERABLE, GL_TRUE,
782 GLX_Y_INVERTED_EXT, GL_TRUE,
789 int pixmap_attrs[10] = {
790 GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
791 GLX_MIPMAP_TEXTURE_EXT, GL_FALSE,
798 screen = DefaultScreen(dpy);
799 rootwin = RootWindow(dpy, screen);
801 /* XXX: this won't work for different displays */
802 if (!gl_vtable->has_texture_from_pixmap) {
803 const char *glx_extensions = glXQueryExtensionsString(dpy, screen);
806 if (!find_string("GLX_EXT_texture_from_pixmap", glx_extensions, " "))
808 gl_vtable->has_texture_from_pixmap = TRUE;
811 pixo = calloc(1, sizeof(*pixo));
817 pixo->height = height;
819 pixo->glx_pixmap = None;
820 pixo->is_bound = FALSE;
822 XGetWindowAttributes(dpy, rootwin, &wattr);
823 pixo->pixmap = XCreatePixmap(dpy, rootwin, width, height, wattr.depth);
827 /* Initialize FBConfig attributes */
828 for (attr = fbconfig_attrs; *attr != GL_NONE; attr += 2)
830 *attr++ = GLX_DEPTH_SIZE; *attr++ = wattr.depth;
831 if (wattr.depth == 32) {
832 *attr++ = GLX_ALPHA_SIZE; *attr++ = 8;
833 *attr++ = GLX_BIND_TO_TEXTURE_RGBA_EXT; *attr++ = GL_TRUE;
836 *attr++ = GLX_BIND_TO_TEXTURE_RGB_EXT; *attr++ = GL_TRUE;
840 fbconfig = glXChooseFBConfig(
843 fbconfig_attrs, &n_fbconfig_attrs
848 /* Initialize GLX Pixmap attributes */
849 for (attr = pixmap_attrs; *attr != GL_NONE; attr += 2)
851 *attr++ = GLX_TEXTURE_FORMAT_EXT;
852 if (wattr.depth == 32)
853 *attr++ = GLX_TEXTURE_FORMAT_RGBA_EXT;
855 *attr++ = GLX_TEXTURE_FORMAT_RGB_EXT;
859 pixo->glx_pixmap = gl_vtable->glx_create_pixmap(
866 if (x11_untrap_errors() != 0)
869 pixo->target = GL_TEXTURE_2D;
870 glGenTextures(1, &pixo->texture);
871 if (!gl_bind_texture(&pixo->old_texture, pixo->target, pixo->texture))
873 glTexParameteri(pixo->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
874 glTexParameteri(pixo->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
875 gl_unbind_texture(&pixo->old_texture);
879 gl_destroy_pixmap_object(pixo);
884 * gl_destroy_pixmap_object:
885 * @pixo: a #GLPixmapObject
887 * Destroys the #GLPixmapObject object.
890 gl_destroy_pixmap_object(GLPixmapObject *pixo)
892 GLVTable * const gl_vtable = gl_get_vtable();
897 gl_unbind_pixmap_object(pixo);
900 glDeleteTextures(1, &pixo->texture);
904 if (pixo->glx_pixmap) {
905 gl_vtable->glx_destroy_pixmap(pixo->dpy, pixo->glx_pixmap);
906 pixo->glx_pixmap = None;
910 XFreePixmap(pixo->dpy, pixo->pixmap);
917 * gl_bind_pixmap_object:
918 * @pixo: a #GLPixmapObject
920 * Defines a two-dimensional texture image. The texture image is taken
921 * from the @pixo pixmap and need not be copied. The texture target,
922 * format and size are derived from attributes of the @pixo pixmap.
924 * Return value: %TRUE on success
927 gl_bind_pixmap_object(GLPixmapObject *pixo)
929 GLVTable * const gl_vtable = gl_get_vtable();
934 if (!gl_bind_texture(&pixo->old_texture, pixo->target, pixo->texture))
938 gl_vtable->glx_bind_tex_image(
944 XSync(pixo->dpy, False);
945 if (x11_untrap_errors() != 0) {
946 GST_DEBUG("failed to bind pixmap");
950 pixo->is_bound = TRUE;
955 * gl_unbind_pixmap_object:
956 * @pixo: a #GLPixmapObject
958 * Releases a color buffers that is being used as a texture.
960 * Return value: %TRUE on success
963 gl_unbind_pixmap_object(GLPixmapObject *pixo)
965 GLVTable * const gl_vtable = gl_get_vtable();
971 gl_vtable->glx_release_tex_image(
976 XSync(pixo->dpy, False);
977 if (x11_untrap_errors() != 0) {
978 GST_DEBUG("failed to release pixmap");
982 gl_unbind_texture(&pixo->old_texture);
984 pixo->is_bound = FALSE;
989 * gl_create_framebuffer_object:
990 * @target: the target to which the texture is bound
991 * @texture: the GL texture to hold the framebuffer
992 * @width: the requested width, in pixels
993 * @height: the requested height, in pixels
995 * Creates an FBO with the specified texture and size.
997 * Return value: the newly created #GLFramebufferObject, or %NULL if
1000 GLFramebufferObject *
1001 gl_create_framebuffer_object(
1008 GLVTable * const gl_vtable = gl_get_vtable();
1009 GLFramebufferObject *fbo;
1012 if (!gl_vtable || !gl_vtable->has_framebuffer_object)
1015 /* XXX: we only support GL_TEXTURE_2D at this time */
1016 if (target != GL_TEXTURE_2D)
1019 fbo = calloc(1, sizeof(*fbo));
1024 fbo->height = height;
1027 fbo->is_bound = FALSE;
1029 gl_get_param(GL_FRAMEBUFFER_BINDING, &fbo->old_fbo);
1030 gl_vtable->gl_gen_framebuffers(1, &fbo->fbo);
1031 gl_vtable->gl_bind_framebuffer(GL_FRAMEBUFFER_EXT, fbo->fbo);
1032 gl_vtable->gl_framebuffer_texture_2d(
1034 GL_COLOR_ATTACHMENT0_EXT,
1039 status = gl_vtable->gl_check_framebuffer_status(GL_DRAW_FRAMEBUFFER_EXT);
1040 gl_vtable->gl_bind_framebuffer(GL_FRAMEBUFFER_EXT, fbo->old_fbo);
1041 if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
1046 gl_destroy_framebuffer_object(fbo);
1051 * gl_destroy_framebuffer_object:
1052 * @fbo: a #GLFramebufferObject
1054 * Destroys the @fbo object.
1057 gl_destroy_framebuffer_object(GLFramebufferObject *fbo)
1059 GLVTable * const gl_vtable = gl_get_vtable();
1064 gl_unbind_framebuffer_object(fbo);
1067 gl_vtable->gl_delete_framebuffers(1, &fbo->fbo);
1074 * gl_bind_framebuffer_object:
1075 * @fbo: a #GLFramebufferObject
1077 * Binds @fbo object.
1079 * Return value: %TRUE on success
1082 gl_bind_framebuffer_object(GLFramebufferObject *fbo)
1084 GLVTable * const gl_vtable = gl_get_vtable();
1085 const guint width = fbo->width;
1086 const guint height = fbo->height;
1088 const guint attribs = (GL_VIEWPORT_BIT|
1092 GL_COLOR_BUFFER_BIT);
1097 gl_get_param(GL_FRAMEBUFFER_BINDING, &fbo->old_fbo);
1098 gl_vtable->gl_bind_framebuffer(GL_FRAMEBUFFER_EXT, fbo->fbo);
1099 glPushAttrib(attribs);
1100 glMatrixMode(GL_PROJECTION);
1103 glMatrixMode(GL_MODELVIEW);
1106 glViewport(0, 0, width, height);
1107 glTranslatef(-1.0f, -1.0f, 0.0f);
1108 glScalef(2.0f / width, 2.0f / height, 1.0f);
1110 fbo->is_bound = TRUE;
1115 * gl_unbind_framebuffer_object:
1116 * @fbo: a #GLFramebufferObject
1118 * Releases @fbo object.
1120 * Return value: %TRUE on success
1123 gl_unbind_framebuffer_object(GLFramebufferObject *fbo)
1125 GLVTable * const gl_vtable = gl_get_vtable();
1131 glMatrixMode(GL_PROJECTION);
1133 glMatrixMode(GL_MODELVIEW);
1135 gl_vtable->gl_bind_framebuffer(GL_FRAMEBUFFER_EXT, fbo->old_fbo);
1137 fbo->is_bound = FALSE;