Commit d2335a5d authored by Ken Martin's avatar Ken Martin

Some more fixes for apple to make VTK more 3.2 core compliant

Apple with 3.2 must use VAOs
parent 780a38c1
......@@ -399,8 +399,9 @@ void vtkOpenGLContextDevice2D::ReadyVBOProgram()
"gl_Position = vertex*MCWCMatrix*WCDCMatrix; }\n",
// fragment shader
"//VTK::System::Dec\n"
"//VTK::Output::Dec\n"
"uniform vec4 vertexColor;\n"
"void main() { gl_FragColor = vertexColor; }",
"void main() { gl_FragData[0] = vertexColor; }",
// geometry shader
"");
}
......@@ -429,8 +430,9 @@ void vtkOpenGLContextDevice2D::ReadyVCBOProgram()
"gl_Position = vertex*MCWCMatrix*WCDCMatrix; }\n",
// fragment shader
"//VTK::System::Dec\n"
"//VTK::Output::Dec\n"
"varying vec4 vertexColor;\n"
"void main() { gl_FragColor = vertexColor; }",
"void main() { gl_FragData[0] = vertexColor; }",
// geometry shader
"");
}
......@@ -459,9 +461,10 @@ void vtkOpenGLContextDevice2D::ReadyVTBOProgram()
"gl_Position = vertex*MCWCMatrix*WCDCMatrix; }\n",
// fragment shader
"//VTK::System::Dec\n"
"//VTK::Output::Dec\n"
"varying vec2 tcoord;\n"
"uniform sampler2D texture1;\n"
"void main() { gl_FragColor = texture2D(texture1, tcoord); }",
"void main() { gl_FragData[0] = texture2D(texture1, tcoord); }",
// geometry shader
"");
}
......@@ -487,9 +490,10 @@ void vtkOpenGLContextDevice2D::ReadySBOProgram()
"gl_Position = vertex*MCWCMatrix*WCDCMatrix; }\n",
// fragment shader
"//VTK::System::Dec\n"
"//VTK::Output::Dec\n"
"uniform vec4 vertexColor;\n"
"uniform sampler2D texture1;\n"
"void main() { gl_FragColor = vertexColor*texture2D(texture1, gl_PointCoord); }",
"void main() { gl_FragData[0] = vertexColor*texture2D(texture1, gl_PointCoord); }",
// geometry shader
"");
}
......@@ -518,9 +522,10 @@ void vtkOpenGLContextDevice2D::ReadySCBOProgram()
"gl_Position = vertex*MCWCMatrix*WCDCMatrix; }\n",
// fragment shader
"//VTK::System::Dec\n"
"//VTK::Output::Dec\n"
"varying vec4 vertexColor;\n"
"uniform sampler2D texture1;\n"
"void main() { gl_FragColor = vertexColor*texture2D(texture1, gl_PointCoord); }",
"void main() { gl_FragData[0] = vertexColor*texture2D(texture1, gl_PointCoord); }",
// geometry shader
"");
}
......
......@@ -296,6 +296,7 @@ void vtkOpenGLContextDevice3D::ReadyVBOProgram()
"gl_Position = vertex*MCWCMatrix*WCDCMatrix; }\n",
// fragment shader
"//VTK::System::Dec\n"
"//VTK::Output::Dec\n"
"uniform vec4 vertexColor;\n"
"uniform int numClipPlanes;\n"
"varying float clipDistances[6];\n"
......@@ -304,7 +305,7 @@ void vtkOpenGLContextDevice3D::ReadyVBOProgram()
" {\n"
" if (clipDistances[planeNum] < 0.0) discard;\n"
" }\n"
" gl_FragColor = vertexColor; }",
" gl_FragData[0] = vertexColor; }",
// geometry shader
"");
}
......@@ -340,6 +341,7 @@ void vtkOpenGLContextDevice3D::ReadyVCBOProgram()
"gl_Position = vertex*MCWCMatrix*WCDCMatrix; }\n",
// fragment shader
"//VTK::System::Dec\n"
"//VTK::Output::Dec\n"
"varying vec4 vertexColor;\n"
"uniform int numClipPlanes;\n"
"varying float clipDistances[6];\n"
......@@ -348,7 +350,7 @@ void vtkOpenGLContextDevice3D::ReadyVCBOProgram()
" {\n"
" if (clipDistances[planeNum] < 0.0) discard;\n"
" }\n"
" gl_FragColor = vertexColor; }",
" gl_FragData[0] = vertexColor; }",
// geometry shader
"");
}
......
......@@ -97,9 +97,11 @@ static const char *DepthTextureCompareFunctionAsString[8]=
//----------------------------------------------------------------------------
static GLenum OpenGLAlphaInternalFormat[5]=
{
GL_R,
GL_R8,
GL_R16
GL_R8,
GL_R16,
GL_R16F,
GL_R32F
};
#else
......@@ -122,9 +124,11 @@ static const char *DepthTextureCompareFunctionAsString[8]=
//----------------------------------------------------------------------------
static GLenum OpenGLAlphaInternalFormat[5]=
{
GL_R,
GL_R,
GL_R
GL_RED,
GL_RED,
GL_RED,
GL_RED,
GL_RED
};
#endif
......@@ -1017,7 +1021,7 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
switch (numComps)
{
case 1:
this->InternalFormat = GL_R;
this->InternalFormat = GL_RED;
break;
case 2:
this->InternalFormat = GL_RG;
......
......@@ -106,6 +106,8 @@ public:
alpha=0,
alpha8,
alpha16,
alpha16f,
alpha32f,
NumberOfAlphaFormats
};
......
......@@ -88,9 +88,7 @@ public:
this->LoadDepthTextureExtensionsSucceeded = false;
this->CameraWasInsideInLastUpdate = false;
this->CubeVBOId = 0;
#ifndef __APPLE__
this->CubeVAOId = 0;
#endif
this->CubeIndicesId = 0;
this->VolumeTextureObject = 0;
this->NoiseTextureObject = 0;
......@@ -251,9 +249,7 @@ public:
bool HandleLargeDataTypes;
GLuint CubeVBOId;
#ifndef __APPLE__
GLuint CubeVAOId;
#endif
GLuint CubeIndicesId;
vtkTextureObject* VolumeTextureObject;
......@@ -573,7 +569,7 @@ bool vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::LoadVolume(vtkRenderer* ren,
switch(noOfComponents)
{
case 1:
internalFormat = GL_R8;
internalFormat = GL_RED;
format = GL_RED;
break;
case 2:
......@@ -1687,9 +1683,14 @@ void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::UpdateVolumeGeometry(
// Now create new ones
this->CreateBufferObjects();
#ifndef __APPLE__
glBindVertexArray(this->CubeVAOId);
// TODO: should realy use the built in VAO class
// which handles these apple issues internally
#ifdef __APPLE__
if (this->ContextCache->GetContextSupportsOpenGL32())
#endif
{
glBindVertexArray(this->CubeVAOId);
}
// Pass cube vertices to buffer object memory
glBindBuffer (GL_ARRAY_BUFFER, this->CubeVBOId);
glBufferData (GL_ARRAY_BUFFER, points->GetData()->GetDataSize() *
......@@ -1707,15 +1708,20 @@ void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::UpdateVolumeGeometry(
}
else
{
#ifndef __APPLE__
glBindVertexArray(this->CubeVAOId);
#else
glBindBuffer (GL_ARRAY_BUFFER, this->CubeVBOId);
this->ShaderProgram->EnableAttributeArray("in_vertexPos");
this->ShaderProgram->UseAttributeArray("in_vertexPos", 0, 0, VTK_FLOAT,
3, vtkShaderProgram::NoNormalize);
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, this->CubeIndicesId);
#ifdef __APPLE__
if (!this->ContextCache->GetContextSupportsOpenGL32())
{
glBindBuffer (GL_ARRAY_BUFFER, this->CubeVBOId);
this->ShaderProgram->EnableAttributeArray("in_vertexPos");
this->ShaderProgram->UseAttributeArray("in_vertexPos", 0, 0, VTK_FLOAT,
3, vtkShaderProgram::NoNormalize);
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, this->CubeIndicesId);
}
else
#endif
{
glBindVertexArray(this->CubeVAOId);
}
}
}
......@@ -1918,9 +1924,12 @@ void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::
//----------------------------------------------------------------------------
void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::CreateBufferObjects()
{
#ifndef __APPLE__
glGenVertexArrays(1, &this->CubeVAOId);
#ifdef __APPLE__
if (this->ContextCache->GetContextSupportsOpenGL32())
#endif
{
glGenVertexArrays(1, &this->CubeVAOId);
}
glGenBuffers(1, &this->CubeVBOId);
glGenBuffers(1, &this->CubeIndicesId);
}
......@@ -1928,12 +1937,15 @@ void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::CreateBufferObjects()
//----------------------------------------------------------------------------
void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::DeleteBufferObjects()
{
#ifndef __APPLE__
if (this->CubeVAOId)
{
glDeleteVertexArrays(1, &this->CubeVAOId);
}
#ifdef __APPLE__
if (this->ContextCache->GetContextSupportsOpenGL32())
#endif
{
glDeleteVertexArrays(1, &this->CubeVAOId);
}
}
if (this->CubeVBOId)
{
......@@ -2933,9 +2945,12 @@ void vtkOpenGLGPUVolumeRayCastMapper::GPURender(vtkRenderer* ren,
this->Impl->ShaderProgram->SetUniform4fv("in_componentWeight", 1, &fvalue4);
}
#ifndef __APPLE__
glBindVertexArray(this->Impl->CubeVAOId);
#ifdef __APPLE__
if (this->Impl->ContextCache->GetContextSupportsOpenGL32())
#endif
{
glBindVertexArray(this->Impl->CubeVAOId);
}
glDrawElements(GL_TRIANGLES,
this->Impl->BBoxPolyData->GetNumberOfCells() * 3,
GL_UNSIGNED_INT, 0);
......
......@@ -203,6 +203,7 @@ void vtkOpenGLRayCastImageDisplayHelper::RenderTextureInternal( vtkVolume *vol,
std::string VSSource = vtkTextureObjectVS;
std::string FSSource =
"//VTK::System::Dec\n"
"//VTK::Output::Dec\n"
"varying vec2 tcoordVC;\n"
"uniform sampler2D source;\n"
"uniform float scale;\n"
......
......@@ -56,9 +56,12 @@ class vtkVolumeStateRAII
~vtkVolumeStateRAII()
{
#ifndef __APPLE__
glBindVertexArray(0);
#ifdef __PPLE__
if (vtkOpenGLRenderWindow::GetContextSupports32())
#endif
{
glBindVertexArray(0);
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
......
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