PCMGLXGLContext.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "../include/PCMGLXGLContext.h"
00030
00031 #include "../include/PCMGLXRenderWindow.h"
00032
00033 #include "../include/PCMStringConverter.h"
00034
00035 namespace ParCompMark
00036 {
00037
00038
00039
00040
00041
00042 GLXGLContext::GLXGLContext(XDisplay::Pointer & display, GLXRenderWindow * glxWindow,::XVisualInfo * visualInfo):
00043
00044 mDisplay(display
00045 ),
00046
00047 mGLXWindow(glxWindow
00048 )
00049
00050
00051
00052
00053
00054
00055
00056 {
00057 Assert(display.isNotNull() && glxWindow && visualInfo, NULL_POINTER_ERROR, "GLXGLContext::GLXGLContext()");
00058
00059 mInitialized = false;
00060 mGLXContext = 0;
00061 mTainted = false;
00062
00063
00064 mVisualInfo = new::XVisualInfo();
00065 memcpy(mVisualInfo, visualInfo, sizeof(::XVisualInfo));
00066
00067 Logger::getInstance()->log(Logger::NOTICE,
00068 "GLX Context for window `" + mGLXWindow->getCaption() + "\' has been created");
00069 }
00070
00071
00072
00073 GLXGLContext::~GLXGLContext()
00074 {
00075 if(mInitialized)
00076 finalize();
00077
00078
00079 Assert(mVisualInfo, NULL_POINTER_ERROR, "GLXGLContext::finalize()");
00080 delete mVisualInfo;
00081
00082 Logger::getInstance()->log(Logger::NOTICE,
00083 "GLX Context for window `" + mGLXWindow->getCaption() + "\' has been destroyed");
00084 }
00085
00086
00087
00088
00089
00090
00091
00092 void GLXGLContext::initialize()
00093 {
00094 Assert(!mInitialized, INVALID_OPERATION_ERROR, "GLXGLContext::initialize()");
00095
00096
00097 mDisplay.lock();
00098 mDisplay->synchronize();
00099
00100
00101 mGLXContext = glXCreateContext(mDisplay->getDisplay(), mVisualInfo, NULL, True);
00102 Assert(mGLXContext, INVALID_OPERATION_ERROR, "GLXGLContext::initialize()");
00103
00104 mDisplay.unlock();
00105
00106 mInitialized = true;
00107 Logger::getInstance()->log(Logger::DEBUG,
00108 "GLX Context for window `" + mGLXWindow->getCaption() + "\' has been initialized: " +
00109 StringConverter::toString((void *) mGLXContext));
00110 }
00111
00112
00113
00114 void GLXGLContext::finalize()
00115 {
00116 Assert(mInitialized, INVALID_OPERATION_ERROR, "GLXGLContext::finalize()");
00117
00118
00119 mDisplay.lock();
00120 mDisplay->synchronize();
00121
00122
00123 Assert(mGLXContext, NULL_POINTER_ERROR, "GLXGLContext::finalize()");
00124 if(!mTainted)
00125 glXDestroyContext(mDisplay->getDisplay(), mGLXContext);
00126
00127 mDisplay.unlock();
00128
00129 mInitialized = false;
00130 Logger::getInstance()->log(Logger::DEBUG,
00131 "GLX Context for window `" + mGLXWindow->getCaption() + "\' has been finalized");
00132 }
00133
00134
00135
00136 void GLXGLContext::setCurrent()
00137 {
00138 Assert(mInitialized, INVALID_OPERATION_ERROR, "GLXGLContext::setCurrent()");
00139
00140 mDisplay.lock();
00141 if(glXMakeCurrent(mDisplay->getDisplay(), mGLXWindow->getWindow(), mGLXContext) != True)
00142 {
00143 Except(INTERNAL_ERROR, "GLXGLContext::setCurrent()", "calling glXMakeCurrent");
00144 }
00145 mDisplay.unlock();
00146 }
00147
00148
00149
00150 void GLXGLContext::releaseCurrent()
00151 {
00152 Assert(mInitialized, INVALID_OPERATION_ERROR, "GLXGLContext::releaseCurrent()");
00153
00154 mDisplay.lock();
00155 if(glXMakeCurrent(mDisplay->getDisplay(), None, 0) != True)
00156 {
00157 Except(INTERNAL_ERROR, "GLXGLContext::releaseCurrent()", "calling glXMakeCurrent");
00158 }
00159 mDisplay.unlock();
00160 }
00161
00162
00163
00164 }