120
122
NUX_SAFE_DELETE( m_DeviceFactory );
122
124
if (m_CreatedFromForeignWindow == false)
123
126
DestroyOpenGLWindow();
125
129
NUX_SAFE_DELETE( m_pEvent );
127
130
inlSetThreadLocalStorage(_TLS_GraphicsDisplay, 0);
133
int GraphicsDisplay::X11ErrorHandler(Display *display, XErrorEvent *error)
135
if (error->display == NULL)
138
static char str_buffer[256];
140
XGetErrorText(error->display, error->error_code, str_buffer, 256);
141
nuxDebugMsg("[GraphicsDisplay::X11ErrorHandler] X Error of failed request: %s", str_buffer);
142
nuxDebugMsg("[GraphicsDisplay::X11ErrorHandler] Major opcode of failed request: %s", error->request_code);
143
nuxDebugMsg("[GraphicsDisplay::X11ErrorHandler] Minor opcode of failed request: %s", error->minor_code);
144
nuxDebugMsg("[GraphicsDisplay::X11ErrorHandler] Serial number of failed request: %s", error->serial);
130
149
NString GraphicsDisplay::FindResourceLocation(const char *ResourceFileName, bool ErrorOnFail)
132
151
NString path = m_ResourcePathLocation.GetFile(ResourceFileName);
322
static int DoubleBufferAttributes[] =
343
int DoubleBufferAttributes[] =
324
345
//GLX_X_RENDERABLE, True,
325
346
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
326
347
GLX_RENDER_TYPE, GLX_RGBA_BIT,
327
//GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
348
GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
328
349
GLX_DOUBLEBUFFER, True,
329
350
GLX_RED_SIZE, 8, /* the maximum number of bits per component */
330
351
GLX_GREEN_SIZE, 8,
331
352
GLX_BLUE_SIZE, 8,
333
//GLX_DEPTH_SIZE, 24,
334
//GLX_STENCIL_SIZE, 8,
338
//XSetWindowAttributes swa;
339
GLXFBConfig *fbconfigs;
340
//GLXContext context;
359
GLXFBConfig *fbconfigs = NULL;
362
#define GET_PROC(proc_type, proc_name, check) \
365
proc_name = (proc_type) glXGetProcAddress((const GLubyte *) #proc_name); \
369
// GET_PROC(GLXCREATECONTEXTPROC, glXCreateContext, true);
370
// GET_PROC(GLXDESTROYCONTEXTPROC, glXDestroyContext, true);
371
// GET_PROC(GLXMAKECURRENTPROC, glXMakeCurrent, true);
372
// GET_PROC(GLXSWAPBUFFERSPROC, glXSwapBuffers, true);
373
// GET_PROC(GLXCREATEGLXPIXMAPPROC, glXCreateGLXPixmap, true);
374
// GET_PROC(GLXDESTROYGLXPIXMAPPROC, glXDestroyGLXPixmap, true);
375
// GET_PROC(GLXQUERYVERSIONPROC, glXQueryVersion, true);
376
// GET_PROC(GLXGETCONFIGPROC, glXGetConfig, true);
377
// GET_PROC(GLXWAITGLPROC, glXWaitGL, true);
378
// GET_PROC(GLXWAITXPROC, glXWaitX, true);
381
// GET_PROC(GLXQUERYEXTENSIONSSTRINGPROC, glXQueryExtensionsString, true);
382
// GET_PROC(GLXQUERYSERVERSTRINGPROC, glXQueryServerString, true);
383
// GET_PROC(GLXGETCLIENTSTRINGPROC, glXGetClientString, true);
386
GET_PROC(PFNGLXGETFBCONFIGSPROC, glXGetFBConfigs, false);
387
GET_PROC(PFNGLXGETFBCONFIGATTRIBPROC, glXGetFBConfigAttrib, false);
388
GET_PROC(PFNGLXGETVISUALFROMFBCONFIGPROC, glXGetVisualFromFBConfig, false);
389
GET_PROC(PFNGLXCREATEWINDOWPROC, glXCreateWindow, false);
390
GET_PROC(PFNGLXDESTROYWINDOWPROC, glXDestroyWindow, false);
391
GET_PROC(PFNGLXCREATEPIXMAPPROC, glXCreatePixmap, false);
392
GET_PROC(PFNGLXDESTROYPIXMAPPROC, glXDestroyPixmap, false);
393
GET_PROC(PFNGLXCREATEPBUFFERPROC, glXCreatePbuffer, false);
394
GET_PROC(PFNGLXDESTROYPBUFFERPROC, glXDestroyPbuffer, false);
395
GET_PROC(PFNGLXCREATENEWCONTEXTPROC, glXCreateNewContext, false);
396
GET_PROC(PFNGLXMAKECONTEXTCURRENTPROC, glXMakeContextCurrent, false);
397
GET_PROC(PFNGLXCHOOSEFBCONFIGPROC, glXChooseFBConfig, false);
399
/* GLX_SGIX_pbuffer */
400
GET_PROC(PFNGLXCREATEGLXPBUFFERSGIXPROC, glXCreateGLXPbufferSGIX, false);
401
GET_PROC(PFNGLXDESTROYGLXPBUFFERSGIXPROC, glXDestroyGLXPbufferSGIX, false);
344
405
// Request a double buffer configuration
345
fbconfigs = glXChooseFBConfig(m_X11Display, DefaultScreen(m_X11Display), DoubleBufferAttributes, &fbcount );
406
fbconfigs = glXChooseFBConfig(m_X11Display, DefaultScreen(m_X11Display), DoubleBufferAttributes, &fbcount);
347
408
if (fbconfigs == NULL)
353
// Select the best config
354
int best_fbc = -1, worst_fbc = -1, best_num_samp = -1, worst_num_samp = 999;
355
for (int i = 0; i < fbcount; i++)
414
// Select best multi-sample config.
415
if ((_glx_major >= 1) && (_glx_minor >= 4))
357
XVisualInfo *vi = glXGetVisualFromFBConfig(m_X11Display, fbconfigs[i]);
417
int best_fbc = -1, worst_fbc = -1, best_num_samp = -1, worst_num_samp = 999;
418
for (int i = 0; i < fbcount; i++)
360
int samp_buf, samples;
361
glXGetFBConfigAttrib(m_X11Display, fbconfigs[i], GLX_SAMPLE_BUFFERS, &samp_buf);
362
glXGetFBConfigAttrib(m_X11Display, fbconfigs[i], GLX_SAMPLES , &samples);
364
nuxDebugMsg("Matching fbconfig %d, visual ID 0x%2x: SAMPLE_BUFFERS = %d SAMPLES = %d\n", i, vi->visualid, samp_buf, samples);
366
if (((best_fbc < 0) || samp_buf) && (samples > best_num_samp))
367
best_fbc = i, best_num_samp = samples;
368
if ((worst_fbc < 0) || (!samp_buf) || (samples < worst_num_samp))
369
worst_fbc = i, worst_num_samp = samples;
420
XVisualInfo *vi = glXGetVisualFromFBConfig(m_X11Display, fbconfigs[i]);
423
int sample_buf, samples;
424
glXGetFBConfigAttrib(m_X11Display, fbconfigs[i], GLX_SAMPLE_BUFFERS, &sample_buf);
425
glXGetFBConfigAttrib(m_X11Display, fbconfigs[i], GLX_SAMPLES , &samples);
427
//nuxDebugMsg("Matching fbconfig %d, visual ID 0x%2x: SAMPLE_BUFFERS = %d SAMPLES = %d\n", i, vi->visualid, sample_buf, samples);
429
if (((best_fbc < 0) || sample_buf) && (samples > best_num_samp))
432
best_num_samp = samples;
435
if ((worst_fbc < 0) || (!sample_buf) || (samples < worst_num_samp))
438
worst_num_samp = samples;
374
_fb_config = fbconfigs[best_fbc];
444
nuxAssertMsg(best_fbc >= 0, "[GraphicsDisplay::CreateOpenGLWindow] Invalid frame buffer config.");
446
_fb_config = fbconfigs[best_fbc];
450
// Choose the first one
451
_fb_config = fbconfigs[0];
376
454
XFree(fbconfigs);
550
628
/* Create a GLX context for OpenGL rendering */
551
629
m_GLCtx = glXCreateNewContext(m_X11Display, _fb_config, GLX_RGBA_TYPE, NULL, True);
633
nuxDebugMsg("[GraphicsDisplay::CreateOpenGLWindow] m_GLCtx is null");
553
636
/* Create a GLX window to associate the frame buffer configuration
554
637
** with the created X window */
555
GLXWindow glxWin = glXCreateWindow(m_X11Display, _fb_config, m_X11Window, NULL );
638
glx_window_ = glXCreateWindow(m_X11Display, _fb_config, m_X11Window, NULL);
557
640
// Map the window to the screen, and wait for it to appear */
558
641
XMapWindow(m_X11Display, m_X11Window);
933
1016
Rect GraphicsDisplay::GetWindowGeometry()
935
XWindowAttributes attrib;
936
int status = XGetWindowAttributes(m_X11Display, m_X11Window, &attrib);
940
nuxAssert("[GraphicsDisplay::GetWindowGeometry] Failed to get the window attributes.");
941
return Rect(0, 0, 0, 0);
944
return Rect(attrib.x, attrib.y, attrib.width, attrib.height);
1020
// unsigned int w, h, b, d;
1021
// Window child_return;
1023
// int status = XGetGeometry(m_X11Display, m_X11Window, &rw, &x, &y, &w, &h, &b, &d);
1027
// nuxAssert("[GraphicsDisplay::GetWindowGeometry] Failed to get the window attributes.");
1028
// return Rect(0, 0, 0, 0);
1031
// XSync(m_X11Display, False);
1033
// status = XTranslateCoordinates(m_X11Display, m_X11Window, RootWindow(m_X11Display, 0), x, y, &x, &y, &child_return);
1037
// nuxAssert("[GraphicsDisplay::GetWindowGeometry] Failed to get the window attributes.");
1038
// return Rect(0, 0, 0, 0);
1041
// XSync(m_X11Display, False);
1042
return Rect(m_WindowPosition.x, m_WindowPosition.y, m_WindowSize.width, m_WindowSize.height);
947
1045
Rect GraphicsDisplay::GetNCWindowGeometry()
949
XWindowAttributes attrib;
950
int status = XGetWindowAttributes(m_X11Display, m_X11Window, &attrib);
954
nuxAssert("[GraphicsDisplay::GetWindowGeometry] Failed to get the window attributes.");
955
return Rect(0, 0, 0, 0);
958
return Rect(attrib.x, attrib.y, attrib.width, attrib.height);
1047
// XWindowAttributes attrib;
1048
// int status = XGetWindowAttributes(m_X11Display, m_X11Window, &attrib);
1052
// nuxAssert("[GraphicsDisplay::GetWindowGeometry] Failed to get the window attributes.");
1053
// return Rect(0, 0, 0, 0);
1056
// return Rect(attrib.x, attrib.y, attrib.width, attrib.height);
1058
return Rect(m_WindowPosition.x, m_WindowPosition.y, m_WindowSize.width, m_WindowSize.height);
961
1061
void GraphicsDisplay::MakeGLContextCurrent()
963
1063
#ifndef NUX_OPENGLES_20
964
if (!glXMakeCurrent(m_X11Display, m_X11Window, m_GLCtx))
1066
nuxDebugMsg("Has glx 1.3");
1067
if (!glXMakeContextCurrent(m_X11Display, glx_window_, glx_window_, m_GLCtx))
1069
nuxDebugMsg("Destroy");
1070
DestroyOpenGLWindow();
1073
else if (!glXMakeCurrent(m_X11Display, m_X11Window, m_GLCtx))
966
1075
DestroyOpenGLWindow();
1617
1738
m_pEvent->width = xevent.xconfigure.width;
1618
1739
m_pEvent->height = xevent.xconfigure.height;
1619
1740
m_WindowSize = Size(xevent.xconfigure.width, xevent.xconfigure.height);
1620
m_WindowPosition = Point(xevent.xconfigure.x, xevent.xconfigure.y);
1622
//nuxDebugMsg("[GraphicsDisplay::ProcessXEvents]: ConfigureNotify event.");
1744
unsigned int w, h, b, d;
1745
Window child_return;
1747
int status = XTranslateCoordinates(m_X11Display, m_X11Window, RootWindow(m_X11Display, 0), 0, 0, &x, &y, &child_return);
1748
m_WindowPosition = Point(x, y);
1750
//nuxDebugMsg("[GraphicsDisplay::ProcessXEvents]: ConfigureNotify event. %d %d", x, y);