Commit 8bc98a02 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell

Made vtkRenderingOpenGL2 independent of vtkRenderingOpenGL

This required several classes to be copied over, they may not stay.
It also required me to port many calls from vtkgl to GLEW, and get
rid of checks for features in OpenGL 2.1 or less. The extension
manager has been removed, and its functionality replaced.

Change-Id: I60f8858a315a0e91c175aef6152ab57d26650cb4
parent a631132a
......@@ -7,16 +7,31 @@ if(WIN32 AND NOT BUILD_SHARED_LIBS)
add_definitions(-DGLEW_STATIC)
endif()
# Now we need to generate the object factory for this module. Create a list of
# overrides, and then generate the class that overrides those classes.
macro(vtk_add_override base override)
list(APPEND vtk_module_overrides ${base})
set(vtk_module_${base}_override ${override})
endmacro()
set(${vtk-module}_SYSTEM_INCLUDE_DIRS
${OPENGL_INCLUDE_DIR}
${GLEW_INCLUDE_DIRS})
# FIXME: The TDx support needs some refactoring before we can build it in a
# modular fashion, for now it must remain an option on vtkRenderingOpenGL.
option(VTK_USE_TDX "Use TDx interaction devices" OFF)
mark_as_advanced(VTK_USE_TDX)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/vtkTDxConfigure.h.in
${CMAKE_CURRENT_BINARY_DIR}/vtkTDxConfigure.h)
set(Module_SRCS
vtkglBufferObject.cxx
vtkglVBOHelper.cxx
vtkglShader.cxx
vtkglShaderProgram.cxx
vtkglVertexArrayObject.cxx
vtkFrameBufferObject.cxx
vtkOpenGL2Actor.cxx
vtkOpenGL2Camera.cxx
vtkOpenGL2ImageMapper.cxx
......@@ -32,9 +47,20 @@ set(Module_SRCS
vtkOpenGL2ShaderCache.cxx
vtkOpenGL2Texture.cxx
vtkOpenGL2TextureUnitManager.cxx
vtkPixelBufferObject.cxx
vtkRenderbuffer.cxx
vtkRenderPass.cxx
vtkRenderState.cxx
vtkTextureObject.cxx
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}ObjectFactory.cxx
)
set(${vtk-module}_HDRS
vtkOpenGL.h
${CMAKE_CURRENT_BINARY_DIR}/vtkTDxConfigure.h
${CMAKE_CURRENT_BINARY_DIR}/vtkOpenGLError.h
)
set(shader_files
# lighting in the VS
glsl/vtkglPolyData2DVS.glsl
......@@ -92,7 +118,6 @@ set_source_files_properties(
ABSTRACT
)
set_source_files_properties(
vtkRenderingOpenGL2ObjectFactory
WRAP_EXCLUDE
......@@ -203,6 +228,14 @@ VTK_CREATE_CREATE_FUNCTION(${_override})")
vtkObjectFactoryCreate${_override});")
endforeach()
# Detect and clear OpenGL errors. If not then other classes/user code
# may detect VTK's OpenGL errors and vice-versa.
set(VTK_REPORT_OPENGL_ERRORS ON CACHE BOOL "Enable OpenGL error check and report")
mark_as_advanced(VTK_REPORT_OPENGL_ERRORS)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/vtkOpenGLError.h.in
${CMAKE_CURRENT_BINARY_DIR}/vtkOpenGLError.h)
# Now lets create the object factory classes
string(TOUPPER ${vtk-module} VTK-MODULE)
configure_file(${VTK_CMAKE_DIR}/vtkObjectFactory.h.in
......
vtk_module(vtkRenderingOpenGL2
DEPENDS
vtkCommonExecutionModel
vtkRenderingOpenGL
IMPLEMENTS
vtkRenderingCore
PRIVATE_DEPENDS
......
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkFrameBufferObject.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 vtkFrameBufferObject - internal class which encapsulates OpenGL
// frame buffer object. Not to be used directly.
// .SECTION Description
// Encapsulates an OpenGL Frame Buffer Object.
// For use by vtkOpenGLFBORenderWindow, not to be used directly.
// Use vtkFrameBufferObject2 instead.
// .SECTION Caveats
// DON'T PLAY WITH IT YET.
// .SECTION See Also
// vtkFrameBufferObject2, vtkRenderbufferObject
#ifndef __vtkFrameBufferObject_h
#define __vtkFrameBufferObject_h
#include "vtkObject.h"
#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkSmartPointer.h" // needed for vtkSmartPointer.
#include "vtkWeakPointer.h" // needed for vtkWeakPointer.
//BTX
#include <vector> // for the lists of logical buffers.
//ETX
class vtkRenderWindow;
class vtkTextureObject;
class vtkRenderbuffer;
class vtkPixelBufferObject;
class vtkOpenGLRenderWindow;
class VTKRENDERINGOPENGL2_EXPORT vtkFrameBufferObject : public vtkObject
{
public:
static vtkFrameBufferObject* New();
vtkTypeMacro(vtkFrameBufferObject, vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Get/Set the context. Context must be a vtkOpenGLRenderWindow.
// This does not increase the reference count of the
// context to avoid reference loops.
// SetContext() may raise an error is the OpenGL context does not support the
// required OpenGL extensions.
void SetContext(vtkRenderWindow *context);
vtkRenderWindow *GetContext();
// Description:
// User must take care that width/height match the dimensions of
// the user defined texture attachments.
// This method makes the "active buffers" the buffers that will get drawn
// into by subsequent drawing calls.
// Note that this does not clear the render buffers i.e. no glClear() calls
// are made by either of these methods. It's up to the caller to clear the
// buffers if needed.
bool Start(int width, int height, bool shaderSupportsTextureInt);
bool StartNonOrtho(int width, int height, bool shaderSupportsTextureInt);
// Description:
// Renders a quad at the given location with pixel coordinates. This method
// is provided as a convenience, since we often render quads in a FBO.
// \pre positive_minX: minX>=0
// \pre increasing_x: minX<=maxX
// \pre valid_maxX: maxX<LastSize[0]
// \pre positive_minY: minY>=0
// \pre increasing_y: minY<=maxY
// \pre valid_maxY: maxY<LastSize[1]
void RenderQuad(int minX, int maxX, int minY, int maxY);
// Description:
// Make the draw frame buffer active (uses FRAMEBUFFER).
void Bind();
// Description:
// Restore the previous draw framebuffer if saved, else
// bind the default buffer.
void UnBind();
// Description:
// Choose the buffers to render into.
void SetActiveBuffer(unsigned int index)
{
this->SetActiveBuffers(1, &index);
}
// Description:
// User provided color buffers are attached by index
// to color buffers. This command lets you select which
// attachments are written to. See set color buffer.
// This call overwrites what the previous list of active
// buffers.
void SetActiveBuffers(int numbuffers, unsigned int indices[]);
// Description:
// Insert a color buffer into the list of available color buffers.
// 0 to NumberOfRenderTargets of these are attached to color attachments
// by index. See SetActiveBuffers to select them for writing.
// All user specified texture objects must match the FBO dimensions
// and must have been created by the time Start() gets called.
// If texture is a 3D texture, zslice identifies the zslice that will be
// attached to the color buffer.
// .SECTION Caveat
// Currently, 1D textures are not supported.
void SetColorBuffer(
unsigned int index,
vtkTextureObject *texture,
unsigned int zslice=0);
vtkTextureObject *GetColorBuffer(unsigned int index);
void RemoveColorBuffer(unsigned int index);
void RemoveAllColorBuffers();
// Description:
// Set the texture to use as depth buffer.
void SetDepthBuffer(vtkTextureObject *depthTexture);
void RemoveDepthBuffer();
// Description:
// If true, the frame buffer object will be initialized with a depth buffer.
// Initial value is true.
vtkSetMacro(DepthBufferNeeded,bool);
vtkGetMacro(DepthBufferNeeded,bool);
// Description:
// Set/Get the number of render targets to render into at once.
// Textures (user supplied or generated internally) are attached
// to color attachment 0 to NumberOfRenderTargets. You can use
// SetActiveBuffer to specify which of these are actually written to.
// If zero then all of the user provided color buffers are used.
void SetNumberOfRenderTargets(unsigned int);
vtkGetMacro(NumberOfRenderTargets,unsigned int);
// Description:
// Returns the maximum number of targets that can be rendered to at one time.
// This limits the active targets set by SetActiveTargets().
// The return value is valid only if GetContext is non-null.
unsigned int GetMaximumNumberOfActiveTargets();
// Description:
// Returns the maximum number of render targets available. This limits the
// available attachement points for SetColorAttachment().
// The return value is valid only if GetContext is non-null.
unsigned int GetMaximumNumberOfRenderTargets();
// Description:
// Dimensions in pixels of the framebuffer.
vtkGetVector2Macro(LastSize,int);
// Description:
// Returns if the context supports the required extensions.
// Extension will be loaded when the conetxt is set.
static bool IsSupported(vtkRenderWindow *renWin);
// Description:
// Validate the current FBO configuration (attachments, formats, etc)
// prints detected errors to vtkErrorMacro.
int CheckFrameBufferStatus(unsigned int mode);
//BTX
protected:
// Description:
// Load all necessary extensions.
static
bool LoadRequiredExtensions(vtkRenderWindow *renWin);
// gen buffer (occurs when context is set)
void CreateFBO();
// delete buffer (occurs during destruction or context swicth)
void DestroyFBO();
// create texture or renderbuffer and attach
// if user provided a texture just use that
// mode specifies DRAW or READ
void CreateDepthBuffer(int width, int height, unsigned int mode);
// create textures for each target and attach
// if user provided textures use those, if the user
// provides any then they need to provide all
// mode specifies DRAW or READ
void CreateColorBuffers(
int width,
int height,
unsigned int mode,
bool shaderSupportsTextureInt);
// detach and delete our reference(s)
void DestroyDepthBuffer();
void DestroyColorBuffers();
// glDrawBuffers
void ActivateBuffers();
// Description:
// Display all the attachments of the current framebuffer object.
void DisplayFrameBufferAttachments();
// Description:
// Display a given attachment for the current framebuffer object.
void DisplayFrameBufferAttachment(unsigned int uattachment);
// Description:
// Display the draw buffers.
void DisplayDrawBuffers();
// Description:
// Display the read buffer.
void DisplayReadBuffer();
// Description:
// Display any buffer (convert value into string).
void DisplayBuffer(int value);
vtkFrameBufferObject();
~vtkFrameBufferObject();
vtkWeakPointer<vtkRenderWindow> Context;
bool DepthBufferNeeded;
bool ColorBuffersDirty;
unsigned int FBOIndex;
int PreviousFBOIndex;
unsigned int DepthBuffer;
unsigned int NumberOfRenderTargets;
int LastSize[2];
std::vector<unsigned int> UserZSlices;
std::vector<vtkSmartPointer<vtkTextureObject> > UserColorBuffers;
std::vector<vtkSmartPointer<vtkTextureObject> > ColorBuffers;
std::vector<unsigned int> ActiveBuffers;
vtkSmartPointer<vtkTextureObject> UserDepthBuffer;
bool DepthBufferDirty;
private:
vtkFrameBufferObject(const vtkFrameBufferObject&); // Not implemented.
void operator=(const vtkFrameBufferObject&); // Not implemented.
//ETX
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOpenGL.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.
=========================================================================*/
#ifndef __vtkOpenGL_h
#define __vtkOpenGL_h
#include "vtkConfigure.h"
// To prevent gl.h to include glext.h provided by the system
#define GL_GLEXT_LEGACY
#if defined(__APPLE__) && (defined(VTK_USE_CARBON) || defined(VTK_USE_COCOA))
# include <OpenGL/gl.h> // Include OpenGL API.
#else
# include "vtkWindows.h" // Needed to include OpenGL header on Windows.
# include <GL/gl.h> // Include OpenGL API.
#endif
#endif
// VTK-HeaderTest-Exclude: vtkOpenGL.h
......@@ -17,10 +17,10 @@
#include "vtkMapper.h"
#include "vtkMatrix4x4.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkOpenGL2Renderer.h"
#include "vtkProperty.h"
#include "vtkOpenGLError.h"
#include "vtkRenderWindow.h"
#include "vtkOpenGL.h"
#include <math.h>
......
......@@ -19,7 +19,6 @@
#include "vtkOutputWindow.h"
#include "vtkOpenGL2RenderWindow.h"
#include "vtkOpenGLError.h"
#include "vtkgluPickMatrix.h"
#include "vtkOpenGL.h"
......
......@@ -14,13 +14,13 @@
=========================================================================*/
#include "vtkOpenGL2HardwareSelector.h"
#include <GL/glew.h>
#include "vtkObjectFactory.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkOpenGL2RenderWindow.h"
#include "vtkOpenGLExtensionManager.h"
#include "vtkgl.h"
#include "vtkOpenGLError.h"
#define ID_OFFSET 1
......@@ -49,22 +49,7 @@ public:
{
if (this->Context != context)
{
this->MultisampleSupport = false;
this->Context = vtkOpenGL2RenderWindow::SafeDownCast(context);
if (this->Context)
{
vtkOpenGLExtensionManager *manager
= this->Context->GetExtensionManager();
// don't need any of the functions so don't bother
// to load the extension, but do make sure enums are
// defined.
this->MultisampleSupport
= manager->ExtensionSupported("GL_ARB_multisample")==1;
// todo the above line currently does not work so we hard code it to true
this->MultisampleSupport = true;
}
this->MultisampleSupport = true;
}
}
......@@ -90,11 +75,11 @@ public:
{
if (mode)
{
glEnable(vtkgl::MULTISAMPLE);
glEnable(GL_MULTISAMPLE);
}
else
{
glDisable(vtkgl::MULTISAMPLE);
glDisable(GL_MULTISAMPLE);
}
}
}
......@@ -103,7 +88,7 @@ public:
// Check if multisample is enabled.
bool QueryMultisampling()
{
if (this->MultisampleSupport && glIsEnabled(vtkgl::MULTISAMPLE))
if (this->MultisampleSupport && glIsEnabled(GL_MULTISAMPLE))
{
return true;
}
......
......@@ -14,6 +14,8 @@
=========================================================================*/
#include "vtkOpenGL2ImageMapper.h"
#include <GL/glew.h>
#include "vtkActor2D.h"
#include "vtkDataArray.h"
#include "vtkImageData.h"
......@@ -36,7 +38,6 @@
#include "vtkNew.h"
#include "vtkOpenGL.h"
#include "vtkOpenGLError.h"
vtkStandardNewMacro(vtkOpenGL2ImageMapper);
......
......@@ -14,6 +14,8 @@
=========================================================================*/
#include "vtkOpenGL2ImageSliceMapper.h"
#include <GL/glew.h>
#include "vtkObjectFactory.h"
#include "vtkImageData.h"
#include "vtkImageSlice.h"
......@@ -27,7 +29,6 @@
#include "vtkOpenGL2Camera.h"
#include "vtkOpenGL2Renderer.h"
#include "vtkOpenGL2RenderWindow.h"
#include "vtkOpenGLExtensionManager.h"
#include "vtkTimerLog.h"
#include "vtkGarbageCollector.h"
#include "vtkTemplateAliasMacro.h"
......@@ -48,9 +49,7 @@
#include <math.h>
#include "vtkOpenGL.h"
#include "vtkOpenGLError.h"
#include "vtkgl.h" // vtkgl namespace
vtkStandardNewMacro(vtkOpenGL2ImageSliceMapper);
......@@ -373,7 +372,7 @@ void vtkOpenGL2ImageSliceMapper::RenderTexturedPolygon(
if (useFragmentProgram)
{
glDisable(vtkgl::FRAGMENT_PROGRAM_ARB);
glDisable(GL_FRAGMENT_PROGRAM_ARB);
}
vtkOpenGLCheckErrorMacro("failed after RenderTexturedPolygon");
......@@ -608,7 +607,7 @@ void vtkOpenGL2ImageSliceMapper::BindFragmentProgram(
// Bind the bicubic interpolation fragment program, it will
// not do anything if modern shader objects are also in play.
vtkgl::BindProgramARB(vtkgl::FRAGMENT_PROGRAM_ARB,
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB,
this->FragmentShaderIndex);
// checkerboard information
......@@ -632,7 +631,7 @@ void vtkOpenGL2ImageSliceMapper::BindFragmentProgram(
vtkMatrix4x4::Multiply4x4(*c->Element, mat, mat);
// first parameter: texture size needed for bicubic interpolator
vtkgl::ProgramLocalParameter4fARB(vtkgl::FRAGMENT_PROGRAM_ARB, 0,
glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0,
static_cast<float>(this->TextureSize[0]),
static_cast<float>(this->TextureSize[1]),
static_cast<float>(1.0/this->TextureSize[0]),
......@@ -640,7 +639,7 @@ void vtkOpenGL2ImageSliceMapper::BindFragmentProgram(
// second parameter: scale and offset for converting texture coords
// into the input image's data coords
vtkgl::ProgramLocalParameter4fARB(vtkgl::FRAGMENT_PROGRAM_ARB, 1,
glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 1,
static_cast<float>(this->TextureSize[0]*spacing[xdim]),
static_cast<float>(this->TextureSize[1]*spacing[ydim]),
static_cast<float>(origin[xdim] +
......@@ -650,7 +649,7 @@ void vtkOpenGL2ImageSliceMapper::BindFragmentProgram(
// third parameter: scale and offset for converting data coords into
// checkboard square indices, for checkerboarding
vtkgl::ProgramLocalParameter4fARB(vtkgl::FRAGMENT_PROGRAM_ARB, 2,
glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 2,
static_cast<float>(0.5/checkSpacing[0]),
static_cast<float>(0.5/checkSpacing[1]),
static_cast<float>(-0.5*checkOffset[0]),
......@@ -660,10 +659,10 @@ void vtkOpenGL2ImageSliceMapper::BindFragmentProgram(
// from data coords to camera coords (including a pre-translation of
// z from zero to the z position of the slice, since the texture coords
// are 2D and do not provide the z position)
vtkgl::ProgramLocalParameter4fARB(vtkgl::FRAGMENT_PROGRAM_ARB, 3,
glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 3,
static_cast<float>(mat[0]), static_cast<float>(mat[1]),
static_cast<float>(mat[2]), static_cast<float>(mat[3]));
vtkgl::ProgramLocalParameter4fARB(vtkgl::FRAGMENT_PROGRAM_ARB, 4,
glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 4,
static_cast<float>(mat[4]), static_cast<float>(mat[5]),
static_cast<float>(mat[6]), static_cast<float>(mat[7]));
......@@ -988,34 +987,11 @@ void vtkOpenGL2ImageSliceMapper::Render(vtkRenderer *ren, vtkImageSlice *prop)
}
//----------------------------------------------------------------------------
void vtkOpenGL2ImageSliceMapper::CheckOpenGLCapabilities(
vtkOpenGL2RenderWindow *renWin)
void vtkOpenGL2ImageSliceMapper::CheckOpenGLCapabilities(vtkOpenGL2RenderWindow*)
{
vtkOpenGLExtensionManager *manager = 0;
if (renWin)
{
manager = renWin->GetExtensionManager();
}
if (renWin && manager)
{
this->UseClampToEdge =
(manager->ExtensionSupported("GL_VERSION_1_2") ||
manager->ExtensionSupported("GL_EXT_texture_edge_clamp"));
this->UsePowerOfTwoTextures =
!(manager->ExtensionSupported("GL_VERSION_2_0") ||
manager->ExtensionSupported("GL_ARB_texture_non_power_of_two"));
this->UseFragmentProgram =
(manager->ExtensionSupported("GL_VERSION_1_3") &&
manager->LoadSupportedExtension("GL_ARB_fragment_program"));
}
else
{
this->UseClampToEdge = false;
this->UsePowerOfTwoTextures = true;
this->UseFragmentProgram = false;
}
this->UseClampToEdge = true;
this->UsePowerOfTwoTextures = true;
this->UseFragmentProgram = true;
}
//----------------------------------------------------------------------------
......
......@@ -21,7 +21,6 @@
#include "vtkCellArray.h"
#include "vtkMath.h"
#include "vtkMatrix4x4.h"
#include "vtkOpenGLGL2PSHelper.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGL2Texture.h"
#include "vtkPlane.h"
......@@ -33,7 +32,6 @@
#include "vtkUnsignedCharArray.h"
#include "vtkViewport.h"
#include "vtkWindow.h"
#include "vtkgluPickMatrix.h"
#include "vtkOpenGLError.h"
#include "vtkOpenGL2RenderWindow.h"
......@@ -571,7 +569,6 @@ void vtkOpenGL2PolyDataMapper2D::RenderOverlay(vtkViewport* viewport,
{
// Set the PointSize
glPointSize(actor->GetProperty()->GetPointSize());
//vtkOpenGLGL2PSHelper::SetPointSize(actor->GetProperty()->GetPointSize());
this->Internal->points.ibo.