OSGXWindow.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
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <cstdlib>
00044 #include <cstdio>
00045
00046 #include <OSGConfig.h>
00047
00048 #define OSG_COMPILEWINDOWXINST
00049
00050 #include <OSGGLU.h>
00051 #include "OSGXWindow.h"
00052
00053 OSG_USING_NAMESPACE
00054
00055
00056
00057
00058
00059
00060
00061
00063 XWindow::XWindow(void) :
00064 Inherited()
00065 {
00066 }
00067
00069 XWindow::XWindow(const XWindow &source) :
00070 Inherited(source)
00071 {
00072 }
00073
00075 XWindow::~XWindow(void)
00076 {
00077 }
00078
00079
00080
00082 void XWindow::initMethod(InitPhase ePhase)
00083 {
00084 Inherited::initMethod(ePhase);
00085 }
00086
00088 void XWindow::changed(ConstFieldMaskArg whichField,
00089 UInt32 origin,
00090 BitVector details)
00091 {
00092 Inherited::changed(whichField, origin, details);
00093 }
00094
00096 void XWindow::dump( UInt32 ,
00097 const BitVector ) const
00098 {
00099 SLOG << "Dump XWindow NI" << std::endl;
00100 }
00101
00102
00103
00106 void XWindow::init(void)
00107 {
00108 XVisualInfo *vi, visInfo;
00109 XWindowAttributes winAttr;
00110
00111 XGetWindowAttributes(getDisplay(), getWindow(), &winAttr);
00112
00113
00114 memset(&visInfo, 0, sizeof(XVisualInfo));
00115
00116 visInfo.visualid = XVisualIDFromVisual(winAttr.visual);
00117
00118
00119 if(getDisplay() == NULL)
00120 {
00121 setDisplay(XOpenDisplay(DisplayString(getDisplay())));
00122 }
00123
00124
00125 int nvis;
00126
00127 vi = XGetVisualInfo(getDisplay(), VisualIDMask, &visInfo, &nvis);
00128
00129
00130 int useGL;
00131 glXGetConfig(getDisplay(),
00132 vi,
00133 GLX_USE_GL,
00134 &useGL );
00135 if (!useGL)
00136 {
00137 SFATAL << "Visual is not OpenGL-capable!" << std::endl;
00138 }
00139
00140
00141 this->setContext(glXCreateContext(getDisplay(), vi, None, GL_TRUE));
00142
00143 XFree(vi);
00144
00145 glXMakeCurrent(getDisplay(), getWindow(), getContext());
00146
00147 setupGL();
00148 }
00149
00150 void XWindow::terminate(void)
00151 {
00152 if(getDisplay() != NULL && getContext() != NULL)
00153 {
00154 deactivate();
00155
00156 glXDestroyContext(getDisplay(), getContext());
00157 }
00158 }
00159
00160
00161 void XWindow::activate(void)
00162 {
00163 Bool res;
00164 res = glXMakeCurrent(getDisplay(), getWindow(), getContext());
00165
00166 if(res != True)
00167 {
00168 FWARNING(("XWindow::activate: makeCurrent failed!\n"));
00169 glErr("XWindow::activate");
00170 glErr("XWindow::activate");
00171 glErr("XWindow::activate");
00172 }
00173 }
00174
00175
00176 void XWindow::deactivate(void)
00177 {
00178 glXMakeCurrent(getDisplay(), None, NULL);
00179 }
00180
00181
00182 bool XWindow::swap(void)
00183 {
00184 glXSwapBuffers(getDisplay(), getWindow());
00185 return true;
00186 }
00187
00188 #include <OSGSField.ins>
00189 #include <OSGMField.ins>
00190
00191 #if defined(OSG_TMPL_STATIC_MEMBER_NEEDS_FUNCTION_INSTANTIATION) || \
00192 defined(OSG_TMPL_STATIC_MEMBER_NEEDS_CLASS_INSTANTIATION )
00193
00194 #include "OSGSFieldFuncs.ins"
00195 #include "OSGMFieldFuncs.ins"
00196 #endif
00197
00198 OSG_BEGIN_NAMESPACE
00199
00200
00201 #ifndef OSG_DO_DOC
00202
00203 DataType FieldTraits<DisplayP >::_type("DisplayP", NULL);
00204 DataType FieldTraits<X11Window >::_type("X11Window", NULL);
00205 DataType FieldTraits<GLXContext, 1>::_type("GLXContext", NULL);
00206
00207 #endif
00208
00209 OSG_FIELD_DLLEXPORT_DEF1(SField, DisplayP );
00210 OSG_FIELD_DLLEXPORT_DEF1(MField, DisplayP );
00211 OSG_FIELD_DLLEXPORT_DEF1(SField, X11Window );
00212 OSG_FIELD_DLLEXPORT_DEF1(MField, X11Window );
00213 OSG_FIELD_DLLEXPORT_DEF2(SField, GLXContext, 1);
00214 OSG_FIELD_DLLEXPORT_DEF2(MField, GLXContext, 1);
00215
00216 OSG_END_NAMESPACE