glxgears_fbconfig: Use glXCreateWindow and glXDestroyWindow
This commit is contained in:
parent
6518f6037c
commit
381d5e2098
|
@ -49,6 +49,8 @@
|
||||||
static PFNGLXCHOOSEFBCONFIGPROC choose_fbconfig = NULL;
|
static PFNGLXCHOOSEFBCONFIGPROC choose_fbconfig = NULL;
|
||||||
static PFNGLXGETVISUALFROMFBCONFIGPROC get_visual_from_fbconfig = NULL;
|
static PFNGLXGETVISUALFROMFBCONFIGPROC get_visual_from_fbconfig = NULL;
|
||||||
static PFNGLXCREATENEWCONTEXTPROC create_new_context = NULL;
|
static PFNGLXCREATENEWCONTEXTPROC create_new_context = NULL;
|
||||||
|
static PFNGLXCREATEWINDOWPROC create_window = NULL;
|
||||||
|
static PFNGLXDESTROYWINDOWPROC destroy_window = NULL;
|
||||||
|
|
||||||
#define BENCHMARK
|
#define BENCHMARK
|
||||||
|
|
||||||
|
@ -320,6 +322,26 @@ init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static GLXWindow
|
||||||
|
dummy_create_window(Display *dpy, GLXFBConfig config, Window win,
|
||||||
|
const int *attrib_list)
|
||||||
|
{
|
||||||
|
(void) dpy;
|
||||||
|
(void) config;
|
||||||
|
(void) attrib_list;
|
||||||
|
|
||||||
|
return (GLXWindow) win;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
dummy_destroy_window(Display *dpy, GLXWindow win)
|
||||||
|
{
|
||||||
|
(void) dpy;
|
||||||
|
(void) win;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize fbconfig related function pointers.
|
* Initialize fbconfig related function pointers.
|
||||||
*/
|
*/
|
||||||
|
@ -361,6 +383,10 @@ init_fbconfig_functions(Display *dpy, int scrnum)
|
||||||
glXGetProcAddressARB((GLubyte *) "glXGetVisualFromFBConfig");
|
glXGetProcAddressARB((GLubyte *) "glXGetVisualFromFBConfig");
|
||||||
create_new_context = (PFNGLXCREATENEWCONTEXTPROC)
|
create_new_context = (PFNGLXCREATENEWCONTEXTPROC)
|
||||||
glXGetProcAddressARB((GLubyte *) "glXCreateNewContext");
|
glXGetProcAddressARB((GLubyte *) "glXCreateNewContext");
|
||||||
|
create_window = (PFNGLXCREATEWINDOWPROC)
|
||||||
|
glXGetProcAddressARB((GLubyte *) "glXCreateWindow");
|
||||||
|
destroy_window = (PFNGLXDESTROYWINDOWPROC)
|
||||||
|
glXGetProcAddressARB((GLubyte *) "glXDestroyWindow");
|
||||||
}
|
}
|
||||||
else if ( ext_version_supported ) {
|
else if ( ext_version_supported ) {
|
||||||
choose_fbconfig = (PFNGLXCHOOSEFBCONFIGPROC)
|
choose_fbconfig = (PFNGLXCHOOSEFBCONFIGPROC)
|
||||||
|
@ -369,6 +395,8 @@ init_fbconfig_functions(Display *dpy, int scrnum)
|
||||||
glXGetProcAddressARB((GLubyte *) "glXGetVisualFromFBConfigSGIX");
|
glXGetProcAddressARB((GLubyte *) "glXGetVisualFromFBConfigSGIX");
|
||||||
create_new_context = (PFNGLXCREATENEWCONTEXTPROC)
|
create_new_context = (PFNGLXCREATENEWCONTEXTPROC)
|
||||||
glXGetProcAddressARB((GLubyte *) "glXCreateContextWithConfigSGIX");
|
glXGetProcAddressARB((GLubyte *) "glXCreateContextWithConfigSGIX");
|
||||||
|
create_window = dummy_create_window;
|
||||||
|
destroy_window = dummy_destroy_window;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf( "This demo requires either GLX 1.3 or %s be supported.\n",
|
printf( "This demo requires either GLX 1.3 or %s be supported.\n",
|
||||||
|
@ -400,7 +428,7 @@ init_fbconfig_functions(Display *dpy, int scrnum)
|
||||||
static void
|
static void
|
||||||
make_window( Display *dpy, const char *name,
|
make_window( Display *dpy, const char *name,
|
||||||
int x, int y, int width, int height,
|
int x, int y, int width, int height,
|
||||||
Window *winRet, GLXContext *ctxRet)
|
Window *winRet, GLXWindow *glxWinRet, GLXContext *ctxRet)
|
||||||
{
|
{
|
||||||
int attrib[] = { GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
|
int attrib[] = { GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
|
||||||
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
||||||
|
@ -418,6 +446,7 @@ make_window( Display *dpy, const char *name,
|
||||||
unsigned long mask;
|
unsigned long mask;
|
||||||
Window root;
|
Window root;
|
||||||
Window win;
|
Window win;
|
||||||
|
GLXWindow glxWin;
|
||||||
GLXContext ctx;
|
GLXContext ctx;
|
||||||
XVisualInfo *visinfo;
|
XVisualInfo *visinfo;
|
||||||
|
|
||||||
|
@ -463,6 +492,8 @@ make_window( Display *dpy, const char *name,
|
||||||
None, (char **)NULL, 0, &sizehints);
|
None, (char **)NULL, 0, &sizehints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glxWin = (*create_window)(dpy, fbconfig[0], win, NULL);
|
||||||
|
|
||||||
ctx = (*create_new_context)(dpy, fbconfig[0], GLX_RGBA_TYPE, NULL, GL_TRUE);
|
ctx = (*create_new_context)(dpy, fbconfig[0], GLX_RGBA_TYPE, NULL, GL_TRUE);
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
printf("Error: glXCreateNewContext failed\n");
|
printf("Error: glXCreateNewContext failed\n");
|
||||||
|
@ -471,13 +502,14 @@ make_window( Display *dpy, const char *name,
|
||||||
|
|
||||||
XFree(fbconfig);
|
XFree(fbconfig);
|
||||||
|
|
||||||
|
*glxWinRet = glxWin;
|
||||||
*winRet = win;
|
*winRet = win;
|
||||||
*ctxRet = ctx;
|
*ctxRet = ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
event_loop(Display *dpy, Window win)
|
event_loop(Display *dpy, GLXWindow win)
|
||||||
{
|
{
|
||||||
while (1) {
|
while (1) {
|
||||||
while (XPending(dpy) > 0) {
|
while (XPending(dpy) > 0) {
|
||||||
|
@ -554,6 +586,7 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
Display *dpy;
|
Display *dpy;
|
||||||
Window win;
|
Window win;
|
||||||
|
GLXWindow glxWin;
|
||||||
GLXContext ctx;
|
GLXContext ctx;
|
||||||
const char *dpyName = NULL;
|
const char *dpyName = NULL;
|
||||||
GLboolean printInfo = GL_FALSE;
|
GLboolean printInfo = GL_FALSE;
|
||||||
|
@ -575,9 +608,9 @@ main(int argc, char *argv[])
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
make_window(dpy, "glxgears", 0, 0, 300, 300, &win, &ctx);
|
make_window(dpy, "glxgears", 0, 0, 300, 300, &win, &glxWin, &ctx);
|
||||||
XMapWindow(dpy, win);
|
XMapWindow(dpy, win);
|
||||||
glXMakeCurrent(dpy, win, ctx);
|
glXMakeCurrent(dpy, glxWin, ctx);
|
||||||
|
|
||||||
if (printInfo) {
|
if (printInfo) {
|
||||||
printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
|
printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
|
||||||
|
@ -588,9 +621,10 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
event_loop(dpy, win);
|
event_loop(dpy, glxWin);
|
||||||
|
|
||||||
glXDestroyContext(dpy, ctx);
|
glXDestroyContext(dpy, ctx);
|
||||||
|
destroy_window(dpy, glxWin);
|
||||||
XDestroyWindow(dpy, win);
|
XDestroyWindow(dpy, win);
|
||||||
XCloseDisplay(dpy);
|
XCloseDisplay(dpy);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue