Commit ab600cb3 authored by Ken Martin's avatar Ken Martin

change how object factory is done

parent 3c2af931
......@@ -398,15 +398,6 @@ foreach(_override ${opengl_overrides})
vtk_add_override(vtk${_override} vtkOpenGL${_override})
endforeach()
# A crazy hack, Ken encouraged me to write, where we override the overrides
# when the option is set to see what the new OpenGL2 code does in all regression
# tests. Right now there is just one (the poly data mapper) with more to follow.
if(VTK_REPLACE_OPENGL_OVERRIDES)
set(vtk_module_vtkPolyDataMapper_override "vtkVBOPolyDataMapper")
set(vtk_module_vtkLight_override "vtkOpenGL2Light")
# set(vtk_module_vtkCamera_override "vtkOpenGL2Camera")
endif()
# Now we iterate and create that class file...
foreach(_class ${vtk_module_overrides})
set(_override ${vtk_module_${_class}_override})
......
# A hack to let us inject OpenGL2 as a dependency, and change overrides.
unset(_injectOpenGL2)
if(VTK_REPLACE_OPENGL_OVERRIDES)
set(_injectOpenGL2 vtkRenderingOpenGL2)
endif()
vtk_module(vtkRenderingOpenGL
GROUPS
Rendering
......@@ -13,7 +7,6 @@ vtk_module(vtkRenderingOpenGL
# These are likely to be removed soon - split Rendering/OpenGL further.
vtkImagingHybrid # For vtkSampleFunction
vtksys
${_injectOpenGL2}
COMPILE_DEPENDS
vtkParseOGLExt
vtkUtilitiesEncodeString
......
......@@ -18,8 +18,8 @@ set(Module_SRCS
vtkglShader.cxx
vtkglShaderProgram.cxx
vtkglTexture2D.cxx
vtkOpenGL2Camera.cxx
vtkOpenGL2Light.cxx
# vtkOpenGL2Camera.cxx
vtkVBOPolyDataMapper.cxx
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}ObjectFactory.cxx
)
......@@ -66,6 +66,26 @@ if(VTK_USE_X)
)
endif()
set_source_files_properties(
vtkRenderingOpenGL2ObjectFactory
WRAP_EXCLUDE
)
# A crazy hack, Marcus endorsed :-P, where we override the overrides
# when the option is set to see what the new OpenGL2 code does in all regression
# tests.
if(VTK_REPLACE_OPENGL_OVERRIDES)
set(opengl_overrides
Camera
Light
)
endif()
foreach(_override ${opengl_overrides})
vtk_add_override(vtk${_override} vtkOpenGL2${_override})
endforeach()
# Now we iterate and create that class file...
foreach(_class ${vtk_module_overrides})
set(_override ${vtk_module_${_class}_override})
......@@ -84,9 +104,10 @@ endforeach()
string(TOUPPER ${vtk-module} VTK-MODULE)
configure_file(${VTK_CMAKE_DIR}/vtkObjectFactory.h.in
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}ObjectFactory.h)
configure_file(${VTK_CMAKE_DIR}/vtkObjectFactory.cxx.in
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/vtkRenderingOpenGL2ObjectFactory.cxx.in
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}ObjectFactory.cxx)
vtk_module_library(${vtk-module} ${Module_SRCS})
target_link_libraries(${vtk-module}
LINK_PRIVATE ${GLEW_LIBRARY}
......
......@@ -41,7 +41,6 @@ int TestVBOPLYMapper(int argc, char *argv[])
renderWindow->SetSize(300, 300);
renderWindow->AddRenderer(renderer.Get());
renderer->AddActor(actor.Get());
vtkNew<vtkLightKit> lightKit;
lightKit->AddLightsToRenderer(renderer.Get());
......
......@@ -5,6 +5,7 @@ vtk_module(vtkRenderingOpenGL2
vtkRenderingCore
PRIVATE_DEPENDS
vtksys
vtkRenderingOpenGL
COMPILE_DEPENDS
vtkUtilitiesEncodeString
TEST_DEPENDS
......
/*=========================================================================
Program: Visualization Toolkit
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 "vtkOpenGL2Camera.h"
#include "vtkMatrix4x4.h"
#include "vtkObjectFactory.h"
#include "vtkRenderer.h"
#include "vtkOutputWindow.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLError.h"
#include "vtkgluPickMatrix.h"
#include "vtkOpenGL.h"
#include <math.h>
vtkStandardNewMacro(vtkOpenGL2Camera);
// Implement base class method.
void vtkOpenGL2Camera::Render(vtkRenderer *ren)
{
vtkOpenGLClearErrorMacro();
double aspect[2];
int lowerLeft[2];
int usize, vsize;
vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
vtkOpenGLRenderWindow *win = vtkOpenGLRenderWindow::SafeDownCast(ren->GetRenderWindow());
// find out if we should stereo render
this->Stereo = (ren->GetRenderWindow())->GetStereoRender();
ren->GetTiledSizeAndOrigin(&usize, &vsize, lowerLeft, lowerLeft+1);
// if were on a stereo renderer draw to special parts of screen
if (this->Stereo)
{
switch ((ren->GetRenderWindow())->GetStereoType())
{
case VTK_STEREO_CRYSTAL_EYES:
if (this->LeftEye)
{
if (ren->GetRenderWindow()->GetDoubleBuffer())
{
glDrawBuffer(static_cast<GLenum>(win->GetBackLeftBuffer()));
glReadBuffer(static_cast<GLenum>(win->GetBackLeftBuffer()));
}
else
{
glDrawBuffer(static_cast<GLenum>(win->GetFrontLeftBuffer()));
glReadBuffer(static_cast<GLenum>(win->GetFrontLeftBuffer()));
}
}
else
{
if (ren->GetRenderWindow()->GetDoubleBuffer())
{
glDrawBuffer(static_cast<GLenum>(win->GetBackRightBuffer()));
glReadBuffer(static_cast<GLenum>(win->GetBackRightBuffer()));
}
else
{
glDrawBuffer(static_cast<GLenum>(win->GetFrontRightBuffer()));
glReadBuffer(static_cast<GLenum>(win->GetFrontRightBuffer()));
}
}
break;
case VTK_STEREO_LEFT:
this->LeftEye = 1;
break;
case VTK_STEREO_RIGHT:
this->LeftEye = 0;
break;
default:
break;
}
}
else
{
if (ren->GetRenderWindow()->GetDoubleBuffer())
{
glDrawBuffer(static_cast<GLenum>(win->GetBackBuffer()));
// Reading back buffer means back left. see OpenGL spec.
// because one can write to two buffers at a time but can only read from
// one buffer at a time.
glReadBuffer(static_cast<GLenum>(win->GetBackBuffer()));
}
else
{
glDrawBuffer(static_cast<GLenum>(win->GetFrontBuffer()));
// Reading front buffer means front left. see OpenGL spec.
// because one can write to two buffers at a time but can only read from
// one buffer at a time.
glReadBuffer(static_cast<GLenum>(win->GetFrontBuffer()));
}
}
glViewport(lowerLeft[0], lowerLeft[1], usize, vsize);
glEnable(GL_SCISSOR_TEST);
glScissor(lowerLeft[0], lowerLeft[1], usize, vsize);
// some renderer subclasses may have more complicated computations for the
// aspect ratio. So take that into account by computing the difference
// between our simple aspect ratio and what the actual renderer is reporting.
ren->ComputeAspect();
ren->GetAspect(aspect);
double aspect2[2];
ren->vtkViewport::ComputeAspect();
ren->vtkViewport::GetAspect(aspect2);
double aspectModification = aspect[0] * aspect2[1] / (aspect[1] * aspect2[0]);
/*
glMatrixMode(GL_PROJECTION);
if (usize && vsize)
{
matrix->DeepCopy(this->GetProjectionTransformMatrix(
aspectModification * usize / vsize, -1, 1));
matrix->Transpose();
}
if (ren->GetIsPicking())
{
int size[2] = {usize, vsize};
glLoadIdentity();
vtkgluPickMatrix(ren->GetPickX(), ren->GetPickY(),
ren->GetPickWidth(), ren->GetPickHeight(),
lowerLeft, size);
glMultMatrixd(matrix->Element[0]);
}
else
{
// insert camera view transformation
glLoadMatrixd(matrix->Element[0]);
}
*/
if ((ren->GetRenderWindow())->GetErase() && ren->GetErase()
&& !ren->GetIsPicking())
{
ren->Clear();
}
matrix->Delete();
vtkOpenGLCheckErrorMacro("failed after Render");
}
//----------------------------------------------------------------------------
void vtkOpenGL2Camera::UpdateViewport(vtkRenderer *ren)
{
vtkOpenGLClearErrorMacro();
int lowerLeft[2];
int usize, vsize;
ren->GetTiledSizeAndOrigin(&usize, &vsize, lowerLeft, lowerLeft+1);
glViewport(lowerLeft[0], lowerLeft[1], usize, vsize);
glEnable(GL_SCISSOR_TEST);
glScissor(lowerLeft[0], lowerLeft[1], usize, vsize);
vtkOpenGLCheckErrorMacro("failed after UpdateViewport");
}
//----------------------------------------------------------------------------
void vtkOpenGL2Camera::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
/*=========================================================================
Program: Visualization Toolkit
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 vtkOpenGLCamera - OpenGL camera
// .SECTION Description
// vtkOpenGLCamera is a concrete implementation of the abstract class
// vtkCamera. vtkOpenGLCamera interfaces to the OpenGL rendering library.
#ifndef __vtkOpenGL2Camera_h
#define __vtkOpenGL2Camera_h
#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkCamera.h"
class vtkOpenGL2Renderer;
class VTKRENDERINGOPENGL2_EXPORT vtkOpenGL2Camera : public vtkCamera
{
public:
static vtkOpenGL2Camera *New();
vtkTypeMacro(vtkOpenGL2Camera, vtkCamera);
virtual void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Implement base class method.
void Render(vtkRenderer *ren);
void UpdateViewport(vtkRenderer *ren);
protected:
vtkOpenGL2Camera() {}
~vtkOpenGL2Camera() {}
private:
vtkOpenGL2Camera(const vtkOpenGL2Camera&); // Not implemented.
void operator=(const vtkOpenGL2Camera&); // Not implemented.
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: @vtk-module@ObjectFactory.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 "@vtk-module@ObjectFactory.h"
#include "vtkVersion.h"
#include "vtkObjectFactoryCollection.h"
// Include all of the classes we want to create overrides for.
@_vtk_override_includes@
vtkStandardNewMacro(@vtk-module@ObjectFactory)
// Now create the functions to create overrides with.
@_vtk_override_creates@
@vtk-module@ObjectFactory::@vtk-module@ObjectFactory()
{
@_vtk_override_do@
}
const char * @vtk-module@ObjectFactory::GetVTKSourceVersion()
{
return VTK_SOURCE_VERSION;
}
void @vtk-module@ObjectFactory::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
// Registration of object factories.
static unsigned int @vtk-module@Count;
@VTK-MODULE@_EXPORT void @vtk-module@_AutoInit_Construct()
{
if(++@vtk-module@Count == 1)
{
@vtk-module@ObjectFactory* factory = @vtk-module@ObjectFactory::New();
if (factory)
{
// for any factories that registered before we did,
// delete any common overrides from them so we win!
int numOverrides = factory->GetNumberOfOverrides();
vtkObjectFactoryCollection *ofc = vtkObjectFactory::GetRegisteredFactories();
vtkObjectFactory* ofactory;
vtkCollectionSimpleIterator osit;
for(ofc->InitTraversal(osit);
(ofactory = ofc->GetNextObjectFactory(osit));)
{
for (int i = 0; i < numOverrides; ++i)
{
ofactory->Disable(factory->GetClassOverrideName(i));
}
}
// vtkObjectFactory keeps a reference to the "factory",
vtkObjectFactory::RegisterFactory(factory);
factory->Delete();
}
}
}
@VTK-MODULE@_EXPORT void @vtk-module@_AutoInit_Destruct()
{
if(--@vtk-module@Count == 0)
{
// Do not call vtkObjectFactory::UnRegisterFactory because
// vtkObjectFactory.cxx statically unregisters all factories.
}
}
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