Commit f3a79950 authored by Clinton Stimpson's avatar Clinton Stimpson

ENH: Add vtkGenericOpenGLRenderWindow class.

This allows one to use their own drawable/context with VTK.
To effectively use this class, one must add observers for events as documented.
parent 6d5299cd
......@@ -359,6 +359,9 @@ public:
LoadStateEvent,
SaveStateEvent,
StateChangedEvent,
WindowMakeCurrentEvent,
WindowIsCurrentEvent,
WindowFrameEvent,
UserEvent = 1000
};
//ETX
......
......@@ -587,6 +587,10 @@ IF(VTK_USE_GL2PS)
ENDIF(VTK_USE_SYSTEM_GL2PS)
ENDIF(VTK_USE_GL2PS)
IF(OPENGL_gl_LIBRARY)
SET(KitOpenGL_SRCS ${KitOpenGL_SRCS} vtkGenericOpenGLRenderWindow.cxx)
ENDIF(OPENGL_gl_LIBRARY)
IF (WIN32)
IF(VTK_USE_X)
IF (OPENGL_gl_LIBRARY)
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkGenericRenderWindowInteractor.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkGenericOpenGLRenderWindow.h"
#include "vtkObjectFactory.h"
#include "vtkRendererCollection.h"
#include "vtkOpenGLRenderer.h"
#include "vtkCommand.h"
vtkStandardNewMacro(vtkGenericOpenGLRenderWindow);
vtkGenericOpenGLRenderWindow::vtkGenericOpenGLRenderWindow()
{
this->WindowId = NULL;
}
vtkGenericOpenGLRenderWindow::~vtkGenericOpenGLRenderWindow()
{
this->Finalize();
vtkRenderer* ren;
this->Renderers->InitTraversal();
for ( ren = vtkOpenGLRenderer::SafeDownCast(this->Renderers->GetNextItemAsObject());
ren != NULL;
ren = vtkOpenGLRenderer::SafeDownCast(this->Renderers->GetNextItemAsObject()))
{
ren->SetRenderWindow(NULL);
}
}
void vtkGenericOpenGLRenderWindow::SetFrontBuffer(unsigned int b)
{
this->FrontBuffer = b;
}
void vtkGenericOpenGLRenderWindow::SetFrontLeftBuffer(unsigned int b)
{
this->FrontLeftBuffer = b;
}
void vtkGenericOpenGLRenderWindow::SetFrontRightBuffer(unsigned int b)
{
this->FrontRightBuffer = b;
}
void vtkGenericOpenGLRenderWindow::SetBackBuffer(unsigned int b)
{
this->BackBuffer = b;
}
void vtkGenericOpenGLRenderWindow::SetBackLeftBuffer(unsigned int b)
{
this->BackLeftBuffer = b;
}
void vtkGenericOpenGLRenderWindow::SetBackRightBuffer(unsigned int b)
{
this->BackRightBuffer = b;
}
void vtkGenericOpenGLRenderWindow::Render()
{
// save/restore state as well as set up the state to what VTK assumes
glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
glPushAttrib(GL_ALL_ATTRIB_BITS);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ZERO);
glDepthFunc( GL_LEQUAL );
// OpenGLInit() has more ... should fix this so we can call some code in vtkOpenGLRenderWindow to re-establish
// the OpenGL state that VTK wants.
this->Superclass::Render();
glPopClientAttrib();
glPopAttrib();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
void vtkGenericOpenGLRenderWindow::Finalize()
{
// tell each of the renderers that this render window/graphics context
// is being removed (the RendererCollection is removed by vtkRenderWindow's
// destructor)
vtkRenderer* ren;
this->Renderers->InitTraversal();
for ( ren = vtkOpenGLRenderer::SafeDownCast(this->Renderers->GetNextItemAsObject());
ren != NULL;
ren = vtkOpenGLRenderer::SafeDownCast(this->Renderers->GetNextItemAsObject()) )
{
ren->SetRenderWindow(NULL);
ren->SetRenderWindow(this);
}
}
void vtkGenericOpenGLRenderWindow::Frame()
{
this->InvokeEvent(vtkCommand::WindowFrameEvent, NULL);
}
void vtkGenericOpenGLRenderWindow::MakeCurrent()
{
this->InvokeEvent(vtkCommand::WindowMakeCurrentEvent, NULL);
}
bool vtkGenericOpenGLRenderWindow::IsCurrent()
{
int current = 0;
this->InvokeEvent(vtkCommand::WindowIsCurrentEvent, &current);
return current;
}
void vtkGenericOpenGLRenderWindow::SetWindowId(void* w)
{
// user settable window id
this->WindowId = w;
}
void* vtkGenericOpenGLRenderWindow::GetGenericWindowId()
{
return this->WindowId;
}
void vtkGenericOpenGLRenderWindow::SetDisplayId(void*)
{
}
void vtkGenericOpenGLRenderWindow::SetParentId(void*)
{
}
void* vtkGenericOpenGLRenderWindow::GetGenericDisplayId()
{
return NULL;
}
void* vtkGenericOpenGLRenderWindow::GetGenericParentId()
{
return NULL;
}
void* vtkGenericOpenGLRenderWindow::GetGenericContext()
{
return NULL;
}
void* vtkGenericOpenGLRenderWindow::GetGenericDrawable()
{
return NULL;
}
void vtkGenericOpenGLRenderWindow::SetWindowInfo(char*)
{
}
void vtkGenericOpenGLRenderWindow::SetParentInfo(char*)
{
}
int* vtkGenericOpenGLRenderWindow::GetScreenSize()
{
return NULL;
}
void vtkGenericOpenGLRenderWindow::Start()
{
}
void vtkGenericOpenGLRenderWindow::HideCursor()
{
}
void vtkGenericOpenGLRenderWindow::ShowCursor()
{
}
void vtkGenericOpenGLRenderWindow::SetFullScreen(int)
{
}
void vtkGenericOpenGLRenderWindow::WindowRemap()
{
}
int vtkGenericOpenGLRenderWindow::GetEventPending()
{
return 0;
}
void vtkGenericOpenGLRenderWindow::SetNextWindowId(void*)
{
}
void vtkGenericOpenGLRenderWindow::SetNextWindowInfo(char*)
{
}
void vtkGenericOpenGLRenderWindow::CreateAWindow()
{
}
void vtkGenericOpenGLRenderWindow::DestroyWindow()
{
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkRenderWindow.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkGenericOpenGLRenderWindow - platform independent render window
// .SECTION Description
// vtkGenericOpenGLRenderWindow provides a skeleton for implementing a render window
// using one's own OpenGL context and drawable.
// To be effective, one must register an observer for WindowMakeCurrentEvent,
// WindowIsCurrentEvent and WindowFrameEvent. When this class sends a WindowIsCurrentEvent,
// the call data is an int* which one can use to return whether the context is current.
#ifndef vtkGenericOpenGLRenderWindow_hpp
#define vtkGenericOpenGLRenderWindow_hpp
#include "vtkOpenGLRenderWindow.h"
class vtkGenericOpenGLRenderWindow : public vtkOpenGLRenderWindow
{
public:
static vtkGenericOpenGLRenderWindow* New();
vtkTypeMacro(vtkGenericOpenGLRenderWindow, vtkOpenGLRenderWindow);
protected:
vtkGenericOpenGLRenderWindow();
~vtkGenericOpenGLRenderWindow();
public:
//! Cleans up graphics resources allocated in the context for this VTK scene.
void Finalize();
//! Specific implementation for Render() to save/restore the OpenGL state.
void Render();
//! flush the pending drawing operations
//! Class user may to watch for WindowFrameEvent and act on it
void Frame();
//! Makes the context current. It is the class user's
//! responsibility to watch for WindowMakeCurrentEvent and set it current.
void MakeCurrent();
//! Returns if the context is current. It is the class user's
//! responsibility to watch for WindowIsCurrentEvent and set the integer flag
//! passed through the call data parameter.
bool IsCurrent();
//! Set the window id. This does nothing but store the value.
void SetWindowId(void*);
//! Get the window id
void* GetGenericWindowId();
// {@
//! set the drawing buffers to use
void SetFrontBuffer(unsigned int);
void SetFrontLeftBuffer(unsigned int);
void SetFrontRightBuffer(unsigned int);
void SetBackBuffer(unsigned int);
void SetBackLeftBuffer(unsigned int);
void SetBackRightBuffer(unsigned int);
// }@
// {@
//! does nothing
void SetDisplayId(void*);
void SetParentId(void*);
void* GetGenericDisplayId();
void* GetGenericParentId();
void* GetGenericContext();
void* GetGenericDrawable();
void SetWindowInfo(char*);
void SetParentInfo(char*);
int* GetScreenSize();
void Start();
void HideCursor();
void ShowCursor();
void SetFullScreen(int);
void WindowRemap();
int GetEventPending();
void SetNextWindowId(void*);
void SetNextWindowInfo(char*);
void CreateAWindow();
void DestroyWindow();
// }@
protected:
void* WindowId;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment