25 #include "glfRenderingContext_GLX.hh"
26 #include <OpenGLFramework/Base/glfException.hh>
42 BIASASSERT(display_ == NULL);
43 BIASASSERT(drawable_ == None);
44 BIASASSERT(context_ == NULL);
52 display_ = XOpenDisplay(NULL);
53 if (display_ == NULL) {
54 GLF_THROW_EXCEPTION(
"Failed to connect to the X server");
59 if (glXQueryVersion(display_, &major, &minor) == False) {
60 GLF_THROW_EXCEPTION(
"Failed to query GLX version");
64 GLX_DRAWABLE_TYPE, GetDrawableType(),
68 GLXFBConfig* fbConfigs =
69 glXChooseFBConfig(display_, DefaultScreen(display_),
70 attribs, &numFbConfigs);
71 if (fbConfigs == NULL || numFbConfigs == 0) {
72 GLF_THROW_EXCEPTION(
"Failed to get GLX framebuffer configurations");
76 GLXFBConfig fbConfig = None;
88 for (
int i = 0; i < numFbConfigs; i++) {
89 int doubleBuffer, redSize, greenSize, blueSize, alphaSize, depthSize, stencilSize;
90 glXGetFBConfigAttrib(display_, fbConfigs[i], GLX_DOUBLEBUFFER, &doubleBuffer);
91 glXGetFBConfigAttrib(display_, fbConfigs[i], GLX_RED_SIZE, &redSize);
92 glXGetFBConfigAttrib(display_, fbConfigs[i], GLX_GREEN_SIZE, &greenSize);
93 glXGetFBConfigAttrib(display_, fbConfigs[i], GLX_BLUE_SIZE, &blueSize);
94 glXGetFBConfigAttrib(display_, fbConfigs[i], GLX_ALPHA_SIZE, &alphaSize);
95 glXGetFBConfigAttrib(display_, fbConfigs[i], GLX_DEPTH_SIZE, &depthSize);
96 glXGetFBConfigAttrib(display_, fbConfigs[i], GLX_STENCIL_SIZE, &stencilSize);
115 fbConfig = fbConfigs[i];
119 if (fbConfig == None) {
120 GLF_THROW_EXCEPTION(
"Rendering context configuration is unsupported");
124 drawable_ = CreateDrawable(config.
width, config.
height, fbConfig);
125 BIASASSERT(drawable_ != None);
128 context_ = glXCreateNewContext(display_, fbConfig,
129 GLX_RGBA_TYPE, NULL, True);
130 if (context_ == NULL) {
131 GLF_THROW_EXCEPTION(
"Failed to create GLX context");
133 if(!glXIsDirect(display_, context_)){
134 GLF_THROW_EXCEPTION(
"Failed to create a direct GLX context");
143 if (context_ != NULL) {
144 if (glXGetCurrentContext() == context_) {
145 glXMakeCurrent(display_, None, NULL);
147 glXDestroyContext(display_, context_);
152 if (display_ != NULL) {
153 XCloseDisplay(display_);
161 BIASASSERT(display_ != NULL && drawable_ != None && context_ != NULL);
163 if (glXMakeCurrent(display_, drawable_, context_) == False) {
164 GLF_THROW_EXCEPTION(
"Failed to set current GLX context");
170 BIASASSERT(display_ != NULL && drawable_ != None && context_ != NULL);
172 if (glXMakeCurrent(display_, None, NULL) == False) {
173 GLF_THROW_EXCEPTION(
"Failed to release current GLX context");
179 BIASASSERT(display_ != NULL && drawable_ != None && context_ != NULL);
182 unsigned int width, height;
183 glXQueryDrawable(display_, drawable_, GLX_WIDTH, &width);
184 glXQueryDrawable(display_, drawable_, GLX_HEIGHT, &height);
185 config.
width = width;
189 unsigned int fbConfigId;
190 glXQueryDrawable(display_, drawable_, GLX_FBCONFIG_ID, &fbConfigId);
193 int signedFbConfigId = (int)fbConfigId;
195 GLX_FBCONFIG_ID, signedFbConfigId,
199 GLXFBConfig* fbConfig =
200 glXChooseFBConfig(display_, DefaultScreen(display_), attribs, &numFbConfigs);
201 if (fbConfig == NULL || numFbConfigs == 0) {
202 GLF_THROW_EXCEPTION(
"Failed to get framebuffer config");
207 glXGetFBConfigAttrib(display_, *fbConfig, GLX_DOUBLEBUFFER, &tmp);
208 glXGetFBConfigAttrib(display_, *fbConfig, GLX_RED_SIZE, &config.
redSize);
209 glXGetFBConfigAttrib(display_, *fbConfig, GLX_GREEN_SIZE, &config.
greenSize);
210 glXGetFBConfigAttrib(display_, *fbConfig, GLX_BLUE_SIZE, &config.
blueSize);
211 glXGetFBConfigAttrib(display_, *fbConfig, GLX_ALPHA_SIZE, &config.
alphaSize);
212 glXGetFBConfigAttrib(display_, *fbConfig, GLX_DEPTH_SIZE, &config.
depthSize);
213 glXGetFBConfigAttrib(display_, *fbConfig, GLX_STENCIL_SIZE, &config.
stencilSize);
glfRenderingContext_GLX()
virtual void MakeCurrent()
Makes this context the current target for OpenGL calls.
virtual void Destroy()
Uninitializes the rendering context.
virtual void GetConfig(glfRenderingContextConfig &config)
Gets the currently used config of the rendering context.
virtual void Init(const glfRenderingContextConfig &config)
Initializes the rendering context with the given configuration.
virtual void DoneCurrent()
Removes the current state of this context.
~glfRenderingContext_GLX()
Configuration for a rendering context.