Commit 2577188a authored by Ken Martin's avatar Ken Martin
Browse files

Use MCDCMatrix in shaders

A few changes here. The motivation is to support using the MCDCMatrix
in the vertex shader where possible. This has the advantage of
performing the MCVC x VCDC multiplication in double precision
on the CPU as opposed to float precision on the shader. This fixes
a couple test failures.

Along with that change cleanup a bit how we determine what uniforms
to set. There were some uniforms being set when they did not exist
in the program. Provided a more general approach for passing that
type of information between the code that builds the shader program
and the code that sets the uniforms.

Add a substitute helper function that does the same job as replace
but returns a bool if a replacement was made. Also operates on
the source string by reference.

make a more generic way for texture units to be passed to a mapper.

Cleaned up some long lines to be shorter.

Change-Id: I7f8cbc4892e57cd4c3bed11d497940d1f2a7c63b
parent de8deb6a
......@@ -7,15 +7,11 @@
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkCommand.h>
#include <vtkWidgetEvent.h>
#include <vtkCallbackCommand.h>
#include <vtkWidgetEventTranslator.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkSliderWidget.h>
#include <vtkSliderRepresentation2D.h>
#include <vtkProperty.h>
......
......@@ -19,10 +19,13 @@
#include "vtkInformation.h"
#include "vtkInformationIterator.h"
#include "vtkInformationKey.h"
#include "vtkInformationIntegerKey.h"
#include <cassert>
vtkCxxSetObjectMacro(vtkProp,PropertyKeys,vtkInformation);
vtkInformationKeyMacro(vtkProp,GeneralTextureUnit,Integer);
//----------------------------------------------------------------------------
// Creates an Prop with the following defaults: visibility on.
vtkProp::vtkProp()
......
......@@ -35,6 +35,7 @@ class vtkPropCollection;
class vtkViewport;
class vtkWindow;
class vtkInformation;
class vtkInformationIntegerKey;
class VTKRENDERINGCORE_EXPORT vtkProp : public vtkObject
{
......@@ -153,6 +154,17 @@ public:
virtual vtkIdType GetConvertedPickValue(vtkIdType idIn,
int vtkNotUsed(fieldassociation)) { return idIn; }
// Description:
// Optional Key Indicating the texture unit for general texture mapping
// Old OpenGL was a state machine where you would push or pop
// items. The new OpenGL design is more mapper centric. Some
// classes push a texture and then assume a mapper will use it.
// The new design wants explicit comunication of when a texture
// is being used. This key can be used to pass that information
// down to a mapper.
static vtkInformationIntegerKey *GeneralTextureUnit();
//BTX
// Description:
// WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
......
......@@ -18,6 +18,7 @@
#include "vtkCellArray.h"
#include "vtkFloatArray.h"
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
......@@ -345,20 +346,37 @@ int vtkTextMapper::SetMultipleRelativeFontSize(vtkViewport *viewport,
void vtkTextMapper::RenderOverlay(vtkViewport *viewport, vtkActor2D *actor)
{
vtkDebugMacro(<<"RenderOverlay called");
vtkRenderer *ren = NULL;
if (this->Input && this->Input[0])
{
this->UpdateImage();
this->UpdateQuad(actor);
if (vtkRenderer *ren = vtkRenderer::SafeDownCast(viewport))
if (ren = vtkRenderer::SafeDownCast(viewport))
{
vtkDebugMacro(<<"Texture::Render called");
this->Texture->Render(ren);
vtkInformation *info = actor->GetPropertyKeys();
if (!info)
{
info = vtkInformation::New();
actor->SetPropertyKeys(info);
info->Delete();
}
info->Set(vtkProp::GeneralTextureUnit(),
this->Texture->GetTextureUnit());
}
}
vtkDebugMacro(<<"PolyData::RenderOverlay called");
this->Mapper->RenderOverlay(viewport, actor);
// clean up
if (ren)
{
this->Texture->PostRender(ren);
}
vtkDebugMacro(<<"Superclass::RenderOverlay called");
this->Superclass::RenderOverlay(viewport, actor);
}
......
......@@ -204,6 +204,10 @@ public:
// Interpolate flag is turn off.
virtual int IsTranslucent();
// Description:
// Return the texture unit used for this texture
virtual int GetTextureUnit() { return 0; }
protected:
vtkTexture();
~vtkTexture();
......
......@@ -14,6 +14,7 @@
=========================================================================*/
#include "vtkTexturedActor2D.h"
#include "vtkInformation.h"
#include "vtkObjectFactory.h"
#include "vtkRenderer.h"
#include "vtkTexture.h"
......@@ -51,9 +52,22 @@ int vtkTexturedActor2D::RenderOverlay(vtkViewport* viewport)
{
// Render the texture.
vtkRenderer* ren = vtkRenderer::SafeDownCast(viewport);
vtkInformation *info = this->GetPropertyKeys();
if (this->Texture)
{
this->Texture->Render(ren);
if (!info)
{
info = vtkInformation::New();
this->SetPropertyKeys(info);
info->Delete();
}
info->Set(vtkProp::GeneralTextureUnit(),
this->Texture->GetTextureUnit());
}
else if (info)
{
info->Remove(vtkProp::GeneralTextureUnit());
}
int result=this->Superclass::RenderOverlay(viewport);
if (this->Texture)
......
......@@ -57,6 +57,8 @@
#include "vtkglPolyDataVSNoLighting.h"
#include "vtkglPolyDataFSNoLighting.h"
#include <algorithm>
using vtkgl::substitute;
//-----------------------------------------------------------------------------
......
......@@ -18,6 +18,7 @@
#include "vtkActor2D.h"
#include "vtkCellArray.h"
#include "vtkInformation.h"
#include "vtkMath.h"
#include "vtkMatrix4x4.h"
#include "vtkObjectFactory.h"
......@@ -31,7 +32,6 @@
#include "vtkProperty2D.h"
#include "vtkShader.h"
#include "vtkShaderProgram.h"
#include "vtkTexturedActor2D.h"
#include "vtkUnsignedCharArray.h"
#include "vtkViewport.h"
......@@ -222,14 +222,12 @@ void vtkOpenGLPolyDataMapper2D::SetMapperShaderParameters(
if (layout.TCoordComponents)
{
vtkTexturedActor2D *ta = vtkTexturedActor2D::SafeDownCast(actor);
int tunit = 0;
if (ta)
vtkInformation *info = actor->GetPropertyKeys();
if (info && info->Has(vtkProp::GeneralTextureUnit()))
{
vtkOpenGLTexture *texture = vtkOpenGLTexture::SafeDownCast(ta->GetTexture());
tunit = texture->GetTextureUnit();
int tunit = info->Get(vtkProp::GeneralTextureUnit());
cellBO.Program->SetUniformi("texture1", tunit);
}
cellBO.Program->SetUniformi("texture1", tunit);
}
}
......@@ -244,7 +242,10 @@ void vtkOpenGLPolyDataMapper2D::SetPropertyShaderParameters(
// Query the actor for some of the properties that can be applied.
float opacity = static_cast<float>(actor->GetProperty()->GetOpacity());
double *dColor = actor->GetProperty()->GetColor();
float diffuseColor[4] = {static_cast<float>(dColor[0]), static_cast<float>(dColor[1]), static_cast<float>(dColor[2]), static_cast<float>(opacity)};
float diffuseColor[4] = {static_cast<float>(dColor[0]),
static_cast<float>(dColor[1]),
static_cast<float>(dColor[2]),
static_cast<float>(opacity)};
program->SetUniform4f("diffuseColor", diffuseColor);
}
......@@ -381,11 +382,10 @@ void vtkOpenGLPolyDataMapper2D::UpdateVBO(vtkActor2D *act, vtkViewport *viewport
// do we have texture maps?
bool haveTextures = false;
vtkTexturedActor2D *ta =
vtkTexturedActor2D::SafeDownCast(act);
if (ta)
vtkInformation *info = act->GetPropertyKeys();
if (info && info->Has(vtkProp::GeneralTextureUnit()))
{
haveTextures = (ta->GetTexture() != NULL);
haveTextures = true;
}
// Transform the points, if necessary
......
......@@ -78,7 +78,7 @@ public:
// Description:
// Return the texture unit used for this texture
int GetTextureUnit();
virtual int GetTextureUnit();
// Description:
// Is this Texture Translucent?
......
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