kaszewczyk
26th March 2013, 19:55
Hello everyone
I try to set up custom opengl context on Widget, but i run into X Error
X Error: BadMatch (invalid parameter attributes) 8
Extension: 135 (Uknown extension)
Minor opcode: 5 (Unknown request)
Resource id: 0x4400003
I think that this could be problem with colormap, because default window colormap could be created based on different frame buffer than frame buffer used to created context.
I don't know how change colormap attached to window, can anyone help please?
Some code below:
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
Widget::Widget(QWidget *parent) :
QWidget(parent)
{
this->setAutoFillBackground(false);
this->setAttribute(Qt::WA_OpaquePaintEvent);
this->setAttribute(Qt::WA_NoSystemBackground);
this->setAttribute(Qt::WA_NativeWindow);
this->setAttribute(Qt::WA_PaintOnScreen, true);
this->setAttribute(Qt::WA_StyledBackground, false);
this->setAttribute(Qt::WA_PaintUnclipped);
this->xInfo = this->x11Info();
this->findBestFrameBuffer();
GLXContext context = 0;
glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressA RB( (const GLubyte *) "glXCreateContextAttribsARB" );
int contextAttribs[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 3,
//GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
None
};
context = glXCreateContextAttribsARB(this->xInfo.display(), this->fbConfig, 0, True, contextAttribs);
qDebug("context %p ", context);
glXMakeCurrent(this->xInfo.display(), this->winId(), context);
}
void Widget::findBestFrameBuffer()
{
static int visualAttribs[] =
{
GLX_X_RENDERABLE , True,
GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
GLX_RENDER_TYPE , GLX_RGBA_BIT,
GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
GLX_RED_SIZE , 8,
GLX_GREEN_SIZE , 8,
GLX_BLUE_SIZE , 8,
GLX_ALPHA_SIZE , 8,
GLX_DEPTH_SIZE , 24,
GLX_STENCIL_SIZE , 8,
GLX_DOUBLEBUFFER , True,
//GLX_SAMPLE_BUFFERS , 1,
//GLX_SAMPLES , 4,
None
};
int fbCount = 0;
GLXFBConfig* fbConfigsList = glXChooseFBConfig(this->xInfo.display(), this->xInfo.screen(), visualAttribs, &fbCount);
qDebug("%i frame buffers found", fbCount);
int bestFbCfg = -1;
int worstFbCfg = -1;
int bestNumberOfSamples = -1;
int worstNumberOfSamples = 999;
XVisualInfo* visualInfo = NULL;
int sampleBuffers = 0;
int samples = 0;
for( int i = 0 ; i < fbCount ; i++ )
{
visualInfo = glXGetVisualFromFBConfig(this->xInfo.display(), fbConfigsList[i]);
if( visualInfo != NULL )
{
glXGetFBConfigAttrib(this->xInfo.display(), fbConfigsList[i], GLX_SAMPLE_BUFFERS, &sampleBuffers);
glXGetFBConfigAttrib(this->xInfo.display(), fbConfigsList[i], GLX_SAMPLES, &samples);
qDebug("\t matching %i fbCOnfig, visualId %p sampleBUffers %i samples %i", i+1, visualInfo->visualid, sampleBuffers, samples);
if( bestFbCfg < 0 || sampleBuffers && samples > bestNumberOfSamples )
{
bestFbCfg = i;
bestNumberOfSamples = samples;
}
if( worstFbCfg < 0 || !sampleBuffers | samples < worstNumberOfSamples )
{
worstFbCfg = i;
worstNumberOfSamples = samples;
}
}
XFree(visualInfo);
}
qDebug("best fb %i worst fb %i", bestFbCfg+1, worstFbCfg+1);
this->fbConfig = fbConfigsList[bestFbCfg];
XFree(fbConfigsList);
}
void Widget::paintEvent(QPaintEvent *)
{
}
Regards
I try to set up custom opengl context on Widget, but i run into X Error
X Error: BadMatch (invalid parameter attributes) 8
Extension: 135 (Uknown extension)
Minor opcode: 5 (Unknown request)
Resource id: 0x4400003
I think that this could be problem with colormap, because default window colormap could be created based on different frame buffer than frame buffer used to created context.
I don't know how change colormap attached to window, can anyone help please?
Some code below:
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
Widget::Widget(QWidget *parent) :
QWidget(parent)
{
this->setAutoFillBackground(false);
this->setAttribute(Qt::WA_OpaquePaintEvent);
this->setAttribute(Qt::WA_NoSystemBackground);
this->setAttribute(Qt::WA_NativeWindow);
this->setAttribute(Qt::WA_PaintOnScreen, true);
this->setAttribute(Qt::WA_StyledBackground, false);
this->setAttribute(Qt::WA_PaintUnclipped);
this->xInfo = this->x11Info();
this->findBestFrameBuffer();
GLXContext context = 0;
glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressA RB( (const GLubyte *) "glXCreateContextAttribsARB" );
int contextAttribs[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 3,
//GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
None
};
context = glXCreateContextAttribsARB(this->xInfo.display(), this->fbConfig, 0, True, contextAttribs);
qDebug("context %p ", context);
glXMakeCurrent(this->xInfo.display(), this->winId(), context);
}
void Widget::findBestFrameBuffer()
{
static int visualAttribs[] =
{
GLX_X_RENDERABLE , True,
GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
GLX_RENDER_TYPE , GLX_RGBA_BIT,
GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
GLX_RED_SIZE , 8,
GLX_GREEN_SIZE , 8,
GLX_BLUE_SIZE , 8,
GLX_ALPHA_SIZE , 8,
GLX_DEPTH_SIZE , 24,
GLX_STENCIL_SIZE , 8,
GLX_DOUBLEBUFFER , True,
//GLX_SAMPLE_BUFFERS , 1,
//GLX_SAMPLES , 4,
None
};
int fbCount = 0;
GLXFBConfig* fbConfigsList = glXChooseFBConfig(this->xInfo.display(), this->xInfo.screen(), visualAttribs, &fbCount);
qDebug("%i frame buffers found", fbCount);
int bestFbCfg = -1;
int worstFbCfg = -1;
int bestNumberOfSamples = -1;
int worstNumberOfSamples = 999;
XVisualInfo* visualInfo = NULL;
int sampleBuffers = 0;
int samples = 0;
for( int i = 0 ; i < fbCount ; i++ )
{
visualInfo = glXGetVisualFromFBConfig(this->xInfo.display(), fbConfigsList[i]);
if( visualInfo != NULL )
{
glXGetFBConfigAttrib(this->xInfo.display(), fbConfigsList[i], GLX_SAMPLE_BUFFERS, &sampleBuffers);
glXGetFBConfigAttrib(this->xInfo.display(), fbConfigsList[i], GLX_SAMPLES, &samples);
qDebug("\t matching %i fbCOnfig, visualId %p sampleBUffers %i samples %i", i+1, visualInfo->visualid, sampleBuffers, samples);
if( bestFbCfg < 0 || sampleBuffers && samples > bestNumberOfSamples )
{
bestFbCfg = i;
bestNumberOfSamples = samples;
}
if( worstFbCfg < 0 || !sampleBuffers | samples < worstNumberOfSamples )
{
worstFbCfg = i;
worstNumberOfSamples = samples;
}
}
XFree(visualInfo);
}
qDebug("best fb %i worst fb %i", bestFbCfg+1, worstFbCfg+1);
this->fbConfig = fbConfigsList[bestFbCfg];
XFree(fbConfigsList);
}
void Widget::paintEvent(QPaintEvent *)
{
}
Regards