Commit 93875452 authored by Ken Martin's avatar Ken Martin

Add a geometry shader and some cleanup and fixes

The LIC shaders were not converted properly for gl 3.2

Cleanup some code standard issues
parent 9e0107e5
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
// default precisions, or defining precisions to null // default precisions, or defining precisions to null
//VTK::System::Dec //VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texLIC; // inout texture uniform sampler2D texLIC; // inout texture
uniform vec2 uLICTexSize; // input texture size uniform vec2 uLICTexSize; // input texture size
uniform vec4 uComputeBounds; // valid region of texture uniform vec4 uComputeBounds; // valid region of texture
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
// default precisions, or defining precisions to null // default precisions, or defining precisions to null
//VTK::System::Dec //VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texLIC; // input texture uniform sampler2D texLIC; // input texture
uniform float uDx; // fragment size uniform float uDx; // fragment size
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
// default precisions, or defining precisions to null // default precisions, or defining precisions to null
//VTK::System::Dec //VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texLIC; // input texture uniform sampler2D texLIC; // input texture
uniform float uDy; // fragment size uniform float uDy; // fragment size
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
// default precisions, or defining precisions to null // default precisions, or defining precisions to null
//VTK::System::Dec //VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texLIC; // most recent lic pass uniform sampler2D texLIC; // most recent lic pass
uniform float uMin; // min gray scale color value uniform float uMin; // min gray scale color value
uniform float uMaxMinDiff; // max-min uniform float uMaxMinDiff; // max-min
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
// default precisions, or defining precisions to null // default precisions, or defining precisions to null
//VTK::System::Dec //VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texLIC; // most recent lic pass uniform sampler2D texLIC; // most recent lic pass
uniform float uDx; // fragment size uniform float uDx; // fragment size
uniform float uDy; // fragment size uniform float uDy; // fragment size
......
...@@ -21,6 +21,9 @@ This shader initializes the convolution for the LIC computation. ...@@ -21,6 +21,9 @@ This shader initializes the convolution for the LIC computation.
// default precisions, or defining precisions to null // default precisions, or defining precisions to null
//VTK::System::Dec //VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texMaskVectors; uniform sampler2D texMaskVectors;
uniform sampler2D texNoise; uniform sampler2D texNoise;
uniform sampler2D texLIC; uniform sampler2D texLIC;
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
// default precisions, or defining precisions to null // default precisions, or defining precisions to null
//VTK::System::Dec //VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texVectors; uniform sampler2D texVectors;
uniform sampler2D texNoise; uniform sampler2D texNoise;
uniform sampler2D texLIC; uniform sampler2D texLIC;
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
// default precisions, or defining precisions to null // default precisions, or defining precisions to null
//VTK::System::Dec //VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
/** /**
This shader finalizes the convolution for the LIC computation This shader finalizes the convolution for the LIC computation
applying the normalization. eg. if box kernel is used the this applying the normalization. eg. if box kernel is used the this
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
// default precisions, or defining precisions to null // default precisions, or defining precisions to null
//VTK::System::Dec //VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
// Fragment shader used by the gaussian blur filter render pass. // Fragment shader used by the gaussian blur filter render pass.
uniform sampler2D texVectors; // input texture uniform sampler2D texVectors; // input texture
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
// default precisions, or defining precisions to null // default precisions, or defining precisions to null
//VTK::System::Dec //VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
varying vec2 tcoordVC; varying vec2 tcoordVC;
/* /*
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
// default precisions, or defining precisions to null // default precisions, or defining precisions to null
//VTK::System::Dec //VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texGeomColors; // scalars + lighting uniform sampler2D texGeomColors; // scalars + lighting
uniform sampler2D texLIC; // image lic, mask uniform sampler2D texLIC; // image lic, mask
uniform sampler2D texHSLColors; // hsla colors uniform sampler2D texHSLColors; // hsla colors
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
// default precisions, or defining precisions to null // default precisions, or defining precisions to null
//VTK::System::Dec //VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texDepth; // z values from vertex shader uniform sampler2D texDepth; // z values from vertex shader
uniform sampler2D texRGBColors; // final rgb LIC colors uniform sampler2D texRGBColors; // final rgb LIC colors
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
// default precisions, or defining precisions to null // default precisions, or defining precisions to null
//VTK::System::Dec //VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texVectors; // vectors, depth uniform sampler2D texVectors; // vectors, depth
uniform sampler2D texGeomColors; // scalar colors + lighting uniform sampler2D texGeomColors; // scalar colors + lighting
uniform sampler2D texLIC; // image lic uniform sampler2D texLIC; // image lic
......
...@@ -128,6 +128,7 @@ set(shader_files ...@@ -128,6 +128,7 @@ set(shader_files
glsl/vtkglPolyData2DFS.glsl glsl/vtkglPolyData2DFS.glsl
glsl/vtkglPolyData2DVS.glsl glsl/vtkglPolyData2DVS.glsl
glsl/vtkglPolyDataFS.glsl glsl/vtkglPolyDataFS.glsl
glsl/vtkglPolyDataGS.glsl
glsl/vtkglPolyDataVSFragmentLit.glsl glsl/vtkglPolyDataVSFragmentLit.glsl
) )
unset(shader_h_files) unset(shader_h_files)
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkglPolyDataGS.glsl
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.
=========================================================================*/
// Template for the polydata mappers geometry shader
// The following line handle system declarations such a
// default precisions, or defining precisions to null
//VTK::System::Dec
// all variables that represent positions or directions have a suffix
// indicating the coordinate system they are in. The possible values are
// MC - Model Coordinates
// WC - WC world coordinates
// VC - View Coordinates
// DC - Display Coordinates
// VC position of this fragment
//VTK::PositionVC::Dec
// optional color passed in from the vertex shader, vertexColor
//VTK::Color::Dec
// optional surface normal declaration
//VTK::Normal::Dec
// extra lighting parameters
//VTK::Light::Dec
// Texture coordinates
//VTK::TCoord::Dec
// picking support
//VTK::Picking::Dec
// Depth Peeling Support
//VTK::DepthPeeling::Dec
// clipping plane vars
//VTK::Clip::Dec
// the output of this shader
//VTK::Output::Dec
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
void main()
{
for(int i = 0; i < 3; i++)
{
//VTK::Normal::Impl
gl_Position = gl_in[i].gl_Position;
gl_PrimitiveID = gl_PrimitiveIDIn;
EmitVertex();
}
EndPrimitive();
}
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
// Bring in our fragment lit shader symbols. // Bring in our fragment lit shader symbols.
#include "vtkglPolyDataVSFragmentLit.h" #include "vtkglPolyDataVSFragmentLit.h"
#include "vtkglPolyDataFS.h" #include "vtkglPolyDataFS.h"
#include "vtkglPolyDataGS.h"
#include <algorithm> #include <algorithm>
...@@ -191,6 +192,7 @@ void vtkOpenGLPolyDataMapper::GetShaderTemplate( ...@@ -191,6 +192,7 @@ void vtkOpenGLPolyDataMapper::GetShaderTemplate(
{ {
VSSource = vtkglPolyDataVSFragmentLit; VSSource = vtkglPolyDataVSFragmentLit;
FSSource = vtkglPolyDataFS; FSSource = vtkglPolyDataFS;
//GSSource = vtkglPolyDataGS;
GSSource.clear(); GSSource.clear();
} }
...@@ -580,6 +582,13 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderValues( ...@@ -580,6 +582,13 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderValues(
substitute(VSSource, substitute(VSSource,
"//VTK::Normal::Impl", "//VTK::Normal::Impl",
"normalVCVarying = normalMatrix * normalMC;"); "normalVCVarying = normalMatrix * normalMC;");
// substitute(GSSource,
// "//VTK::Normal::Dec",
// "in vec3 normalVCVaryingGS[];\n"
// "out vec3 normalVCVarying;");
// substitute(GSSource,
// "//VTK::Normal::Impl",
// "normalVCVarying = normalVCVaryingGS[i];");
substitute(FSSource, substitute(FSSource,
"//VTK::Normal::Dec", "//VTK::Normal::Dec",
"varying vec3 normalVCVarying;"); "varying vec3 normalVCVarying;");
......
...@@ -405,11 +405,23 @@ void vtkOpenGLRenderWindow::OpenGLInitContext() ...@@ -405,11 +405,23 @@ void vtkOpenGLRenderWindow::OpenGLInitContext()
return; return;
} }
if (!GLEW_VERSION_2_1) if (!GLEW_VERSION_3_2)
{ {
vtkErrorMacro("GL version 2.1 is not supported by your graphics driver."); if (!GLEW_VERSION_2_1)
//m_valid = false; {
return; vtkErrorMacro("GL version 2.1 is not supported by your graphics driver.");
//m_valid = false;
return;
}
vtkWarningMacro(
"VTK is designed to work with OpenGL version 3.2 but it appears "
"it has been given a context that does not support 3.2. VTK will "
"run in a compatibility mode designed to work with OpenGL 2.1 but "
"some features may not work.");
}
else
{
this->SetContextSupportsOpenGL32(true);
} }
#endif #endif
this->Initialized = true; this->Initialized = true;
......
...@@ -128,6 +128,12 @@ vtkShaderProgram *vtkOpenGLShaderCache::ReadyShader( ...@@ -128,6 +128,12 @@ vtkShaderProgram *vtkOpenGLShaderCache::ReadyShader(
"#define texture2D texture\n" "#define texture2D texture\n"
"#define texture3D texture\n" "#define texture3D texture\n"
); );
GSSource = replace(GSSource,"//VTK::System::Dec",
"#version 150\n"
"#define highp\n"
"#define mediump\n"
"#define lowp"
);
std::string fragDecls; std::string fragDecls;
bool done = false; bool done = false;
while (!done) while (!done)
......
...@@ -50,14 +50,26 @@ bool vtkShader::Compile() ...@@ -50,14 +50,26 @@ bool vtkShader::Compile()
} }
// Ensure we delete the previous shader if necessary. // Ensure we delete the previous shader if necessary.
if (Handle != 0) if (this->Handle != 0)
{ {
glDeleteShader(static_cast<GLuint>(Handle)); glDeleteShader(static_cast<GLuint>(this->Handle));
Handle = 0; this->Handle = 0;
} }
GLenum type = ShaderType == Vertex ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER; GLenum type = GL_VERTEX_SHADER;
// TODO: handle geometry shaders if supported switch (this->ShaderType)
{
case vtkShader::Geometry:
type = GL_GEOMETRY_SHADER;
break;
case vtkShader::Fragment:
type = GL_FRAGMENT_SHADER;
break;
case vtkShader::Vertex:
default:
type = GL_VERTEX_SHADER;
break;
}
GLuint handle = glCreateShader(type); GLuint handle = glCreateShader(type);
const GLchar *source = static_cast<const GLchar *>(this->Source.c_str()); const GLchar *source = static_cast<const GLchar *>(this->Source.c_str());
......
...@@ -49,19 +49,19 @@ public: ...@@ -49,19 +49,19 @@ public:
void SetType(Type type); void SetType(Type type);
/** Get the shader type, typically Vertex or Fragment. */ /** Get the shader type, typically Vertex or Fragment. */
Type GetType() const { return ShaderType; } Type GetType() const { return this->ShaderType; }
/** Set the shader source to the supplied string. */ /** Set the shader source to the supplied string. */
void SetSource(const std::string &source); void SetSource(const std::string &source);
/** Get the source for the shader. */ /** Get the source for the shader. */
std::string GetSource() const { return Source; } std::string GetSource() const { return this->Source; }
/** Get the error message (empty if none) for the shader. */ /** Get the error message (empty if none) for the shader. */
std::string GetError() const { return Error; } std::string GetError() const { return this->Error; }
/** Get the handle of the shader. */ /** Get the handle of the shader. */
int GetHandle() const { return Handle; } int GetHandle() const { return this->Handle; }
/** Compile the shader. /** Compile the shader.
* @note A valid context must to current in order to compile the shader. * @note A valid context must to current in order to compile the shader.
......
...@@ -60,18 +60,23 @@ inline GLenum convertTypeToGL(int type) ...@@ -60,18 +60,23 @@ inline GLenum convertTypeToGL(int type)
vtkStandardNewMacro(vtkShaderProgram) vtkStandardNewMacro(vtkShaderProgram)
vtkShaderProgram::vtkShaderProgram() : Handle(0), VertexShaderHandle(0), vtkShaderProgram::vtkShaderProgram()
FragmentShaderHandle(0), Linked(false), Bound(false) {
{ this->VertexShader = vtkShader::New();
this->VertexShader = vtkShader::New(); this->VertexShader->SetType(vtkShader::Vertex);
this->VertexShader->SetType(vtkShader::Vertex); this->FragmentShader = vtkShader::New();
this->FragmentShader = vtkShader::New(); this->FragmentShader->SetType(vtkShader::Fragment);
this->FragmentShader->SetType(vtkShader::Fragment); this->GeometryShader = vtkShader::New();
this->GeometryShader = vtkShader::New(); this->GeometryShader->SetType(vtkShader::Geometry);
this->GeometryShader->SetType(vtkShader::Geometry);
this->Compiled = false;
this->Compiled = false; this->NumberOfOutputs = 0;
this->NumberOfOutputs = 0; this->Handle = 0;
this->VertexShaderHandle = 0;
this->FragmentShaderHandle = 0;
this->GeometryShaderHandle = 0;
this->Linked = false;
this->Bound = false;
} }
vtkShaderProgram::~vtkShaderProgram() vtkShaderProgram::~vtkShaderProgram()
...@@ -134,22 +139,31 @@ bool vtkShaderProgram::AttachShader(const vtkShader *shader) ...@@ -134,22 +139,31 @@ bool vtkShaderProgram::AttachShader(const vtkShader *shader)
if (shader->GetType() == vtkShader::Vertex) if (shader->GetType() == vtkShader::Vertex)
{ {
if (VertexShaderHandle != 0) if (this->VertexShaderHandle != 0)
{ {
glDetachShader(static_cast<GLuint>(Handle), glDetachShader(static_cast<GLuint>(this->Handle),
static_cast<GLuint>(VertexShaderHandle)); static_cast<GLuint>(this->VertexShaderHandle));
} }
this->VertexShaderHandle = shader->GetHandle(); this->VertexShaderHandle = shader->GetHandle();
} }
else if (shader->GetType() == vtkShader::Fragment) else if (shader->GetType() == vtkShader::Fragment)
{ {
if (FragmentShaderHandle != 0) if (this->FragmentShaderHandle != 0)
{ {
glDetachShader(static_cast<GLuint>(Handle), glDetachShader(static_cast<GLuint>(this->Handle),
static_cast<GLuint>(FragmentShaderHandle)); static_cast<GLuint>(this->FragmentShaderHandle));
} }
this->FragmentShaderHandle = shader->GetHandle(); this->FragmentShaderHandle = shader->GetHandle();
} }
else if (shader->GetType() == vtkShader::Geometry)
{
if (this->GeometryShaderHandle != 0)
{
glDetachShader(static_cast<GLuint>(this->Handle),
static_cast<GLuint>(this->GeometryShaderHandle));
}
this->GeometryShaderHandle = shader->GetHandle();
}
else else
{ {
this->Error = "Unknown shader type encountered - this should not happen."; this->Error = "Unknown shader type encountered - this should not happen.";
...@@ -209,6 +223,20 @@ bool vtkShaderProgram::DetachShader(const vtkShader *shader) ...@@ -209,6 +223,20 @@ bool vtkShaderProgram::DetachShader(const vtkShader *shader)
this->Linked = false; this->Linked = false;
return true; return true;
} }
case vtkShader::Geometry:
if (this->GeometryShaderHandle != shader->GetHandle())
{
this->Error = "The supplied shader was not attached to this program.";
return false;
}
else
{
glDetachShader(static_cast<GLuint>(this->Handle),
static_cast<GLuint>(shader->GetHandle()));
this->GeometryShaderHandle = 0;
this->Linked = false;
return true;
}
default: default:
return false; return false;
} }
...@@ -309,6 +337,22 @@ int vtkShaderProgram::CompileShader() ...@@ -309,6 +337,22 @@ int vtkShaderProgram::CompileShader()
vtkErrorMacro(<< this->GetFragmentShader()->GetError()); vtkErrorMacro(<< this->GetFragmentShader()->GetError());
return 0; return 0;
} }
if (this->GetGeometryShader()->GetSource().size() > 0 &&
!this->GetGeometryShader()->Compile())
{
int lineNum = 1;
std::istringstream stream(this->GetGeometryShader()->GetSource());
std::stringstream sstm;
std::string aline;
while (std::getline(stream, aline))
{
sstm << lineNum << ": " << aline << "\n";
lineNum++;
}
vtkErrorMacro(<< sstm.str());
vtkErrorMacro(<< this->GetGeometryShader()->GetError());
return 0;
}
if (!this->AttachShader(this->GetVertexShader())) if (!this->AttachShader(this->GetVertexShader()))
{ {
vtkErrorMacro(<< this->GetError()); vtkErrorMacro(<< this->GetError());
...@@ -319,6 +363,12 @@ int vtkShaderProgram::CompileShader() ...@@ -319,6 +363,12 @@ int vtkShaderProgram::CompileShader()
vtkErrorMacro(<< this->GetError()); vtkErrorMacro(<< this->GetError());
return 0; return 0;
} }
if (this->GetGeometryShader()->GetSource().size() > 0 &&
!this->AttachShader(this->GetGeometryShader()))
{
vtkErrorMacro(<< this->GetError());
return 0;
}
if (!this->Link()) if (!this->Link())
{ {
vtkErrorMacro(<< "Links failed: " << this->GetError()); vtkErrorMacro(<< "Links failed: " << this->GetError());
...@@ -345,8 +395,10 @@ void vtkShaderProgram::ReleaseGraphicsResources(vtkWindow *win) ...@@ -345,8 +395,10 @@ void vtkShaderProgram::ReleaseGraphicsResources(vtkWindow *win)
{ {
this->DetachShader(this->VertexShader); this->DetachShader(this->VertexShader);
this->DetachShader(this->FragmentShader); this->DetachShader(this->FragmentShader);
this->DetachShader(this->GeometryShader);
this->VertexShader->Cleanup(); this->VertexShader->Cleanup();
this->FragmentShader->Cleanup(); this->FragmentShader->Cleanup();
this->GeometryShader->Cleanup();
this->Compiled = false; this->Compiled = false;
} }
......
...@@ -238,6 +238,7 @@ protected: ...@@ -238,6 +238,7 @@ protected:
int Handle; int Handle;
int VertexShaderHandle; int VertexShaderHandle;
int FragmentShaderHandle; int FragmentShaderHandle;
int GeometryShaderHandle;
bool Linked; bool Linked;
bool Bound; bool Bound;
......
...@@ -631,7 +631,7 @@ void vtkWin32OpenGLRenderWindow::SetupPixelFormatPaletteAndContext( ...@@ -631,7 +631,7 @@ void vtkWin32OpenGLRenderWindow::SetupPixelFormatPaletteAndContext(
this->SetupPalette(hDC); this->SetupPalette(hDC);
// create a context // create a context
//#define USE_32_CONTEXT #define USE_32_CONTEXT
#ifdef USE_32_CONTEXT #ifdef USE_32_CONTEXT
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB =
reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribsARB")); reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribsARB"));
......
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