#include <vrj/Draw/OGL/GlWindow.h>
Inheritance diagram for vrj::GlWindow:


Public Member Functions | |
| GlWindow () | |
| virtual | ~GlWindow () |
| Virtual destructor. | |
| virtual bool | open () |
| Opens the OpenGL window. | |
| virtual bool | close () |
| Closes the OpenGL window. | |
| virtual bool | makeCurrent () |
| Sets the current OpenGL context to this window. | |
| virtual void | configWindow (vrj::Display *displayWindow) |
| Configures the window. | |
| virtual void | swapBuffers () |
| Performs an OpenGL swap buffers command. | |
| virtual void | checkEvents () |
| Handles any window events that have occured. | |
| virtual void | finishSetup () |
| Complete any setup that is needed after open. | |
| void | setProjection (vrj::Projection *proj) |
| Sets the projection matrix for this window to proj. | |
| void | setLeftEyeProjection () |
| Sets the projection matrix for this window to draw the left eye frame. | |
| void | setRightEyeProjection () |
| Sets the projection matrix for this window to draw the right eye frame. | |
| void | setViewBuffer (vrj::Viewport::View view) |
| Sets the view buffer for the window (issues glDrawBuffer command). | |
| void | setViewport (float xo, float yo, float xSize, float ySize) |
| Sets the viewport in the GL window based on float values. | |
| void | updateViewport () |
| Updates the viewport and does any viewport cleaning. | |
| bool | hasDirtyContext () const |
| Is the context dirty? | |
| void | setDirtyContext (bool val=true) |
| Sets the dirty bit for the context. | |
| bool | hasDirtyViewport () const |
| Is the viewport dirty? | |
| void | setDirtyViewport (bool val=true) |
| Sets the dirty bit for the viewport. | |
| bool | isOpen () const |
| Queries wether the window is open. | |
| bool | isStereo () const |
| Queries wether the window is in stereo. | |
| bool | isEventSource () const |
| vrj::Display * | getDisplay () |
| int | getId () const |
| |
| void | updateOriginSize (const int originX, const int originY, const int width, const int height) |
| Called by event function to update size info. | |
| void | getOriginSize (int &originX, int &originY, int &width, int &height) const |
| Returns the origin and size of the current window. | |
| vpr::Uint64 | getSwapCount () |
Protected Attributes | |
| vrj::Display * | mVrjDisplay |
| We store a pointer to the display that we're created from in order to config and to get the viewing transforms from. | |
| vpr::Uint64 | mSwapCount |
| The number of times that swapBuffers() has been called. | |
| bool | mDirtyContext |
| The context is dirty. | |
| bool | mDirtyViewport |
| The GL window setup (viewport, etc) is dirty and needs to be reinited. | |
| bool | mInStereo |
| Whether the display is actually in stereo if we wanted a stereo display but couldn't open it we fall back to mono, and this will be false. | |
| bool | mHasBorder |
| Do we have a border? | |
| bool | mHideMouse |
| Should we hide the mouse pointer? | |
| bool | mWindowIsOpen |
| Is the window open? | |
| int | mWindowWidth |
| int | mWindowHeight |
| int | mOriginX |
| X component of the lower left-hand corner of the window. | |
| int | mOriginY |
| Y component of the lower left-hand corner of the window. | |
| int | mWindowId |
| A unique window id to identify us. | |
| bool | mIsEventSource |
| Should we act as an event source too? | |
Friends | |
| std::ostream & | operator<< (std::ostream &out, GlWindow &win) |
This interface is used by the OpenGL Draw Manager in order to keep all platform-specific code in this one class.
Definition at line 66 of file GlWindow.h.
| vrj::GlWindow::GlWindow | ( | ) | [inline] |
Definition at line 69 of file GlWindow.h.
00070 : mVrjDisplay(NULL) 00071 , mSwapCount(0) 00072 // The context is always dirty when the window is first created 00073 , mDirtyContext(true) 00074 , mDirtyViewport(true) 00075 , mInStereo(false) 00076 , mHasBorder(false) 00077 , mHideMouse(false) 00078 , mWindowIsOpen(false) 00079 , mWindowWidth(0) 00080 , mWindowHeight(0) 00081 , mOriginX(0) 00082 , mOriginY(0) 00083 // XXX: Sync problem on window id value assignment 00084 , mWindowId(getNextWindowId()) 00085 , mIsEventSource(false) 00086 { 00087 /* Do nothing. */ ; 00088 }
| virtual vrj::GlWindow::~GlWindow | ( | ) | [inline, virtual] |
| virtual bool vrj::GlWindow::open | ( | ) | [inline, virtual] |
Opens the OpenGL window.
Reimplemented in vrj::GlWindowOSX, vrj::GlWindowWin32, and vrj::GlWindowXWin.
Definition at line 102 of file GlWindow.h.
| virtual bool vrj::GlWindow::close | ( | ) | [inline, virtual] |
Closes the OpenGL window.
Reimplemented in vrj::GlWindowOSX, vrj::GlWindowWin32, and vrj::GlWindowXWin.
Definition at line 108 of file GlWindow.h.
| virtual bool vrj::GlWindow::makeCurrent | ( | ) | [inline, virtual] |
Sets the current OpenGL context to this window.
Reimplemented in vrj::GlWindowOSX, vrj::GlWindowWin32, and vrj::GlWindowXWin.
Definition at line 117 of file GlWindow.h.
| void vrj::GlWindow::configWindow | ( | vrj::Display * | displayWindow | ) | [virtual] |
Configures the window.
Reimplemented in vrj::GlWindowOSX, vrj::GlWindowWin32, and vrj::GlWindowXWin.
Definition at line 82 of file GlWindow.cpp.
References vrj::Display::getOriginAndSize(), mHasBorder, mHideMouse, mOriginX, mOriginY, mVrjDisplay, mWindowHeight, mWindowWidth, vrj::Display::shouldDrawBorder(), and vrj::Display::shouldHideMouse().
Referenced by vrj::GlDrawManager::addDisplay(), vrj::GlWindowXWin::configWindow(), vrj::GlWindowWin32::configWindow(), and vrj::GlWindowOSX::configWindow().
00083 { 00084 vprASSERT(displayWindow != NULL); // We can't config to a NULL display 00085 mVrjDisplay = displayWindow; 00086 mVrjDisplay->getOriginAndSize(mOriginX, mOriginY, mWindowWidth, 00087 mWindowHeight); 00088 mHasBorder = mVrjDisplay->shouldDrawBorder(); 00089 mHideMouse = mVrjDisplay->shouldHideMouse(); 00090 }
| void vrj::GlWindow::swapBuffers | ( | ) | [virtual] |
Performs an OpenGL swap buffers command.
Reimplemented in vrj::GlWindowOSX, vrj::GlWindowWin32, and vrj::GlWindowXWin.
Definition at line 92 of file GlWindow.cpp.
References mSwapCount.
Referenced by vrj::GlWindowXWin::swapBuffers(), vrj::GlWindowWin32::swapBuffers(), and vrj::GlWindowOSX::swapBuffers().
00093 { 00094 mSwapCount++; 00095 }
| virtual void vrj::GlWindow::checkEvents | ( | ) | [inline, virtual] |
Handles any window events that have occured.
Reimplemented in vrj::GlWindowWin32, and vrj::GlWindowXWin.
Definition at line 138 of file GlWindow.h.
| void vrj::GlWindow::finishSetup | ( | ) | [virtual] |
Complete any setup that is needed after open.
Definition at line 100 of file GlWindow.cpp.
References mWindowIsOpen.
00101 { 00102 vprASSERT(mWindowIsOpen && "Pre-condition of being open failed"); 00103 00104 // --- Setup any attached simulator that is needed --- // 00105 // XXX: This is where we used to set the keyboard proxy for the simulator 00106 // this needs to be customized now since we do not acutally have a device here any more 00107 // Ideas: - look up device based on registry 00108 // - Do something else??? 00109 /* 00110 Viewport* viewport(NULL); 00111 SimViewport* sim_vp(NULL); 00112 unsigned num_vps = mVrjDisplay->getNumViewports(); 00113 for(unsigned vp_num=0; vp_num < num_vps; vp_num++) 00114 { 00115 viewport = mVrjDisplay->getViewport(vp_num); 00116 if(viewport->isSimulator()) 00117 { 00118 sim_vp = dynamic_cast<SimViewport*>(viewport); 00119 vprASSERT(NULL != sim_vp && "isSimulator lied"); 00120 00121 DrawSimInterface* draw_sim = sim_vp->getDrawSimInterface(); 00122 GlSimInterface* gl_draw_sim = dynamic_cast<GlSimInterface*>(draw_sim); 00123 if(NULL != gl_draw_sim) 00124 { 00125 // Setup the simulator 00126 // - Get the keyboard/mouse device 00127 // - Register a proxy that we will use 00128 // - Make device interface for that proxy 00129 // - Intialize the simulator 00130 vprASSERT(mIsEventSource && "Tried to use simulator with a non-keyboard enabled GL window. Bad programmer."); 00131 gadget::EventWindow* kb_dev = dynamic_cast<gadget::EventWindow*>(this); 00132 gadget::Input* input_dev = dynamic_cast<gadget::Input*>(this); 00133 vprASSERT((kb_dev != NULL) && (input_dev != NULL) && "Failed to cast glWindow impl to a gadget::EventWindow"); 00134 std::string kb_dev_name = input_dev->getInstanceName(); 00135 vprASSERT( gadget::InputManager::instance()->getDevice(kb_dev_name) != NULL); 00136 00137 gadget::EventWindowProxy* kb_proxy = new gadget::EventWindowProxy; 00138 kb_proxy->set(kb_dev_name, kb_dev); 00139 00140 std::string kb_proxy_name("GlWin-Sim-EventWindow-"); 00141 kb_proxy_name += kb_dev_name; 00142 kb_proxy_name += std::string("-Proxy"); 00143 kb_proxy->setName(kb_proxy_name); 00144 bool add_success = gadget::InputManager::instance()->addProxy(kb_proxy); 00145 00146 if ( ! add_success ) 00147 { 00148 vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL) 00149 << clrOutBOLD(clrYELLOW, "WARNING") 00150 << ": [vrj::GlWindow::finishSetup()] Failed to add the " 00151 << "keyboard/mouse proxy. Check for a unique name." 00152 << std::endl << vprDEBUG_FLUSH; 00153 vprASSERT(false && "Failed to add sim wind kb proxy: Check for unique name"); 00154 } 00155 else 00156 { 00157 gadget::EventWindowInterface kb_interface; 00158 kb_interface.setProxy(kb_proxy); 00159 gl_draw_sim->setEventWindow(kb_interface); // Initialize the simulator 00160 } 00161 } 00162 else 00163 { 00164 vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CRITICAL_LVL) 00165 << clrOutBOLD(clrRED, "ERROR") 00166 << ": [vrj::GlWindow::finishSetup()] You configured a simulator " 00167 << "viewport, but I cannot find a DrawSimInterface for it.\n" 00168 << vprDEBUG_FLUSH; 00169 vprDEBUG_CONT(vrjDBG_DRAW_MGR, vprDBG_CRITICAL_LVL) 00170 << "Check your configuration for missing information.\n" 00171 << vprDEBUG_FLUSH; 00172 vprASSERT(false && "You configured a simulator viewport, but I cannot find a DrawSimInterface for it"); 00173 } 00174 } 00175 } 00176 */ 00177 }
| void vrj::GlWindow::setProjection | ( | vrj::Projection * | proj | ) |
Sets the projection matrix for this window to proj.
Definition at line 214 of file GlWindow.cpp.
References vrj::Frustum::frust, vrj::Projection::getFrustum(), vrj::Projection::getViewMatrix(), mWindowIsOpen, vrj::Frustum::VJ_BOTTOM, vrj::Frustum::VJ_FAR, vrj::Frustum::VJ_LEFT, vrj::Frustum::VJ_NEAR, vrj::Frustum::VJ_RIGHT, vrj::Frustum::VJ_TOP, and vrjDBG_DRAW_MGR().
00215 { 00216 if (!mWindowIsOpen) 00217 { 00218 return; 00219 } 00220 00221 const float* frust = proj->getFrustum().frust; 00222 00223 vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_HEX_LVL) << "---- Frustum ----\n" 00224 << proj->getFrustum().frust << std::endl 00225 << vprDEBUG_FLUSH; 00226 00227 // --- Set up the projection --- // 00228 glMatrixMode(GL_PROJECTION); 00229 { 00230 glLoadIdentity(); // Load identity matrix 00231 glFrustum(frust[Frustum::VJ_LEFT],frust[Frustum::VJ_RIGHT], 00232 frust[Frustum::VJ_BOTTOM],frust[Frustum::VJ_TOP], 00233 frust[Frustum::VJ_NEAR],frust[Frustum::VJ_FAR]); 00234 #ifdef USE_PROJECTION_MATRIX 00235 // Set camera rotation and position 00236 glMultMatrixf(proj->getViewMatrix().mData); 00237 #endif 00238 } 00239 glMatrixMode(GL_MODELVIEW); 00240 #ifndef USE_PROJECTION_MATRIX 00241 // Set camera rotation and position 00242 glLoadIdentity(); 00243 glMultMatrixf(proj->getViewMatrix().mData); 00244 #endif 00245 }
| void vrj::GlWindow::setLeftEyeProjection | ( | ) |
Sets the projection matrix for this window to draw the left eye frame.
If the window is in stereo, it changes to the left buffer.
| void vrj::GlWindow::setRightEyeProjection | ( | ) |
Sets the projection matrix for this window to draw the right eye frame.
If the window is in stereo, it changes to the right buffer.
| void vrj::GlWindow::setViewBuffer | ( | vrj::Viewport::View | view | ) |
Sets the view buffer for the window (issues glDrawBuffer command).
Definition at line 198 of file GlWindow.cpp.
References isStereo(), vrj::Viewport::LEFT_EYE, and vrj::Viewport::RIGHT_EYE.
00199 { 00200 if(!isStereo()) 00201 { 00202 glDrawBuffer(GL_BACK); 00203 } 00204 else if(Viewport::LEFT_EYE == view) 00205 { 00206 glDrawBuffer(GL_BACK_LEFT); 00207 } 00208 else if(Viewport::RIGHT_EYE == view) 00209 { 00210 glDrawBuffer(GL_BACK_RIGHT); 00211 } 00212 }
| void vrj::GlWindow::setViewport | ( | float | xo, | |
| float | yo, | |||
| float | xSize, | |||
| float | ySize | |||
| ) |
Sets the viewport in the GL window based on float values.
| xo | X-coordinate for the viewport origin. | |
| yo | Y-coordinate for the viewport origin. | |
| xSize | Width of the viewport. | |
| ySize | Height of the viewport. |
Definition at line 185 of file GlWindow.cpp.
References mWindowHeight, and mWindowWidth.
00186 { 00187 vprASSERT( ((xo+xSize) <= 1.0f) && "X viewport sizes are out of range"); 00188 vprASSERT( ((yo+ySize) <= 1.0f) && "Y viewport sizes are out of range"); 00189 00190 unsigned ll_x = unsigned(xo * float(mWindowWidth)); 00191 unsigned ll_y = unsigned(yo * float(mWindowHeight)); 00192 unsigned x_size = unsigned(xSize * float(mWindowWidth)); 00193 unsigned y_size = unsigned(ySize * float(mWindowHeight)); 00194 00195 glViewport(ll_x, ll_y, x_size, y_size); 00196 }
| void vrj::GlWindow::updateViewport | ( | ) |
Updates the viewport and does any viewport cleaning.
Definition at line 179 of file GlWindow.cpp.
References mWindowHeight, mWindowWidth, and setDirtyViewport().
00180 { 00181 glViewport(0, 0, mWindowWidth, mWindowHeight); 00182 setDirtyViewport(false); 00183 }
| bool vrj::GlWindow::hasDirtyContext | ( | ) | const [inline] |
Is the context dirty?
Definition at line 183 of file GlWindow.h.
00184 { 00185 return mDirtyContext; 00186 }
| void vrj::GlWindow::setDirtyContext | ( | bool | val = true |
) | [inline] |
Sets the dirty bit for the context.
Definition at line 189 of file GlWindow.h.
00190 { 00191 mDirtyContext = val; 00192 }
| bool vrj::GlWindow::hasDirtyViewport | ( | ) | const [inline] |
Is the viewport dirty?
Definition at line 195 of file GlWindow.h.
00196 { 00197 return mDirtyViewport; 00198 }
| void vrj::GlWindow::setDirtyViewport | ( | bool | val = true |
) | [inline] |
Sets the dirty bit for the viewport.
Definition at line 201 of file GlWindow.h.
Referenced by vrj::GlWindowXWin::checkEvents(), vrj::GlWindowXWin::processEvent(), vrj::GlWindowWin32::sizeChanged(), and updateViewport().
00202 { 00203 mDirtyViewport = val; 00204 }
| bool vrj::GlWindow::isOpen | ( | ) | const [inline] |
Queries wether the window is open.
Definition at line 210 of file GlWindow.h.
00211 { 00212 return mWindowIsOpen; 00213 }
| bool vrj::GlWindow::isStereo | ( | ) | const [inline] |
Queries wether the window is in stereo.
Definition at line 219 of file GlWindow.h.
Referenced by setViewBuffer().
00220 { 00221 return mInStereo; 00222 }
| bool vrj::GlWindow::isEventSource | ( | ) | const [inline] |
| vrj::Display* vrj::GlWindow::getDisplay | ( | ) | [inline] |
Definition at line 229 of file GlWindow.h.
Referenced by vrj::GlDrawManager::addDisplay(), and vrj::GlDrawManager::removeDisplay().
00230 { 00231 return mVrjDisplay; 00232 }
| int vrj::GlWindow::getId | ( | ) | const [inline] |
Definition at line 237 of file GlWindow.h.
00238 { 00239 return mWindowId; 00240 }
| void vrj::GlWindow::updateOriginSize | ( | const int | originX, | |
| const int | originY, | |||
| const int | width, | |||
| const int | height | |||
| ) | [inline] |
Called by event function to update size info.
Definition at line 244 of file GlWindow.h.
Referenced by vrj::GlWindowXWin::checkEvents(), vrj::GlWindowXWin::processEvent(), and vrj::GlWindowWin32::sizeChanged().
00246 { 00247 mOriginX = originX; 00248 mOriginY = originY; 00249 mWindowWidth = width; 00250 mWindowHeight = height; 00251 00252 // Update the display configuration 00253 mVrjDisplay->setOriginAndSize(originX, originY, width, height); 00254 }
| void vrj::GlWindow::getOriginSize | ( | int & | originX, | |
| int & | originY, | |||
| int & | width, | |||
| int & | height | |||
| ) | const [inline] |
Returns the origin and size of the current window.
Definition at line 257 of file GlWindow.h.
Referenced by vrj::OsgApp::draw().
00259 { 00260 originX = mOriginX; 00261 originY = mOriginY; 00262 width = mWindowWidth; 00263 height = mWindowHeight; 00264 }
| vpr::Uint64 vrj::GlWindow::getSwapCount | ( | ) | [inline] |
| std::ostream& operator<< | ( | std::ostream & | out, | |
| GlWindow & | win | |||
| ) | [friend] |
Definition at line 254 of file GlWindow.cpp.
00255 { 00256 vprASSERT(win.mVrjDisplay != NULL); 00257 00258 //out << "-------- GlWindow --------" << endl; 00259 out << "Open: " << (win.mWindowIsOpen ? "Yes" : "No") << std::endl; 00260 out << "Stereo: " << (win.mInStereo ? "Yes" : "No") << std::endl; 00261 out << "Swap Count: " << win.mSwapCount << std::endl; 00262 out << "Display Info:\n" << *(win.mVrjDisplay) << std::endl; 00263 return out; 00264 }
vrj::Display* vrj::GlWindow::mVrjDisplay [protected] |
We store a pointer to the display that we're created from in order to config and to get the viewing transforms from.
Definition at line 278 of file GlWindow.h.
Referenced by configWindow(), vrj::GlWindowXWin::getGlxVisInfo(), vrj::operator<<(), and vrj::GlWindowWin32::setPixelFormat().
vpr::Uint64 vrj::GlWindow::mSwapCount [protected] |
The number of times that swapBuffers() has been called.
Definition at line 280 of file GlWindow.h.
Referenced by vrj::operator<<(), and swapBuffers().
bool vrj::GlWindow::mDirtyContext [protected] |
The context is dirty.
We need to (re)initialize it next draw.
Definition at line 282 of file GlWindow.h.
bool vrj::GlWindow::mDirtyViewport [protected] |
The GL window setup (viewport, etc) is dirty and needs to be reinited.
Definition at line 283 of file GlWindow.h.
bool vrj::GlWindow::mInStereo [protected] |
Whether the display is actually in stereo if we wanted a stereo display but couldn't open it we fall back to mono, and this will be false.
Definition at line 289 of file GlWindow.h.
Referenced by vrj::GlWindowXWin::getGlxVisInfo(), vrj::operator<<(), and vrj::GlWindowWin32::setPixelFormat().
bool vrj::GlWindow::mHasBorder [protected] |
Do we have a border?
Definition at line 291 of file GlWindow.h.
Referenced by configWindow(), vrj::GlWindowXWin::open(), and vrj::GlWindowWin32::open().
bool vrj::GlWindow::mHideMouse [protected] |
Should we hide the mouse pointer?
Definition at line 292 of file GlWindow.h.
Referenced by configWindow(), vrj::GlWindowXWin::open(), and vrj::GlWindowWin32::open().
bool vrj::GlWindow::mWindowIsOpen [protected] |
Is the window open?
Definition at line 293 of file GlWindow.h.
Referenced by vrj::GlWindowXWin::close(), vrj::GlWindowWin32::close(), finishSetup(), vrj::GlWindowXWin::GlWindowXWin(), vrj::GlWindowXWin::makeCurrent(), vrj::GlWindowXWin::open(), vrj::GlWindowWin32::open(), vrj::GlWindowOSX::open(), vrj::operator<<(), and setProjection().
int vrj::GlWindow::mWindowWidth [protected] |
Definition at line 294 of file GlWindow.h.
Referenced by configWindow(), vrj::GlWindowXWin::GlWindowXWin(), vrj::GlWindowXWin::open(), vrj::GlWindowWin32::open(), vrj::GlWindowOSX::open(), setViewport(), and updateViewport().
int vrj::GlWindow::mWindowHeight [protected] |
Definition at line 295 of file GlWindow.h.
Referenced by configWindow(), vrj::GlWindowXWin::GlWindowXWin(), vrj::GlWindowXWin::open(), vrj::GlWindowWin32::open(), vrj::GlWindowOSX::open(), setViewport(), and updateViewport().
int vrj::GlWindow::mOriginX [protected] |
X component of the lower left-hand corner of the window.
Definition at line 296 of file GlWindow.h.
Referenced by vrj::GlWindowXWin::checkEvents(), configWindow(), vrj::GlWindowXWin::open(), vrj::GlWindowWin32::open(), vrj::GlWindowOSX::open(), vrj::GlWindowXWin::processEvent(), and vrj::GlWindowWin32::sizeChanged().
int vrj::GlWindow::mOriginY [protected] |
Y component of the lower left-hand corner of the window.
Definition at line 297 of file GlWindow.h.
Referenced by vrj::GlWindowXWin::checkEvents(), configWindow(), vrj::GlWindowXWin::open(), vrj::GlWindowWin32::open(), vrj::GlWindowOSX::open(), vrj::GlWindowXWin::processEvent(), and vrj::GlWindowWin32::sizeChanged().
int vrj::GlWindow::mWindowId [protected] |
bool vrj::GlWindow::mIsEventSource [protected] |
Should we act as an event source too?
Definition at line 299 of file GlWindow.h.
Referenced by vrj::GlWindowXWin::close(), vrj::GlWindowOSX::configWindow(), and vrj::GlWindowOSX::open().
1.5.1