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 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texLIC; // inout texture
uniform vec2 uLICTexSize; // input texture size
uniform vec4 uComputeBounds; // valid region of texture
......
......@@ -20,6 +20,9 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texLIC; // input texture
uniform float uDx; // fragment size
......
......@@ -20,6 +20,9 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texLIC; // input texture
uniform float uDy; // fragment size
......
......@@ -21,6 +21,9 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texLIC; // most recent lic pass
uniform float uMin; // min gray scale color value
uniform float uMaxMinDiff; // max-min
......
......@@ -21,6 +21,9 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texLIC; // most recent lic pass
uniform float uDx; // fragment size
uniform float uDy; // fragment size
......
......@@ -21,6 +21,9 @@ This shader initializes the convolution for the LIC computation.
// default precisions, or defining precisions to null
//VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texMaskVectors;
uniform sampler2D texNoise;
uniform sampler2D texLIC;
......
......@@ -17,6 +17,9 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texVectors;
uniform sampler2D texNoise;
uniform sampler2D texLIC;
......
......@@ -17,6 +17,9 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
/**
This shader finalizes the convolution for the LIC computation
applying the normalization. eg. if box kernel is used the this
......
......@@ -20,6 +20,9 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
// Fragment shader used by the gaussian blur filter render pass.
uniform sampler2D texVectors; // input texture
......
......@@ -20,6 +20,9 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
varying vec2 tcoordVC;
/*
......
......@@ -21,6 +21,9 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texGeomColors; // scalars + lighting
uniform sampler2D texLIC; // image lic, mask
uniform sampler2D texHSLColors; // hsla colors
......
......@@ -19,6 +19,9 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texDepth; // z values from vertex shader
uniform sampler2D texRGBColors; // final rgb LIC colors
......
......@@ -19,6 +19,9 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// the output of this shader
//VTK::Output::Dec
uniform sampler2D texVectors; // vectors, depth
uniform sampler2D texGeomColors; // scalar colors + lighting
uniform sampler2D texLIC; // image lic
......
......@@ -128,6 +128,7 @@ set(shader_files
glsl/vtkglPolyData2DFS.glsl
glsl/vtkglPolyData2DVS.glsl
glsl/vtkglPolyDataFS.glsl
glsl/vtkglPolyDataGS.glsl
glsl/vtkglPolyDataVSFragmentLit.glsl
)
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 @@
// Bring in our fragment lit shader symbols.
#include "vtkglPolyDataVSFragmentLit.h"
#include "vtkglPolyDataFS.h"
#include "vtkglPolyDataGS.h"
#include <algorithm>
......@@ -191,6 +192,7 @@ void vtkOpenGLPolyDataMapper::GetShaderTemplate(
{
VSSource = vtkglPolyDataVSFragmentLit;
FSSource = vtkglPolyDataFS;
//GSSource = vtkglPolyDataGS;
GSSource.clear();
}
......@@ -580,6 +582,13 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderValues(
substitute(VSSource,
"//VTK::Normal::Impl",
"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,
"//VTK::Normal::Dec",
"varying vec3 normalVCVarying;");
......
......@@ -405,11 +405,23 @@ void vtkOpenGLRenderWindow::OpenGLInitContext()
return;
}
if (!GLEW_VERSION_2_1)
if (!GLEW_VERSION_3_2)
{
vtkErrorMacro("GL version 2.1 is not supported by your graphics driver.");
//m_valid = false;
return;
if (!GLEW_VERSION_2_1)
{
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
this->Initialized = true;
......
......@@ -128,6 +128,12 @@ vtkShaderProgram *vtkOpenGLShaderCache::ReadyShader(
"#define texture2D 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;
bool done = false;
while (!done)
......
......@@ -50,14 +50,26 @@ bool vtkShader::Compile()
}
// Ensure we delete the previous shader if necessary.
if (Handle != 0)
if (this->Handle != 0)
{
glDeleteShader(static_cast<GLuint>(Handle));
Handle = 0;
glDeleteShader(static_cast<GLuint>(this->Handle));
this->Handle = 0;
}
GLenum type = ShaderType == Vertex ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER;
// TODO: handle geometry shaders if supported
GLenum type = GL_VERTEX_SHADER;
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);
const GLchar *source = static_cast<const GLchar *>(this->Source.c_str());
......
......@@ -49,19 +49,19 @@ public:
void SetType(Type type);
/** 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. */
void SetSource(const std::string &source);
/** 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. */
std::string GetError() const { return Error; }
std::string GetError() const { return this->Error; }
/** Get the handle of the shader. */
int GetHandle() const { return Handle; }
int GetHandle() const { return this->Handle; }
/** 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)
vtkStandardNewMacro(vtkShaderProgram)
vtkShaderProgram::vtkShaderProgram() : Handle(0), VertexShaderHandle(0),
FragmentShaderHandle(0), Linked(false), Bound(false)
{
this->VertexShader = vtkShader::New();
this->VertexShader->SetType(vtkShader::Vertex);
this->FragmentShader = vtkShader::New();
this->FragmentShader->SetType(vtkShader::Fragment);
this->GeometryShader = vtkShader::New();
this->GeometryShader->SetType(vtkShader::Geometry);
this->Compiled = false;
this->NumberOfOutputs = 0;
vtkShaderProgram::vtkShaderProgram()
{
this->VertexShader = vtkShader::New();
this->VertexShader->SetType(vtkShader::Vertex);
this->FragmentShader = vtkShader::New();
this->FragmentShader->SetType(vtkShader::Fragment);
this->GeometryShader = vtkShader::New();
this->GeometryShader->SetType(vtkShader::Geometry);
this->Compiled = false;
this->NumberOfOutputs = 0;
this->Handle = 0;
this->VertexShaderHandle = 0;
this->FragmentShaderHandle = 0;
this->GeometryShaderHandle = 0;
this->Linked = false;
this->Bound = false;
}
vtkShaderProgram::~vtkShaderProgram()
......@@ -134,22 +139,31 @@ bool vtkShaderProgram::AttachShader(const vtkShader *shader)
if (shader->GetType() == vtkShader::Vertex)
{
if (VertexShaderHandle != 0)
if (this->VertexShaderHandle != 0)
{
glDetachShader(static_cast<GLuint>(Handle),
static_cast<GLuint>(VertexShaderHandle));
glDetachShader(static_cast<GLuint>(this->Handle),
static_cast<GLuint>(this->VertexShaderHandle));
}
this->VertexShaderHandle = shader->GetHandle();
}
else if (shader->GetType() == vtkShader::Fragment)
{
if (FragmentShaderHandle != 0)
if (this->FragmentShaderHandle != 0)
{
glDetachShader(static_cast<GLuint>(Handle),
static_cast<GLuint>(FragmentShaderHandle));
glDetachShader(static_cast<GLuint>(this->Handle),
static_cast<GLuint>(this->FragmentShaderHandle));
}
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
{
this->Error = "Unknown shader type encountered - this should not happen.";
......@@ -209,6 +223,20 @@ bool vtkShaderProgram::DetachShader(const vtkShader *shader)
this->Linked = false;
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:
return false;
}
......@@ -309,6 +337,22 @@ int vtkShaderProgram::CompileShader()
vtkErrorMacro(<< this->GetFragmentShader()->GetError());
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()))
{
vtkErrorMacro(<< this->GetError());
......@@ -319,6 +363,12 @@ int vtkShaderProgram::CompileShader()
vtkErrorMacro(<< this->GetError());
return 0;
}
if (this->GetGeometryShader()->GetSource().size() > 0 &&
!this->AttachShader(this->GetGeometryShader()))
{
vtkErrorMacro(<< this->GetError());
return 0;
}
if (!this->Link())
{
vtkErrorMacro(<< "Links failed: " << this->GetError());
......@@ -345,8 +395,10 @@ void vtkShaderProgram::ReleaseGraphicsResources(vtkWindow *win)
{
this->DetachShader(this->VertexShader);
this->DetachShader(this->FragmentShader);
this->DetachShader(this->GeometryShader);
this->VertexShader->Cleanup();
this->FragmentShader->Cleanup();
this->GeometryShader->Cleanup();
this->Compiled = false;
}
......
......@@ -238,6 +238,7 @@ protected:
int Handle;
int VertexShaderHandle;
int FragmentShaderHandle;
int GeometryShaderHandle;
bool Linked;
bool Bound;
......
......@@ -631,7 +631,7 @@ void vtkWin32OpenGLRenderWindow::SetupPixelFormatPaletteAndContext(
this->SetupPalette(hDC);
// create a context
//#define USE_32_CONTEXT
#define USE_32_CONTEXT
#ifdef USE_32_CONTEXT
PFNWGLCREATECONTEXTATTRIBSARBPROC 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