Commit 2cb5e3da authored by Alvaro Sanchez's avatar Alvaro Sanchez Committed by Kitware Robot

Merge topic 'float-value-pass'

f133d013 Fixed broken tests and updated documentation.
582ada60 vtkValuePass::FLOATING_POINT supports cell data.
9bbf0457 vtkValuePass::FLOATING_POINT handles viewport size changes.
58b93bcc Made vtkFBO2 derive from vtkFBOBase.
0983eaba Added vtkValuePass::FLOATING_POINT for point data.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: David E. DeMarle's avatarDavid E DeMarle <dave.demarle@kitware.com>
Merge-request: !1958
parents c37ed290 f133d013
......@@ -12,6 +12,7 @@ if(VTK_RENDERING_BACKEND STREQUAL "OpenGL2")
TestTranslucentLUTAlphaBlending.cxx
TestTranslucentLUTTextureAlphaBlending.cxx
TestAreaSelections.cxx
TestValuePassFloatingPoint.cxx
)
else()
set(extra_opengl2_tests
......
This diff is collapsed.
......@@ -32,4 +32,4 @@ vtk_module(vtkRenderingCore
vtkFiltersGeometry
vtkFiltersSources
vtksys
)
\ No newline at end of file
)
......@@ -32,6 +32,8 @@ class VTKRENDERINGCORE_EXPORT vtkFrameBufferObjectBase : public vtkObject
vtkTypeMacro(vtkFrameBufferObjectBase, vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Dimensions in pixels of the framebuffer.
virtual int *GetLastSize() = 0;
virtual void GetLastSize (int &_arg1, int &_arg2) = 0;
virtual void GetLastSize (int _arg[2]) = 0;
......
......@@ -77,6 +77,7 @@ set(Module_SRCS
vtkTransformFeedback.cxx
vtkTranslucentPass.cxx
vtkValuePass.cxx
vtkValuePassHelper.cxx
vtkVolumetricPass.cxx
)
......@@ -123,6 +124,7 @@ set_source_files_properties(
vtkTextureObject
vtkTextureUnitManager
vtkTransformFeedback
vtkValuePassHelper
WRAP_EXCLUDE)
set_source_files_properties(
......@@ -130,6 +132,7 @@ set_source_files_properties(
vtkOpenGLGL2PSHelper
vtkOpenGLGlyph3DHelper
vtkOpenGLHelper
vtkValuePassHelper
PROPERTIES WRAP_EXCLUDE_PYTHON 1)
set_source_files_properties(
......
......@@ -51,6 +51,9 @@ uniform int PrimitiveIDOffset;
// handle coincident offsets
//VTK::Coincident::Dec
// Value raster
//VTK::ValuePass::Dec
void main()
{
// VC position of this fragment. This should not branch/return/discard.
......
......@@ -41,6 +41,9 @@ attribute vec4 vertexMC;
// Apple Bug
//VTK::PrimID::Dec
// Value raster
//VTK::ValuePass::Dec
void main()
{
//VTK::Color::Impl
......@@ -55,5 +58,7 @@ void main()
//VTK::PositionVC::Impl
//VTK::ValuePass::Impl
//VTK::Light::Impl
}
......@@ -39,6 +39,8 @@ vtkFrameBufferObject2::vtkFrameBufferObject2()
this->PreviousReadFBO = 0;
this->PreviousDrawBuffer = GL_NONE;
this->PreviousReadBuffer = GL_NONE;
this->LastViewportSize[0] = -1;
this->LastViewportSize[1] = -1;
}
//----------------------------------------------------------------------------
......@@ -176,7 +178,7 @@ void vtkFrameBufferObject2::Bind(unsigned int mode)
{
assert(this->FBOIndex!=0); // need to call glGenFramebuffers first
// need to ensure that binding is esxtablished *every* time because
// need to ensure that binding is established *every* time because
// if other code binds over us then all of our subsequent calls
// will affect that fbo not ours.
glBindFramebuffer((GLenum)mode, this->FBOIndex);
......@@ -551,6 +553,54 @@ void vtkFrameBufferObject2::Download(
pbo->UnBind();
}
//-----------------------------------------------------------------------------
int* vtkFrameBufferObject2::GetLastSize(bool forceUpdate)
{
if (forceUpdate)
this->QueryViewportSize();
return this->LastViewportSize;
}
//-----------------------------------------------------------------------------
int* vtkFrameBufferObject2::GetLastSize()
{
this->QueryViewportSize();
return this->LastViewportSize;
}
//-----------------------------------------------------------------------------
void vtkFrameBufferObject2::GetLastSize(int &width, int &height)
{
this->QueryViewportSize();
width = this->LastViewportSize[0];
height = this->LastViewportSize[1];
}
//-----------------------------------------------------------------------------
void vtkFrameBufferObject2::GetLastSize(int size[2])
{
this->GetLastSize(size[0], size[1]);
}
//-----------------------------------------------------------------------------
void vtkFrameBufferObject2::QueryViewportSize()
{
if (!this->Context)
{
vtkErrorMacro("Failed to query viewport size because"
"there is no context set!");
return;
}
GLint vp[4];
glGetIntegerv(GL_VIEWPORT, vp);
vtkOpenGLStaticCheckErrorMacro("Error querying viewport size!");
this->LastViewportSize[0] = vp[2];
this->LastViewportSize[1] = vp[3];
}
//-----------------------------------------------------------------------------
int vtkFrameBufferObject2::GetOpenGLType(int vtkType)
{
......@@ -727,5 +777,7 @@ void vtkFrameBufferObject2::PrintSelf(ostream& os, vtkIndent indent)
<< indent << "PreviousReadFBO=" << this->PreviousReadFBO << endl
<< indent << "PreviousDrawBuffer=" << this->PreviousDrawBuffer << endl
<< indent << "PreviousReadBuffer=" << this->PreviousReadBuffer << endl
<< indent << "Last Viewport Size =" << "[" << this->LastViewportSize[0] << ", "
<< this->LastViewportSize[1] << "]" << endl
<< endl;
}
......@@ -42,7 +42,7 @@
#ifndef vtkFrameBufferObject2_h
#define vtkFrameBufferObject2_h
#include "vtkObject.h"
#include "vtkFrameBufferObjectBase.h"
#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkSmartPointer.h" // needed for vtkSmartPointer.
#include "vtkWeakPointer.h" // needed for vtkWeakPointer.
......@@ -78,11 +78,11 @@ class vtkRenderbuffer;
class vtkPixelBufferObject;
class vtkOpenGLRenderWindow;
class VTKRENDERINGOPENGL2_EXPORT vtkFrameBufferObject2 : public vtkObject
class VTKRENDERINGOPENGL2_EXPORT vtkFrameBufferObject2 : public vtkFrameBufferObjectBase
{
public:
static vtkFrameBufferObject2* New();
vtkTypeMacro(vtkFrameBufferObject2, vtkObject);
vtkTypeMacro(vtkFrameBufferObject2, vtkFrameBufferObjectBase);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
......@@ -274,6 +274,23 @@ public:
int oglFormat,
vtkPixelBufferObject *pbo);
// Description:
// Dimensions in pixels of the framebuffer. Given that InitializeViewport
// is static, these methods query the viewport size directly from GL. The
// cached size (LastViewportSize) will appear uninitialized (-1) until one
// one of these methods has been called. As with InitializeViewport, the
// methods affect the currently bound FBO (user must bind first).
virtual int* GetLastSize();
virtual void GetLastSize(int &width, int &height);
virtual void GetLastSize(int size[2]);
// Description:
// Additional overload which lets the user decide whether the returned size
// should be the currently cached value or first be updated from GL. As with
// InitializeViewport, the method affects the currently bound FBO (user must
// bind first).
int* GetLastSize(bool forceUpdate);
protected:
// Description:
// Load all necessary extensions.
......@@ -286,7 +303,6 @@ protected:
// delete buffer (occurs during destruction or context swicth)
void DestroyFBO();
// Description:
// Given a vtk type get a compatible open gl type.
int GetOpenGLType(int vtkType);
......@@ -301,8 +317,13 @@ protected:
unsigned int PreviousReadFBO;
unsigned int PreviousDrawBuffer;
unsigned int PreviousReadBuffer;
int LastViewportSize[2];
private:
// Description:
// Queries viewport dimensions from GL.
inline void QueryViewportSize();
vtkFrameBufferObject2(const vtkFrameBufferObject2&) VTK_DELETE_FUNCTION;
void operator=(const vtkFrameBufferObject2&) VTK_DELETE_FUNCTION;
......
......@@ -51,7 +51,7 @@
#include "vtkTransform.h"
#include "vtkUnsignedIntArray.h"
#include "vtkValuePass.h"
#include "vtkValuePassHelper.h"
#include "vtkShadowMapPass.h"
// Bring in our fragment lit shader symbols.
......@@ -115,6 +115,7 @@ vtkOpenGLPolyDataMapper::vtkOpenGLPolyDataMapper()
this->TimerQuery = 0;
this->ResourceCallback = new vtkOpenGLResourceFreeCallback<vtkOpenGLPolyDataMapper>(this,
&vtkOpenGLPolyDataMapper::ReleaseGraphicsResources);
this->ValuePassHelper = vtkSmartPointer<vtkValuePassHelper>::New();
}
//-----------------------------------------------------------------------------
......@@ -210,6 +211,9 @@ void vtkOpenGLPolyDataMapper::ReleaseGraphicsResources(vtkWindow* win)
{
this->CellNormalBuffer->ReleaseGraphicsResources();
}
this->ValuePassHelper->ReleaseGraphicsResources(win);
if (this->AppleBugPrimIDBuffer)
{
this->AppleBugPrimIDBuffer->ReleaseGraphicsResources();
......@@ -579,9 +583,15 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderColor(
// the following are always defined variables. We start
// by assiging a default value from the uniform
std::string colorImpl =
"vec3 ambientColor;\n"
" vec3 ambientColor;\n"
" vec3 diffuseColor;\n"
" float opacity;\n";
if (this->ValuePassHelper->GetRenderingMode() == vtkValuePass::FLOATING_POINT)
{
this->ValuePassHelper->UpdateShaders(VSSource, FSSource, colorImpl);
}
if (this->LastLightComplexity[this->LastBoundBO])
{
colorImpl +=
......@@ -793,6 +803,8 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderLight(
int lastLightComplexity = this->LastLightComplexity[this->LastBoundBO];
if (info && info->Has(vtkValuePass::RENDER_VALUES()))
{
// Although vtkValuePass::FLOATING_POINT does not require this, it is for
// simplicity left unchanged (only required when using INVERTIBLE_LUT mode).
lastLightComplexity = 0;
}
......@@ -1563,7 +1575,8 @@ bool vtkOpenGLPolyDataMapper::GetNeedToRebuildShaders(
cellBO.ShaderSourceTime < this->CurrentInput->GetMTime() ||
cellBO.ShaderSourceTime < this->SelectionStateChanged ||
cellBO.ShaderSourceTime < renderPassMTime ||
cellBO.ShaderSourceTime < this->LightComplexityChanged[&cellBO])
cellBO.ShaderSourceTime < this->LightComplexityChanged[&cellBO] ||
this->ValuePassHelper->RequiresShaderRebuild())
{
return true;
}
......@@ -1694,6 +1707,12 @@ void vtkOpenGLPolyDataMapper::SetMapperShaderParameters(vtkOpenGLHelper &cellBO,
vtkErrorMacro(<< "Error setting 'appleBugPrimID' in shader VAO.");
}
}
if (this->ValuePassHelper->GetRenderingMode() == vtkValuePass::FLOATING_POINT)
{
this->ValuePassHelper->BindAttributes(cellBO);
}
cellBO.AttributeUpdateTime.Modified();
}
......@@ -1745,6 +1764,11 @@ void vtkOpenGLPolyDataMapper::SetMapperShaderParameters(vtkOpenGLHelper &cellBO,
cellBO.Program->SetUniformi("textureN", tunit);
}
if (this->ValuePassHelper->GetRenderingMode() == vtkValuePass::FLOATING_POINT)
{
this->ValuePassHelper->BindUniforms(cellBO);
}
// Handle render pass setup:
vtkInformation *info = actor->GetPropertyKeys();
if (info && info->Has(vtkOpenGLRenderPass::RenderPasses()))
......@@ -2291,6 +2315,11 @@ void vtkOpenGLPolyDataMapper::RenderPieceStart(vtkRenderer* ren, vtkActor *actor
this->CellNormalTexture->Activate();
}
if (this->ValuePassHelper->GetRenderingMode() == vtkValuePass::FLOATING_POINT)
{
this->ValuePassHelper->RenderPieceStart(actor, this->CurrentInput);
}
// If we are coloring by texture, then load the texture map.
// Use Map as indicator, because texture hangs around.
if (this->ColorTextureMap)
......@@ -2522,6 +2551,11 @@ void vtkOpenGLPolyDataMapper::RenderPieceFinish(vtkRenderer* ren,
this->CellNormalTexture->Deactivate();
}
if (this->ValuePassHelper->GetRenderingMode() == vtkValuePass::FLOATING_POINT)
{
this->ValuePassHelper->RenderPieceFinish();
}
this->UpdateProgress(1.0);
}
......@@ -2640,22 +2674,10 @@ void vtkOpenGLPolyDataMapper::ComputeBounds()
//-------------------------------------------------------------------------
void vtkOpenGLPolyDataMapper::UpdateBufferObjects(vtkRenderer *ren, vtkActor *act)
{
// First check if the color mapping needs to be changed
vtkInformation *info = act->GetPropertyKeys();
if (info && info->Has(vtkValuePass::RENDER_VALUES()))
{
this->UseInvertibleColorFor(this->CurrentInput,
info->Get(vtkValuePass::SCALAR_MODE()),
info->Get(vtkValuePass::ARRAY_MODE()),
info->Get(vtkValuePass::ARRAY_ID()),
info->Get(vtkValuePass::ARRAY_NAME()),
info->Get(vtkValuePass::ARRAY_COMPONENT()),
info->Get(vtkValuePass::SCALAR_RANGE()));
}
else
{
this->ClearInvertibleColor();
}
// Checks for the pass's rendering mode and updates its configuration.
// Depending on the case, updates the mapper's color mapping or allocates
// a buffer.
this->ValuePassHelper->UpdateConfiguration(ren, act, this);
// Rebuild buffers if needed
if (this->GetNeedToRebuildBufferObjects(ren,act))
......
......@@ -37,6 +37,7 @@ class vtkOpenGLVertexBufferObject;
class vtkTextureObject;
class vtkTransform;
class vtkGenericOpenGLResourceFreeCallback;
class vtkValuePassHelper;
class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper
{
......@@ -182,6 +183,7 @@ public:
* the VBO's shift+scale transform.
*/
void SetVBOShiftScaleMethod(int m);
protected:
vtkOpenGLPolyDataMapper();
~vtkOpenGLPolyDataMapper();
......@@ -436,6 +438,7 @@ protected:
char *FragmentShaderCode;
char *GeometryShaderCode;
unsigned int TimerQuery;
vtkSmartPointer<vtkValuePassHelper> ValuePassHelper;
private:
vtkOpenGLPolyDataMapper(const vtkOpenGLPolyDataMapper&) VTK_DELETE_FUNCTION;
......
This diff is collapsed.
......@@ -12,12 +12,26 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkValuePass - TO DO
// .NAME vtkValuePass
//
// .SECTION Description
// TO DO
// Renders geometry using the values of a field array as fragment colors. The
// output can be used for deferred color mapping. It supports using arrays of
// either point or cell data. The target array can be selected by setting an
// array name/id and a component number. Only opaque geometry is supported.
//
// There are two rendering modes available:
//
// * INVERTIBLE_LUT Encodes array values as RGB data and renders the result to
// the default framebuffer.
//
// * FLOATING_POINT Renders actual array values as floating point data to an
// internal RGBA32F framebuffer. This class binds and unbinds the framebuffer
// on each render pass.
//
// .SECTION See Also
// vtkRenderPass vtkDefaultPass
// vtkRenderPass vtkDefaultPass vtkValuePassHelper vtkMapper
#ifndef vtkValuePass_h
#define vtkValuePass_h
......@@ -28,16 +42,26 @@
class vtkInformationDoubleVectorKey;
class vtkInformationIntegerKey;
class vtkInformationStringKey;
class vtkRenderer;
class vtkRenderWindow;
class vtkFloatArray;
class VTKRENDERINGOPENGL2_EXPORT vtkValuePass : public vtkDefaultPass
{
public:
enum Mode {
INVERTIBLE_LUT = 1,
FLOATING_POINT = 2 };
static vtkValuePass *New();
vtkTypeMacro(vtkValuePass, vtkDefaultPass);
void PrintSelf(ostream& os, vtkIndent indent);
static vtkInformationIntegerKey *RENDER_VALUES();
vtkSetMacro(RenderingMode, int);
vtkGetMacro(RenderingMode, int);
void SetInputArrayToProcess(int fieldAssociation, const char *name);
void SetInputArrayToProcess(int fieldAssociation, int fieldAttributeType);
void SetInputComponentToProcess(int component);
......@@ -51,12 +75,31 @@ public:
static vtkInformationStringKey *ARRAY_NAME();
static vtkInformationIntegerKey *ARRAY_COMPONENT();
static vtkInformationDoubleVectorKey *SCALAR_RANGE();
static vtkInformationIntegerKey *RELOAD_DATA();
// Description:
// Perform rendering according to a render state \p s.
// \pre s_exists: s!=0
virtual void Render(const vtkRenderState *s);
// Description:
// Interface to get the rendered image in FLOATING_POINT mode. Returns a
// single component array containing the rendered values. The returned array
// is owned by vtkValuePass so it is intended to be deep copied.
vtkFloatArray* GetFloatImageDataArray(vtkRenderer* ren);
// Description:
// Interface to get the rendered image in FLOATING_POINT mode. Low level API,
// a format for the internal glReadPixels call can be specified. 'data' is expected
// to be allocated and cleaned-up by the caller.
void GetFloatImageData(int const format, int const width, int const height,
void* data);
// Description:
// Interface to get the rendered image in FLOATING_POINT mode. Image extents of
// the value array.
int* GetFloatImageExtents();
protected:
// Description:
// Default constructor.
......@@ -71,12 +114,31 @@ public:
// \pre s_exists: s!=0
virtual void RenderOpaqueGeometry(const vtkRenderState *s);
// Description:
// Manages graphics resources depending on the rendering mode. Binds internal
// FBO when FLOATING_POINT mode is enabled.
void BeginPass(vtkRenderer* ren);
// Description:
// Unbinds internal FBO when FLOATING_POINT mode is enabled.
void EndPass();
// Description:
// Methods managing graphics resources required during FLOATING_POINT mode.
bool IsFloatFBOSupported(vtkRenderWindow* renWin);
bool HasWindowSizeChanged(vtkRenderer* ren);
bool InitializeFloatingPointMode(vtkRenderer* ren);
void ReleaseFloatingPointMode(vtkRenderer* ren);
class vtkInternals;
vtkInternals *Internals;
int RenderingMode;
private:
vtkValuePass(const vtkValuePass&) VTK_DELETE_FUNCTION;
void operator=(const vtkValuePass&) VTK_DELETE_FUNCTION;
};
#endif
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkValuePassHelper.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 vtkValuePassHelper
//
// .SECTION Description
// Implementation of both rendering modes of vtkValuePass for the
// vtkOpenGLPolyDataMapper. The mapper is intended to call various methods
// of this helper in order to setup the appropriate rendering state.
//
// * INVERTIBLE_LUT It uses a texture as a color LUT to map the values to RGB
// data. Texture size constraints limit its precision (currently 12-bit). Most
// of the implementation of this mode is in vtkMapper (InvertibleLookupTable)
// where the color LUT is generated.
//
// * FLOATING_POINT Resources are allocated on demand. When rendering point data
// values are uploaded to the GPU as vertex attributes. When rendering cell data
// values are uploaded as a texture buffer. Custom vertex and fragment shaders are
// defined in order to adjust its behavior for either type of data.
//
// .SECTION See Also
// vtkValuePass vtkOpenGLPolyDataMapper vtkMapper
#ifndef vtkValuePassHelper_h
#define vtkValuePassHelper_h
#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkObject.h"
class vtkActor;
class vtkDataSet;
class vtkMapper;
class vtkOpenGLHelper;
class vtkRenderer;
class vtkWindow;
class VTKRENDERINGOPENGL2_EXPORT vtkValuePassHelper : public vtkObject
{
friend class vtkOpenGLPolyDataMapper;
public:
static vtkValuePassHelper* New();
vtkTypeMacro(vtkValuePassHelper, vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
protected:
vtkValuePassHelper();
~vtkValuePassHelper();
vtkGetMacro(RenderingMode, int);
// Description:
// Configure the internal state depending on the settings defined by the
// vtkValuePass (RenderingMode, RENDER_VALUES, SCALAR_MODE, etc.).
void UpdateConfiguration(vtkRenderer* ren, vtkActor* act, vtkMapper* mapper);
// Description:
// Upload new data if necessary, bind textures, etc.
void RenderPieceStart(vtkActor* actor, vtkDataSet* input);
// Description:
// Add necessary shader definitions.
void UpdateShaders(std::string & VSSource, std::string & FSSource,
std::string & required);
// Description:
// Bind shader variables.
void BindAttributes(vtkOpenGLHelper& cellBO);
void BindUniforms(vtkOpenGLHelper& cellBO);
// Description:
// Unbind textures, etc.
void RenderPieceFinish();
// Description:
// Query whether a shader rebuild will be required.
bool RequiresShaderRebuild();
void ReleaseGraphicsResources(vtkWindow* win);
private:
void AllocateGraphicsResources(vtkRenderer* ren);
vtkValuePassHelper(const vtkValuePassHelper &) VTK_DELETE_FUNCTION;
void operator=(const vtkValuePassHelper &) VTK_DELETE_FUNCTION;
class vtkInternals;
vtkInternals* Impl;
int RenderingMode;
};
#endif // vtkValuePassHelper_h
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