David Reveman davidr at
Tue Jun 7 17:59:42 PDT 2005

I've implemented "render texture"-like support in Xgl. I've used the
GLX_MESA_render_texture name for now but I'm not even sure that we want
to call it something with render_texture.

When we've figured out an appropriate way for supporting direct
rendering with Xgl we might have a better solution for allowing a client
to bind a redirected window to a texture. However, this seems to be a
good solution, at least for now.

The server-side implementation is already in CVS. The attached patch
will add necessary client-side code to Mesa. glXQueryDrawable is
required but to avoid implementing GLX 1.3 support in the server just to
get this running I've added a glXQueryDrawableMESA to the extension for
now. This should of course be removed once we have GLX 1.3 support in
the server.

Vendor private opcodes and enumeration values are completely bogus right
now. I should be using temporary enumeration values in the range
[0x6000,0x7FFF] during development, right? How about vendor private
opcodes? Are there any temporary opcodes that can be used for

The attached patch to glxproto.h will define the vendor private opcodes
I'm currently using.

I've created a very preliminary specification for
GLX_MESA_render_texture, just so that we have something to start from.
I've attached a copy of it. There's some example code in it for those of
you who are interested in how this extensions is supposed to be used.

The current implementation works surprisingly well. I've implemented a
OpenGL compositing manager with some simple but nice effects. It works
very well and I'm actually using Xgl and this compositing manager for
everyday work now. Those of you who went to GUADEC last week had the
chance to see this in action during the Lightning Talks.

The OpenGL compositing manager isn't available from anywhere yet. As
soon as I've cleaned it up a little, I'll add it to

-------------- next part --------------
A non-text attachment was scrubbed...
Name: mesa-glx-x11-render-texture.diff
Type: text/x-patch
Size: 4810 bytes
Desc: not available
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: glxproto.h-mesa-render-texture.diff
Type: text/x-patch
Size: 452 bytes
Desc: not available
URL: <>
-------------- next part --------------


Name Strings



    David Reveman

    To discuss, join the dri-egl at list.


    Preliminary - totally subject to change.
    Implemented in Xgl


    1 (7 June 2005)




    OpenGL 1.1 is required.
    May be implemented in any version of GLX.
    GL_ARB_texture_rectangle affects the definition of this extension.

    This extension allows a color buffer to be used for both rendering and
    texturing. When a color buffer is bound to a texture target it cannot 
    be rendered to. Once it has been released from the texture it can be 
    rendered to once again.

    The functionality of this extension is similar to WGL_ARB_render_texture. 
    However, the purpose of this extension is not to provide 
    "render to texture" like functionality but rather the ability to bind
    an existing window system drawable to a texture. Though, there
    is nothing that prohibits it from being used for "render to texture".

    This extension is based on WGL_ARB_render_texture. However, some changes
    were made to make it better fit the new purpose and make implementation

    -   Not only color buffers of a pbuffer can be bound as a texture. 
        Color buffers of any GLXDrawable can be bound.

    -   The requirement that the application must release the color buffer
        from the texture before it can render to the drawable again only
        applies to drawing using contexts that share this texture.


    1. What should this extension be called?


    2. Do we need a glXDrawableAttribMESA?

    Yes, clients should be able to select texture target using it. However,
    there will be no garantee that a requested target can be used. Current
    texture target must always be queried using glXQueryDrawable. 

    3. Should glXQueryDrawableMESA be removed?

    Yes, and GLX 1.3 will be required.

    4. Should we support everything that WGL_ARB_render_texture supports
       or should we try to keep this extensions minimal?
       GL_ARB_texture_cube_map? 1D textures? mipmapping?


New Procedures and Functions

    Bool glXBindTexImageMESA (Display     *display, 
                              GLXDrawable drawable, 
                              int         buffer)

    Bool glXReleaseTexImageMESA (Display     *display, 
                                 GLXDrawable drawable, 
                                 int         buffer)

    Bool glXQueryDrawableMESA (Display      *display,
                               GLXDrawable  drawable,
                               int          attribute,
                               unsigned int *value) 

New Tokens

    GLX_FRONT_LEFT_MESA                 0x????
    GLX_FRONT_RIGHT_MESA                0x????
    GLX_BACK_LEFT_MESA                  0x????
    GLX_BACK_RIGHT_MESA                 0x????
    GLX_AUX0_MESA                       0x???? 
    GLX_AUX1_MESA                       0x???? 
    GLX_AUX2_MESA                       0x???? 
    GLX_AUX3_MESA                       0x???? 
    GLX_AUX4_MESA                       0x???? 
    GLX_AUX5_MESA                       0x???? 
    GLX_AUX6_MESA                       0x????
    GLX_AUX7_MESA                       0x???? 
    GLX_AUX8_MESA                       0x???? 
    GLX_AUX9_MESA                       0x????

    GLX_TEXTURE_TARGET_MESA             0x????
    GLX_TEXTURE_2D_MESA                 0x????
    GLX_TEXTURE_RECTANGLE_MESA          0x????

GLX Protocol

    Three new GLX protocol commands are added.

            1           CARD8           opcode (X assigned)
            1           16              GLX opcode (glXVendorPrivateWithReply)
            2           8               request length
            4           65544           vendor specific opcode
            4           GLX_DRAWABLE    drawable
            4           INT32           buffer

            1           CARD8           opcode (X assigned)
            1           16              GLX opcode (glXVendorPrivateWithReply)
            2           4               request length
            4           65544           vendor specific opcode
            4           GLX_DRAWABLE    drawable
            4           INT32           buffer

            1           CARD8           opcode (X assigned)
            1           16              GLX opcode (glXVendorPrivateWithReply)
            2           4               request length
            4           65544           vendor specific opcode
            4           GLX_DRAWABLE    drawable
            4           INT32           attribute



Usage Examples

    Example 1: Bind redirected window to texture:

    XGetWindowAttributes (display, window, &attrib);

    templ.visualid = XVisualIDFromVisual (attrib.visual);
    visinfo = XGetVisualInfo (display, VisualIDMask, &templ, &n_items);

    glXGetConfig (display, visinfo, GLX_USE_GL, &value);
    if (value == False)
        return ERROR_CODE_1;

    pixmap = XCompositeNameWindowPixmap (display, window);
    glxpixmap = glXCreateGLXPixmap (display, visinfo, pixmap);
    status = glXQueryDrawableMESA (display, glxpixmap, 
    if (status != TRUE)
	return ERROR_CODE_2;

    if (value == GLX_TEXTURE_2D_MESA)
	target = GL_TEXTURE_2D;
    else if (value == GLX_TEXTURE_RECTANGLE_MESA)
    else /* window can't be bound to texture */
        return ERROR_CODE_3;

    glGenTextures (1, &texture);
    glBindTexture (target, texture);

    status = glXBindTexImageMESA (display, glxpixmap, GLX_FRONT_LEFT_MESA);
    if (status != TRUE)
	return ERROR_CODE_4;

    glTexParameteri (target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri (target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Version History

    1. 7 June 2005 - DavidR
        Initial version

More information about the xorg mailing list