Example #1
0
/* Shutdown X11 */
void X11_Shutdown (struct _video_out *vout)
{
	X11VID ();

	if (xWindow->output_3d_mode==1) {
#ifdef GPAC_HAS_OPENGL
		X11_ReleaseGL(xWindow);
#endif
	} else {
		X11_ReleaseBackBuffer (vout);
	}
#ifdef GPAC_HAS_OPENGL
	if (xWindow->glx_visualinfo)
	  XFree(xWindow->glx_visualinfo);
	xWindow->glx_visualinfo = NULL;
#endif
	XFreeGC (xWindow->display, xWindow->the_gc);
	XUnmapWindow (xWindow->display, (Window) xWindow->wnd);
	XDestroyWindow (xWindow->display, (Window) xWindow->wnd);
	XDestroyWindow (xWindow->display, (Window) xWindow->full_wnd);
#ifdef GPAC_HAS_OPENGL
	if (xWindow->gl_offscreen) glXDestroyGLXPixmap(xWindow->display, xWindow->gl_offscreen);
	if (xWindow->gl_pixmap) XFreePixmap(xWindow->display, xWindow->gl_pixmap);
	XUnmapWindow (xWindow->display, (Window) xWindow->gl_wnd);
	XDestroyWindow (xWindow->display, (Window) xWindow->gl_wnd);
#endif

	/*restore xscreen saver*/
	X11_XScreenSaverState(xWindow, 1);

	XCloseDisplay (xWindow->display);
	gf_free(xWindow);
}
GraphicsContext3DPrivate::~GraphicsContext3DPrivate()
{
    if (m_context) {
        // This may be necessary to prevent crashes with NVidia's closed source drivers. Originally
        // from Mozilla's 3D canvas implementation at: http://bitbucket.org/ilmari/canvas3d/
        ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

        ::glXMakeContextCurrent(sharedDisplay(), 0, 0, 0);
        ::glXDestroyContext(sharedDisplay(), m_context);
        m_context = 0;
    }

    if (m_pbuffer) {
        ::glXDestroyPbuffer(sharedDisplay(), m_pbuffer);
        m_pbuffer = 0;
    }
    if (m_glxPixmap) {
        glXDestroyGLXPixmap(sharedDisplay(), m_glxPixmap);
        m_glxPixmap = 0;
    }
    if (m_pixmap) {
        XFreePixmap(sharedDisplay(), m_pixmap);
        m_pixmap = 0;
    }
}
Example #3
0
void
_gdk_gl_pixmap_destroy (GdkGLPixmap *glpixmap)
{
  GdkGLPixmapImplX11 *impl = GDK_GL_PIXMAP_IMPL_X11 (glpixmap);
  Display *xdisplay;

  GDK_GL_NOTE_FUNC_PRIVATE ();

  if (impl->is_destroyed)
    return;

  xdisplay = GDK_GL_CONFIG_XDISPLAY (impl->glconfig);

  if (impl->glxpixmap == glXGetCurrentDrawable ())
    {
      glXWaitGL ();

      GDK_GL_NOTE_FUNC_IMPL ("glXMakeCurrent");
      glXMakeCurrent (xdisplay, None, NULL);
    }

  GDK_GL_NOTE_FUNC_IMPL ("glXDestroyGLXPixmap");
  glXDestroyGLXPixmap (xdisplay, impl->glxpixmap);

  impl->glxpixmap = None;

  impl->is_destroyed = TRUE;
}
void
releasePixmapFromTexture (CompScreen  *screen,
			  CompTexture *texture)
{
    if (texture->pixmap)
    {
	makeScreenCurrent (screen);
	glEnable (texture->target);
	if (!strictBinding)
	{
	    glBindTexture (texture->target, texture->name);

	    (*screen->releaseTexImage) (screen->display->display,
					texture->pixmap,
					GLX_FRONT_LEFT_EXT);
	}

	glBindTexture (texture->target, 0);
	glDisable (texture->target);

	glXDestroyGLXPixmap (screen->display->display, texture->pixmap);

	texture->pixmap = None;
    }
}
Example #5
0
JNIEXPORT void JNICALL GLX_NATIVE(glXDestroyGLXPixmap)
	(JNIEnv *env, jclass that, jint arg0, jint arg1)
{
	GLX_NATIVE_ENTER(env, that, glXDestroyGLXPixmap_FUNC);
	glXDestroyGLXPixmap(arg0, arg1);
	GLX_NATIVE_EXIT(env, that, glXDestroyGLXPixmap_FUNC);
}
Example #6
0
void BC_Synchronous::delete_pixmap_sync(BC_SynchronousCommand *command)
{
#ifdef HAVE_GL
	Display *display = command->display;
	Window win = command->win;
	glXMakeCurrent(display,
		win,
		command->gl_context);
	glXDestroyContext(display, command->gl_context);
	glXDestroyGLXPixmap(display, command->gl_pixmap);
#endif
}
Example #7
0
void
gl_context_destroy( Handle context)
{
	CLEAR_ERROR;
	XCHECKPOINT;
	if ( glXGetCurrentContext() == ctx-> context) 
		glXMakeCurrent( DISP, 0, NULL);
	if ( ctx-> pixmap)
		glXDestroyGLXPixmap( DISP, ctx-> drawable);
	glXDestroyContext( DISP, ctx-> context );
	free(( void*)  ctx );
}
Example #8
0
static GF_Err X11_SetupGLPixmap(GF_VideoOutput *vout, u32 width, u32 height)
{
  XWindow *xWin = (XWindow *)vout->opaque;

  if (xWin->glx_context) {
    glXMakeCurrent(xWin->display, None, NULL);
    glXDestroyContext(xWin->display, xWin->glx_context);
    xWin->glx_context = NULL;
  }
  if (xWin->gl_offscreen) glXDestroyGLXPixmap(xWin->display, xWin->gl_offscreen);
  xWin->gl_offscreen = 0;
  if (xWin->gl_pixmap) XFreePixmap(xWin->display, xWin->gl_pixmap);
  xWin->gl_pixmap = 0;

  if (xWin->offscreen_type) {
	  GF_LOG(GF_LOG_INFO, GF_LOG_MMIO, ("[X11] Using offscreen GL context through XWindow\n"));
	  if (xWin->offscreen_type==2) {
		XSync(xWin->display, False);
		XMapWindow (xWin->display, (Window) xWin->gl_wnd);
		XSync(xWin->display, False);
//		XSetWMNormalHints (xWin->display, xWin->gl_wnd, Hints);
 		XStoreName (xWin->display, xWin->gl_wnd, "GPAC Offscreeen Window - debug mode");
	}

	  XSync(xWin->display, False);
	  xWin->glx_context = glXCreateContext(xWin->display,xWin->glx_visualinfo, NULL, True);
	  XSync(xWin->display, False);
	  if (!xWin->glx_context) return GF_IO_ERR;
	  if ( ! glXMakeCurrent(xWin->display, xWin->gl_wnd, xWin->glx_context) ) return GF_IO_ERR;
	  XSync(xWin->display, False);

  } else {
  GF_LOG(GF_LOG_INFO, GF_LOG_MMIO, ("[X11] Using offscreen GL context through glXPixmap\n"));
  xWin->gl_pixmap = XCreatePixmap(xWin->display, xWin->gl_wnd, width, height, xWin->depth);
  if (!xWin->gl_pixmap) return GF_IO_ERR;
 
  xWin->gl_offscreen = glXCreateGLXPixmap(xWin->display, xWin->glx_visualinfo, xWin->gl_pixmap);
  if (!xWin->gl_offscreen) return GF_IO_ERR;
 
  XSync(xWin->display, False);
  xWin->glx_context = glXCreateContext(xWin->display, xWin->glx_visualinfo, 0, GL_FALSE);
  XSync(xWin->display, False);
  if (!xWin->glx_context) return GF_IO_ERR;

 XSync(xWin->display, False);
 GF_LOG(GF_LOG_WARNING, GF_LOG_MMIO, ("[X11] Activating GLContext on GLPixmap - this may crash !!\n"));
 glXMakeCurrent(xWin->display, xWin->gl_offscreen, xWin->glx_context);
  }

  GF_LOG(GF_LOG_INFO, GF_LOG_MMIO, ("[X11] Offscreen GL context setup\n"));
  return GF_OK;
}
Example #9
0
static void
glxglue_contextdata_cleanup(struct glxglue_contextdata * ctx)
{
  if (ctx == NULL) { return; }

  Display * display = glxglue_get_display(NULL);
  if (ctx->glxcontext) glXDestroyContext(display, ctx->glxcontext);
  if (ctx->glxpixmap) {
    if (ctx->pbuffer) { glxglue_glXDestroyPbuffer(display, ctx->glxpixmap); }
    else { glXDestroyGLXPixmap(display, ctx->glxpixmap); }
  }
  if (ctx->pixmap) XFreePixmap(display, ctx->pixmap);
  if (ctx->visinfo) XFree(ctx->visinfo);

  free(ctx);
}
void SkNativeSharedGLContext::destroyGLResources() {
    if (fGL) {
        // We need this thread to grab the GLX context before we can make
        // OpenGL calls.  But glXMakeCurrent() will flush the old context,
        // which might have been uninitialized.  Calling with (None, NULL)
        // first solves this problem (somehow).
        glXMakeCurrent(fDisplay, None, NULL);
        glXMakeCurrent(fDisplay, fGlxPixmap, fContext);

        SK_GL_NOERRCHECK(*this, DeleteFramebuffers(1, &fFBO));
        SK_GL_NOERRCHECK(*this, DeleteTextures(1, &fTextureID));
        SK_GL_NOERRCHECK(*this, DeleteRenderbuffers(1, &fDepthStencilBufferID));
    }

    glXMakeCurrent(fDisplay, None, NULL);
    glXDestroyGLXPixmap(fDisplay, fGlxPixmap);
    fGlxPixmap = 0;
}
Example #11
0
                   P3DGLMemoryContextPixmap::~P3DGLMemoryContextPixmap
                                      ()
 {
  if (Ok)
   {
    glXDestroyContext(Connection,OffScreenGLXContext);
    glXDestroyGLXPixmap(Connection,TargetGLXPixmap);
    XFreePixmap(Connection,TargetPixmap);
   }

  if (OwnConnection)
   {
    if (Connection != NULL)
     {
      XCloseDisplay(Connection);
     }
   }
 }
Example #12
0
void QGLContext::reset()
{
    if ( !d->valid )
	return;
    doneCurrent();
    if ( gpm )
	glXDestroyGLXPixmap( d->paintDevice->x11Display(), (GLXPixmap)gpm );
    gpm = 0;
    glXDestroyContext( d->paintDevice->x11Display(), (GLXContext)cx );
    if ( vi )
	XFree( vi );
    vi = 0;
    cx = 0;
    d->crWin = FALSE;
    d->sharing = FALSE;
    d->valid = FALSE;
    d->transpColor = QColor();
    d->initDone = FALSE;
}
void
releasePixmapFromTexture (CompScreen  *screen,
			  CompTexture *texture)
{
    if (texture->pixmap)
    {
	glEnable (texture->target);
	glBindTexture (texture->target, texture->name);

	screen->releaseTexImage (screen->display->display,
				 texture->pixmap,
				 GLX_FRONT_LEFT_EXT);

	glBindTexture (texture->target, 0);
	glDisable (texture->target);

	glXDestroyGLXPixmap (screen->display->display, texture->pixmap);
	texture->pixmap = None;
    }
}
static void
clutter_glx_texture_pixmap_dispose (GObject *object)
{
  ClutterGLXTexturePixmapPrivate *priv;

  priv = CLUTTER_GLX_TEXTURE_PIXMAP (object)->priv;

  if (priv->glx_pixmap != None)
    {
      clutter_x11_trap_x_errors ();

      glXDestroyGLXPixmap (clutter_x11_get_default_display(),
                           priv->glx_pixmap);
      XSync (clutter_x11_get_default_display(), FALSE);

      clutter_x11_untrap_x_errors ();

      priv->glx_pixmap = None;
    }

  G_OBJECT_CLASS (clutter_glx_texture_pixmap_parent_class)->dispose (object);
}
void SkNativeGLContext::destroyGLContext() {
    if (fDisplay) {
        glXMakeCurrent(fDisplay, 0, 0);

        if (fContext) {
            glXDestroyContext(fDisplay, fContext);
            fContext = NULL;
        }

        if (fGlxPixmap) {
            glXDestroyGLXPixmap(fDisplay, fGlxPixmap);
            fGlxPixmap = 0;
        }

        if (fPixmap) {
            XFreePixmap(fDisplay, fPixmap);
            fPixmap = 0;
        }

        XCloseDisplay(fDisplay);
        fDisplay = NULL;
    }
}
Example #16
0
void QGLContext::reset()
{
    Q_D(QGLContext);
    if (!d->valid)
        return;
    d->cleanup();
    const QX11Info *xinfo = qt_x11Info(d->paintDevice);
    doneCurrent();
    if (d->gpm)
        glXDestroyGLXPixmap(xinfo->display(), (GLXPixmap)d->gpm);
    d->gpm = 0;
    glXDestroyContext(xinfo->display(), (GLXContext)d->cx);
    if (d->vi)
        XFree(d->vi);
    d->vi = 0;
    d->cx = 0;
    d->crWin = false;
    d->sharing = false;
    d->valid = false;
    d->transpColor = QColor();
    d->initDone = false;
    qgl_share_reg()->removeShare(this);
}
static void
clutter_glx_texture_pixmap_free_glx_pixmap (ClutterGLXTexturePixmap *texture)
{
  ClutterGLXTexturePixmapPrivate *priv = texture->priv;
  Display                        *dpy;

  dpy = clutter_x11_get_default_display ();

  if (priv->glx_pixmap &&
      priv->bound)
    {
      texture_bind (texture);

      clutter_x11_trap_x_errors ();

      (_gl_release_tex_image) (dpy,
			       priv->glx_pixmap,
			       GLX_FRONT_LEFT_EXT);

      XSync (clutter_x11_get_default_display(), FALSE);

      if (clutter_x11_untrap_x_errors ())
	CLUTTER_NOTE (TEXTURE, "Failed to release?");

      CLUTTER_NOTE (TEXTURE, "Destroyed pxm: %li", priv->glx_pixmap);

      priv->bound = FALSE;
    }

  clutter_x11_trap_x_errors ();
  if (priv->glx_pixmap)
    glXDestroyGLXPixmap (dpy, priv->glx_pixmap);
  XSync (dpy, FALSE);
  clutter_x11_untrap_x_errors ();
  priv->glx_pixmap = None;
}
Example #18
0
bool               P3DGLMemoryContextPixmap::Create
                                      (unsigned int        Width,
                                       unsigned int        Height,
                                       bool                NeedAlpha)
 {
  bool                                 Result;
  XVisualInfo                         *VisualInfo;

  Result = true;

  if (Connection == NULL)
   {
    OwnConnection = true;
    Connection = XOpenDisplay(NULL);

    if (Connection == NULL)
     {
      return(false);
     }
   }
  else
   {
    OwnConnection = false;
   }

  Result = true;

  if (NeedAlpha)
   {
    VisualInfo = glXChooseVisual(Connection,
                                 DefaultScreen(Connection),
                                 VisualAttrArrayAlpha);
   }
  else
   {
    VisualInfo = glXChooseVisual(Connection,
                                 DefaultScreen(Connection),
                                 VisualAttrArray);
   }

  if (VisualInfo != NULL)
   {
    TargetPixmap = XCreatePixmap(Connection,
                                 DefaultRootWindow(Connection),
                                 Width,
                                 Height,
                                 VisualInfo->depth);

    TargetGLXPixmap = glXCreateGLXPixmap(Connection,VisualInfo,TargetPixmap);

    /*FIXME: check for errors here */

    OffScreenGLXContext = glXCreateContext(Connection,VisualInfo,NULL,False);

    if (OffScreenGLXContext != NULL)
     {
      Ok = true;

      Result = MakeCurrent();

      if (Result)
       {
        Result = P3DGLExtInit();
       }

      Ok = Result;
     }
    else
     {
      Result = false;
     }

    if (!Result)
     {
      glXDestroyGLXPixmap(Connection,TargetGLXPixmap);
      XFreePixmap(Connection,TargetPixmap);
     }

    XFree(VisualInfo);
   }
  else
   {
    Result = false;
   }

  if (!Result)
   {
    if (OwnConnection)
     {
      XCloseDisplay(Connection);
     }

    Connection = NULL;
   }

  Ok = Result;

  return(Result);
 }
Bool
bindPixmapToTexture (CompScreen  *screen,
		     CompTexture *texture,
		     Pixmap	 pixmap,
		     int	 width,
		     int	 height,
		     int	 depth)
{
    unsigned int target = 0;
    CompFBConfig *config = &screen->glxPixmapFBConfigs[depth];
    int          attribs[7], i = 0;

    if (!config->fbConfig)
    {
	compLogMessage ("core", CompLogLevelWarn,
			"No GLXFBConfig for depth %d",
			depth);

	return FALSE;
    }

    attribs[i++] = GLX_TEXTURE_FORMAT_EXT;
    attribs[i++] = config->textureFormat;
    attribs[i++] = GLX_MIPMAP_TEXTURE_EXT;
    attribs[i++] = config->mipmap;

    /* If no texture target is specified in the fbconfig, or only the
       TEXTURE_2D target is specified and GL_texture_non_power_of_two
       is not supported, then allow the server to choose the texture target. */
    if (config->textureTargets & GLX_TEXTURE_2D_BIT_EXT &&
       (screen->textureNonPowerOfTwo ||
       (POWER_OF_TWO (width) && POWER_OF_TWO (height))))
	target = GLX_TEXTURE_2D_EXT;
    else if (config->textureTargets & GLX_TEXTURE_RECTANGLE_BIT_EXT)
	target = GLX_TEXTURE_RECTANGLE_EXT;

    /* Workaround for broken texture from pixmap implementations,
       that don't advertise any texture target in the fbconfig. */
    if (!target)
    {
	if (!(config->textureTargets & GLX_TEXTURE_2D_BIT_EXT))
	    target = GLX_TEXTURE_RECTANGLE_EXT;
	else if (!(config->textureTargets & GLX_TEXTURE_RECTANGLE_BIT_EXT))
	    target = GLX_TEXTURE_2D_EXT;
    }

    if (target)
    {
	attribs[i++] = GLX_TEXTURE_TARGET_EXT;
	attribs[i++] = target;
    }

    attribs[i++] = None;

    makeScreenCurrent (screen);
    texture->pixmap = (*screen->createPixmap) (screen->display->display,
					       config->fbConfig, pixmap,
					       attribs);
    if (!texture->pixmap)
    {
	compLogMessage ("core", CompLogLevelWarn,
			"glXCreatePixmap failed");

	return FALSE;
    }

    if (!target)
	(*screen->queryDrawable) (screen->display->display,
				  texture->pixmap,
				  GLX_TEXTURE_TARGET_EXT,
				  &target);

    switch (target) {
    case GLX_TEXTURE_2D_EXT:
	texture->target = GL_TEXTURE_2D;

	texture->matrix.xx = 1.0f / width;
	if (config->yInverted)
	{
	    texture->matrix.yy = 1.0f / height;
	    texture->matrix.y0 = 0.0f;
	}
	else
	{
	    texture->matrix.yy = -1.0f / height;
	    texture->matrix.y0 = 1.0f;
	}
	texture->mipmap = config->mipmap;
	break;
    case GLX_TEXTURE_RECTANGLE_EXT:
	texture->target = GL_TEXTURE_RECTANGLE_ARB;

	texture->matrix.xx = 1.0f;
	if (config->yInverted)
	{
	    texture->matrix.yy = 1.0f;
	    texture->matrix.y0 = 0;
	}
	else
	{
	    texture->matrix.yy = -1.0f;
	    texture->matrix.y0 = height;
	}
	texture->mipmap = FALSE;
	break;
    default:
	compLogMessage ("core", CompLogLevelWarn,
			"pixmap 0x%x can't be bound to texture",
			(int) pixmap);

	glXDestroyGLXPixmap (screen->display->display, texture->pixmap);
	texture->pixmap = None;

	return FALSE;
    }

    if (!texture->name)
	glGenTextures (1, &texture->name);

    glBindTexture (texture->target, texture->name);

    if (!strictBinding)
    {
	(*screen->bindTexImage) (screen->display->display,
				 texture->pixmap,
				 GLX_FRONT_LEFT_EXT,
				 NULL);
    }

    texture->filter = GL_NEAREST;

    glTexParameteri (texture->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri (texture->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    glTexParameteri (texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri (texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    texture->wrap = GL_CLAMP_TO_EDGE;

    glBindTexture (texture->target, 0);

    return TRUE;
}
Example #20
0
template<> void XUniqueResource<XResource::GLXPixmap>::deleteXResource(unsigned long resource)
{
    if (resource)
        glXDestroyGLXPixmap(sharedDisplay(), resource);
}
Bool
bindPixmapToTexture (CompScreen  *screen,
		     CompTexture *texture,
		     Pixmap	 pixmap,
		     int	 width,
		     int	 height,
		     int	 depth)
{
    XVisualInfo  *visinfo;
    unsigned int target;
    int success = 0;

    visinfo = screen->glxPixmapVisuals[depth];
    if (!visinfo)
    {
	fprintf (stderr, "%s: No GL visual for depth %d\n",
		 programName, depth);

	return FALSE;
    }

    texture->pixmap = glXCreateGLXPixmap (screen->display->display,
					  visinfo, pixmap);
    if (!texture->pixmap)
    {
	fprintf (stderr, "%s: glXCreateGLXPixmap failed\n", programName);

	return FALSE;
    }

    if (screen->queryDrawable (screen->display->display,
			       texture->pixmap,
			       GLX_TEXTURE_TARGET_EXT,
			       &target))
    {
	fprintf (stderr, "%s: glXQueryDrawable failed\n", programName);

	glXDestroyGLXPixmap (screen->display->display, texture->pixmap);
	texture->pixmap = None;

	return FALSE;
    }

    switch (target) {
    case GLX_TEXTURE_2D_EXT:
	texture->target = GL_TEXTURE_2D;
	texture->matrix.xx = 1.0f / width;
	texture->matrix.yy = -1.0f / height;
	texture->matrix.y0 = 1.0f;
	break;
    case GLX_TEXTURE_RECTANGLE_EXT:
	texture->target = GL_TEXTURE_RECTANGLE_ARB;
	texture->matrix.xx = 1.0f;
	texture->matrix.yy = -1.0f;
	texture->matrix.y0 = height;
	break;
    default:
	fprintf (stderr, "%s: pixmap 0x%x can't be bound to texture\n",
		 programName, (int) pixmap);

	glXDestroyGLXPixmap (screen->display->display, texture->pixmap);
	texture->pixmap = None;

	return FALSE;
    }

    if (!texture->name)
	glGenTextures (1, &texture->name);

    glBindTexture (texture->target, texture->name);

    if (screen->bindTexImageExt)
        success = screen->bindTexImageExt(screen->display->display,
                                          texture->pixmap,
                                          GLX_FRONT_LEFT_EXT,
                                          NULL);
    else if (screen->bindTexImageMesa)
        success = screen->bindTexImageMesa(screen->display->display,
                                           texture->pixmap,
                                           GLX_FRONT_LEFT_EXT);

    if (!success)
    {
	fprintf (stderr, "%s: glXBindTexImage failed\n", programName);

	glXDestroyGLXPixmap (screen->display->display, texture->pixmap);
	texture->pixmap = None;

	return FALSE;
    }

    texture->filter = COMP_TEXTURE_FILTER_FAST;

    glTexParameteri (texture->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri (texture->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    glTexParameteri (texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri (texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    glBindTexture (texture->target, 0);

    return TRUE;
}
Example #22
0
Handle
gl_context_create( Handle widget, GLRequest * request)
{
	int attr_list[64], *attr = attr_list;
	XVisualInfo * visual;
	GLXContext context;
	Context * ret;

	if ( pguts == NULL )
		pguts = (UnixGuts*) apc_system_action("unix_guts");

	CLEAR_ERROR;
	XCHECKPOINT;

#define ATTR(in,out) \
	if ( request-> in) { \
		*(attr++) = out; \
		*(attr++) = request-> in; \
	}

	*(attr++) = GLX_USE_GL;
	if ( request-> pixels         == GLREQ_PIXEL_RGBA) *(attr++) = GLX_RGBA;
	if ( request-> double_buffer  == GLREQ_TRUE) *(attr++) = GLX_DOUBLEBUFFER;
	if ( request-> stereo         == GLREQ_TRUE) *(attr++) = GLX_STEREO;
	ATTR( layer           , GLX_LEVEL            )
	ATTR( color_bits      , GLX_BUFFER_SIZE      )
	ATTR( aux_buffers     , GLX_AUX_BUFFERS      )
	ATTR( red_bits        , GLX_RED_SIZE         )
	ATTR( green_bits      , GLX_GREEN_SIZE       )
	ATTR( blue_bits       , GLX_BLUE_SIZE        )
	ATTR( alpha_bits      , GLX_ALPHA_SIZE       )
	ATTR( depth_bits      , GLX_DEPTH_SIZE       )
	ATTR( stencil_bits    , GLX_STENCIL_SIZE     )
	ATTR( accum_red_bits  , GLX_ACCUM_RED_SIZE   )
	ATTR( accum_green_bits, GLX_ACCUM_GREEN_SIZE )
	ATTR( accum_blue_bits , GLX_ACCUM_BLUE_SIZE  )
	ATTR( accum_alpha_bits, GLX_ACCUM_ALPHA_SIZE )
	*(attr++) = 0;

	if ( request-> target == GLREQ_TARGET_WINDOW && sys-> flags. layered) {
		visual = sys-> visual;
	} else if ( !( visual = glXChooseVisual( DISP, SCREEN, attr_list ))) {
		if ( request-> pixels != GLREQ_PIXEL_RGBA) {
			/* emulate win32 which does it softly, i.e. if RGBA fails, it proposes PALETTED */
			request-> pixels = GLREQ_PIXEL_RGBA;
			return gl_context_create( widget, request);
		}
		if ( request-> double_buffer == GLREQ_DONTCARE) {
			request-> double_buffer = GLREQ_TRUE;
			return gl_context_create( widget, request );
		}
		SET_ERROR( ERROR_CHOOSE_VISUAL );
		return (Handle) 0;
	}

	XCHECKPOINT;
	if ( !( context = glXCreateContext( DISP, visual, 0, request-> render != GLREQ_RENDER_XSERVER))) {
		SET_ERROR( ERROR_CREATE_CONTEXT );
		return (Handle) 0;
	}

	ret = malloc( sizeof( Context ));
	memset( ret, 0, sizeof( Context));
	ret-> context  = context;

	switch ( request-> target) {
	case GLREQ_TARGET_WINDOW:
		ret-> drawable   = var-> handle;
		break;
	case GLREQ_TARGET_APPLICATION:
		/* doesn't work with gnome and kde anyway */
		ret-> drawable   = RootWindow( DISP, SCREEN);
		break;
	case GLREQ_TARGET_BITMAP:
	case GLREQ_TARGET_IMAGE: 
	{
		GLXContext  old_context;
		GLXDrawable old_drawable;
		Bool success;
		XCHECKPOINT;

		ret-> drawable = glXCreateGLXPixmap( DISP, visual, sys-> gdrawable);
		ret-> pixmap   = 1;

		/* check if pixmaps are supported on this visual at all */
		old_context  = glXGetCurrentContext();
		old_drawable = glXGetCurrentDrawable();
		success = glXMakeCurrent( DISP, ret-> drawable, ret-> context);
		glXMakeCurrent( DISP, old_drawable, old_context);
		if ( !success ) {
			SET_ERROR( ERROR_NO_PIXMAPS );
			glXDestroyGLXPixmap( DISP, ret-> drawable);
			glXDestroyContext( DISP, ret-> context );
			free(ret);
			return 0;
		}


		break;
	}
	case GLREQ_TARGET_PRINTER:
		SET_ERROR(ERROR_NO_PRINTER);
		free(ret);
		return 0;
	}

	return (Handle) ret;
}
Example #23
0
File: ximage.c Project: 0x0all/ROOT
Bool
asimage2drawable_gl(	ASVisual *asv, Drawable d, ASImage *im,
                  		int src_x, int src_y, int dest_x, int dest_y,
        		  		int width, int height, int d_width, int d_height, 
						Bool force_direct )
{
	if( im != NULL && get_flags( asv->glx_support, ASGLX_Available ) && d != None )
	{
#ifdef HAVE_GLX
		int glbuf_size = (get_flags( asv->glx_support, ASGLX_RGBA )? 4 : 3 ) * width * height;
		CARD8 *glbuf = NULL;
		ASImageDecoder *imdec  = NULL ;
		GLXPixmap glxp = None;
		
		if ((imdec = start_image_decoding( asv, im, 
									   	get_flags( asv->glx_support, ASGLX_RGBA )?SCL_DO_ALL:SCL_DO_COLOR, 
									   	src_x, src_y, width, height, NULL)) != NULL )
		{	 
			int i, l = glbuf_size;
			glbuf = safemalloc( glbuf_size );
			for (i = 0; i < (int)height; i++)
			{	
				int k = width;
				imdec->decode_image_scanline( imdec ); 
				if( get_flags( asv->glx_support, ASGLX_RGBA ) ) 
				{	  
					while( --k >= 0 ) 
					{
						glbuf[--l] = imdec->buffer.alpha[k] ;
						glbuf[--l] = imdec->buffer.blue[k] ;
						glbuf[--l] = imdec->buffer.green[k] ;
						glbuf[--l] = imdec->buffer.red[k] ;
					}	 
				}else
				{	
					while( --k >= 0 ) 
					{
						glbuf[--l] = imdec->buffer.blue[k] ;
						glbuf[--l] = imdec->buffer.green[k] ;
						glbuf[--l] = imdec->buffer.red[k] ;
					}	 
				}
			}
			stop_image_decoding( &imdec );
		}else
			return False;

		if( !force_direct ) 
		{	
			glxp = glXCreateGLXPixmap( asv->dpy, &(asv->visual_info), d);
			/* d is either invalid drawable or is a window */
			if( glxp == None ) 
				force_direct = True ; 
		}                      
		if( glxp == None ) 
		{
			if( asv->glx_scratch_gc_direct	!= NULL )
				glXMakeCurrent (asv->dpy, d, asv->glx_scratch_gc_direct);
			else
				glXMakeCurrent (asv->dpy, d, asv->glx_scratch_gc_indirect);
		}else
			glXMakeCurrent (asv->dpy, glxp, asv->glx_scratch_gc_indirect);
		
		if( glGetError() != 0 ) 
			return False;

  		if ( get_flags( asv->glx_support, ASGLX_DoubleBuffer ) ) 
   			glDrawBuffer (GL_FRONT);

		glDisable(GL_BLEND);		/* optimize pixel transfer rates */
	  	glDisable (GL_DEPTH_TEST);
	  	glDisable (GL_DITHER);
	  	glDisable (GL_FOG);
	  	glDisable (GL_LIGHTING);

		glViewport( 0, 0, d_width, d_height);
		glMatrixMode (GL_PROJECTION);
		glLoadIdentity ();
		/* gluOrtho2D (0, d_width, 0, d_height); */
		glMatrixMode (GL_MODELVIEW);
		glLoadIdentity ();
		glTranslatef (0.375, 0.375, 0.0);


#if 1
		if( !IS_POWER_OF2(width) || !IS_POWER_OF2(height))
		{
			/* now put pixels on */
			glRasterPos2i( dest_x, d_height - (dest_y+height) );
			glDrawPixels(   width, height, 
							get_flags( asv->glx_support, ASGLX_RGBA )?GL_RGBA:GL_RGB, 
							GL_UNSIGNED_BYTE, glbuf );
		}else
#endif		
		{ /* this stuff might be faster : */
			GLuint texture ;

#define TARGET_TEXTURE_ID GL_TEXTURE_2D

#if TARGET_TEXTURE_ID!=GL_TEXTURE_2D
			glEnable(GL_TEXTURE_2D);
#endif			
			glEnable(TARGET_TEXTURE_ID);
			glGenTextures(1, &texture);

			glBindTexture(TARGET_TEXTURE_ID, texture);
	    	glTexParameteri(TARGET_TEXTURE_ID, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	     	glTexParameteri(TARGET_TEXTURE_ID, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexImage2D(TARGET_TEXTURE_ID, 0, get_flags( asv->glx_support, ASGLX_RGBA )?GL_RGBA:GL_RGB, 
					      /* width and height must be the power of 2 !!! */
						  width, height, 
						  0, GL_RGBA, GL_UNSIGNED_BYTE, glbuf);

		 	glBegin(GL_QUADS);
			/* bottom-left */
		   	glTexCoord2d(0., 0.); glVertex2i(dest_x, d_height - (dest_y+height) );
			/* bottom-right */
		   	glTexCoord2d(1.0, 0.0); glVertex2i(dest_x+width, d_height - (dest_y+height));
			/* top-right */
		   	glTexCoord2d(1.0, 1.0); glVertex2i(dest_x+width, d_height - dest_y);    
			/* top-left */ 
		   	glTexCoord2d(0.0, 1.0); glVertex2i(dest_x, d_height - dest_y);
		   	glEnd();

			glBindTexture(TARGET_TEXTURE_ID, 0);
			glFinish();
		}							

		free( glbuf );
		glXMakeCurrent (asv->dpy, None, NULL);	  
		if( glxp ) 
			glXDestroyGLXPixmap( asv->dpy, glxp);
		glFinish(); 				   
		return True;
#endif /* #ifdef HAVE_GLX */
	}
	{
		static Bool warning_shown = False ; 
		if( !warning_shown ) 
		{
			warning_shown = True ;
			show_warning( "Support for GLX is unavailable.");
		}
	}
	return False;
}