[英]context sharing in FreeGLUT under Linux with xorg
I am trying to use OpenGL with shared context (because of sharing textures between windows) via FreeGLUT library... It work fine, I can share textures, but i failed on the end of program or during windows closing by mouse... 我正在尝试通过FreeGLUT库在共享上下文中使用OpenGL(因为在窗口之间共享纹理)。它工作正常,可以共享纹理,但是在程序结束时或在用鼠标关闭窗口期间失败了...
I have cerated the code which emulate the problem: ( http://pastie.org/9437038 ) 我已经证明了模拟该问题的代码:( http://pastie.org/9437038 )
// file: main.c
// compile: gcc -o test -lglut main.c
// compile: gcc -o test -lglut -DTIME_LIMIT main.c
#include "GL/freeglut.h"
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
int winA, winB, winC;
int n;
glutInit(&argc, argv);
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE , GLUT_ACTION_CONTINUE_EXECUTION);
//glutSetOption(GLUT_RENDERING_CONTEXT, GLUT_USE_CURRENT_CONTEXT);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
winA = glutCreateWindow("Test A");
glutSetOption(GLUT_RENDERING_CONTEXT, GLUT_USE_CURRENT_CONTEXT);
winB = glutCreateWindow("Test B");
winC = glutCreateWindow("Test C");
printf("loop\n");
#ifdef TIME_LIMIT
for (n=0;n<50;n++)
{
glutMainLoopEvent();
usleep(5000);
}
#else //TIMELIMIT
glutMainLoop();
#endif // TIME_LIMIT
printf("Destroy winC\n");
glutDestroyWindow(winC);
printf("Destroy winB\n");
glutDestroyWindow(winB);
printf("Destroy winA\n");
glutDestroyWindow(winA);
printf("Normal end\n");
return 0;
}
Output: 输出:
loop
X Error of failed request: GLXBadContext
Major opcode of failed request: 153 (GLX)
Minor opcode of failed request: 4 (X_GLXDestroyContext)
Serial number of failed request: 113
Current serial number in output stream: 114
Segmentation fault
output with TIME_LIMIT: 输出TIME_LIMIT:
loop
Destroy winC
Destroy winB
Destroy winA
Segmentation fault
Without calling glutSetOption(GLUT_RENDERING_CONTEXT, GLUT_USE_CURRENT_CONTEXT);, it works well. 无需调用glutSetOption(GLUT_RENDERING_CONTEXT,GLUT_USE_CURRENT_CONTEXT);,它就可以很好地工作。
Do anybody have idea what am I doing bad? 有人知道我在做什么不好吗?
The option GLUT_USE_CURRENT_CONTEXT
does not create shared contexts . 选项
GLUT_USE_CURRENT_CONTEXT
不创建共享的上下文 。 It just means that the same GL context is used for all windows. 这仅表示所有窗口都使用相同的 GL上下文。 You only have one GL conxtext, and destroy it when you first destroy a window which uses that, so the other destruction calls fail.
您只有一个GL conxtext,并且在您第一次销毁使用它的窗口时销毁它,因此其他销毁调用将失败。 None of the GLUT implementations I'm aware of actually supports GL context sharing.
我知道的所有GLUT实现都没有真正支持GL上下文共享。
GLUT_USE_CURRENT_CONTEXT
is more like a hack (and it is nor part of the GLUT specification anyway), and not really a well-implemented. GLUT_USE_CURRENT_CONTEXT
是一种GLUT_USE_CURRENT_CONTEXT
(无论如何,它也不是GLUT规范的一部分),并且并不是一个很好的实现。 It could use some reference counting to destroy the context not before the last window using it is destroyed, but that is simply not the case. 它可以使用引用计数来破坏上下文,而不要在使用它的最后一个窗口被破坏之前,但是事实并非如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.