Commit 780a38c1 authored by Ken Martin's avatar Ken Martin
Browse files

Convert Cocoa to default to OpenGL 3.2

OSX is a bit more strict on its opengl so a bunch more changes were
required such as using in/out instead of attribute/varying. Also
handle gl_FragData properly for 3.2 as an output variable.

glew had a bug preventing glGenVertextAttribute... from being
defined. Made a change to correct that.
parent 326eed21
......@@ -22,6 +22,9 @@ varying vec2 tcoordVC;
uniform sampler2D translucentRGBATexture;
uniform sampler2D opaqueRGBATexture;
// the output of this shader
//VTK::Output::Dec
void main()
{
vec4 t1Color = texture2D(translucentRGBATexture, tcoordVC);
......
......@@ -23,6 +23,9 @@ uniform sampler2D currentRGBATexture;
uniform int lastpass;
// the output of this shader
//VTK::Output::Dec
void main()
{
// current is what is most recently rendered
......
......@@ -26,6 +26,9 @@ uniform float coef[3];
uniform float offsetx;
uniform float offsety;
// the output of this shader
//VTK::Output::Dec
void main(void)
{
vec2 offset=vec2(offsetx,offsety);
......
......@@ -23,6 +23,9 @@ varying vec2 tcoordVC;
uniform sampler2D source;
uniform float stepSize; // 1/W
// the output of this shader
//VTK::Output::Dec
void main(void)
{
vec2 offset=vec2(stepSize,0.0);
......
......@@ -25,6 +25,9 @@ uniform sampler2D gx1;
uniform sampler2D gy1;
uniform float stepSize; // 1/H
// the output of this shader
//VTK::Output::Dec
void main(void)
{
vec2 offset=vec2(0.0,stepSize);
......
......@@ -22,6 +22,9 @@
varying vec2 tcoordVC;
uniform sampler2D source;
// the output of this shader
//VTK::Output::Dec
void main(void)
{
gl_FragData[0] = texture2D(source,tcoordVC);
......
......@@ -28,6 +28,9 @@ uniform int PrimitiveIDOffset;
// Depth Peeling
//VTK::DepthPeeling::Dec
// the output of this shader
//VTK::Output::Dec
void main()
{
//VTK::Color::Impl
......
......@@ -51,6 +51,9 @@ uniform int PrimitiveIDOffset;
// clipping plane vars
//VTK::Clip::Dec
// the output of this shader
//VTK::Output::Dec
void main()
{
//VTK::Clip::Impl
......
......@@ -886,6 +886,8 @@ void vtkCocoaRenderWindow::CreateGLContext()
int i = 0;
NSOpenGLPixelFormatAttribute attribs[20];
attribs[i++] = NSOpenGLPFAOpenGLProfile;
attribs[i++] = NSOpenGLProfileVersion3_2Core;
attribs[i++] = NSOpenGLPFAAccelerated;
attribs[i++] = NSOpenGLPFADepthSize;
attribs[i++] = (NSOpenGLPixelFormatAttribute)32;
......@@ -928,6 +930,10 @@ void vtkCocoaRenderWindow::CreateGLContext()
this->MultiSamples /= 2;
}
}
else
{
this->SetContextSupportsOpenGL32(true);
}
}
NSOpenGLContext *context = [[NSOpenGLContext alloc]
......
......@@ -32,7 +32,7 @@
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkLookupTable.h"
#include "vtkLookupTable.h"
#include "vtkShaderProgram.h"
#include "vtkTextureObject.h"
......@@ -727,7 +727,7 @@ void vtkCompositePolyDataMapper2::AppendOneBufferObject(
// create the cell scalar array adjusted for ogl Cells
unsigned char *colorPtr = this->Colors->GetPointer(0);
int numComp = this->Colors->GetNumberOfComponents();
for (int i = 0; i < cellCellMap.size(); i++)
for (unsigned int i = 0; i < cellCellMap.size(); i++)
{
for (int j = 0; j < numComp; j++)
{
......@@ -746,7 +746,7 @@ void vtkCompositePolyDataMapper2::AppendOneBufferObject(
this->CellNormalTexture->SetContext(
static_cast<vtkOpenGLRenderWindow*>(ren->GetVTKWindow()));
// create the cell scalar array adjusted for ogl Cells
for (int i = 0; i < cellCellMap.size(); i++)
for (unsigned int i = 0; i < cellCellMap.size(); i++)
{
double *norms = n->GetTuple(cellCellMap[i]);
newNorms.push_back(norms[0]);
......
......@@ -1885,7 +1885,7 @@ void vtkOpenGLPolyDataMapper::BuildCellTextures(
if (this->HavePickScalars)
{
for (int i = 0; i < cellCellMap.size(); i++)
for (unsigned int i = 0; i < cellCellMap.size(); i++)
{
unsigned int value = cellCellMap[i]+1;
if (mapArray)
......@@ -1903,7 +1903,7 @@ void vtkOpenGLPolyDataMapper::BuildCellTextures(
unsigned char *colorPtr = this->Colors->GetPointer(0);
numComp = this->Colors->GetNumberOfComponents();
assert(numComp == 4);
for (int i = 0; i < cellCellMap.size(); i++)
for (unsigned int i = 0; i < cellCellMap.size(); i++)
{
for (int j = 0; j < numComp; j++)
{
......@@ -1932,7 +1932,7 @@ void vtkOpenGLPolyDataMapper::BuildCellTextures(
// create the cell scalar array adjusted for ogl Cells
std::vector<float> newNorms;
vtkDataArray *n = this->CurrentInput->GetCellData()->GetNormals();
for (int i = 0; i < cellCellMap.size(); i++)
for (unsigned int i = 0; i < cellCellMap.size(); i++)
{
double *norms = n->GetTuple(cellCellMap[i]);
newNorms.push_back(norms[0]);
......
......@@ -447,9 +447,9 @@ void vtkOpenGLPolyDataMapper2D::UpdateVBO(vtkActor2D *act, vtkViewport *viewport
unsigned char *colorPtr = this->Colors->GetPointer(0);
int numComp = this->Colors->GetNumberOfComponents();
assert(numComp == 4);
for (int i = 0; i < cellCellMap.size(); i++)
for (unsigned int i = 0; i < cellCellMap.size(); i++)
{
for (int j = 0; j < numComp; j++)
for (j = 0; j < numComp; j++)
{
newColors.push_back(colorPtr[cellCellMap[i]*numComp + j]);
}
......
......@@ -15,20 +15,21 @@
#include "vtkOpenGLShaderCache.h"
#include "vtk_glew.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLError.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkShader.h"
#include "vtkShaderProgram.h"
#include "vtkglVBOHelper.h"
#include <math.h>
#include <sstream>
#include "vtkObjectFactory.h"
#include "vtkglVBOHelper.h"
#include "vtkShader.h"
#include "vtkShaderProgram.h"
#include "vtksys/MD5.h"
using vtkgl::replace;
using vtkgl::substitute;
class vtkOpenGLShaderCache::Private
{
......@@ -101,7 +102,9 @@ vtkShaderProgram *vtkOpenGLShaderCache::ReadyShader(
{
// perform system wide shader replacements
// desktops to not use percision statements
#if GL_ES_VERSION_2_0 != 1
unsigned int count = 0;
std::string VSSource = vertexCode;
std::string FSSource = fragmentCode;
std::string GSSource = geometryCode;
......@@ -109,18 +112,39 @@ vtkShaderProgram *vtkOpenGLShaderCache::ReadyShader(
{
VSSource = replace(VSSource,"//VTK::System::Dec",
"#version 150\n"
"#define attribute in\n"
"#define varying out\n"
"#define highp\n"
"#define mediump\n"
"#define lowp");
FSSource = replace(FSSource,"//VTK::System::Dec",
"#version 150\n"
"#define varying in\n"
"#define highp\n"
"#define mediump\n"
"#define lowp\n"
"#define texelFetchBuffer texelFetch\n"
"#define texture1D texture\n"
"#define texture2D texture\n"
"#define texture3D texture\n"
);
std::string fragDecls;
bool done = false;
while (!done)
{
std::ostringstream src;
std::ostringstream dst;
src << "gl_FragData[" << count << "]";
// this naming has to match the bindings
// in vtkOpenGLShaderProgram.cxx
dst << "fragOutput" << count;
done = !substitute(FSSource, src.str(),dst.str());
if (!done)
{
fragDecls += "out vec4 " + dst.str() + ";\n";
}
}
FSSource = replace(FSSource,"//VTK::Output::Dec",fragDecls);
GSSource = replace(GSSource,"//VTK::System::Dec",
"#version 150\n"
"#define highp\n"
......@@ -147,6 +171,7 @@ vtkShaderProgram *vtkOpenGLShaderCache::ReadyShader(
"#define lowp");
}
vtkShaderProgram *shader = this->GetShader(VSSource.c_str(), FSSource.c_str(), GSSource.c_str());
shader->SetNumberOfOutputs(count);
#else
std::string FSSource = fragmentCode;
FSSource = replace(FSSource,"//VTK::System::Dec",
......
......@@ -71,6 +71,7 @@ vtkShaderProgram::vtkShaderProgram() : Handle(0), VertexShaderHandle(0),
this->GeometryShader->SetType(vtkShader::Geometry);
this->Compiled = false;
this->NumberOfOutputs = 0;
}
vtkShaderProgram::~vtkShaderProgram()
......@@ -226,6 +227,20 @@ bool vtkShaderProgram::Link()
return false;
}
// bind the outputs if specified
if (this->NumberOfOutputs)
{
for (unsigned int i = 0; i < this->NumberOfOutputs; i++)
{
// this naming has to match the bindings
// in vtkOpenGLShaderProgram.cxx
std::ostringstream dst;
dst << "fragOutput" << i;
glBindFragDataLocation(static_cast<GLuint>(this->Handle), i,
dst.str().c_str());
}
}
GLint isCompiled;
glLinkProgram(static_cast<GLuint>(this->Handle));
glGetProgramiv(static_cast<GLuint>(this->Handle), GL_LINK_STATUS, &isCompiled);
......
......@@ -172,6 +172,10 @@ public:
bool SetUniform3fv(const char *name, const int count, const float (*f)[3]);
bool SetUniform4fv(const char *name, const int count, const float (*f)[4]);
// How many outputs does this program produce
// only valid for OpenGL 3.2 or later
vtkSetMacro(NumberOfOutputs,unsigned int);
protected:
vtkShaderProgram();
~vtkShaderProgram();
......@@ -239,6 +243,12 @@ protected:
bool Bound;
bool Compiled;
// for glsl 1.5 or later, how many outputs
// does this shader create
// they will be bound in order to
// fragOutput0 fragOutput1 etc...
unsigned int NumberOfOutputs;
std::string Error;
std::map<std::string, int> Attributes;
......
......@@ -47,6 +47,8 @@ vec4 g_eyePosObj;
uniform vec4 in_volume_scale;
uniform vec4 in_volume_bias;
//VTK::Output::Dec
//VTK::Base::Dec
//VTK::Termination::Dec
......@@ -131,5 +133,5 @@ void main()
g_fragColor.r = g_fragColor.r * in_scale + in_bias * g_fragColor.a;
g_fragColor.g = g_fragColor.g * in_scale + in_bias * g_fragColor.a;
g_fragColor.b = g_fragColor.b * in_scale + in_bias * g_fragColor.a;
gl_FragColor = g_fragColor;
gl_FragData[0] = g_fragColor;
}
......@@ -17,6 +17,8 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
//VTK::Output::Dec
varying vec3 fcolor;
varying float fdepth;
varying float fattenuation;
......@@ -30,9 +32,9 @@ void main()
float opacity = 1.0 - exp(-1.0*fattenuation*fdepth);
gl_FragColor = vec4(opacity*fcolor,opacity);
gl_FragData[0] = vec4(opacity*fcolor,opacity);
if (gl_FragColor.a <= 0.0)
if (gl_FragData[0].a <= 0.0)
{
discard;
}
......
......@@ -3845,6 +3845,10 @@ static GLboolean _glewInit_GL_VERSION_3_2 (GLEW_CONTEXT_ARG_DEF_INIT)
r = ((glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC)glewGetProcAddress((const GLubyte*)"glFramebufferTexture")) == NULL) || r;
r = ((glGetBufferParameteri64v = (PFNGLGETBUFFERPARAMETERI64VPROC)glewGetProcAddress((const GLubyte*)"glGetBufferParameteri64v")) == NULL) || r;
r = ((glGetInteger64i_v = (PFNGLGETINTEGER64I_VPROC)glewGetProcAddress((const GLubyte*)"glGetInteger64i_v")) == NULL) || r;
r = ((glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC)glewGetProcAddress((const GLubyte*)"glBindVertexArray")) == NULL) || r;
r = ((glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC)glewGetProcAddress((const GLubyte*)"glDeleteVertexArrays")) == NULL) || r;
r = ((glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC)glewGetProcAddress((const GLubyte*)"glGenVertexArrays")) == NULL) || r;
r = ((glIsVertexArray = (PFNGLISVERTEXARRAYPROC)glewGetProcAddress((const GLubyte*)"glIsVertexArray")) == NULL) || r;
 
return r;
}
......
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