VRUT::GLWindow Class Reference

GL window class. More...

#include <glwindow.h>

List of all members.

Public Member Functions

 GLWindow (wxWindow *parent, RenderModule *_module, RENDER_WINDOW_ID winID, wxPoint position=wxDefaultPosition, wxSize size=wxDefaultSize, int *attribList=(int *) NULL, wxString title=wxT("GLWindow"))
 Class constructor.
virtual ~GLWindow ()
 Class destructor.
RENDER_WINDOW_ID GetID () const
 Get window ID.
void Deinitialize ()
 Deinitialize window and associated module's data on window close.
void SetRenderManager (RenderManager *_renderManager)
 Set RenderManager pointer - to inform manager when window is destroyed.
RenderModuleGetRenderModule () const
 Get associated render module.
bool CreateGLContext ()
 Create GL context.
wxGLContext * GetGLContext () const
 Get associated GL context.

Protected Member Functions

 GLWindow ()
 Class constructor.
void draw ()
 Update window contents.
void toggleFullscreen ()
 Switch to/from fullscreen.
void setFullscreen (bool fullscreen)
 Enable/disable fullscreen.
void onPaint (wxPaintEvent &WXUNUSED(evt))
 On paint event method.
void onResize (wxSizeEvent &evt)
 On window resize event method.
void onKeyEvent (wxKeyEvent &evt)
 Set window ID and propagate key event to event handler.
void onMouseEvent (wxMouseEvent &evt)
 Set window ID and propagate mouse event to event handler.
void onCommandEvent (wxCommandEvent &evt)
 On any command event.

Protected Attributes

RENDER_WINDOW_ID windowID
 Assigned render window ID.
RenderModulemodule
 Module implementing drawing method.
wxWindow * fsWindow
 Alternative parent for fullscreen view.
wxGLContext * glContext
 Gl context associated with window.
FrameRate frameRate
 Framerate counter.
int nbPageIndex
 Page index in render windows notebook - auxiliary for fullscreen.
unsigned beingReparented
 Prevents GTK bad behaviour when reparenting GLCanvas - auxiliary for fullscreen.

Private Attributes

RenderManagerrenderManager
 Pointer to RenderManager.

Friends

class RenderManager


Detailed Description

GL window class.

Definition at line 26 of file glwindow.h.


Constructor & Destructor Documentation

GLWindow::GLWindow (  )  [protected]

Class constructor.

Definition at line 23 of file glwindow.cpp.

00024               : wxGLCanvas((wxWindow *)NULL, wxID_ANY, (int *)NULL)
00025 {
00026        module = (RenderModule *)NULL;
00027        renderManager = (RenderManager *)NULL;
00028        glContext = (wxGLContext *)NULL;
00029        fsWindow = (wxWindow *)NULL;
00030        nbPageIndex = wxNOT_FOUND;
00031        beingReparented = 0;
00032 }

GLWindow::GLWindow ( wxWindow *  parent,
RenderModule _module,
RENDER_WINDOW_ID  winID,
wxPoint  position = wxDefaultPosition,
wxSize  size = wxDefaultSize,
int *  attribList = (int *)NULL,
wxString  title = wxT("GLWindow") 
)

Class constructor.

Definition at line 35 of file glwindow.cpp.

00042               : wxGLCanvas(parent, wxID_ANY, attribList, position, size, 0, title)
00043 {
00044        windowID = winID;
00045        module = _module;
00046        renderManager = (RenderManager *)NULL;
00047        glContext = (wxGLContext *)NULL;
00048        fsWindow = (wxWindow *)NULL;
00049        nbPageIndex = wxNOT_FOUND;
00050        beingReparented = 0;
00051 
00052        KERNEL->GetMessageSink()->RegisterListener(this, Event::EVT_RENDER_FULLSCREEN_TOGGLE);
00053        KERNEL->GetMessageSink()->RegisterListener(this, Event::EVT_RENDER_FULLSCREEN_SET);
00054        Connect(wxID_ANY, Event::EVT_RENDER_FULLSCREEN_TOGGLE, wxCommandEventHandler(GLWindow::onCommandEvent), (wxObject *)NULL, this);
00055        Connect(wxID_ANY, Event::EVT_RENDER_FULLSCREEN_SET, wxCommandEventHandler(GLWindow::onCommandEvent), (wxObject *)NULL, this);
00056 
00057        Connect(wxID_ANY, wxEVT_PAINT, wxPaintEventHandler(GLWindow::onPaint), (wxObject *)NULL, this);
00058        Connect(wxID_ANY, wxEVT_SIZE, wxSizeEventHandler(GLWindow::onResize), (wxObject *)NULL, this);
00059        Connect(wxID_ANY, wxEVT_KEY_DOWN, wxKeyEventHandler(GLWindow::onKeyEvent), (wxObject *)NULL, this);
00060        Connect(wxID_ANY, wxEVT_KEY_UP, wxKeyEventHandler(GLWindow::onKeyEvent), (wxObject *)NULL, this);
00061 
00062        Connect(wxID_ANY, wxEVT_ENTER_WINDOW, wxMouseEventHandler(GLWindow::onMouseEvent), (wxObject *)NULL, this);
00063        Connect(wxID_ANY, wxEVT_LEAVE_WINDOW, wxMouseEventHandler(GLWindow::onMouseEvent), (wxObject *)NULL, this);
00064        Connect(wxID_ANY, wxEVT_LEFT_DOWN, wxMouseEventHandler(GLWindow::onMouseEvent), (wxObject *)NULL, this);
00065        Connect(wxID_ANY, wxEVT_LEFT_UP, wxMouseEventHandler(GLWindow::onMouseEvent), (wxObject *)NULL, this);
00066        Connect(wxID_ANY, wxEVT_LEFT_DCLICK, wxMouseEventHandler(GLWindow::onMouseEvent), (wxObject *)NULL, this);
00067        Connect(wxID_ANY, wxEVT_RIGHT_DOWN, wxMouseEventHandler(GLWindow::onMouseEvent), (wxObject *)NULL, this);
00068        Connect(wxID_ANY, wxEVT_RIGHT_UP, wxMouseEventHandler(GLWindow::onMouseEvent), (wxObject *)NULL, this);
00069        Connect(wxID_ANY, wxEVT_RIGHT_DCLICK, wxMouseEventHandler(GLWindow::onMouseEvent), (wxObject *)NULL, this);
00070        Connect(wxID_ANY, wxEVT_MIDDLE_DOWN, wxMouseEventHandler(GLWindow::onMouseEvent), (wxObject *)NULL, this);
00071        Connect(wxID_ANY, wxEVT_MIDDLE_UP, wxMouseEventHandler(GLWindow::onMouseEvent), (wxObject *)NULL, this);
00072        Connect(wxID_ANY, wxEVT_MIDDLE_DCLICK, wxMouseEventHandler(GLWindow::onMouseEvent), (wxObject *)NULL, this);
00073        Connect(wxID_ANY, wxEVT_MOTION, wxMouseEventHandler(GLWindow::onMouseEvent), (wxObject *)NULL, this);
00074        Connect(wxID_ANY, wxEVT_MOUSEWHEEL, wxMouseEventHandler(GLWindow::onMouseEvent), (wxObject *)NULL, this);
00075 }

GLWindow::~GLWindow (  )  [virtual]

Class destructor.

Let RenderManager know about our death

Definition at line 78 of file glwindow.cpp.

00079 {
00080        if (KERNEL && !KERNEL->IsExiting())
00081               KERNEL->GetMessageSink()->UnregisterListener(this);
00083        if (renderManager)
00084               renderManager->DestroyGLWindow(this);
00085        SAFE_DELETE(glContext);
00086 }


Member Function Documentation

void GLWindow::draw (  )  [protected]

Update window contents.

Skip first draw after fullscreen toggle and then redraw several times This fixes problem with reparenting in GTK and window update

Calling UpdateBVH here prevents allocating memory later in render module which could lead to bad behaviour if render module is unloaded before deallocating

Update camera params if camera changed

Update framerate

Definition at line 89 of file glwindow.cpp.

00090 {
00091        if (!IsShownOnScreen() || !module || !glContext || !KERNEL || KERNEL->IsExiting())
00092               return;
00093 
00096        if (beingReparented)
00097        {
00098               wxCommandEvent rndEvt = Event::GET_EVT_RENDER_UPDATE(module->GetSceneID());
00099               KERNEL->GetMessageSink()->PostEvent(rndEvt);
00100               --beingReparented;
00101               return;
00102        }
00103 
00104        Scene * scene = KERNEL->sceneManager->GetScene(module->GetSceneID());
00105        if (scene)
00106        {
00109               scene->UpdateBVH();
00111               int w = 0, h = 0;
00112               GetClientSize(&w, &h);
00113               scene->SetProjectionParams(module->GetCameraID(), w, h);
00114        }
00115 
00116        SetCurrent(*glContext);
00117 
00118        module->Draw();
00119        SwapBuffers();
00120        GLCHECKERROR;
00121 
00123        frameRate.IncFrame();
00124        wxCommandEvent evt = Event::GET_EVT_RENDER_FRAMERATE(windowID, int(frameRate.GetFPS() * 1000));
00125        KERNEL->GetMessageSink()->PostEvent(evt);
00126 }

void GLWindow::toggleFullscreen (  )  [protected]

Switch to/from fullscreen.

Definition at line 129 of file glwindow.cpp.

00130 {
00131        setFullscreen(!fsWindow);
00132 }

void GLWindow::setFullscreen ( bool  fullscreen  )  [protected]

Enable/disable fullscreen.

Definition at line 135 of file glwindow.cpp.

00136 {
00137        if (((fsWindow == (wxWindow *)NULL) == !fullscreen) ||
00138                beingReparented ||
00139                !IsShownOnScreen())
00140               return;
00141 
00142        wxAuiNotebook * renderNotebook = KERNEL->GetMainWindow()->GetRenderNotebook();
00143        if (fsWindow)
00144        {
00145               wxWindow * fsParent = GetParent();
00146               Reparent(fsWindow);
00147               renderNotebook->InsertPage(nbPageIndex, this, GetName(), true);
00148               SetFocus();
00149               fsParent->Destroy();
00150               fsWindow = (wxWindow *)NULL;
00151        }
00152        else
00153        {
00154               fsWindow = GetParent();
00155               nbPageIndex = renderNotebook->GetPageIndex(this);
00156               wxASSERT_MSG(nbPageIndex != wxNOT_FOUND, wxT("<GLWindow>Render window not found in notebook pages"));
00157               renderNotebook->RemovePage(nbPageIndex);
00158 
00159               wxFrame * frame = new wxFrame(GetParent(), wxID_ANY, GetName());
00160               frame->Connect(wxID_ANY, wxEVT_SIZE, wxSizeEventHandler(GLWindow::onResize), (wxObject *)NULL, this);
00161               Reparent(frame);
00162               frame->ShowFullScreen(true);
00163               SetFocus();
00164        }
00165        beingReparented = 10;
00166        KERNEL->GetMainWindow()->GetAUIManager()->Update();
00167 }

void GLWindow::onPaint ( wxPaintEvent &  WXUNUSEDevt  )  [protected]

On paint event method.

Definition at line 170 of file glwindow.cpp.

00171 {
00172        wxPaintDC(this);
00173        draw();
00174 }

void GLWindow::onResize ( wxSizeEvent &  evt  )  [protected]

On window resize event method.

Fix size if sent explicitly

Definition at line 177 of file glwindow.cpp.

00178 {
00179        int w = 0, h = 0;
00180        GetClientSize(&w, &h);
00181        if (module && module->GetCameraID() != NODE_ID_NONE)
00182        {
00183               Scene * scene = KERNEL->sceneManager->GetScene(module->GetSceneID());
00184               if (scene)
00185               {
00186                      NODE_ID camID = module->GetCameraID();
00187                      scene->WriteLock(camID);
00188                      scene->SetProjectionParams(camID, w, h);
00189                      scene->WriteUnlock(camID);
00190               }
00191        }
00193        evt.m_size = GetClientSize();
00194        evt.Skip();
00195 }

void GLWindow::onKeyEvent ( wxKeyEvent &  evt  )  [protected]

Set window ID and propagate key event to event handler.

Definition at line 198 of file glwindow.cpp.

00199 {
00200        if (!module || !KERNEL || KERNEL->IsExiting())
00201               return;
00202 
00203        evt.SetId(int(windowID));
00204        KERNEL->GetMessageSink()->ProcessEvent(evt);
00205        evt.Skip();
00206 
00207 #ifdef EVENT_DEBUG
00208        LOG(wxT("<GLWindow>key event"));
00209 #endif
00210 }

void GLWindow::onMouseEvent ( wxMouseEvent &  evt  )  [protected]

Set window ID and propagate mouse event to event handler.

Definition at line 213 of file glwindow.cpp.

00214 {
00215        if (module && KERNEL && !KERNEL->IsExiting())
00216        {
00217               evt.SetId(int(windowID));
00218               KERNEL->GetMessageSink()->ProcessEvent(evt);
00219        }
00220        evt.Skip();
00221 }

void GLWindow::onCommandEvent ( wxCommandEvent &  evt  )  [protected]

On any command event.

Definition at line 224 of file glwindow.cpp.

00225 {
00226        if (!module || !KERNEL || KERNEL->IsExiting())
00227               return;
00228 
00229        switch (evt.GetEventType())
00230        {
00231        case Event::EVT_RENDER_FULLSCREEN_TOGGLE:
00232               if (evt.GetId() == int(GetID()))
00233                      toggleFullscreen();
00234               break;
00235        case Event::EVT_RENDER_FULLSCREEN_SET:
00236               if (evt.GetId() == int(GetID()))
00237                      setFullscreen(evt.GetInt() != 0);
00238               break;
00239        }
00240 }

RENDER_WINDOW_ID VRUT::GLWindow::GetID (  )  const [inline]

Get window ID.

Definition at line 82 of file glwindow.h.

00083               {
00084                      return windowID;
00085               }

void GLWindow::Deinitialize (  ) 

Deinitialize window and associated module's data on window close.

Deinitialize render module and assert there will be no further attempt to render scene

Camera is binded to render window so it should be released now

Emulate EVT_PARAM_SET to set variable in module right away

Definition at line 243 of file glwindow.cpp.

00244 {
00245        wxCommandEvent ev = Event::GET_EVT_RENDER_WIN_CLOSED(int(windowID));
00246        KERNEL->GetMessageSink()->PostEvent(ev, true);
00248        if (module && glContext)
00249        {
00250               Scene * scene = KERNEL->sceneManager->GetScene(module->GetSceneID());
00251               if (scene)
00253                      scene->Remove(module->GetCameraID());
00254               SetCurrent(*glContext);
00255               module->Deinitialize();
00256 
00258               Parameter::ParameterIdentificator camPI(module->GetName(), wxT("cameraID"), module->GetID());
00259               wxCommandEvent ev1 = Event::GET_EVT_PARAM_SET(camPI, wxString::Format(wxT("%i"), NODE_ID_NONE));
00260               module->PostEvent(ev1, true);
00261               Parameter::ParameterIdentificator scenePI(module->GetName(), wxT("sceneID"), module->GetID());
00262               wxCommandEvent ev2 = Event::GET_EVT_PARAM_SET(scenePI, wxString::Format(wxT("%i"), SCENE_ID_NONE));
00263               module->PostEvent(ev2, true);
00264 
00265               module = (RenderModule *)NULL;
00266        }
00267 }

void VRUT::GLWindow::SetRenderManager ( RenderManager _renderManager  )  [inline]

Set RenderManager pointer - to inform manager when window is destroyed.

Definition at line 89 of file glwindow.h.

00090               {
00091                      renderManager = _renderManager;
00092               }

RenderModule* VRUT::GLWindow::GetRenderModule (  )  const [inline]

Get associated render module.

Definition at line 94 of file glwindow.h.

00095               {
00096                      return module;
00097               }

bool GLWindow::CreateGLContext (  ) 

Create GL context.

Definition at line 270 of file glwindow.cpp.

00271 {
00272        SAFE_DELETE(glContext);
00273        glContext = new wxGLContext(this);
00274        return glContext != (wxGLContext *)NULL;
00275 }

wxGLContext* VRUT::GLWindow::GetGLContext (  )  const [inline]

Get associated GL context.

Definition at line 103 of file glwindow.h.

00104               {
00105                      return glContext;
00106               }


Friends And Related Function Documentation

friend class RenderManager [friend]

Definition at line 108 of file glwindow.h.


Member Data Documentation

Pointer to RenderManager.

Definition at line 32 of file glwindow.h.

Assigned render window ID.

Definition at line 36 of file glwindow.h.

Module implementing drawing method.

Definition at line 38 of file glwindow.h.

wxWindow* VRUT::GLWindow::fsWindow [protected]

Alternative parent for fullscreen view.

Definition at line 40 of file glwindow.h.

wxGLContext* VRUT::GLWindow::glContext [protected]

Gl context associated with window.

Definition at line 42 of file glwindow.h.

Framerate counter.

Definition at line 44 of file glwindow.h.

int VRUT::GLWindow::nbPageIndex [protected]

Page index in render windows notebook - auxiliary for fullscreen.

Definition at line 46 of file glwindow.h.

unsigned VRUT::GLWindow::beingReparented [protected]

Prevents GTK bad behaviour when reparenting GLCanvas - auxiliary for fullscreen.

Definition at line 48 of file glwindow.h.


The documentation for this class was generated from the following files:

Generated on Tue Mar 10 14:41:43 2009 for VRUT by  doxygen 1.5.5