static gboolean
create_objects (GstVaapiTextureGLX * texture, guint texture_id)
{
  GstVaapiTexture *const base_texture = GST_VAAPI_TEXTURE (texture);
  Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (texture);
  GLContextState old_cs;
  gboolean success = FALSE;

  gl_get_current_context (&old_cs);

  texture->gl_context = gl_create_context (dpy, DefaultScreen (dpy), &old_cs);
  if (!texture->gl_context ||
      !gl_set_current_context (texture->gl_context, NULL))
    return FALSE;

  texture->pixo = gl_create_pixmap_object (dpy,
      base_texture->width, base_texture->height);
  if (!texture->pixo) {
    GST_ERROR ("failed to create GLX pixmap");
    goto out_reset_context;
  }

  texture->fbo = gl_create_framebuffer_object (base_texture->gl_target,
      texture_id, base_texture->width, base_texture->height);
  if (!texture->fbo) {
    GST_ERROR ("failed to create FBO");
    goto out_reset_context;
  }
  success = TRUE;

out_reset_context:
  gl_set_current_context (&old_cs, NULL);
  return success;
}
static gboolean
_gst_vaapi_window_glx_create_context (GstVaapiWindow * window,
    GLXContext foreign_context)
{
  GstVaapiWindowGLXPrivate *const priv =
      GST_VAAPI_WINDOW_GLX_GET_PRIVATE (window);
  Display *const dpy = GST_VAAPI_WINDOW_NATIVE_DISPLAY (window);
  GLContextState parent_cs;

  parent_cs.display = dpy;
  parent_cs.window = None;
  parent_cs.context = foreign_context;

  GST_VAAPI_WINDOW_LOCK_DISPLAY (window);
  priv->gl_context = gl_create_context (dpy, DefaultScreen (dpy), &parent_cs);
  if (!priv->gl_context) {
    GST_DEBUG ("could not create GLX context");
    goto end;
  }

  if (!glXIsDirect (dpy, priv->gl_context->context)) {
    GST_DEBUG ("could not create a direct-rendering GLX context");
    goto out_destroy_context;
  }
  goto end;

out_destroy_context:
  gl_destroy_context (priv->gl_context);
  priv->gl_context = NULL;
end:
  GST_VAAPI_WINDOW_UNLOCK_DISPLAY (window);
  return priv->gl_context != NULL;
}
Esempio n. 3
0
/*
 * Create an Off-Screen Mesa rendering context.  The only attribute needed is
 * an RGBA vs Color-Index mode flag.
 *
 * Input:  format - either GL_RGBA or GL_COLOR_INDEX
 *         sharelist - specifies another OSMesaContext with which to share
 *                     display lists.  NULL indicates no sharing.
 * Return:  an OSMesaContext or 0 if error
 */
OSMesaContext OSMesaCreateContext( GLenum format, OSMesaContext sharelist )
{
   OSMesaContext osmesa;
   GLfloat rscale, gscale, bscale, ascale;
   GLint rshift, gshift, bshift, ashift;
   GLint rind, gind, bind;
   GLint index_bits;
   GLboolean rgbmode;
   GLboolean swalpha;
   GLuint i4 = 1;
   GLubyte *i1 = (GLubyte *) &i4;
   GLint little_endian = *i1;

   swalpha = GL_FALSE;
   rind = gind = bind = 0;
   if (format==OSMESA_COLOR_INDEX) {
      rscale = gscale = bscale = ascale = 0.0;
      index_bits = 8;
      rshift = gshift = bshift = ashift = 0;
      rgbmode = GL_FALSE;
   }
   else if (format==OSMESA_RGBA) {
      rscale = gscale = bscale = ascale = 255.0;
      index_bits = 0;
      if (little_endian) {
         rshift = 0;
         gshift = 8;
         bshift = 16;
         ashift = 24;
      }
      else {
         rshift = 24;
         gshift = 16;
         bshift = 8;
         ashift = 0;
      }
      rgbmode = GL_TRUE;
   }
   else if (format==OSMESA_BGRA) {
      rscale = gscale = bscale = ascale = 255.0;
      index_bits = 0;
      if (little_endian) {
         ashift = 0;
         rshift = 8;
         gshift = 16;
         bshift = 24;
      }
      else {
         bshift = 24;
         gshift = 16;
         rshift = 8;
         ashift = 0;
      }
      rgbmode = GL_TRUE;
   }
   else if (format==OSMESA_ARGB) {
      rscale = gscale = bscale = ascale = 255.0;
      index_bits = 0;
      if (little_endian) {
         bshift = 0;
         gshift = 8;
         rshift = 16;
         ashift = 24;
      }
      else {
         ashift = 24;
         rshift = 16;
         gshift = 8;
         bshift = 0;
      }
      rgbmode = GL_TRUE;
   }
   else if (format==OSMESA_RGB) {
      rscale = gscale = bscale = ascale = 255.0;
      index_bits = 0;
      bshift = 0;
      gshift = 8;
      rshift = 16;
      ashift = 24;
      bind = 2;
      gind = 1;
      rind = 0;
      rgbmode = GL_TRUE;
      swalpha = GL_TRUE;
   }
   else if (format==OSMESA_BGR) {
      rscale = gscale = bscale = ascale = 255.0;
      index_bits = 0;
      bshift = 0;
      gshift = 8;
      rshift = 16;
      ashift = 24;
      bind = 0;
      gind = 1;
      rind = 2;
      rgbmode = GL_TRUE;
      swalpha = GL_TRUE;
   }
   else {
      return NULL;
   }


   osmesa = (OSMesaContext) calloc( 1, sizeof(struct osmesa_context) );
   if (osmesa) {
      osmesa->gl_visual = gl_create_visual( rgbmode,
					    swalpha,    /* software alpha */
                                            GL_FALSE,	/* db_flag */
                                            DEPTH_BITS,
                                            STENCIL_BITS,
                                            ACCUM_BITS,
                                            index_bits,
                                            rscale, gscale, bscale, ascale );
      if (!osmesa->gl_visual) {
         return NULL;
      }

      osmesa->gl_ctx = gl_create_context( osmesa->gl_visual,
                                          sharelist ? sharelist->gl_ctx : NULL,
                                          (void *) osmesa );
      if (!osmesa->gl_ctx) {
         gl_destroy_visual( osmesa->gl_visual );
         free(osmesa);
         return NULL;
      }
      osmesa->gl_buffer = gl_create_framebuffer( osmesa->gl_visual );
      if (!osmesa->gl_buffer) {
         gl_destroy_visual( osmesa->gl_visual );
         gl_destroy_context( osmesa->gl_ctx );
         free(osmesa);
         return NULL;
      }
      osmesa->format = format;
      osmesa->buffer = NULL;
      osmesa->width = 0;
      osmesa->height = 0;
      osmesa->pixel = 0;
      osmesa->clearpixel = 0;
      osmesa->rowlength = 0;
      osmesa->yup = GL_TRUE;
      osmesa->rshift = rshift;
      osmesa->gshift = gshift;
      osmesa->bshift = bshift;
      osmesa->ashift = ashift;
      osmesa->rind = rind;
      osmesa->gind = gind;
      osmesa->bind = bind;
   }
   return osmesa;
}