Search
lxdream.org :: lxdream/src/drivers/video_glx.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/video_glx.c
changeset 1258:f8a9c0fd2abb
prev1256:a9d29fe74bf3
author nkeynes
date Fri May 29 18:47:05 2015 +1000 (6 years ago)
permissions -rw-r--r--
last change Fix test case
file annotate diff log raw
nkeynes@545
     1
/**
nkeynes@586
     2
 * $Id$
nkeynes@545
     3
 *
nkeynes@545
     4
 * Shared functions for all X11-based display drivers.
nkeynes@545
     5
 *
nkeynes@545
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@545
     7
 *
nkeynes@545
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@545
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@545
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@545
    11
 * (at your option) any later version.
nkeynes@545
    12
 *
nkeynes@545
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@545
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@545
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@545
    16
 * GNU General Public License for more details.
nkeynes@545
    17
 */
nkeynes@545
    18
nkeynes@806
    19
#include <stdlib.h>
nkeynes@635
    20
#include <string.h>
nkeynes@586
    21
#include "display.h"
nkeynes@545
    22
#include <X11/Xlib.h>
nkeynes@545
    23
#include <GL/glx.h>
nkeynes@635
    24
#include "pvr2/pvr2.h"
nkeynes@635
    25
#include "pvr2/glutil.h"
nkeynes@545
    26
#include "drivers/video_glx.h"
nkeynes@635
    27
#include "drivers/video_gl.h"
nkeynes@545
    28
nkeynes@545
    29
/**
nkeynes@545
    30
 * General X11 parameters. The front-end driver is expected to set this up
nkeynes@545
    31
 * by calling video_glx_init after initializing itself.
nkeynes@545
    32
 */
nkeynes@545
    33
Display *video_x11_display = NULL;
nkeynes@545
    34
Window video_x11_window = 0;
nkeynes@545
    35
nkeynes@545
    36
static int glx_version = 100;
nkeynes@606
    37
static XVisualInfo *glx_visual = NULL;
nkeynes@545
    38
static GLXFBConfig glx_fbconfig;
nkeynes@545
    39
static GLXContext glx_context = NULL;
nkeynes@545
    40
static gboolean glx_is_initialized = FALSE;
nkeynes@545
    41
static gboolean glx_fbconfig_supported = FALSE;
nkeynes@545
    42
static gboolean glx_pbuffer_supported = FALSE;
nkeynes@669
    43
static GLuint glx_pbuffer_texture = 0; 
nkeynes@1251
    44
static int glx_depth_bits = 0;
nkeynes@545
    45
nkeynes@1076
    46
static void video_glx_swap_buffers( void );
nkeynes@1134
    47
static void video_glx_print_info( FILE *out );
nkeynes@1076
    48
nkeynes@545
    49
/* Prototypes for pbuffer support methods */
nkeynes@545
    50
static void glx_pbuffer_init( display_driver_t driver );
nkeynes@805
    51
static render_buffer_t glx_pbuffer_create_render_buffer( uint32_t width, uint32_t height, GLuint tex_id );
nkeynes@545
    52
static void glx_pbuffer_destroy_render_buffer( render_buffer_t buffer );
nkeynes@545
    53
static gboolean glx_pbuffer_set_render_target( render_buffer_t buffer );
nkeynes@805
    54
static void glx_pbuffer_finish_render( render_buffer_t buffer );
nkeynes@669
    55
static void glx_pbuffer_display_render_buffer( render_buffer_t buffer );
nkeynes@545
    56
static void glx_pbuffer_load_frame_buffer( frame_buffer_t frame, render_buffer_t buffer );
nkeynes@669
    57
static void glx_pbuffer_display_blank( uint32_t colour );
nkeynes@545
    58
static gboolean glx_pbuffer_read_render_buffer( unsigned char *target, render_buffer_t buffer, int rowstride, int format );
nkeynes@545
    59
nkeynes@545
    60
/**
nkeynes@545
    61
 * Test if a specific extension is supported. From opengl.org
nkeynes@545
    62
 * @param extension extension name to check for
nkeynes@545
    63
 * @return TRUE if supported, otherwise FALSE.
nkeynes@545
    64
 */
nkeynes@545
    65
gboolean isServerGLXExtensionSupported( Display *display, int screen, 
nkeynes@736
    66
                                        const char *extension )
nkeynes@545
    67
{
nkeynes@545
    68
    const char *extensions = NULL;
nkeynes@545
    69
    const char *start;
nkeynes@545
    70
    char *where, *terminator;
nkeynes@545
    71
nkeynes@545
    72
    /* Extension names should not have spaces. */
nkeynes@545
    73
    where = strchr(extension, ' ');
nkeynes@545
    74
    if (where || *extension == '\0')
nkeynes@736
    75
        return 0;
nkeynes@545
    76
    extensions = glXQueryServerString(display, screen, GLX_EXTENSIONS);
nkeynes@545
    77
    start = extensions;
nkeynes@545
    78
    for (;;) {
nkeynes@736
    79
        where = strstr((const char *) start, extension);
nkeynes@736
    80
        if (!where)
nkeynes@736
    81
            break;
nkeynes@736
    82
        terminator = where + strlen(extension);
nkeynes@736
    83
        if (where == start || *(where - 1) == ' ')
nkeynes@736
    84
            if (*terminator == ' ' || *terminator == '\0')
nkeynes@736
    85
                return TRUE;
nkeynes@736
    86
        start = terminator;
nkeynes@545
    87
    }
nkeynes@545
    88
    return FALSE;
nkeynes@545
    89
}
nkeynes@545
    90
nkeynes@545
    91
gboolean video_glx_init( Display *display, int screen )
nkeynes@545
    92
{
nkeynes@545
    93
    int major, minor;
nkeynes@982
    94
    int glx_major, glx_minor, glx_error;
nkeynes@545
    95
nkeynes@545
    96
    if( glx_is_initialized ) {
nkeynes@545
    97
        return TRUE;
nkeynes@545
    98
    }
nkeynes@545
    99
nkeynes@982
   100
    Bool result = XQueryExtension( display, "GLX", &glx_major, &glx_minor, &glx_error ) &&
nkeynes@982
   101
                  glXQueryVersion( display, &major, &minor );
nkeynes@982
   102
    if( result == False ) {
nkeynes@982
   103
        ERROR( "GLX not supported on display" );
nkeynes@982
   104
        return FALSE;
nkeynes@545
   105
    }
nkeynes@545
   106
    
nkeynes@982
   107
    glx_version = (major*100) + minor;
nkeynes@982
   108
nkeynes@863
   109
#ifdef APPLE_BUILD
nkeynes@863
   110
    /* fbconfig is broken on at least the 10.5 GLX implementation */
nkeynes@863
   111
    glx_fbconfig_supported = FALSE;
nkeynes@863
   112
#else
nkeynes@545
   113
    glx_fbconfig_supported = (glx_version >= 103 || 
nkeynes@736
   114
            isServerGLXExtensionSupported(display, screen,
nkeynes@736
   115
                    "GLX_SGIX_fbconfig") );
nkeynes@863
   116
#endif
nkeynes@545
   117
    glx_pbuffer_supported = (glx_version >= 103 ||
nkeynes@736
   118
            isServerGLXExtensionSupported(display, screen,
nkeynes@736
   119
                    "GLX_SGIX_pbuffer") );
nkeynes@863
   120
//    glx_fbconfig_supported = FALSE;
nkeynes@545
   121
    if( glx_fbconfig_supported ) {
nkeynes@736
   122
        int nelem;
nkeynes@1251
   123
        glx_depth_bits = 24;
nkeynes@545
   124
        int fb_attribs[] = { GLX_DRAWABLE_TYPE, 
nkeynes@736
   125
                GLX_PBUFFER_BIT|GLX_WINDOW_BIT, 
nkeynes@736
   126
                GLX_RENDER_TYPE, GLX_RGBA_BIT, 
nkeynes@863
   127
                GLX_DEPTH_SIZE, 24, 
nkeynes@863
   128
                GLX_STENCIL_SIZE, 8, 0 };
nkeynes@736
   129
        GLXFBConfig *configs = glXChooseFBConfig( display, screen, 
nkeynes@736
   130
                fb_attribs, &nelem );
nkeynes@606
   131
nkeynes@736
   132
        if( configs == NULL || nelem == 0 ) {
nkeynes@736
   133
            /* Try a 16-bit depth buffer and see if it helps */
nkeynes@736
   134
            fb_attribs[5] = 16;
nkeynes@1251
   135
            glx_depth_bits = 16;
nkeynes@736
   136
            configs = glXChooseFBConfig( display, screen, fb_attribs, &nelem );
nkeynes@736
   137
            if( nelem > 0 ) {
nkeynes@676
   138
                WARN( "Using a 16-bit depth buffer - expect video glitches" );
nkeynes@676
   139
            }
nkeynes@545
   140
nkeynes@676
   141
        }
nkeynes@676
   142
        if( configs == NULL || nelem == 0 ) {
nkeynes@736
   143
            /* Still didn't work. Fallback to 1.2 methods */
nkeynes@736
   144
            glx_fbconfig_supported = FALSE;
nkeynes@736
   145
            glx_pbuffer_supported = FALSE;
nkeynes@736
   146
        } else {
nkeynes@736
   147
            glx_fbconfig = configs[0];
nkeynes@736
   148
            glx_visual = glXGetVisualFromFBConfig(display, glx_fbconfig);
nkeynes@736
   149
            XFree(configs);
nkeynes@736
   150
        }
nkeynes@545
   151
    }
nkeynes@545
   152
nkeynes@545
   153
    if( !glx_fbconfig_supported ) {
nkeynes@1251
   154
        glx_depth_bits = 24;
nkeynes@863
   155
        int attribs[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, 0 };
nkeynes@736
   156
        glx_visual = glXChooseVisual( display, screen, attribs );
nkeynes@676
   157
        if( glx_visual == NULL ) {
nkeynes@676
   158
            /* Try the 16-bit fallback here too */
nkeynes@1251
   159
            glx_depth_bits = 16;
nkeynes@676
   160
            attribs[2] = 16;
nkeynes@676
   161
            glx_visual = glXChooseVisual( display, screen, attribs );
nkeynes@676
   162
            if( glx_visual != NULL ) {
nkeynes@676
   163
                WARN( "Using a 16-bit depth buffer - expect video glitches" );
nkeynes@676
   164
            }
nkeynes@676
   165
        }
nkeynes@545
   166
    }
nkeynes@606
   167
nkeynes@606
   168
    if( glx_visual == NULL ) {
nkeynes@606
   169
        return FALSE;
nkeynes@606
   170
    }
nkeynes@606
   171
nkeynes@545
   172
    glx_is_initialized = TRUE;
nkeynes@545
   173
    return TRUE;
nkeynes@545
   174
}
nkeynes@545
   175
nkeynes@1134
   176
static void video_glx_print_info( FILE *out )
nkeynes@1134
   177
{
nkeynes@1134
   178
    XWindowAttributes attr;
nkeynes@1134
   179
nkeynes@1134
   180
    if( !XGetWindowAttributes(video_x11_display, video_x11_window, &attr) )
nkeynes@1134
   181
        return; /* Failed */
nkeynes@1134
   182
    int screen = XScreenNumberOfScreen(attr.screen);
nkeynes@1134
   183
nkeynes@1134
   184
    fprintf( out, "GLX Server: %s %s\n", glXQueryServerString(video_x11_display, screen, GLX_VENDOR),
nkeynes@1134
   185
            glXQueryServerString(video_x11_display, screen, GLX_VERSION) );
nkeynes@1134
   186
    fprintf( out, "GLX Client: %s %s\n", glXGetClientString(video_x11_display, GLX_VENDOR),
nkeynes@1134
   187
            glXGetClientString(video_x11_display, GLX_VERSION) );
nkeynes@1134
   188
    fprintf( out, "GLX Server Extensions:\n" );
nkeynes@1134
   189
    fprint_extensions( out, glXQueryServerString(video_x11_display, screen, GLX_EXTENSIONS) );
nkeynes@1134
   190
    fprintf( out, "GLX Client Extensions:\n" );
nkeynes@1134
   191
    fprint_extensions( out, glXGetClientString(video_x11_display, GLX_EXTENSIONS) );
nkeynes@1134
   192
    fprintf( out, "GLX Extensions:\n" );
nkeynes@1134
   193
    fprint_extensions( out, glXQueryExtensionsString(video_x11_display, screen) );
nkeynes@1134
   194
nkeynes@1134
   195
}
nkeynes@1134
   196
nkeynes@545
   197
gboolean video_glx_init_context( Display *display, Window window )
nkeynes@545
   198
{
nkeynes@545
   199
    if( glx_fbconfig_supported ) {
nkeynes@545
   200
        glx_context = glXCreateNewContext( display, glx_fbconfig, 
nkeynes@736
   201
                GLX_RGBA_TYPE, NULL, True );
nkeynes@736
   202
        if( glx_context == NULL ) {
nkeynes@736
   203
            ERROR( "Unable to create a GLX Context.");
nkeynes@736
   204
            return FALSE;
nkeynes@736
   205
        }
nkeynes@545
   206
nkeynes@1001
   207
        if( glXMakeCurrent( display, window,
nkeynes@736
   208
                glx_context ) == False ) {
nkeynes@736
   209
            ERROR( "Unable to prepare GLX context for drawing" );
nkeynes@736
   210
            glXDestroyContext( display, glx_context );
nkeynes@736
   211
            return FALSE;
nkeynes@736
   212
        }
nkeynes@545
   213
    } else {
nkeynes@545
   214
        glx_context = glXCreateContext( display, glx_visual, None, True );
nkeynes@736
   215
        if( glx_context == NULL ) {
nkeynes@736
   216
            ERROR( "Unable to create a GLX Context.");
nkeynes@736
   217
            return FALSE;
nkeynes@736
   218
        }
nkeynes@736
   219
nkeynes@736
   220
        if( glXMakeCurrent( display, window, glx_context ) == False ) {
nkeynes@736
   221
            ERROR( "Unable to prepare GLX context for drawing" );
nkeynes@736
   222
            glXDestroyContext( display, glx_context );
nkeynes@736
   223
            return FALSE;
nkeynes@736
   224
        }
nkeynes@545
   225
    }
nkeynes@545
   226
nkeynes@545
   227
    if( !glXIsDirect(display, glx_context) ) {
nkeynes@736
   228
        WARN( "Not using direct rendering - this is likely to be slow" );
nkeynes@545
   229
    }
nkeynes@545
   230
nkeynes@545
   231
    video_x11_display = display;
nkeynes@545
   232
    video_x11_window = window;
nkeynes@545
   233
nkeynes@545
   234
    return TRUE;
nkeynes@545
   235
}
nkeynes@545
   236
nkeynes@545
   237
gboolean video_glx_init_driver( display_driver_t driver )
nkeynes@545
   238
{
nkeynes@1076
   239
    driver->swap_buffers = video_glx_swap_buffers;
nkeynes@1134
   240
    driver->print_info = video_glx_print_info;
nkeynes@1134
   241
    driver->capabilities.has_gl = TRUE;
nkeynes@1251
   242
    driver->capabilities.depth_bits = glx_depth_bits;
nkeynes@1258
   243
    if( !gl_init_driver(driver, !glx_pbuffer_supported) ) {
nkeynes@545
   244
        video_glx_shutdown();
nkeynes@736
   245
        return FALSE;
nkeynes@545
   246
    }
nkeynes@1258
   247
    if( driver->create_render_buffer == NULL ) {
nkeynes@1258
   248
        /* If we get here, pbuffers are supported and FBO didn't work */
nkeynes@1258
   249
        glx_pbuffer_init(driver);
nkeynes@1258
   250
    }
nkeynes@545
   251
    return TRUE;
nkeynes@545
   252
}
nkeynes@545
   253
nkeynes@545
   254
nkeynes@545
   255
void video_glx_shutdown()
nkeynes@545
   256
{
nkeynes@736
   257
    //    texcache_gl_shutdown();
nkeynes@545
   258
    glx_is_initialized = FALSE;
nkeynes@545
   259
    if( glx_context != NULL ) {
nkeynes@545
   260
        glXDestroyContext( video_x11_display, glx_context );
nkeynes@736
   261
        glx_context = NULL;
nkeynes@545
   262
    }
nkeynes@545
   263
    if( glx_visual != NULL ) {
nkeynes@545
   264
        XFree(glx_visual);
nkeynes@736
   265
        glx_visual = NULL;
nkeynes@545
   266
    }
nkeynes@545
   267
}
nkeynes@545
   268
nkeynes@545
   269
nkeynes@545
   270
XVisualInfo *video_glx_get_visual()
nkeynes@545
   271
{
nkeynes@545
   272
    return glx_visual;
nkeynes@545
   273
}
nkeynes@545
   274
nkeynes@545
   275
nkeynes@545
   276
int video_glx_load_font( const gchar *font_name )
nkeynes@545
   277
{
nkeynes@545
   278
    int lists;
nkeynes@545
   279
    XFontStruct *font = XLoadQueryFont(video_x11_display, font_name );
nkeynes@545
   280
    if (font == NULL)
nkeynes@736
   281
        return -1;
nkeynes@736
   282
nkeynes@545
   283
    lists = glGenLists(96);
nkeynes@545
   284
    glXUseXFont(font->fid, 32, 96, lists);
nkeynes@545
   285
    XFreeFont(video_x11_display, font);
nkeynes@545
   286
    return lists;
nkeynes@545
   287
}
nkeynes@545
   288
nkeynes@545
   289
nkeynes@1076
   290
static void video_glx_swap_buffers( void )
nkeynes@545
   291
{
nkeynes@545
   292
    glXSwapBuffers( video_x11_display, video_x11_window );
nkeynes@545
   293
}
nkeynes@545
   294
nkeynes@545
   295
void video_glx_make_window_current( void )
nkeynes@545
   296
{
nkeynes@545
   297
    glXMakeCurrent( video_x11_display, video_x11_window, glx_context );
nkeynes@545
   298
}
nkeynes@545
   299
nkeynes@545
   300
nkeynes@545
   301
// Pbuffer support
nkeynes@545
   302
nkeynes@545
   303
/**
nkeynes@545
   304
 * Construct the initial frame buffers and allocate ids for everything.
nkeynes@545
   305
 * The render handling driver methods are set to the fbo versions.
nkeynes@545
   306
 */
nkeynes@545
   307
static void glx_pbuffer_init( display_driver_t driver ) 
nkeynes@545
   308
{
nkeynes@863
   309
    GLint stencil_bits = 0;
nkeynes@863
   310
    
nkeynes@863
   311
    /* Retrieve the number of stencil bits */
nkeynes@863
   312
    glGetIntegerv( GL_STENCIL_BITS, &stencil_bits );
nkeynes@863
   313
    driver->capabilities.stencil_bits = stencil_bits;
nkeynes@863
   314
    
nkeynes@545
   315
    glGenTextures( 1, &glx_pbuffer_texture );
nkeynes@545
   316
    driver->create_render_buffer = glx_pbuffer_create_render_buffer;
nkeynes@545
   317
    driver->destroy_render_buffer = glx_pbuffer_destroy_render_buffer;
nkeynes@545
   318
    driver->set_render_target = glx_pbuffer_set_render_target;
nkeynes@805
   319
    driver->finish_render = glx_pbuffer_finish_render;
nkeynes@545
   320
    driver->display_render_buffer = glx_pbuffer_display_render_buffer;
nkeynes@545
   321
    driver->load_frame_buffer = glx_pbuffer_load_frame_buffer;
nkeynes@545
   322
    driver->display_blank = glx_pbuffer_display_blank;
nkeynes@545
   323
    driver->read_render_buffer = glx_pbuffer_read_render_buffer;
nkeynes@545
   324
}
nkeynes@545
   325
nkeynes@545
   326
void glx_pbuffer_shutdown()
nkeynes@545
   327
{
nkeynes@545
   328
    glDeleteTextures( 1, &glx_pbuffer_texture );
nkeynes@545
   329
}
nkeynes@545
   330
nkeynes@805
   331
static render_buffer_t glx_pbuffer_create_render_buffer( uint32_t width, uint32_t height, GLuint tex_id )
nkeynes@545
   332
{
nkeynes@545
   333
    int attribs[] = { GLX_PBUFFER_WIDTH, width, GLX_PBUFFER_HEIGHT, height,
nkeynes@736
   334
            GLX_PRESERVED_CONTENTS, True, 0 };
nkeynes@545
   335
    GLXPbuffer pb = glXCreatePbuffer( video_x11_display, glx_fbconfig, attribs );
nkeynes@545
   336
    if( pb == (GLXPbuffer)NULL ) {
nkeynes@736
   337
        ERROR( "Unable to create pbuffer" );
nkeynes@736
   338
        return NULL;
nkeynes@545
   339
    }
nkeynes@545
   340
    render_buffer_t buffer = calloc( sizeof(struct render_buffer), 1 );
nkeynes@545
   341
    buffer->width = width;
nkeynes@545
   342
    buffer->height = height;
nkeynes@545
   343
    buffer->buf_id = pb;
nkeynes@805
   344
    buffer->tex_id = tex_id;
nkeynes@545
   345
    return buffer;
nkeynes@545
   346
}
nkeynes@545
   347
nkeynes@545
   348
static void glx_pbuffer_destroy_render_buffer( render_buffer_t buffer )
nkeynes@545
   349
{
nkeynes@545
   350
    glXDestroyPbuffer( video_x11_display, (GLXPbuffer)buffer->buf_id );
nkeynes@545
   351
    buffer->buf_id = 0;
nkeynes@545
   352
    free( buffer );
nkeynes@545
   353
}
nkeynes@545
   354
nkeynes@545
   355
static gboolean glx_pbuffer_set_render_target( render_buffer_t buffer )
nkeynes@545
   356
{
nkeynes@545
   357
    glFinish();
nkeynes@545
   358
    if( glXMakeContextCurrent( video_x11_display, (GLXPbuffer)buffer->buf_id, (GLXPbuffer)buffer->buf_id, glx_context ) == False ) {
nkeynes@736
   359
        ERROR( "Make context current (pbuffer) failed!" );
nkeynes@545
   360
    }
nkeynes@545
   361
    /* setup the gl context */
nkeynes@545
   362
    glViewport( 0, 0, buffer->width, buffer->height );
nkeynes@545
   363
    glDrawBuffer(GL_FRONT);
nkeynes@736
   364
nkeynes@545
   365
    return TRUE;
nkeynes@545
   366
}
nkeynes@545
   367
nkeynes@805
   368
static void glx_pbuffer_finish_render( render_buffer_t buffer )
nkeynes@805
   369
{
nkeynes@805
   370
    glFinish();
nkeynes@805
   371
    if( buffer->tex_id != 0 ) {
nkeynes@805
   372
        // The pbuffer should already be the current context, but just in case...
nkeynes@805
   373
        glXMakeContextCurrent( video_x11_display, (GLXPbuffer)buffer->buf_id, (GLXPbuffer)buffer->buf_id, glx_context );
nkeynes@1222
   374
        glBindTexture( GL_TEXTURE_2D, buffer->tex_id );
nkeynes@1222
   375
        glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, buffer->width, buffer->height, 0 );
nkeynes@805
   376
    }
nkeynes@805
   377
}
nkeynes@805
   378
    
nkeynes@805
   379
nkeynes@545
   380
/**
nkeynes@545
   381
 * Render the texture holding the given buffer to the front window
nkeynes@545
   382
 * buffer.
nkeynes@545
   383
 */
nkeynes@669
   384
static void glx_pbuffer_display_render_buffer( render_buffer_t buffer )
nkeynes@545
   385
{
nkeynes@545
   386
    glFinish();
nkeynes@545
   387
    glReadBuffer( GL_FRONT );
nkeynes@545
   388
    glXMakeContextCurrent( video_x11_display, (GLXPbuffer)buffer->buf_id, (GLXPbuffer)buffer->buf_id, glx_context );
nkeynes@1222
   389
    glBindTexture( GL_TEXTURE_2D, glx_pbuffer_texture );
nkeynes@1222
   390
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, buffer->width, buffer->height, 0 );
nkeynes@545
   391
    video_glx_make_window_current();
nkeynes@545
   392
    gl_texture_window( buffer->width, buffer->height, glx_pbuffer_texture, buffer->inverted );
nkeynes@545
   393
}
nkeynes@545
   394
nkeynes@545
   395
static void glx_pbuffer_load_frame_buffer( frame_buffer_t frame, render_buffer_t buffer )
nkeynes@545
   396
{
nkeynes@545
   397
    glFinish();
nkeynes@545
   398
    glXMakeContextCurrent( video_x11_display, (GLXPbuffer)buffer->buf_id, (GLXPbuffer)buffer->buf_id, glx_context );
nkeynes@545
   399
    GLenum type = colour_formats[frame->colour_format].type;
nkeynes@545
   400
    GLenum format = colour_formats[frame->colour_format].format;
nkeynes@545
   401
    int bpp = colour_formats[frame->colour_format].bpp;
nkeynes@545
   402
    int rowstride = (frame->rowstride / bpp) - frame->width;
nkeynes@736
   403
nkeynes@1246
   404
    gl_framebuffer_setup();
nkeynes@545
   405
    glPixelStorei( GL_UNPACK_ROW_LENGTH, rowstride );
nkeynes@545
   406
    glRasterPos2f(0.375, frame->height-0.375);
nkeynes@545
   407
    glPixelZoom( 1.0, 1.0 );
nkeynes@545
   408
    glDrawPixels( frame->width, frame->height, format, type, frame->data );
nkeynes@1236
   409
    glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
nkeynes@545
   410
    glFlush();
nkeynes@1246
   411
    gl_framebuffer_cleanup();
nkeynes@545
   412
}
nkeynes@545
   413
nkeynes@669
   414
static void glx_pbuffer_display_blank( uint32_t colour )
nkeynes@545
   415
{
nkeynes@545
   416
    glFinish();
nkeynes@545
   417
    video_glx_make_window_current();
nkeynes@669
   418
    gl_display_blank( colour );
nkeynes@545
   419
}
nkeynes@545
   420
nkeynes@545
   421
static gboolean glx_pbuffer_read_render_buffer( unsigned char *target, render_buffer_t buffer, 
nkeynes@736
   422
                                                int rowstride, int format )
nkeynes@545
   423
{
nkeynes@545
   424
    glXMakeCurrent( video_x11_display, (GLXDrawable)buffer->buf_id, glx_context );
nkeynes@545
   425
    glReadBuffer( GL_FRONT );
nkeynes@545
   426
    return gl_read_render_buffer( target, buffer, rowstride, format );
nkeynes@545
   427
}
nkeynes@545
   428
nkeynes@545
   429
.