|
8 | 8 |
|
9 | 9 | #include "pxr/base/tf/diagnostic.h" |
10 | 10 |
|
11 | | -#include <GL/glx.h> |
| 11 | +#ifdef PXR_X11_SUPPORT_ENABLED |
| 12 | +#include "pxr/imaging/glf/testGLXContext.h" |
| 13 | +#else |
| 14 | +#include "pxr/imaging/glf/testGLNullContext.h" |
| 15 | +#endif |
12 | 16 |
|
13 | | -#include <stdio.h> |
14 | 17 |
|
15 | 18 | PXR_NAMESPACE_OPEN_SCOPE |
16 | 19 |
|
17 | 20 |
|
18 | | -class Glf_TestGLContextPrivate { |
19 | | -public: |
20 | | - Glf_TestGLContextPrivate( Glf_TestGLContextPrivate const * other=NULL ); |
21 | | - |
22 | | - void makeCurrent( ) const; |
23 | | - |
24 | | - bool isValid(); |
25 | | - |
26 | | - bool operator==(const Glf_TestGLContextPrivate& rhs) const |
27 | | - { |
28 | | - return _dpy == rhs._dpy && _context == rhs._context; |
29 | | - } |
30 | | - |
31 | | - static const Glf_TestGLContextPrivate * currentContext(); |
32 | | - |
33 | | - static bool areSharing( const Glf_TestGLContextPrivate * context1, |
34 | | - const Glf_TestGLContextPrivate * context2 ); |
35 | | - |
36 | | -private: |
37 | | - Display * _dpy; |
38 | | - |
39 | | - GLXContext _context; |
40 | | - |
41 | | - Glf_TestGLContextPrivate const * _sharedContext; |
42 | | - |
43 | | - static GLXWindow _win; |
44 | | - |
45 | | - static Glf_TestGLContextPrivate const * _currenGLContext; |
46 | | -}; |
47 | | - |
48 | | -Glf_TestGLContextPrivate const * Glf_TestGLContextPrivate::_currenGLContext=NULL; |
49 | | -GLXWindow Glf_TestGLContextPrivate::_win=0; |
50 | | - |
51 | | -Glf_TestGLContextPrivate::Glf_TestGLContextPrivate( Glf_TestGLContextPrivate const * other ) |
52 | | - : _dpy(NULL), _context(NULL) |
53 | | -{ |
54 | | - static int attribs[] = { GLX_DOUBLEBUFFER, GLX_RGBA_BIT, |
55 | | - GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, |
56 | | - GLX_SAMPLE_BUFFERS, 1, GLX_SAMPLES, 4, None }; |
57 | | - |
58 | | - _dpy = XOpenDisplay(0); |
59 | | - |
60 | | - int n; |
61 | | - GLXFBConfig * fbConfigs = glXChooseFBConfig( _dpy, |
62 | | - DefaultScreen(_dpy), attribs, &n ); |
63 | | - |
64 | | - GLXContext share = other ? other->_context : 0; |
65 | | - |
66 | | - _context = glXCreateNewContext( _dpy, |
67 | | - fbConfigs[0], GLX_RGBA_TYPE, share, true); |
68 | | - |
69 | | - _sharedContext=other ? other : this; |
70 | | - |
71 | | - if (!_win) { |
72 | | - XVisualInfo * vi = glXGetVisualFromFBConfig( _dpy, fbConfigs[0] ); |
73 | | - |
74 | | - XSetWindowAttributes swa; |
75 | | - swa.colormap = XCreateColormap(_dpy, RootWindow(_dpy, vi->screen), |
76 | | - vi->visual, AllocNone); |
77 | | - swa.border_pixel = 0; |
78 | | - swa.event_mask = StructureNotifyMask; |
79 | | - |
80 | | - Window xwin = XCreateWindow( _dpy, RootWindow(_dpy, vi->screen), |
81 | | - 0, 0, 256, 256, 0, vi->depth, InputOutput, vi->visual, |
82 | | - CWBorderPixel|CWColormap|CWEventMask, &swa ); |
83 | | - |
84 | | - _win = glXCreateWindow( _dpy, fbConfigs[0], xwin, NULL ); |
85 | | - } |
86 | | -} |
87 | | - |
88 | | -void |
89 | | -Glf_TestGLContextPrivate::makeCurrent( ) const |
90 | | -{ |
91 | | - glXMakeContextCurrent(_dpy, _win, _win, _context); |
92 | | - |
93 | | - _currenGLContext=this; |
94 | | -} |
95 | | - |
96 | | -bool |
97 | | -Glf_TestGLContextPrivate::isValid() |
98 | | -{ |
99 | | - return _context!=NULL; |
100 | | -} |
101 | | - |
102 | | -const Glf_TestGLContextPrivate * |
103 | | -Glf_TestGLContextPrivate::currentContext() |
104 | | -{ |
105 | | - return _currenGLContext; |
106 | | -} |
107 | | - |
108 | | -bool |
109 | | -Glf_TestGLContextPrivate::areSharing( const Glf_TestGLContextPrivate * context1, const Glf_TestGLContextPrivate * context2 ) |
110 | | -{ |
111 | | - if (!context1 || !context2) |
112 | | - return false; |
113 | | - |
114 | | - return context1->_sharedContext==context2->_sharedContext; |
115 | | -} |
116 | | - |
117 | 21 | Glf_TestGLContextPrivate * |
118 | 22 | _GetSharedContext() |
119 | 23 | { |
@@ -217,4 +121,3 @@ GlfTestGLContext::_IsEqual(GlfGLContextSharedPtr const &rhs) const |
217 | 121 | } |
218 | 122 |
|
219 | 123 | PXR_NAMESPACE_CLOSE_SCOPE |
220 | | - |
0 commit comments