Пример #1
0
void glx_init(int scr, int w, int h, int radius, float sigma) {
    int i;
    configs = glXChooseFBConfig(display, scr, pixmap_config, &i);
    vis = glXGetVisualFromFBConfig(display, configs[0]);
    ctx = glXCreateContext(display, vis, NULL, True);

    glXBindTexImageEXT_f = (PFNGLXBINDTEXIMAGEEXTPROC)glXGetProcAddress(
        (GLubyte *)"glXBindTexImageEXT");
    if (glXBindTexImageEXT_f == NULL) {
        errx(EXIT_FAILURE, "Failed to load extension glXBindTexImageEXT.\n");
    }

    glXReleaseTexImageEXT_f = (PFNGLXRELEASETEXIMAGEEXTPROC)glXGetProcAddress(
        (GLubyte *)"glXReleaseTexImageEXT");

    if (glXReleaseTexImageEXT_f == NULL) {
        errx(EXIT_FAILURE, "Failed to load extension glXReleaseTexImageEXT.\n");
    }

    tmp = XCreatePixmap(display, RootWindow(display, vis->screen), w, h,
                        vis->depth);
    glx_tmp = glXCreatePixmap(display, configs[0], tmp, pixmap_attribs);
    glXMakeCurrent(display, glx_tmp, ctx);

    tmp1 = XCreatePixmap(display, RootWindow(display, vis->screen), w, h,
                         vis->depth);
    glx_tmp1 = glXCreatePixmap(display, configs[0], tmp1, pixmap_attribs);

    v_shader = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(v_shader, 1, &VERT_SHADER, NULL);
    glCompileShader(v_shader);
    glGetShaderiv(v_shader, GL_COMPILE_STATUS, &i);
#if DEBUG_GL
    printf("V Shader: %d\n", i);
    printShaderInfoLog(v_shader);
#endif
    f_shader = glCreateShader(GL_FRAGMENT_SHADER);
    char *fragment_shader = generate_fragment_shader(radius, sigma);
    GLchar const *files[] = {fragment_shader};
    glShaderSource(f_shader, 1, files, NULL);
    free(fragment_shader);
    glCompileShader(f_shader);
    glGetShaderiv(f_shader, GL_COMPILE_STATUS, &i);
#if DEBUG_GL
    printf("F Shader: %d\n", i);
    printShaderInfoLog(f_shader);
#endif
    shader_prog = glCreateProgram();
    glAttachShader(shader_prog, v_shader);
    glAttachShader(shader_prog, f_shader);
    glLinkProgram(shader_prog);
    glGetShaderiv(f_shader, GL_LINK_STATUS, &i);
#if DEBUG_GL
    printf("Program: %d\n", i);
    printShaderInfoLog(f_shader);
    printProgramInfoLog(shader_prog);
#endif
}
Пример #2
0
void glx_resize(int w, int h) {
    /* free old pixmaps */
    glx_free_pixmaps();

    /* create new pixmaps */
    tmp = XCreatePixmap(display, RootWindow(display, vis->screen), w, h,
                        vis->depth);
    glx_tmp = glXCreatePixmap(display, configs[0], tmp, pixmap_attribs);
    glXMakeCurrent(display, glx_tmp, ctx);
    tmp1 = XCreatePixmap(display, RootWindow(display, vis->screen), w, h,
                         vis->depth);
    glx_tmp1 = glXCreatePixmap(display, configs[0], tmp1, pixmap_attribs);
}
Пример #3
0
GLXPixmap
createGLXPixmap(Display* display, Pixmap pixmap)
{
  const int attribs[] = {
      GLX_RENDER_TYPE, GLX_RGBA_BIT,
      GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
      None
  };

  int numConfigs = 0;
  GLXFBConfig* config = glXChooseFBConfig(display, 0, attribs, &numConfigs);

  if (numConfigs == 0) {
    fprintf(stderr, "Failed to find a valid GLX FBConfig.\n");
    return None;
  }

  GLXFBConfig cfg = config[0];

  if (verbose) {
    GLXFBConfigID id;
    glXGetFBConfigAttrib(display, cfg, GLX_FBCONFIG_ID, (int*) &id);
    printf("Using FBConfig with ID 0x%X\n", id);
  }

  return glXCreatePixmap(display, cfg, pixmap, NULL);
}
void XCompositeGLXClientBufferIntegration::bindTextureToBuffer(struct ::wl_resource *buffer)
{
    XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(buffer);
    Pixmap pixmap = XCompositeNameWindowPixmap(mDisplay, compositorBuffer->window());

    QVector<int> glxConfigSpec = qglx_buildSpec();
    int numberOfConfigs;
    GLXFBConfig *configs = glXChooseFBConfig(mDisplay,mScreen,glxConfigSpec.constData(),&numberOfConfigs);

    QVector<int> attribList;
    attribList.append(GLX_TEXTURE_FORMAT_EXT);
    attribList.append(GLX_TEXTURE_FORMAT_RGB_EXT);
    attribList.append(GLX_TEXTURE_TARGET_EXT);
    attribList.append(GLX_TEXTURE_2D_EXT);
    attribList.append(0);
    GLXPixmap glxPixmap = glXCreatePixmap(mDisplay,*configs,pixmap,attribList.constData());

    uint inverted = 0;
    glXQueryDrawable(mDisplay, glxPixmap, GLX_Y_INVERTED_EXT,&inverted);
    compositorBuffer->setInvertedY(!inverted);

    XFree(configs);

    m_glxBindTexImageEXT(mDisplay,glxPixmap,GLX_FRONT_EXT, 0);
    //Do we need to change the api so that we do bind and release in the painevent?
    //The specification states that when deleting the texture the color buffer is deleted
//    m_glxReleaseTexImageEXT(mDisplay,glxPixmap,GLX_FRONT_EXT);
}
Пример #5
0
void X11TextureFromPixmap::createClientBuffer(Surface* surface){
    LOG_DEBUG("X11TextureFromPixmap", "creating clientBuffer for window: " << surface->getNativeContent());
    GLXPlatformSurface* platformSurface = (GLXPlatformSurface*)surface->platform;
    if (NULL!=platformSurface)
    {
        Pixmap pixmap = 0;
        LOG_DEBUG("X11TextureFromPixmap", "get X Pixmap");
        pixmap= XCompositeNameWindowPixmap (dpy, surface->getNativeContent());
        if (pixmap==0)
        {
            LOG_ERROR("X11TextureFromPixmap", "didnt create pixmap!");
        }
        XSync(dpy, 0);

        GLXPixmap glxPixmap = 0;
        LOG_DEBUG("X11TextureFromPixmap", "creating glx pixmap from xpixmap");
        glxPixmap = glXCreatePixmap(dpy, pixmapConfig, pixmap, pixmapAttribs);
        if (glxPixmap ==0)
        {
            LOG_DEBUG("X11TextureFromPixmap", "could not allocate glxpixmap for window");
        }
        platformSurface->glxPixmap = glxPixmap;
        platformSurface->pixmap = pixmap;
    }
}
Пример #6
0
int createPixmapForTexture(GLXContextType *glxContext, GLuint texture, uint32_t width, uint32_t height, Pixmap *pixmap, GLXPixmap *glxPixmap)
{
    int i;

    if (!glxContext || !texture || !width || !height || !pixmap || !glxPixmap)
        return -1;

    Display *x11Display = glxContext->x11Display;
    // query/choose config/attributes for GLXPixmap/Pixmap
    const int pixmapAttr[] = { GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
       GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT,
       GL_NONE};
    const int fbConfigAttr[] = { GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
        GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_BIT_EXT,
        GLX_BIND_TO_TEXTURE_RGB_EXT, GL_TRUE,
        GLX_Y_INVERTED_EXT, GL_TRUE,
        GL_NONE};
    int numFbConfigs;
    GLXFBConfig *fbConfig = glXChooseFBConfig(x11Display, DefaultScreen(x11Display), fbConfigAttr, &numFbConfigs);
    ASSERT(fbConfig && numFbConfigs);

    int depth =  XDefaultDepth(x11Display, DefaultScreen(x11Display));
    *pixmap = XCreatePixmap(x11Display, DEFAULT_ROOT_WINDOW(x11Display), width, height, depth);
    ASSERT(*pixmap);
    *glxPixmap = glXCreatePixmap(x11Display, *fbConfig, *pixmap, pixmapAttr);
    ASSERT(*glxPixmap);
    glBindTexture(GL_TEXTURE_2D, texture);
    glXBindTexImageEXT_func(x11Display, *glxPixmap, GLX_FRONT_LEFT_EXT, NULL);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    ASSERT_GL_ERROR();
    return 0;
}
Пример #7
0
Файл: main.c Проект: czaber/ogwm
void add(Window w) {
    XWindowAttributes attr;
	int i;
	if (w == root || w == overlay || w == canvas-1)
		return;

	debug("[AddWindow] Adding window 0x%x\n", w);

	if (workspace == NULL) {
		workspace = malloc(sizeof(Client) * MAX_CLIENTS);
		memset(workspace, 0, sizeof(Client) * MAX_CLIENTS);
	}

	for (i=0; i<MAX_CLIENTS && workspace[i].window != 0; i++)
		if (workspace[i].window == 0)
			break;
	
	unsigned int v;
    int target;
	GLuint texture;
	GLXFBConfig fbc = choose_fbconfig();
	Pixmap pixmap = XCompositeNameWindowPixmap(dpy, w);
    debug("Got pixmap 0x%x for 0x%x\n", pixmap, w);
    XGetWindowAttributes(dpy, w, &attr);
    if (attr.depth == 32)
        pixmap_attr[1] = GLX_TEXTURE_FORMAT_RGBA_EXT;
    else
        pixmap_attr[1] = GLX_TEXTURE_FORMAT_RGB_EXT;
	GLXPixmap glxpixmap = glXCreatePixmap(dpy, fbc, pixmap, pixmap_attr);
    debug("Got glxpixmap 0x%x for 0x%x\n", glxpixmap, pixmap);
	check_gl(__LINE__);
	glXQueryDrawable(dpy, glxpixmap, GLX_WIDTH, &v);
	check_gl(__LINE__); debug("GLX is %d width\n", v);
	glXQueryDrawable(dpy, glxpixmap, GLX_HEIGHT, &v);
	check_gl(__LINE__); debug("GLX is %d height\n", v);
    glXQueryDrawableProc(dpy, glxpixmap, GLX_TEXTURE_TARGET_EXT, &target);
	check_gl(__LINE__); debug("GLX is 0x%x\n", target);
	glGenTextures(1, &texture);
	check_gl(__LINE__);
	
	switch (target) {
		case GLX_TEXTURE_2D_EXT:
			warn("GLX_TEXTURE_2D_EXT requested but we don't support that yet\n");
			target = GL_TEXTURE_2D;
			break;
		case GLX_TEXTURE_RECTANGLE_EXT:
			target = GL_TEXTURE_RECTANGLE_ARB;
			break;
		default:
			die(ERR_INVALID_TEXTURE, "Invalid target: 0x%x\n", target);
	}

	info("Window 0x%x has glx = %x, target 0x%x and texture %d\n",
		w, glxpixmap, target, texture);
	workspace[i].window = w;
	workspace[i].glxpixmap = glxpixmap;
	workspace[i].target = target;
	workspace[i].texture = texture;
    XGetWindowAttributes(dpy, w, &(workspace[i].geom));
}
Пример #8
0
DECLEXPORT(EGLSurface) eglCreatePixmapSurface(EGLDisplay hDisplay, EGLConfig config, EGLNativePixmapType hPixmap,
                                              const EGLint *paAttributes)
{
    Display *pDisplay = (Display *)hDisplay;
    GLXPixmap hGLXPixmap;

    if (!VALID_PTR(hDisplay))
    {
        setEGLError(EGL_NOT_INITIALIZED);
        return EGL_NO_SURFACE;
    }
    if (paAttributes != NULL)  /* Sanity test only. */
        if (*paAttributes != EGL_NONE)
        {
            if (*paAttributes == EGL_VG_COLORSPACE || *paAttributes == EGL_VG_ALPHA_FORMAT)
            {
                setEGLError(EGL_BAD_MATCH);
                return EGL_NO_SURFACE;
            }
            else
            {
                setEGLError(EGL_BAD_ATTRIBUTE);
                return EGL_NO_SURFACE;
            }
        }
    hGLXPixmap = glXCreatePixmap(pDisplay, (GLXFBConfig)config, (Pixmap)hPixmap, NULL);
    if (hGLXPixmap == None)
    {
        setEGLError(EGL_BAD_MATCH);
        return EGL_NO_SURFACE;
    }
    EGL_ASSERT(hGLXPixmap < VBEGL_WINDOW_SURFACE);  /* Greater than the maximum XID. */
    clearEGLError();
    return (EGLSurface)(hGLXPixmap | VBEGL_PIXMAP_SURFACE);
}
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_GLX13_nglXCreatePixmap(JNIEnv *__env, jclass clazz, jlong displayAddress, jlong configAddress, jlong pixmap, jlong attrib_listAddress, jlong __functionAddress) {
	Display *display = (Display *)(intptr_t)displayAddress;
	GLXFBConfig config = (GLXFBConfig)(intptr_t)configAddress;
	const int *attrib_list = (const int *)(intptr_t)attrib_listAddress;
	glXCreatePixmapPROC glXCreatePixmap = (glXCreatePixmapPROC)(intptr_t)__functionAddress;
	UNUSED_PARAMS(__env, clazz)
	return (jlong)(intptr_t)glXCreatePixmap(display, config, (Pixmap)pixmap, attrib_list);
}
void
ppb_video_decoder_assign_picture_buffers(PP_Resource video_decoder, uint32_t no_of_buffers,
                                         const struct PP_PictureBuffer_Dev buffers[])
{
    struct pp_video_decoder_s *vd = pp_resource_acquire(video_decoder, PP_RESOURCE_VIDEO_DECODER);
    if (!vd) {
        trace_error("%s, bad resource\n", __func__);
        goto err_1;
    }

    struct pp_graphics3d_s *g3d = pp_resource_acquire(vd->graphics3d, PP_RESOURCE_GRAPHICS3D);
    if (!g3d) {
        trace_error("%s, bad graphics3d context\n", __func__);
        goto err_2;
    }

    vd->buffers = malloc(no_of_buffers * sizeof(*vd->buffers));
    if (!vd->buffers) {
        trace_error("%s, memory allocation failure\n", __func__);
        goto err_3;
    }

    vd->buffer_count = no_of_buffers;
    for (uintptr_t k = 0; k < no_of_buffers; k ++) {
        vd->buffers[k].id =         buffers[k].id;
        vd->buffers[k].width =      buffers[k].size.width;
        vd->buffers[k].height =     buffers[k].size.height;
        vd->buffers[k].texture_id = buffers[k].texture_id;
        vd->buffers[k].used =       0;

        pthread_mutex_lock(&display.lock);
        vd->buffers[k].pixmap = XCreatePixmap(display.x, DefaultRootWindow(display.x),
                                              buffers[k].size.width, buffers[k].size.height,
                                              g3d->depth);
        int tfp_pixmap_attrs[] = {
            GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
            GLX_MIPMAP_TEXTURE_EXT, GL_FALSE,
            GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT,
            GL_NONE
        };
        vd->buffers[k].glx_pixmap = glXCreatePixmap(display.x, g3d->fb_config,
                                                    vd->buffers[k].pixmap, tfp_pixmap_attrs);
        pthread_mutex_unlock(&display.lock);
        if (vd->buffers[k].glx_pixmap == None) {
            trace_error("%s, failed to create GLX pixmap\n", __func__);
            goto err_3;
        }
    }

err_3:
    pp_resource_release(vd->graphics3d);
err_2:
    pp_resource_release(video_decoder);
err_1:
    ;
}
Пример #11
0
static gboolean on_ref_mapped(GtkWidget *widget, GdkEvent  *event,
               gpointer   user_data)
{
    g_debug("%s", __func__);
    if (!back_pixmap) {
        g_assert(gtk_widget_is_visible(ref));
        GdkWindow* gdkwin = gtk_widget_get_window(ref);
        back_pixmap = XCompositeNameWindowPixmap(display, GDK_WINDOW_XID(gdkwin));
        glx_pm = glXCreatePixmap(display, bestFbc, back_pixmap, pixmap_attribs);
    }
    return FALSE;
}
Пример #12
0
CAMLprim value
ml_glXCreatePixmapEXT( value dpy, value config, value pixmap, value attrib_list )
{
    static const int GLX_TEXTURE_FORMAT_EXT_table[] = {
        GLX_TEXTURE_FORMAT_NONE_EXT,
        GLX_TEXTURE_FORMAT_RGB_EXT,
        GLX_TEXTURE_FORMAT_RGBA_EXT,
    };
    static const int GLX_TEXTURE_TARGET_EXT_table[] = {
        GLX_TEXTURE_1D_EXT,
        GLX_TEXTURE_2D_EXT,
        GLX_TEXTURE_RECTANGLE_EXT,
    };

    int attrs[30]; // TODO: is this thread safe ? or should we do a malloc ?
    int i = 0;
    while ( attrib_list != Val_emptylist )
    {
        value attrib = Field(attrib_list, 0);
        {
            switch (Tag_val(attrib))
            {
                case 0:
                    attrs[i]   = GLX_TEXTURE_FORMAT_EXT;
                    attrs[i+1] = GLX_TEXTURE_FORMAT_EXT_table[Long_val(Field(attrib,0))];
                    break;
                case 1:
                    attrs[i]   = GLX_TEXTURE_TARGET_EXT;
                    attrs[i+1] = GLX_TEXTURE_TARGET_EXT_table[Long_val(Field(attrib,0))];
                    break;
                case 2:
                    attrs[i]   = GLX_MIPMAP_TEXTURE_EXT;
                    attrs[i+1] = Bool_val(Field(attrib,0));
                    break;
                default:
                    caml_failwith("glXCreatePixmap: variant handling bug");
            }
            i += 2;
        }
        attrib_list = Field(attrib_list,1);
        if (i >= 28) break;
    }
    attrs[i] = None;

    GLXPixmap glXPixmap =
        glXCreatePixmap( Display_val(dpy), GLXFBConfig_val(config),
                         Pixmap_val(pixmap), attrs );

    return Val_GLXPixmap(glXPixmap);
}
Пример #13
0
bool CVDPAU::MakePixmapGL()
{
  int num=0;
  int fbConfigIndex = 0;

  int doubleVisAttributes[] = {
    GLX_RENDER_TYPE, GLX_RGBA_BIT,
    GLX_RED_SIZE, 8,
    GLX_GREEN_SIZE, 8,
    GLX_BLUE_SIZE, 8,
    GLX_ALPHA_SIZE, 8,
    GLX_DEPTH_SIZE, 8,
    GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
    GLX_BIND_TO_TEXTURE_RGBA_EXT, True,
    GLX_DOUBLEBUFFER, True,
    GLX_Y_INVERTED_EXT, True,
    GLX_X_RENDERABLE, True,
    None
  };

  int pixmapAttribs[] = {
    GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
    GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT,
    None
  };

  GLXFBConfig *fbConfigs;
  fbConfigs = glXChooseFBConfig(m_Display, DefaultScreen(m_Display), doubleVisAttributes, &num);
  if (fbConfigs==NULL)
  {
    CLog::Log(LOGERROR, "GLX Error: MakePixmap: No compatible framebuffers found");
    return false;
  }
  CLog::Log(LOGDEBUG, "Found %d fbconfigs.", num);
  fbConfigIndex = 0;
  CLog::Log(LOGDEBUG, "Using fbconfig index %d.", fbConfigIndex);

  m_glPixmap = glXCreatePixmap(m_Display, fbConfigs[fbConfigIndex], m_Pixmap, pixmapAttribs);

  if (!m_glPixmap)
  {
    CLog::Log(LOGINFO, "GLX Error: Could not create Pixmap");
    XFree(fbConfigs);
    return false;
  }
  XFree(fbConfigs);

  return true;
}
Пример #14
0
int32_t
ppb_graphics3d_resize_buffers(PP_Resource context, int32_t width, int32_t height)
{
    if (width < 0 || height < 0) {
        trace_error("%s, width or height are negative\n", __func__);
        return PP_ERROR_BADARGUMENT;
    }

    struct pp_graphics3d_s *g3d = pp_resource_acquire(context, PP_RESOURCE_GRAPHICS3D);
    if (!g3d) {
        trace_error("%s, bad resource\n", __func__);
        return PP_ERROR_BADRESOURCE;
    }

    g3d->width = width;
    g3d->height = height;

    GLXPixmap old_glx_pixmap = g3d->glx_pixmap;
    Pixmap    old_pixmap = g3d->pixmap;
    Picture   old_pict = g3d->xr_pict;

    // release possibly bound to other thread g3d->glx_pixmap and bind it to the current one
    pthread_mutex_lock(&display.lock);
    glXMakeCurrent(display.x, g3d->glx_pixmap, g3d->glc);
    g3d->pixmap = XCreatePixmap(display.x, DefaultRootWindow(display.x), g3d->width, g3d->height,
                                g3d->depth);
    g3d->glx_pixmap = glXCreatePixmap(display.x, g3d->fb_config, g3d->pixmap, NULL);
    XFlush(display.x);
    g3d->xr_pict = XRenderCreatePicture(display.x, g3d->pixmap, g3d->xr_pictfmt, 0, 0);

    // make new g3d->glx_pixmap current to the current thread to allow releasing old_glx_pixmap
    glXMakeCurrent(display.x, g3d->glx_pixmap, g3d->glc);

    // clear surface
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);

    // destroy previous glx and x pixmaps
    glXDestroyPixmap(display.x, old_glx_pixmap);
    XRenderFreePicture(display.x, old_pict);
    XFreePixmap(display.x, old_pixmap);

    pthread_mutex_unlock(&display.lock);
    pp_resource_release(context);
    return PP_OK;
}
Пример #15
0
static GLXPixmap
CreatePixmap(Display *dpy, GLXFBConfig config, int w, int h, Pixmap *p)
{
   GLXPixmap gp;
   const int pixmapAttribs[] = {
      GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
      GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT,
      None
   };
   Window root = RootWindow(dpy, 0);

   *p = XCreatePixmap(dpy, root, w, h, 24);
   XSync(dpy, 0);
   gp = glXCreatePixmap(dpy, config, *p, pixmapAttribs);
   XSync(dpy, 0);

   return gp;
}
Пример #16
0
// create destination buffer
bool SceneOpenGL::initBuffer()
{
    if (!initBufferConfigs())
        return false;
    if (fbcbuffer_db != NULL && m_overlayWindow->create()) {
        // we have overlay, try to create double-buffered window in it
        fbcbuffer = fbcbuffer_db;
        XVisualInfo* visual = glXGetVisualFromFBConfig(display(), fbcbuffer);
        XSetWindowAttributes attrs;
        attrs.colormap = XCreateColormap(display(), rootWindow(), visual->visual, AllocNone);
        buffer = XCreateWindow(display(), m_overlayWindow->window(), 0, 0, displayWidth(), displayHeight(),
                               0, visual->depth, InputOutput, visual->visual, CWColormap, &attrs);
        if (hasGLXVersion(1, 3))
            glxbuffer = glXCreateWindow(display(), fbcbuffer, buffer, NULL);
        else
            glxbuffer = buffer;
        m_overlayWindow->setup(buffer);
        db = true;
        XFree(visual);
    } else if (fbcbuffer_nondb != NULL) {
        // cannot get any double-buffered drawable, will double-buffer using a pixmap
        fbcbuffer = fbcbuffer_nondb;
        XVisualInfo* visual = glXGetVisualFromFBConfig(display(), fbcbuffer);
        XGCValues gcattr;
        gcattr.subwindow_mode = IncludeInferiors;
        gcroot = XCreateGC(display(), rootWindow(), GCSubwindowMode, &gcattr);
        buffer = XCreatePixmap(display(), rootWindow(), displayWidth(), displayHeight(),
                               visual->depth);
        glxbuffer = glXCreatePixmap(display(), fbcbuffer, buffer, NULL);
        db = false;
        XFree(visual);
    } else {
        kError(1212) << "Couldn't create output buffer (failed to create overlay window?) !";
        return false; // error
    }
    int vis_buffer;
    glXGetFBConfigAttrib(display(), fbcbuffer, GLX_VISUAL_ID, &vis_buffer);
    XVisualInfo* visinfo_buffer = glXGetVisualFromFBConfig(display(), fbcbuffer);
    kDebug(1212) << "Buffer visual (depth " << visinfo_buffer->depth << "): 0x" << QString::number(vis_buffer, 16);
    XFree(visinfo_buffer);
    return true;
}
Пример #17
0
    void createPixmap(uint32_t winId)
    {
        XWindowAttributes attr;
        XGetWindowAttributes(m_display, winId, &attr);

        XRenderPictFormat* format = XRenderFindVisualFormat(m_display, attr.visual);
        m_hasAlpha = (format->type == PictTypeDirect && format->direct.alphaMask);
        m_size = IntSize(attr.width, attr.height);

        int numberOfConfigs;
        GLXFBConfig* configs = glXChooseFBConfig(m_display, XDefaultScreen(m_display), glxSpec, &numberOfConfigs);

        m_xPixmap = XCompositeNameWindowPixmap(m_display, winId);
        m_glxPixmap = glXCreatePixmap(m_display, *configs, m_xPixmap, glxAttributes);

        uint inverted = 0;
        glXQueryDrawable(m_display, m_glxPixmap, GLX_Y_INVERTED_EXT, &inverted);
        m_textureIsYInverted = !!inverted;

        XFree(configs);
    }
Пример #18
0
static int reinit(struct gl_hwdec *hw, struct mp_image_params *params)
{
    struct priv *p = hw->priv;
    GL *gl = hw->gl;

    destroy_texture(hw);

    params->imgfmt = hw->driver->imgfmt;

    gl->GenTextures(1, &p->gl_texture);
    gl->BindTexture(GL_TEXTURE_2D, p->gl_texture);
    gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    gl->BindTexture(GL_TEXTURE_2D, 0);

    p->pixmap = XCreatePixmap(p->xdisplay,
                        RootWindow(p->xdisplay, DefaultScreen(p->xdisplay)),
                        params->w, params->h, 24);
    if (!p->pixmap) {
        MP_FATAL(hw, "could not create pixmap\n");
        return -1;
    }

    int attribs[] = {
        GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
        GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT,
        GLX_MIPMAP_TEXTURE_EXT, False,
        None,
    };
    p->glxpixmap = glXCreatePixmap(p->xdisplay, p->fbc, p->pixmap, attribs);

    gl->BindTexture(GL_TEXTURE_2D, p->gl_texture);
    p->glXBindTexImage(p->xdisplay, p->glxpixmap, GLX_FRONT_EXT, NULL);
    gl->BindTexture(GL_TEXTURE_2D, 0);

    return 0;
}
Пример #19
0
static gboolean on_ref_configure(GtkWidget *widget, GdkEvent  *event,
               gpointer   user_data)
{
    g_debug("%s", __func__);
    GdkEventConfigure *gec = (GdkEventConfigure*)event;
    g_width = gec->width;
    g_height = gec->height;
    gtk_window_resize(GTK_WINDOW(top), g_width, g_height);

    if (!gtk_widget_get_mapped(ref)) return TRUE;

    if (back_pixmap) {
        glXDestroyPixmap(display, glx_pm);
        XFreePixmap(display, back_pixmap);

        GdkWindow* gdkwin = gtk_widget_get_window(ref);
        back_pixmap = XCompositeNameWindowPixmap(display, GDK_WINDOW_XID(gdkwin));
        glx_pm = glXCreatePixmap(display, bestFbc, back_pixmap, pixmap_attribs);
    }

    return TRUE;
}
Пример #20
0
void BC_Pixmap::enable_opengl()
{
//printf("BC_Pixmap::enable_opengl called but it doesn't work.\n");
#ifdef HAVE_GL
	BC_WindowBase *current_window = BC_WindowBase::get_synchronous()->current_window;
	if(!glx_pixmap_context) {
		GLXFBConfig *glx_fb_configs = current_window->glx_pixmap_fb_configs();
		if( glx_fb_configs ) {
			Display *dpy = current_window->get_display();
			glx_pixmap =
				glXCreatePixmap(dpy, *glx_fb_configs, opaque_pixmap, 0);
			glx_pixmap_context =
				glXCreateNewContext(dpy, *glx_fb_configs, GLX_RGBA_TYPE, 0, True);
		}
	}
	if( !glx_pixmap )
		printf("BC_Pixmap::enable_opengl(): no glx_pixmap\n");
	else if( !glx_pixmap_context )
		printf("BC_Pixmap::enable_opengl(): no glx_pixmap_context\n");
	else
		current_window->glx_make_current(glx_pixmap, glx_pixmap_context);
#endif
}
Пример #21
0
    void createPixmap(uint32_t winId)
    {
        XWindowAttributes attr;
        XGetWindowAttributes(m_display, winId, &attr);

        XRenderPictFormat* format = XRenderFindVisualFormat(m_display, attr.visual);
        m_hasAlpha = (format->type == PictTypeDirect && format->direct.alphaMask);

        int numberOfConfigs;
        GLXFBConfig* configs = glXChooseFBConfig(m_display, XDefaultScreen(m_display), glxSpec, &numberOfConfigs);

        // If origin window has alpha then find config with alpha.
        GLXFBConfig& config = m_hasAlpha ? findFBConfigWithAlpha(configs, numberOfConfigs) : configs[0];

        m_xPixmap = XCompositeNameWindowPixmap(m_display, winId);
        m_glxPixmap = glXCreatePixmap(m_display, config, m_xPixmap, glxAttributes);

        uint inverted = 0;
        glXQueryDrawable(m_display, m_glxPixmap, GLX_Y_INVERTED_EXT, &inverted);
        m_textureIsYInverted = !!inverted;

        XFree(configs);
    }
int glx_1_3_pixmap_dummy(Display *dpy, Bool hybrid)
{
	XVisualInfo *vInfo;
	GLXFBConfig *fbConfigs;
	GLXContext context;
	GLXPixmap glx_pixmap;
	Pixmap x11_pixmap;

	int numReturned;
	int result;
	int dummyAttributes_1_3[] = {
		GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
	        GLX_RENDER_TYPE,   GLX_RGBA_BIT,
		None
	};

	fbConfigs = glXChooseFBConfig( dpy, DefaultScreen(dpy),
					 dummyAttributes_1_3,
					&numReturned );

	vInfo = glXGetVisualFromFBConfig( dpy, fbConfigs[0] );

	dump_vinfo(vInfo);

	x11_pixmap = XCreatePixmap( dpy, DefaultRootWindow(dpy) , 10, 10, 8 );

	if (hybrid)
		glx_pixmap = glXCreateGLXPixmap( dpy, vInfo, x11_pixmap ); //GLX 1.2
	else
		glx_pixmap = glXCreatePixmap( dpy, fbConfigs[0], x11_pixmap, NULL ); // GLX 1.3

        context = glXCreateNewContext( dpy, fbConfigs[0], GLX_RGBA_TYPE, NULL, True );

	glXMakeContextCurrent( dpy, glx_pixmap, glx_pixmap, context );

	return 1;
}
Пример #23
0
/*
 * Create an RGB, double-buffered window.
 * Return the window and context handles.
 */
static void
make_window( Display *dpy, const char *name,
             int x, int y, int width, int height, struct gears *gears)
{
   int attrib[] = { GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
		    GLX_RENDER_TYPE,   GLX_RGBA_BIT,
		    GLX_RED_SIZE,      1,
		    GLX_GREEN_SIZE,    1,
		    GLX_BLUE_SIZE,     1,
		    GLX_DOUBLEBUFFER,  GL_FALSE,
		    GLX_DEPTH_SIZE,    1,
		    None };
   GLXFBConfig * fbconfig;
   int num_configs;
   int scrnum;
   XSetWindowAttributes attr;
   unsigned long mask;
   Window root;
   XVisualInfo *visinfo;

   gears->width = width;
   gears->height = height;

   scrnum = DefaultScreen( dpy );
   root = RootWindow( dpy, scrnum );

   fbconfig = glXChooseFBConfig(dpy, scrnum, attrib, & num_configs);
   if (fbconfig == NULL) {
      printf("Error: couldn't get an RGB, Double-buffered visual\n");
      exit(1);
   }

   /* window attributes */
   visinfo = glXGetVisualFromFBConfig(dpy, fbconfig[0]);
   assert(visinfo != NULL);
   attr.background_pixel = 0;
   attr.border_pixel = 0;
   attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
   attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
   mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;

   gears->win = XCreateWindow( dpy, root, 0, 0, width, height,
			       0, visinfo->depth, InputOutput,
			       visinfo->visual, mask, &attr );

   /* set hints and properties */
   {
      XSizeHints sizehints;
      sizehints.x = x;
      sizehints.y = y;
      sizehints.width  = width;
      sizehints.height = height;
      sizehints.flags = USSize | USPosition;
      XSetNormalHints(dpy, gears->win, &sizehints);
      XSetStandardProperties(dpy, gears->win, name, name,
                              None, (char **)NULL, 0, &sizehints);
   }

   gears->gc = XCreateGC(dpy, gears->win, 0, NULL);

   gears->pixmap = XCreatePixmap(dpy, gears->win,
				 width, height, visinfo->depth);
   if (!gears->pixmap) {
      printf("Error: XCreatePixmap failed\n");
      exit(-1);
   }

   gears->glxpixmap = glXCreatePixmap(dpy, fbconfig[0], gears->pixmap, NULL);
   if (!gears->glxpixmap) {
      printf("Error: glXCreatePixmap failed\n");
      exit(-1);
   }

   gears->ctx = glXCreateNewContext(dpy, fbconfig[0],
				    GLX_RGBA_TYPE, NULL, GL_TRUE);
   if (!gears->ctx) {
      printf("Error: glXCreateNewContext failed\n");
      exit(1);
   }

   XFree(fbconfig);
}
Пример #24
0
enum piglit_result
piglit_glx_iterate_pixmap_fbconfigs(enum piglit_result (*draw)(Display *dpy,
						      GLXFBConfig config))
{
	int screen;
	GLXFBConfig *configs;
	int n_configs;
	int i;
	bool any_fail = false;
	bool any_pass = false;
	Window root_win;

	Display *dpy = XOpenDisplay(NULL);
	if (!dpy) {
		fprintf(stderr, "couldn't open display\n");
		piglit_report_result(PIGLIT_FAIL);
	}
	screen = DefaultScreen(dpy);
	root_win = RootWindow(dpy, screen);

	configs = glXGetFBConfigs(dpy, screen, &n_configs);
	if (!configs) {
		fprintf(stderr, "No GLX FB configs\n");
		piglit_report_result(PIGLIT_SKIP);
	}

	for (i = 0; i < n_configs; i++) {
		GLXFBConfig config = configs[i];
		enum piglit_result result;
		GLXContext ctx;
		Pixmap pix;
		GLXPixmap glx_pix;
		int draw_types;
		int depth;

		glXGetFBConfigAttrib(dpy, config, GLX_DRAWABLE_TYPE,
				     &draw_types);

		if (!(draw_types & GLX_PIXMAP_BIT))
			continue;

		glXGetFBConfigAttrib(dpy, config, GLX_BUFFER_SIZE,
				     &depth);
		ctx = glXCreateNewContext(dpy, config, GLX_RGBA_TYPE,
					  NULL, true);
		pix = XCreatePixmap(dpy, root_win,
				    piglit_width, piglit_height, depth);
		glx_pix = glXCreatePixmap(dpy, config, pix, NULL);
		glXMakeCurrent(dpy, glx_pix, ctx);

		result = draw(dpy, config);

		if (result == PIGLIT_FAIL)
			any_fail = true;
		else if (result == PIGLIT_PASS)
			any_pass = true;

		XFreePixmap(dpy, pix);
		glXDestroyContext(dpy, ctx);
	}

	if (any_fail)
		return PIGLIT_FAIL;
	else if (any_pass)
		return PIGLIT_PASS;
	else
		return PIGLIT_SKIP;
}
Пример #25
0
static int
vdpau_init(glw_video_t *gv)
{
  const glw_video_config_t *gvc = &gv->gv_cfg_cur;
  vdpau_dev_t *vd = gv->w.glw_root->gr_be.gbr_vdpau_dev;
  int i, nconfs;
  VdpStatus st;
  GLXFBConfig *fbconfig;

  for(i = 0; i < GLW_VIDEO_MAX_SURFACES; i++)
    gv->gv_surfaces[i].gvs_vdpau_surface = VDP_INVALID_HANDLE;

  gv->gv_vdpau_pq = VDP_INVALID_HANDLE;
  gv->gv_vdpau_pqt = VDP_INVALID_HANDLE;

  gv->gv_vdpau_initialized = 0;

  /* Pixmap */
  fbconfig = glXChooseFBConfig(vd->vd_dpy, 0, pixmap_attribs, &nconfs);
  if(nconfs < 1) {
    TRACE(TRACE_ERROR, "VDPAU", "Unable to find fbconfig for pixmap");
    return -1;
  }

  XWindowAttributes wndattribs;
  XGetWindowAttributes(vd->vd_dpy, DefaultRootWindow(vd->vd_dpy), &wndattribs);

  gv->gv_xpixmap = XCreatePixmap(vd->vd_dpy, glXGetCurrentDrawable(),
				 VDPAU_PIXMAP_WIDTH, VDPAU_PIXMAP_HEIGHT,
				 wndattribs.depth);

  gv->gv_glx_pixmap = glXCreatePixmap(vd->vd_dpy, *fbconfig, 
				      gv->gv_xpixmap, glx_pixmap_attribs);

  /* Presentation queue */
  st = vd->vdp_presentation_queue_target_create_x11(vd->vd_dev, gv->gv_xpixmap,
						    &gv->gv_vdpau_pqt);

  if(st != VDP_STATUS_OK) {
    TRACE(TRACE_ERROR, "VDPAU", "Unable to create pixmap target");
    return -1;
  }

  st = vd->vdp_presentation_queue_create(vd->vd_dev, gv->gv_vdpau_pqt,
					 &gv->gv_vdpau_pq);

  if(st != VDP_STATUS_OK) {
    TRACE(TRACE_ERROR, "VDPAU", "Unable to create presentation queue");
    return -1;
  }

  /* Video mixer */
  st = vdpau_mixer_create(vd, &gv->gv_vm, 
			  gvc->gvc_width[0], gvc->gvc_height[0]);
			  

  if(st != VDP_STATUS_OK) {
    TRACE(TRACE_ERROR, "VDPAU", "Unable to create video mixer");
    return -1;
  }
  

  /* Surfaces */
  for(i = 0; i < gvc->gvc_nsurfaces; i++) {
    if(surface_init(vd, gv, &gv->gv_surfaces[i], gvc)) {
      return -1;
    }
  }
  gv->gv_nextpts = AV_NOPTS_VALUE;
  return 0;
}
Пример #26
0
/**
 * Creates a Pixmap and GLXPixmap with tex_data as the contents.
 */
static GLXPixmap
create_pixmap(GLenum format)
{
	static const int rgb_fb_config_attribs[] = {
		GLX_RENDER_TYPE, GLX_RGBA_BIT,
		GLX_RED_SIZE, 8,
		GLX_GREEN_SIZE, 8,
		GLX_BLUE_SIZE, 8,
		GLX_ALPHA_SIZE, 0,
		GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
		GLX_BIND_TO_TEXTURE_RGB_EXT, 1,
		None
	};
	static const int rgba_fb_config_attribs[] = {
		GLX_RENDER_TYPE, GLX_RGBA_BIT,
		GLX_RED_SIZE, 8,
		GLX_GREEN_SIZE, 8,
		GLX_BLUE_SIZE, 8,
		GLX_ALPHA_SIZE, 8,
		GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
		GLX_BIND_TO_TEXTURE_RGBA_EXT, 1,
		None
	};
	static const int rgb_pixmap_attribs[] =	{
		GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
		GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT,
		None
	};
	static const int rgba_pixmap_attribs[] =	{
		GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
		GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT,
		None
	};
	static const int *fb_config_attribs, *pixmap_attribs;
	GLXFBConfig *fb_configs;
	GLXFBConfig fb_config;
	int n_fb_configs;
	Pixmap pixmap;
	GLXPixmap glx_pixmap;
	XVisualInfo *vis;
	XRenderPictFormat *render_format;
	Picture picture;

	if (format == GL_RGBA) {
		fb_config_attribs = rgba_fb_config_attribs;
		pixmap_attribs = rgba_pixmap_attribs;
		render_format = XRenderFindStandardFormat(dpy,
							  PictStandardARGB32);
	} else {
		fb_config_attribs = rgb_fb_config_attribs;
		pixmap_attribs = rgb_pixmap_attribs;
		render_format = XRenderFindStandardFormat(dpy,
							  PictStandardRGB24);
	}

	fb_configs = glXChooseFBConfig(dpy, DefaultScreen(dpy),
				       fb_config_attribs,
				       &n_fb_configs);


	if (fb_configs == NULL || n_fb_configs < 1) {
		fprintf(stderr, "No %s TFP FB config found\n",
			format == GL_RGBA ? "RGBA" : "RGB");
		return None;
	}
	fb_config = fb_configs[n_fb_configs - 1];

	pixmap = XCreatePixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)),
			       2, 2, render_format->depth);
	picture = XRenderCreatePicture(dpy, pixmap, render_format, 0, NULL);

	glx_pixmap = glXCreatePixmap(dpy, fb_config, pixmap, pixmap_attribs);

	vis = glXGetVisualFromFBConfig(dpy, fb_config);

	set_pixel(dpy, picture, 0, 0, tex_data[0]);
	set_pixel(dpy, picture, 1, 0, tex_data[1]);
	set_pixel(dpy, picture, 0, 1, tex_data[2]);
	set_pixel(dpy, picture, 1, 1, tex_data[3]);

	XFree(fb_configs);
	XFree(vis);

	return glx_pixmap;
}
Пример #27
0
// -----------------------------------------------------------------------------
// Internal stuff
// -----------------------------------------------------------------------------
static void
create_texture(riftwm_t *wm, riftwin_t *win)
{
  XWindowAttributes attr;

  // Retrieve properties
  if (!XGetWindowAttributes(wm->dpy, win->window, &attr)) {
    riftwm_error(wm, "Cannot retrieve window attributes");
  }

  win->width = attr.width;
  win->height = attr.height;
  if (attr.map_state != IsViewable) {
    return;
  }

  // Free old resources
  if (win->glx_pixmap) {
    glBindTexture(GL_TEXTURE_2D, win->texture);
    wm->glXReleaseTexImageEXT(wm->dpy, win->glx_pixmap, GLX_FRONT_LEFT_EXT);
    glBindTexture(GL_TEXTURE_2D, 0);

    glXDestroyPixmap(wm->dpy, win->glx_pixmap);
    win->glx_pixmap = 0;
  }

  if (win->pixmap) {
    XFreePixmap(wm->dpy, win->pixmap);
    win->pixmap = 0;
  }

  if (!win->texture) {
    glGenTextures(1, &win->texture);
  }

  // Retrieve the pixmap from the XComposite
  win->pixmap = XCompositeNameWindowPixmap(wm->dpy, win->window);

  // Create a backing OpenGL pixmap
  const int ATTR[] =
  {
    GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT,
    GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
    None
  };

  if (!(win->glx_pixmap = glXCreatePixmap(wm->dpy, wm->fb_config[1].config,
                                          win->pixmap, ATTR)))
  {
    riftwm_error(wm, "Cannot create GLX pixmap");
  }

  // Create the texture
  glBindTexture(GL_TEXTURE_2D, win->texture);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  wm->glXBindTexImageEXT(wm->dpy, win->glx_pixmap, GLX_FRONT_LEFT_EXT, NULL);
  glBindTexture(GL_TEXTURE_2D, 0);

  win->dirty = 0;
}
static void
clutter_glx_texture_pixmap_create_glx_pixmap (ClutterGLXTexturePixmap *texture)
{
  ClutterGLXTexturePixmapPrivate *priv = texture->priv;
  GLXPixmap                       glx_pixmap = None;
  int                             attribs[7], i = 0, mipmap = 0;
  GLXFBConfig                    *fbconfig;
  Display                        *dpy;
  guint                           depth;
  Pixmap                          pixmap;
  guint				  pixmap_width, pixmap_height;
  ClutterBackendGLX              *backend_glx;
  ClutterTextureQuality           quality;

  CLUTTER_NOTE (TEXTURE, "Creating GLXPixmap");

  backend_glx = CLUTTER_BACKEND_GLX(clutter_get_default_backend ());

  dpy = clutter_x11_get_default_display ();

  if (priv->use_fallback == TRUE
      || !clutter_glx_texture_pixmap_using_extension (texture))
    goto cleanup;

  priv->use_fallback = FALSE;

  g_object_get (texture,
                "pixmap-width",  &pixmap_width,
                "pixmap-height", &pixmap_height,
                "pixmap-depth",  &depth,
                "pixmap",        &pixmap,
                NULL);

  if (!pixmap)
    {
      goto cleanup;
    }

  fbconfig = get_fbconfig_for_depth (depth);

  if (!fbconfig)
    {
      g_warning ("Could not find an FBConfig for selected pixmap");
      goto cleanup;
    }

  attribs[i++] = GLX_TEXTURE_FORMAT_EXT;

  if (depth == 24)
    {
      attribs[i++] = GLX_TEXTURE_FORMAT_RGB_EXT;
    }
  else if (depth == 32)
    {
      attribs[i++] = GLX_TEXTURE_FORMAT_RGBA_EXT;
    }
  else
    {
      g_warning ("Pixmap with depth bellow 24 are not supported");
      goto cleanup;
    }

  quality = clutter_texture_get_filter_quality (CLUTTER_TEXTURE (texture));

  if (quality == CLUTTER_TEXTURE_QUALITY_HIGH)
    mipmap = 1;

  attribs[i++] = GLX_MIPMAP_TEXTURE_EXT;
  attribs[i++] = mipmap;

  attribs[i++] = GLX_TEXTURE_TARGET_EXT;

  attribs[i++] = GLX_TEXTURE_2D_EXT;

  attribs[i++] = None;

  clutter_x11_trap_x_errors ();
  glx_pixmap = glXCreatePixmap (dpy,
                                *fbconfig,
                                pixmap,
                                attribs);
  XSync (dpy, FALSE);
  if (clutter_x11_untrap_x_errors ())
    {
      CLUTTER_NOTE (TEXTURE, "Failed to create GLXPixmap");

      /* Make sure we don't think the call actually succeeded */
      glx_pixmap = None;
    }

  g_free (fbconfig);

 cleanup:

  if (priv->glx_pixmap)
    clutter_glx_texture_pixmap_free_glx_pixmap (texture);

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

      create_cogl_texture (CLUTTER_TEXTURE (texture), pixmap_width, pixmap_height);

      CLUTTER_NOTE (TEXTURE, "Created GLXPixmap");

      return;
    }
  else
    {
      priv->use_fallback = TRUE;
      priv->glx_pixmap   = None;

      /* Some fucky logic here - we've fallen back and need to make sure
       * we realize here..
      */
      clutter_actor_realize (CLUTTER_ACTOR (texture));
    }
}
Пример #29
0
bool CVDPAU::MakePixmapGL()
{
  int num=0;
  int fbConfigIndex = 0;

  int doubleVisAttributes[] = {
    GLX_RENDER_TYPE, GLX_RGBA_BIT,
    GLX_RED_SIZE, 8,
    GLX_GREEN_SIZE, 8,
    GLX_BLUE_SIZE, 8,
    GLX_ALPHA_SIZE, 8,
    GLX_DEPTH_SIZE, 8,
    GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
    GLX_BIND_TO_TEXTURE_RGBA_EXT, True,
    GLX_DOUBLEBUFFER, True,
    GLX_Y_INVERTED_EXT, True,
    GLX_X_RENDERABLE, True,
    None
  };

  int pixmapAttribs[] = {
    GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
    GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT,
    None
  };

  GLXFBConfig *fbConfigs;
  fbConfigs = glXChooseFBConfig(m_Display, DefaultScreen(m_Display), doubleVisAttributes, &num);
  if (fbConfigs==NULL)
  {
    CLog::Log(LOGERROR, "GLX Error: MakePixmap: No compatible framebuffers found");
    return false;
  }
  CLog::Log(LOGDEBUG, "Found %d fbconfigs.", num);
  fbConfigIndex = 0;
  CLog::Log(LOGDEBUG, "Using fbconfig index %d.", fbConfigIndex);

  m_glPixmap = glXCreatePixmap(m_Display, fbConfigs[fbConfigIndex], m_Pixmap, pixmapAttribs);

  if (!m_glPixmap)
  {
    CLog::Log(LOGINFO, "GLX Error: Could not create Pixmap");
    XFree(fbConfigs);
    return false;
  }

  /* to make the pixmap usable, it needs to have any context associated with it */
  GLXContext  lastctx = glXGetCurrentContext();
  GLXDrawable lastdrw = glXGetCurrentDrawable();

  XVisualInfo *visInfo;
  visInfo = glXGetVisualFromFBConfig(m_Display, fbConfigs[fbConfigIndex]);
  if (!visInfo)
  {
    CLog::Log(LOGINFO, "GLX Error: Could not obtain X Visual Info for pixmap");
    XFree(fbConfigs);
    return false;
  }
  XFree(fbConfigs);

  CLog::Log(LOGINFO, "GLX: Creating Pixmap context");
  m_glContext = glXCreateContext(m_Display, visInfo, NULL, True);
  XFree(visInfo);

  if (!glXMakeCurrent(m_Display, m_glPixmap, m_glContext))
  {
    CLog::Log(LOGINFO, "GLX Error: Could not make Pixmap current");
    return false;
  }

  /* restore what thread had before */
  glXMakeCurrent(m_Display, lastdrw, lastctx);

  return true;

}
Пример #30
0
void XCompcapMain::updateSettings(obs_data_t *settings)
{
	PLock lock(&p->lock);
	XErrorLock xlock;
	ObsGsContextHolder obsctx;

	blog(LOG_DEBUG, "Settings updating");

	Window prevWin = p->win;

	xcc_cleanup(p);

	if (settings) {
		const char *windowName = obs_data_get_string(settings,
				"capture_window");

		p->windowName = windowName;
		p->win = getWindowFromString(windowName);

		p->cut_top = obs_data_get_int(settings, "cut_top");
		p->cut_left = obs_data_get_int(settings, "cut_left");
		p->cut_right = obs_data_get_int(settings, "cut_right");
		p->cut_bot = obs_data_get_int(settings, "cut_bot");
		p->lockX = obs_data_get_bool(settings, "lock_x");
		p->swapRedBlue = obs_data_get_bool(settings, "swap_redblue");
		p->show_cursor = obs_data_get_bool(settings, "show_cursor");
		p->include_border = obs_data_get_bool(settings, "include_border");
		p->exclude_alpha = obs_data_get_bool(settings, "exclude_alpha");
	} else {
		p->win = prevWin;
	}

	xlock.resetError();

	if (p->win)
		XCompositeRedirectWindow(xdisp, p->win,
				CompositeRedirectAutomatic);

	if (xlock.gotError()) {
		blog(LOG_ERROR, "XCompositeRedirectWindow failed: %s",
				xlock.getErrorText().c_str());
		return;
	}

	if (p->win)
		XSelectInput(xdisp, p->win, StructureNotifyMask | ExposureMask);
	XSync(xdisp, 0);

	XWindowAttributes attr;
	if (!p->win || !XGetWindowAttributes(xdisp, p->win, &attr)) {
		p->win = 0;
		p->width = 0;
		p->height = 0;
		return;
	}

	if (p->win && p->cursor && p->show_cursor) {
		Window child;
		int x, y;

		XTranslateCoordinates(xdisp, p->win, attr.root, 0, 0, &x, &y,
				&child);
		xcursor_offset(p->cursor, x, y);
	}

	gs_color_format cf = GS_RGBA;

	if (p->exclude_alpha) {
		cf = GS_BGRX;
	}

	p->border = attr.border_width;

	if (p->include_border) {
		p->width = attr.width + p->border * 2;
		p->height = attr.height + p->border * 2;
	} else {
		p->width = attr.width;
		p->height = attr.height;
	}

	if (p->cut_top + p->cut_bot < (int)p->height) {
		p->cur_cut_top = p->cut_top;
		p->cur_cut_bot = p->cut_bot;
	} else {
		p->cur_cut_top = 0;
		p->cur_cut_bot = 0;
	}

	if (p->cut_left + p->cut_right < (int)p->width) {
		p->cur_cut_left = p->cut_left;
		p->cur_cut_right = p->cut_right;
	} else {
		p->cur_cut_left = 0;
		p->cur_cut_right = 0;
	}

	if (p->tex)
		gs_texture_destroy(p->tex);

	uint8_t *texData = new uint8_t[width() * height() * 4];

	memset(texData, 0, width() * height() * 4);

	const uint8_t* texDataArr[] = { texData, 0 };

	p->tex = gs_texture_create(width(), height(), cf, 1,
			texDataArr, 0);

	delete[] texData;

	if (p->swapRedBlue) {
		GLuint tex = *(GLuint*)gs_texture_get_obj(p->tex);
		glBindTexture(GL_TEXTURE_2D, tex);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
		glBindTexture(GL_TEXTURE_2D, 0);
	}

	const int attrs[] =
	{
		GLX_BIND_TO_TEXTURE_RGBA_EXT, GL_TRUE,
		GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
		GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_BIT_EXT,
		GLX_DOUBLEBUFFER, GL_FALSE,
		None
	};

	int nelem = 0;
	GLXFBConfig* configs = glXChooseFBConfig(xdisp,
			XCompcap::getRootWindowScreen(attr.root),
			attrs, &nelem);

	if (nelem <= 0) {
		blog(LOG_ERROR, "no matching fb config found");
		p->win = 0;
		p->height = 0;
		p->width = 0;
		return;
	}

	glXGetFBConfigAttrib(xdisp, configs[0], GLX_Y_INVERTED_EXT, &nelem);
	p->inverted = nelem != 0;

	xlock.resetError();

	p->pixmap = XCompositeNameWindowPixmap(xdisp, p->win);

	if (xlock.gotError()) {
		blog(LOG_ERROR, "XCompositeNameWindowPixmap failed: %s",
				xlock.getErrorText().c_str());
		p->pixmap = 0;
		XFree(configs);
		return;
	}

	const int attribs[] =
	{
		GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
		GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT,
		None
	};

	p->glxpixmap = glXCreatePixmap(xdisp, configs[0], p->pixmap, attribs);

	if (xlock.gotError()) {
		blog(LOG_ERROR, "glXCreatePixmap failed: %s",
				xlock.getErrorText().c_str());
		XFreePixmap(xdisp, p->pixmap);
		XFree(configs);
		p->pixmap = 0;
		p->glxpixmap = 0;
		return;
	}

	XFree(configs);

	p->gltex = gs_texture_create(p->width, p->height, cf, 1, 0,
			GS_GL_DUMMYTEX);

	GLuint gltex = *(GLuint*)gs_texture_get_obj(p->gltex);
	glBindTexture(GL_TEXTURE_2D, gltex);
	glXBindTexImageEXT(xdisp, p->glxpixmap, GLX_FRONT_LEFT_EXT, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}