125
125
!glXGetVisualFromFBConfig || !glXCreatePixmap || !glXDestroyPixmap ||
126
126
!glXCreateWindow || !glXDestroyWindow )
128
kDebug( 1212 ) << "GLX_SGIX_fbconfig or required GLX functions missing";
128
kError( 1212 ) << "GLX_SGIX_fbconfig or required GLX functions missing";
131
131
if( !selectMode())
135
135
if( !initRenderingContext())
138
137
// Initialize OpenGL
139
if( !hasGLExtension( "GL_ARB_texture_non_power_of_two" )
140
&& !hasGLExtension( "GL_ARB_texture_rectangle" ))
142
kError( 1212 ) << "GL_ARB_texture_non_power_of_two and GL_ARB_texture_rectangle missing";
141
146
glDrawBuffer( GL_BACK );
142
147
// Check whether certain features are supported
143
148
has_waitSync = glXGetVideoSync ? true : false;
145
int vis_buffer, vis_drawable;
146
glXGetFBConfigAttrib( display(), fbcbuffer, GLX_VISUAL_ID, &vis_buffer );
147
XVisualInfo* visinfo_buffer = glXGetVisualFromFBConfig( display(), fbcbuffer );
148
kDebug( 1212 ) << "Buffer visual (depth " << visinfo_buffer->depth << "): 0x" << QString::number( vis_buffer, 16 );
149
XFree( visinfo_buffer );
150
for( int i = 0; i <= 32; i++ )
152
if( fbcdrawableinfo[ i ].fbconfig == NULL )
154
glXGetFBConfigAttrib( display(), fbcdrawableinfo[ i ].fbconfig, GLX_VISUAL_ID, &vis_drawable );
155
kDebug( 1212 ) << "Drawable visual (depth " << i << "): 0x" << QString::number( vis_drawable, 16 );
158
150
// OpenGL scene setup
159
151
glMatrixMode( GL_PROJECTION );
160
152
glLoadIdentity();
162
154
glOrtho( 0, displayWidth(), displayHeight(), 0, 0, 65535 );
163
155
glMatrixMode( GL_MODELVIEW );
164
156
glLoadIdentity();
165
checkGLError( "Init" );
157
if( checkGLError( "Init" ))
159
kError( 1212 ) << "OpenGL compositing setup failed";
166
162
kDebug( 1212 ) << "DB:" << db << ", TFP:" << tfp_mode << ", SHM:" << shm_mode
167
163
<< ", Direct:" << bool( glXIsDirect( display(), ctxbuffer )) << endl;
292
// TODO replace with just KXErrorHandler::errorCode() for 4.1
293
static int xerror = 0;
294
static bool xerrorhandler( int, int error, unsigned long )
296
301
bool SceneOpenGL::initRenderingContext()
298
303
bool direct_rendering = options->glDirect;
299
304
if( !tfp_mode && !shm_mode )
300
305
direct_rendering = false; // fallback doesn't seem to work with direct rendering
307
KXErrorHandler errs1( xerrorhandler );
302
308
ctxbuffer = glXCreateNewContext( display(), fbcbuffer, GLX_RGBA_TYPE, NULL,
303
309
direct_rendering ? GL_TRUE : GL_FALSE );
304
if( ctxbuffer == NULL || !glXMakeCurrent( display(), glxbuffer, ctxbuffer )
305
|| errs.error( true ))
310
bool failed = ( ctxbuffer == NULL || !glXMakeCurrent( display(), glxbuffer, ctxbuffer ));
311
if( errs1.error( true )) // always check for error( having it all in one if() could skip
312
failed = true; // it due to evaluation short-circuiting
307
315
if( !direct_rendering )
309
kDebug( 1212 ) << "Couldn't initialize rendering context";
317
kDebug( 1212 ).nospace() << "Couldn't initialize rendering context (0x" << hex << xerror << ")";
312
320
glXMakeCurrent( display(), None, NULL );
313
glXDestroyContext( display(), ctxbuffer );
321
if( ctxbuffer != NULL )
322
glXDestroyContext( display(), ctxbuffer );
314
323
direct_rendering = false; // try again
325
KXErrorHandler errs2( xerrorhandler );
315
326
ctxbuffer = glXCreateNewContext( display(), fbcbuffer, GLX_RGBA_TYPE, NULL, GL_FALSE );
316
if( ctxbuffer == NULL || !glXMakeCurrent( display(), glxbuffer, ctxbuffer ) || errs.error( true ))
327
bool failed = ( ctxbuffer == NULL || !glXMakeCurrent( display(), glxbuffer, ctxbuffer ));
328
if( errs2.error( true ))
318
kDebug( 1212 ) << "Couldn't initialize rendering context";
332
kDebug( 1212 ).nospace() << "Couldn't initialize rendering context (0x" << hex << xerror << ")";
366
kDebug( 1212 ) << "Couldn't create output buffer (failed to create overlay window?) !";
380
kError( 1212 ) << "Couldn't create output buffer (failed to create overlay window?) !";
367
381
return false; // error
384
glXGetFBConfigAttrib( display(), fbcbuffer, GLX_VISUAL_ID, &vis_buffer );
385
XVisualInfo* visinfo_buffer = glXGetVisualFromFBConfig( display(), fbcbuffer );
386
kDebug( 1212 ) << "Buffer visual (depth " << visinfo_buffer->depth << "): 0x" << QString::number( vis_buffer, 16 );
387
XFree( visinfo_buffer );
403
422
GLX_BUFFER_SIZE, &value );
404
423
if( value != visual_depth && ( value - alpha ) != visual_depth )
425
glXGetFBConfigAttrib( display(), fbconfigs[ j ],
426
GLX_RENDER_TYPE, &value );
427
if( !( value & GLX_RGBA_BIT ))
407
430
glXGetFBConfigAttrib( display(), fbconfigs[ j ],
408
431
GLX_DOUBLEBUFFER, &back_value );
445
468
XFree( fbconfigs );
446
469
if( fbcbuffer_db == NULL && fbcbuffer_nondb == NULL )
448
kDebug( 1212 ) << "Couldn't find framebuffer configuration for buffer!";
471
kError( 1212 ) << "Couldn't find framebuffer configuration for buffer!";
474
for( int i = 0; i <= 32; i++ )
476
if( fbcdrawableinfo[ i ].fbconfig == NULL )
478
int vis_drawable = 0;
479
glXGetFBConfigAttrib( display(), fbcdrawableinfo[ i ].fbconfig, GLX_VISUAL_ID, &vis_drawable );
480
kDebug( 1212 ) << "Drawable visual (depth " << i << "): 0x" << QString::number( vis_drawable, 16 );
488
519
GLX_BUFFER_SIZE, &value );
489
520
if( value != i && ( value - alpha ) != i )
522
glXGetFBConfigAttrib( display(), fbconfigs[ j ],
523
GLX_RENDER_TYPE, &value );
524
if( !( value & GLX_RGBA_BIT ))
558
593
XFree( fbconfigs );
559
594
if( fbcdrawableinfo[ DefaultDepth( display(), DefaultScreen( display())) ].fbconfig == NULL )
561
kDebug( 1212 ) << "Couldn't find framebuffer configuration for default depth!";
596
kError( 1212 ) << "Couldn't find framebuffer configuration for default depth!";
564
599
if( fbcdrawableinfo[ 32 ].fbconfig == NULL )
566
kDebug( 1212 ) << "Couldn't find framebuffer configuration for depth 32!";
601
kError( 1212 ) << "Couldn't find framebuffer configuration for depth 32 (no ARGB GLX visual)!";
1122
1157
texture.discard();
1160
// This call is used in SceneOpenGL::windowGeometryShapeChanged(),
1161
// which originally called discardTexture(), however this was causing performance
1162
// problems with the launch feedback icon - large number of texture rebinds.
1163
// Since the launch feedback icon does not resize, only changes shape, it
1164
// is not necessary to rebind the texture (with no strict binding), therefore
1165
// discard the texture only if size changes.
1166
void SceneOpenGL::Window::checkTextureSize()
1168
if( texture.size() != size())
1125
1172
// when the window's composite pixmap is discarded, undo binding it to the texture
1126
1173
void SceneOpenGL::Window::pixmapDiscarded()