Commit 3c999de5 authored by Ken Martin's avatar Ken Martin

update glsl code to 140 standards

While maintaining backwards compatibility at least
update our code to use the more modern in/out
qualifiers as opposed to attribute/varying  Also
remove old glsl 120 if statements as we no longer support
it and also remove a performance issue in querying the
gl major minor version on every shader test.
parent cf50a2f6
......@@ -75,20 +75,20 @@ namespace
}
const char *myVertShader =
"attribute vec2 vertexMC;\n"
"in vec2 vertexMC;\n"
"uniform mat4 WCDCMatrix;\n"
"uniform mat4 MCWCMatrix;\n"
"#ifdef haveColors\n"
"attribute vec4 vertexScalar;\n"
"varying vec4 vertexColor;\n"
"in vec4 vertexScalar;\n"
"out vec4 vertexColor;\n"
"#endif\n"
"#ifdef haveTCoords\n"
"attribute vec2 tcoordMC;\n"
"varying vec2 tcoord;\n"
"in vec2 tcoordMC;\n"
"out vec2 tcoord;\n"
"#endif\n"
"#ifdef haveLines\n"
"attribute vec2 tcoordMC;\n"
"varying float ldistance;\n"
"in vec2 tcoordMC;\n"
"out float ldistance;\n"
"#endif\n"
"void main() {\n"
"#ifdef haveColors\n"
......@@ -106,16 +106,16 @@ namespace
const char *myFragShader =
"//VTK::Output::Dec\n"
"#ifdef haveColors\n"
"varying vec4 vertexColor;\n"
"in vec4 vertexColor;\n"
"#else\n"
"uniform vec4 vertexColor;\n"
"#endif\n"
"#ifdef haveTCoords\n"
"varying vec2 tcoord;\n"
"in vec2 tcoord;\n"
"uniform sampler2D texture1;\n"
"#endif\n"
"#ifdef haveLines\n"
"varying float ldistance;\n"
"in float ldistance;\n"
"uniform int stipple;\n"
"#endif\n"
"void main() {\n"
......@@ -712,7 +712,7 @@ void vtkOpenGLContextDevice2D::ReadySBOProgram()
this->RenderWindow->GetShaderCache()->ReadyShaderProgram(
// vertex shader
"//VTK::System::Dec\n"
"attribute vec2 vertexMC;\n"
"in vec2 vertexMC;\n"
"uniform mat4 WCDCMatrix;\n"
"uniform mat4 MCWCMatrix;\n"
"void main() {\n"
......@@ -741,11 +741,11 @@ void vtkOpenGLContextDevice2D::ReadySCBOProgram()
this->RenderWindow->GetShaderCache()->ReadyShaderProgram(
// vertex shader
"//VTK::System::Dec\n"
"attribute vec2 vertexMC;\n"
"attribute vec4 vertexScalar;\n"
"in vec2 vertexMC;\n"
"in vec4 vertexScalar;\n"
"uniform mat4 WCDCMatrix;\n"
"uniform mat4 MCWCMatrix;\n"
"varying vec4 vertexColor;\n"
"out vec4 vertexColor;\n"
"void main() {\n"
"vec4 vertex = vec4(vertexMC.xy, 0.0, 1.0);\n"
"vertexColor = vertexScalar;\n"
......@@ -753,7 +753,7 @@ void vtkOpenGLContextDevice2D::ReadySCBOProgram()
// fragment shader
"//VTK::System::Dec\n"
"//VTK::Output::Dec\n"
"varying vec4 vertexColor;\n"
"in vec4 vertexColor;\n"
"uniform sampler2D texture1;\n"
"void main() { gl_FragData[0] = vertexColor*texture2D(texture1, gl_PointCoord); }",
// geometry shader
......
......@@ -250,12 +250,12 @@ void vtkOpenGLContextDevice3D::ReadyVBOProgram()
this->RenderWindow->GetShaderCache()->ReadyShaderProgram(
// vertex shader
"//VTK::System::Dec\n"
"attribute vec3 vertexMC;\n"
"in vec3 vertexMC;\n"
"uniform mat4 WCDCMatrix;\n"
"uniform mat4 MCWCMatrix;\n"
"uniform int numClipPlanes;\n"
"uniform vec4 clipPlanes[6];\n"
"varying float clipDistances[6];\n"
"out float clipDistances[6];\n"
"void main() {\n"
"vec4 vertex = vec4(vertexMC.xyz, 1.0);\n"
"for (int planeNum = 0; planeNum < numClipPlanes; planeNum++)\n"
......@@ -268,7 +268,7 @@ void vtkOpenGLContextDevice3D::ReadyVBOProgram()
"//VTK::Output::Dec\n"
"uniform vec4 vertexColor;\n"
"uniform int numClipPlanes;\n"
"varying float clipDistances[6];\n"
"in float clipDistances[6];\n"
"void main() { \n"
" for (int planeNum = 0; planeNum < numClipPlanes; planeNum++)\n"
" {\n"
......@@ -292,14 +292,14 @@ void vtkOpenGLContextDevice3D::ReadyVCBOProgram()
this->RenderWindow->GetShaderCache()->ReadyShaderProgram(
// vertex shader
"//VTK::System::Dec\n"
"attribute vec3 vertexMC;\n"
"attribute vec4 vertexScalar;\n"
"in vec3 vertexMC;\n"
"in vec4 vertexScalar;\n"
"uniform mat4 WCDCMatrix;\n"
"uniform mat4 MCWCMatrix;\n"
"varying vec4 vertexColor;\n"
"out vec4 vertexColor;\n"
"uniform int numClipPlanes;\n"
"uniform vec4 clipPlanes[6];\n"
"varying float clipDistances[6];\n"
"out float clipDistances[6];\n"
"void main() {\n"
"vec4 vertex = vec4(vertexMC.xyz, 1.0);\n"
"vertexColor = vertexScalar;\n"
......@@ -311,9 +311,9 @@ void vtkOpenGLContextDevice3D::ReadyVCBOProgram()
// fragment shader
"//VTK::System::Dec\n"
"//VTK::Output::Dec\n"
"varying vec4 vertexColor;\n"
"in vec4 vertexColor;\n"
"uniform int numClipPlanes;\n"
"varying float clipDistances[6];\n"
"in float clipDistances[6];\n"
"void main() { \n"
" for (int planeNum = 0; planeNum < numClipPlanes; planeNum++)\n"
" {\n"
......
......@@ -13,8 +13,8 @@ xmlMaterial = '''<?xml version="1.0" encoding="UTF-8"?>
location="Inline"
language="GLSL"
entry="main">
attribute vec3 genAttrVector;
varying vec4 color;
in vec3 genAttrVector;
out vec4 color;
void main(void)
{
......@@ -25,7 +25,7 @@ xmlMaterial = '''<?xml version="1.0" encoding="UTF-8"?>
<Shader scope="Fragment" name="FragmentShader" location="Inline"
language="GLSL" entry="main">
varying vec4 color;
in vec4 color;
void main(void)
{
gl_FragColor = color;
......
......@@ -120,8 +120,8 @@ void vtkCompositeLICHelper::ReplaceShaderValues(
// add some code to handle the LIC vectors and mask
vtkShaderProgram::Substitute(VSSource,
"//VTK::TCoord::Dec",
"attribute vec3 vecsMC;\n"
"varying vec3 tcoordVCVSOutput;\n"
"in vec3 vecsMC;\n"
"out vec3 tcoordVCVSOutput;\n"
);
vtkShaderProgram::Substitute(VSSource, "//VTK::TCoord::Impl",
......@@ -133,7 +133,7 @@ void vtkCompositeLICHelper::ReplaceShaderValues(
// 0/1, when 1 V is projected to surface for |V| computation.
"uniform int uMaskOnSurface;\n"
"uniform mat3 normalMatrix;\n"
"varying vec3 tcoordVCVSOutput;"
"in vec3 tcoordVCVSOutput;"
);
vtkShaderProgram::Substitute(FSSource,
......
......@@ -477,7 +477,7 @@ int vtkImageDataLIC2D::RequestData(
this->Context->GetShaderCache()->ReadyShaderProgram(
vtkTextureObjectVS,
"//VTK::System::Dec\n"
"varying vec2 tcoordVC;\n"
"in vec2 tcoordVC;\n"
"uniform sampler2D source;\n"
"//VTK::Output::Dec\n"
"void main(void) {\n"
......
......@@ -24,7 +24,7 @@ uniform sampler2D texLIC; // inout texture
uniform vec2 uLICTexSize; // input texture size
uniform vec4 uComputeBounds; // valid region of texture
varying vec2 tcoordVC;
in vec2 tcoordVC;
// fragment size
float tcDx = 1.0 / uLICTexSize.x;
......
......@@ -24,7 +24,7 @@
uniform sampler2D texLIC; // input texture
uniform float uDx; // fragment size
varying vec2 tcoordVC;
in vec2 tcoordVC;
// neighbor offsets
vec2 fragDx[3] = vec2[3](vec2(-uDx,0.0), vec2(0.0,0.0), vec2(uDx,0.0));
......
......@@ -24,7 +24,7 @@
uniform sampler2D texLIC; // input texture
uniform float uDy; // fragment size
varying vec2 tcoordVC;
in vec2 tcoordVC;
// neighbor offsets
vec2 fragDy[3] = vec2[3](vec2(0.0,-uDy), vec2(0.0,0.0), vec2(0.0,uDy));
......
......@@ -26,7 +26,7 @@ uniform sampler2D texLIC; // most recent lic pass
uniform float uMin; // min gray scale color value
uniform float uMaxMinDiff; // max-min
varying vec2 tcoordVC;
in vec2 tcoordVC;
void main( void )
{
......
......@@ -26,7 +26,7 @@ uniform sampler2D texLIC; // most recent lic pass
uniform float uDx; // fragment size
uniform float uDy; // fragment size
varying vec2 tcoordVC;
in vec2 tcoordVC;
// kernel for simple laplace edge enhancement.
// p=Laplace(p)+p
......
......@@ -31,7 +31,7 @@ uniform int uPassNo; // in pass 1 hpf of pass 0 is convolved.
uniform float uMaskThreshold; // if |V| < uMaskThreshold render transparent
uniform vec2 uNoiseBoundsPt1; // tc of upper right pt of noise texture
varying vec2 tcoordVC;
in vec2 tcoordVC;
// convert from vector coordinate space to noise coordinate space.
// the noise texture is tiled across the *whole* domain
......
......@@ -28,7 +28,7 @@ uniform float uStepSize; // step size in parametric space
uniform vec2 uNoiseBoundsPt1; // tc of upper right pt of noise texture
varying vec2 tcoordVC;
in vec2 tcoordVC;
//VTK::LICVectorLookup::Impl
......
......@@ -26,7 +26,7 @@ is the number of steps taken.
uniform sampler2D texLIC;
varying vec2 tcoordVC;
in vec2 tcoordVC;
void main(void)
{
......
......@@ -26,7 +26,7 @@
uniform sampler2D texVectors; // input texture
uniform vec2 uTexSize; // size of texture
varying vec2 tcoordVC;
in vec2 tcoordVC;
void main(void)
{
......
......@@ -21,7 +21,7 @@
// the output of this shader
//VTK::Output::Dec
varying vec2 tcoordVC;
in vec2 tcoordVC;
/*
For an input structure grid, this computes the inverse jacobian for each point.
......
......@@ -29,7 +29,7 @@ uniform sampler2D texHSLColors; // hsla colors
uniform float uLMin; // min lightness over all fragments
uniform float uLMaxMinDiff; // max - min lightness over all fragments
varying vec2 tcoordVC;
in vec2 tcoordVC;
vec3 HSLToRGB(vec3 HSL)
{
......
......@@ -23,7 +23,7 @@
uniform sampler2D texDepth; // z values from vertex shader
uniform sampler2D texRGBColors; // final rgb LIC colors
varying vec2 tcoordVC;
in vec2 tcoordVC;
void main()
{
......
......@@ -29,7 +29,7 @@ uniform float uMapBias; // map shader: adjust the brightness of the
uniform float uMaskIntensity; // blending factor for mask color
uniform vec3 uMaskColor; // color for the masked out fragments
varying vec2 tcoordVC;
in vec2 tcoordVC;
/**
Convert from RGB color space into HSL colorspace.
......
......@@ -91,8 +91,8 @@ void vtkSurfaceLICMapper::ReplaceShaderValues(
// add some code to handle the LIC vectors and mask
vtkShaderProgram::Substitute(VSSource,
"//VTK::TCoord::Dec",
"attribute vec3 vecsMC;\n"
"varying vec3 tcoordVCVSOutput;\n"
"in vec3 vecsMC;\n"
"out vec3 tcoordVCVSOutput;\n"
);
vtkShaderProgram::Substitute(VSSource, "//VTK::TCoord::Impl",
......@@ -104,7 +104,7 @@ void vtkSurfaceLICMapper::ReplaceShaderValues(
// 0/1, when 1 V is projected to surface for |V| computation.
"uniform int uMaskOnSurface;\n"
"uniform mat3 normalMatrix;\n"
"varying vec3 tcoordVCVSOutput;"
"in vec3 tcoordVCVSOutput;"
);
vtkShaderProgram::Substitute(FSSource,
......
......@@ -92,7 +92,7 @@ int TestCubeMap(int argc, char *argv[])
"//VTK::PositionVC::Dec", // replace the normal block
true, // before the standard replacements
"//VTK::PositionVC::Dec\n" // we still want the default
"varying vec3 TexCoords;\n",
"out vec3 TexCoords;\n",
false // only do it once
);
mapper->AddShaderReplacement(
......@@ -109,7 +109,7 @@ int TestCubeMap(int argc, char *argv[])
mapper->SetFragmentShaderCode(
"//VTK::System::Dec\n" // always start with this line
"//VTK::Output::Dec\n" // always have this line in your FS
"varying vec3 TexCoords;\n"
"in vec3 TexCoords;\n"
"uniform samplerCube texture_0;\n"
"void main () {\n"
" gl_FragData[0] = texture(texture_0, TexCoords);\n"
......
......@@ -118,7 +118,7 @@ int TestCubeMap2(int argc, char *argv[])
"//VTK::PositionVC::Dec", // replace
true, // before the standard replacements
"//VTK::PositionVC::Dec\n" // we still want the default
"varying vec3 TexCoords;\n",
"out vec3 TexCoords;\n",
false // only do it once
);
mapper->AddShaderReplacement(
......@@ -135,7 +135,7 @@ int TestCubeMap2(int argc, char *argv[])
"//VTK::Light::Dec", // replace
true, // before the standard replacements
"//VTK::Light::Dec\n" // we still want the default
"varying vec3 TexCoords;\n",
"in vec3 TexCoords;\n",
false // only do it once
);
mapper->AddShaderReplacement(
......
......@@ -98,7 +98,7 @@ int TestSphereMap(int argc, char *argv[])
"//VTK::PositionVC::Dec", // replace
true, // before the standard replacements
"//VTK::PositionVC::Dec\n" // we still want the default
"varying vec3 TexCoords;\n",
"out vec3 TexCoords;\n",
false // only do it once
);
mapper->AddShaderReplacement(
......@@ -115,7 +115,7 @@ int TestSphereMap(int argc, char *argv[])
"//VTK::Light::Dec", // replace
true, // before the standard replacements
"//VTK::Light::Dec\n" // we still want the default
"varying vec3 TexCoords;\n",
"in vec3 TexCoords;\n",
false // only do it once
);
mapper->AddShaderReplacement(
......
......@@ -79,7 +79,7 @@ int TestUserShader(int argc, char *argv[])
"//VTK::Normal::Dec", // replace the normal block
true, // before the standard replacements
"//VTK::Normal::Dec\n" // we still want the default
" varying vec3 myNormalMCVSOutput;\n", //but we add this
" out vec3 myNormalMCVSOutput;\n", //but we add this
false // only do it once
);
mapper->AddShaderReplacement(
......@@ -109,7 +109,7 @@ int TestUserShader(int argc, char *argv[])
"//VTK::Normal::Dec", // replace the normal block
true, // before the standard replacements
"//VTK::Normal::Dec\n" // we still want the default
" varying vec3 myNormalMCVSOutput;\n", //but we add this
" in vec3 myNormalMCVSOutput;\n", //but we add this
false // only do it once
);
mapper->AddShaderReplacement(
......
......@@ -138,7 +138,7 @@ int TestUserShader2(int argc, char *argv[])
// use them :-)
mapper->SetVertexShaderCode(
"//VTK::System::Dec\n" // always start with this line
"attribute vec4 vertexMC;\n"
"in vec4 vertexMC;\n"
// use the default normal decl as the mapper
// will then provide the normalMatrix uniform
// which we use later on
......@@ -156,7 +156,7 @@ int TestUserShader2(int argc, char *argv[])
mapper->SetFragmentShaderCode(
"//VTK::System::Dec\n" // always start with this line
"//VTK::Output::Dec\n" // always have this line in your FS
"varying vec3 normalVCVSOutput;\n"
"in vec3 normalVCVSOutput;\n"
"uniform vec3 diffuseColorUniform;\n"
"void main () {\n"
" float df = max(0.0, normalVCVSOutput.z);\n"
......
......@@ -64,7 +64,7 @@ actor.GetProperty().SetOpacity(1.0)
mapper.SetVertexShaderCode(
"//VTK::System::Dec\n"
"attribute vec4 vertexMC;\n"
"in vec4 vertexMC;\n"
"//VTK::Normal::Dec\n"
"uniform mat4 MCDCMatrix;\n"
"void main () {\n"
......@@ -76,7 +76,7 @@ mapper.SetVertexShaderCode(
mapper.SetFragmentShaderCode(
"//VTK::System::Dec\n"
"//VTK::Output::Dec\n"
"varying vec3 normalVCVSOutput;\n"
"in vec3 normalVCVSOutput;\n"
"uniform vec3 diffuseColorUniform;\n"
"void main () {\n"
" float df = max(0.0, normalVCVSOutput.z);\n"
......
......@@ -17,7 +17,7 @@
// Fragment shader used by the DOF render pass.
varying vec2 tcoordVC;
in vec2 tcoordVC;
uniform sampler2D source;
uniform sampler2D depth;
......
......@@ -15,7 +15,7 @@
=========================================================================*/
varying vec2 tcoordVC;
in vec2 tcoordVC;
uniform sampler2D translucentRGBATexture;
uniform sampler2D opaqueRGBATexture;
......
......@@ -15,7 +15,7 @@
=========================================================================*/
varying vec2 tcoordVC;
in vec2 tcoordVC;
uniform sampler2D translucentRGBATexture;
uniform sampler2D currentRGBATexture;
......
......@@ -56,7 +56,7 @@ Ph.D. thesis of Christian BOUCHENY.
// the output of this shader
//VTK::Output::Dec
varying vec2 tcoordVC;
in vec2 tcoordVC;
/****************************************************/
uniform sampler2D s2_I;
......
......@@ -49,7 +49,7 @@ Ph.D. thesis of Christian BOUCHENY.
// the output of this shader
//VTK::Output::Dec
varying vec2 tcoordVC;
in vec2 tcoordVC;
/**************************************************/
uniform sampler2D s2_S1; // fine scale
......
......@@ -56,7 +56,7 @@ Ph.D. thesis of Christian BOUCHENY.
// the output of this shader
//VTK::Output::Dec
varying vec2 tcoordVC;
in vec2 tcoordVC;
/**************************************************/
uniform sampler2D s2_depth; // - Z Map
......
......@@ -17,7 +17,7 @@
// Fragment shader used by the gaussian blur filter render pass.
varying vec2 tcoordVC;
in vec2 tcoordVC;
uniform sampler2D source;
uniform float coef[3];
......
......@@ -15,10 +15,10 @@
=========================================================================*/
attribute vec4 vertexMC;
in vec4 vertexMC;
attribute vec2 tcoordMC;
varying vec2 tcoordVC;
in vec2 tcoordMC;
out vec2 tcoordVC;
void main()
{
......
......@@ -24,7 +24,7 @@
// VC - View Coordinates
// DC - Display Coordinates
attribute vec4 vertexMC;
in vec4 vertexMC;
// frag position in VC
//VTK::PositionVC::Dec
......
......@@ -17,7 +17,7 @@
// Fragment shader used by the DOF render pass.
varying vec2 tcoordVC;
in vec2 tcoordVC;
uniform sampler2D source;
uniform sampler2D depth;
uniform float nearC;
......
......@@ -16,8 +16,8 @@
=========================================================================*/
// this shader implements imposters in OpenGL for Spheres
attribute vec4 vertexMC;
attribute vec2 offsetMC;
in vec4 vertexMC;
in vec2 offsetMC;
// optional normal declaration
//VTK::Normal::Dec
......@@ -34,7 +34,7 @@ attribute vec2 offsetMC;
// camera and actor matrix values
//VTK::Camera::Dec
varying vec2 offsetVCVSOutput;
out vec2 offsetVCVSOutput;
uniform int cameraParallel;
uniform float triangleScale;
......
......@@ -22,7 +22,7 @@
// VC - View Coordinates
// DC - Display Coordinates
attribute vec4 vertexWC;
in vec4 vertexWC;
// material property values
//VTK::Color::Dec
......
......@@ -15,7 +15,7 @@
=========================================================================*/
attribute vec4 vertexMC;
in vec4 vertexMC;
// frag position in VC
//VTK::PositionVC::Dec
......
......@@ -25,7 +25,7 @@ uniform sampler2D source;
uniform float texelWidthOffset;
uniform float texelHeightOffset;
varying vec2 tcoordVC;
in vec2 tcoordVC;
// Note that the texel offsets should be 3/8 of a pixel in the
// resulting image not the source image. Also note that this
......
......@@ -17,7 +17,7 @@
// Fragment shader used by the gaussian blur filter render pass.
varying vec2 tcoordVC;
in vec2 tcoordVC;
uniform sampler2D source;
uniform float blendScale;
......
......@@ -17,7 +17,7 @@
// Fragment shader used by the first pass of the Sobel filter render pass.
varying vec2 tcoordVC;
in vec2 tcoordVC;
uniform sampler2D source;
uniform float stepSize; // 1/W
......
......@@ -17,7 +17,7 @@
// Fragment shader used by the second pass of the Sobel filter render pass.