Commit bba39d5b authored by Ben Boeckel's avatar Ben Boeckel

vtkOpenGLRenderUtilities: move Render{Quad,Triangle}

These methods cause vtkOpenGLRenderWindow to include vtk_glew.h (for
GLuint) which must be included before gl.h to work properly. Since this
header gets included in many places, move the affected methods to
another class rather than forcing all users to do the proper inclusion
order dance.
parent 6e14fa76
......@@ -13,6 +13,8 @@
=========================================================================*/
#include "vtk_glew.h"
#include "vtkExternalOpenGLRenderWindow.h"
#include "vtkObjectFactory.h"
#include "vtkRendererCollection.h"
......
......@@ -24,6 +24,7 @@
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLError.h"
#include "vtkOpenGLRenderUtilities.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLShaderCache.h"
#include "vtkPainterCommunicator.h"
......@@ -717,7 +718,7 @@ public:
computeBounds[1]*2.0-1.0, computeBounds[3]*2.0-1.0, 0.0f,
computeBounds[0]*2.0-1.0, computeBounds[3]*2.0-1.0, 0.0f};
vtkOpenGLRenderWindow::RenderQuad(verts, tcoords,
vtkOpenGLRenderUtilities::RenderQuad(verts, tcoords,
cbo->Program, cbo->VAO);
vtkOpenGLStaticCheckErrorMacro("failed at RenderQuad");
}
......
......@@ -37,6 +37,7 @@
#include "vtkOpenGLActor.h"
#include "vtkOpenGLCamera.h"
#include "vtkOpenGLError.h"
#include "vtkOpenGLRenderUtilities.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLShaderCache.h"
#include "vtkPainterCommunicator.h"
......@@ -1175,7 +1176,7 @@ public:
quadTCoords[1]*2.0-1.0, quadTCoords[3]*2.0-1.0, 0.0f,
quadTCoords[0]*2.0-1.0, quadTCoords[3]*2.0-1.0, 0.0f};
vtkOpenGLRenderWindow::RenderQuad(verts, tcoords,
vtkOpenGLRenderUtilities::RenderQuad(verts, tcoords,
cbo->Program, cbo->VAO);
vtkOpenGLStaticCheckErrorMacro("failed at RenderQuad");
}
......
......@@ -48,6 +48,7 @@ set(Module_SRCS
vtkOpenGLPolyDataMapper2D.cxx
vtkOpenGLProperty.cxx
vtkOpenGLRenderWindow.cxx
vtkOpenGLRenderUtilities.cxx
vtkOpenGLRenderer.cxx
vtkOpenGLShaderCache.cxx
vtkOpenGLTexture.cxx
......
......@@ -17,6 +17,7 @@ PURPOSE. See the above copyright notice for more information.
#import <Cocoa/Cocoa.h>
#import "vtkCocoaMacOSXSDKCompatibility.h" // Needed to support old SDKs
#import "vtkOpenGL.h"
#import "vtkCocoaRenderWindow.h"
#import "vtkRenderWindowInteractor.h"
#import "vtkCommand.h"
......
......@@ -12,6 +12,8 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtk_glew.h"
#include "vtkCompositePolyDataMapper2.h"
#include "vtkCellArray.h"
......
......@@ -17,6 +17,7 @@
#include "vtk_glew.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLRenderUtilities.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkTextureObject.h"
#include "vtkPixelBufferObject.h"
......@@ -890,7 +891,7 @@ void vtkFrameBufferObject::RenderQuad(int minX, int maxX, int minY, int maxY,
1.0, 0,
1.0, maxYTexCoord,
0, maxYTexCoord};
vtkOpenGLRenderWindow::RenderQuad(verts, tcoords, program, vao);
vtkOpenGLRenderUtilities::RenderQuad(verts, tcoords, program, vao);
vtkOpenGLCheckErrorMacro("failed after Render");
......
......@@ -13,6 +13,8 @@
=========================================================================*/
#include "vtk_glew.h"
#include "vtkImageProcessingPass.h"
#include "vtkObjectFactory.h"
#include <cassert>
......
......@@ -20,6 +20,7 @@
#include "vtkOpenGLActor.h"
#include "vtkOpenGLCamera.h"
#include "vtkOpenGLError.h"
#include "vtkOpenGLRenderUtilities.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLShaderCache.h"
#include "vtkOpenGLTexture.h"
......@@ -141,7 +142,7 @@ bool vtkOpenGLLabeledContourMapper::ApplyStencil(vtkRenderer *ren,
this->StencilBO->Program->SetUniformMatrix("MCDCMatrix", wcdc);
}
vtkOpenGLRenderWindow::RenderTriangles(
vtkOpenGLRenderUtilities::RenderTriangles(
this->StencilQuads,
this->StencilQuadsSize/3,
this->StencilQuadIndices,
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOpenGLRenderUtilities.cxx
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.
=========================================================================*/
#include "vtk_glew.h"
#include "vtkOpenGLRenderUtilities.h"
#include "vtkNew.h"
#include "vtkOpenGLBufferObject.h"
#include "vtkOpenGLVertexArrayObject.h"
// ----------------------------------------------------------------------------
vtkOpenGLRenderUtilities::vtkOpenGLRenderUtilities()
{
}
// ----------------------------------------------------------------------------
vtkOpenGLRenderUtilities::~vtkOpenGLRenderUtilities()
{
}
void vtkOpenGLRenderUtilities::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
// ---------------------------------------------------------------------------
// a program must be bound
// a VAO must be bound
void vtkOpenGLRenderUtilities::RenderQuad(
float *verts,
float *tcoords,
vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao)
{
GLuint iboData[] = {0, 1, 2, 0, 2, 3};
vtkOpenGLRenderUtilities::RenderTriangles(verts, 4,
iboData, 6,
tcoords,
program, vao);
}
// ---------------------------------------------------------------------------
// a program must be bound
// a VAO must be bound
void vtkOpenGLRenderUtilities::RenderTriangles(
float *verts, unsigned int numVerts,
GLuint *iboData, unsigned int numIndices,
float *tcoords,
vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao)
{
if (!program || !vao || !verts)
{
vtkGenericWarningMacro(<< "Error must have verts, program and vao");
}
vtkNew<vtkOpenGLBufferObject> vbo;
vbo->Upload(verts, numVerts*3, vtkOpenGLBufferObject::ArrayBuffer);
vao->Bind();
if (!vao->AddAttributeArray(program, vbo.Get(), "vertexMC", 0,
sizeof(float)*3, VTK_FLOAT, 3, false))
{
vtkGenericWarningMacro(<< "Error setting 'vertexMC' in shader VAO.");
}
vtkNew<vtkOpenGLBufferObject> tvbo;
if (tcoords)
{
tvbo->Upload(tcoords, numVerts*2, vtkOpenGLBufferObject::ArrayBuffer);
if (!vao->AddAttributeArray(program, tvbo.Get(), "tcoordMC", 0,
sizeof(float)*2, VTK_FLOAT, 2, false))
{
vtkGenericWarningMacro(<< "Error setting 'tcoordMC' in shader VAO.");
}
}
vtkNew<vtkOpenGLBufferObject> ibo;
vao->Bind();
ibo->Upload(iboData, numIndices, vtkOpenGLBufferObject::ElementArrayBuffer);
glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT,
reinterpret_cast<const GLvoid *>(NULL));
ibo->Release();
vao->RemoveAttributeArray("vertexMC");
vao->RemoveAttributeArray("tcoordMC");
vao->Release();
vbo->Release();
if (tcoords)
{
tvbo->Release();
}
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOpenGLRenderUtilities.h
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.
=========================================================================*/
// .NAME vtkOpenGLRenderUtilities - OpenGL rendering utility functions
// .SECTION Description
// vtkOpenGLRenderUtilities provides functions to help render primitives.
#ifndef vtkOpenGLRenderUtilities_h
#define vtkOpenGLRenderUtilities_h
#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkObject.h"
#include "vtk_glew.h" // Needed for GLuint.
class vtkOpenGLVertexArrayObject;
class vtkShaderProgram;
class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLRenderUtilities : public vtkObject
{
public:
vtkTypeMacro(vtkOpenGLRenderUtilities, vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Helper function that draws a quad on the screen
// at the specified vertex coordinates and if
// tcoords are not NULL with the specified
// texture coordinates.
static void RenderQuad(
float *verts, float *tcoords,
vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao);
static void RenderTriangles(
float *verts, unsigned int numVerts,
GLuint *indices, unsigned int numIndices,
float *tcoords,
vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao);
protected:
vtkOpenGLRenderUtilities();
~vtkOpenGLRenderUtilities();
private:
vtkOpenGLRenderUtilities(const vtkOpenGLRenderUtilities&); // Not implemented.
void operator=(const vtkOpenGLRenderUtilities&); // Not implemented.
};
#endif
......@@ -746,73 +746,6 @@ int vtkOpenGLRenderWindow::SetPixelData(int x1, int y1, int x2, int y2,
}
// ---------------------------------------------------------------------------
// a program must be bound
// a VAO must be bound
void vtkOpenGLRenderWindow::RenderQuad(
float *verts,
float *tcoords,
vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao)
{
GLuint iboData[] = {0, 1, 2, 0, 2, 3};
vtkOpenGLRenderWindow::RenderTriangles(verts, 4,
iboData, 6,
tcoords,
program, vao);
}
// ---------------------------------------------------------------------------
// a program must be bound
// a VAO must be bound
void vtkOpenGLRenderWindow::RenderTriangles(
float *verts, unsigned int numVerts,
GLuint *iboData, unsigned int numIndices,
float *tcoords,
vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao)
{
if (!program || !vao || !verts)
{
vtkGenericWarningMacro(<< "Error must have verts, program and vao");
}
vtkNew<vtkOpenGLBufferObject> vbo;
vbo->Upload(verts, numVerts*3, vtkOpenGLBufferObject::ArrayBuffer);
vao->Bind();
if (!vao->AddAttributeArray(program, vbo.Get(), "vertexMC", 0,
sizeof(float)*3, VTK_FLOAT, 3, false))
{
vtkGenericWarningMacro(<< "Error setting 'vertexMC' in shader VAO.");
}
vtkNew<vtkOpenGLBufferObject> tvbo;
if (tcoords)
{
tvbo->Upload(tcoords, numVerts*2, vtkOpenGLBufferObject::ArrayBuffer);
if (!vao->AddAttributeArray(program, tvbo.Get(), "tcoordMC", 0,
sizeof(float)*2, VTK_FLOAT, 2, false))
{
vtkGenericWarningMacro(<< "Error setting 'tcoordMC' in shader VAO.");
}
}
vtkNew<vtkOpenGLBufferObject> ibo;
vao->Bind();
ibo->Upload(iboData, numIndices, vtkOpenGLBufferObject::ElementArrayBuffer);
glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT,
reinterpret_cast<const GLvoid *>(NULL));
ibo->Release();
vao->RemoveAttributeArray("vertexMC");
vao->RemoveAttributeArray("tcoordMC");
vao->Release();
vbo->Release();
if (tcoords)
{
tvbo->Release();
}
}
// draw (and stretch as needed) the data to the current viewport
void vtkOpenGLRenderWindow::DrawPixels(
int srcWidth, int srcHeight, int numComponents, int dataType, void *data)
......
......@@ -26,8 +26,6 @@
#include "vtkRenderWindow.h"
#include <map> // for ivar
#include "vtk_glew.h" // Needed for GLuint.
class vtkIdList;
class vtkOpenGLHardwareSupport;
class vtkOpenGLShaderCache;
......@@ -209,20 +207,6 @@ public:
// Useful for measurement only.
virtual void WaitForCompletion();
// Description:
// Helper function that draws a quad on the screen
// at the specified vertex coordinates and if
// tcoords are not NULL with the specified
// texture coordinates.
static void RenderQuad(
float *verts, float *tcoords,
vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao);
static void RenderTriangles(
float *verts, unsigned int numVerts,
GLuint *indices, unsigned int numIndices,
float *tcoords,
vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao);
// Description:
// Replacement for the old glDrawPixels function
virtual void DrawPixels(int x1, int y1, int x2, int y2,
......
......@@ -26,6 +26,7 @@
#include "vtkNew.h"
#include "vtkOpenGLBufferObject.h"
#include "vtkOpenGLError.h"
#include "vtkOpenGLRenderUtilities.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLShaderCache.h"
#include "vtkOpenGLTexture.h"
......@@ -2302,13 +2303,13 @@ void vtkTextureObject::CopyToFrameBuffer(float *tcoords, float *verts,
this->Activate();
int sourceId = this->GetTextureUnit();
this->ShaderProgram->Program->SetUniformi("source",sourceId);
vtkOpenGLRenderWindow::RenderQuad(verts, tcoords, this->ShaderProgram->Program,
vtkOpenGLRenderUtilities::RenderQuad(verts, tcoords, this->ShaderProgram->Program,
this->ShaderProgram->VAO);
this->Deactivate();
}
else
{
vtkOpenGLRenderWindow::RenderQuad(verts, tcoords, program, vao);
vtkOpenGLRenderUtilities::RenderQuad(verts, tcoords, program, vao);
}
vtkOpenGLCheckErrorMacro("failed after CopyToFrameBuffer")
......
......@@ -13,6 +13,10 @@
=========================================================================*/
#ifdef VTKGL2
# include "vtk_glew.h"
#endif
#include "vtkCompositeRGBAPass.h"
#include "vtkObjectFactory.h"
#include <cassert>
......
......@@ -20,6 +20,9 @@
#include "vtkPainterCommunicator.h"
#include "vtkPPainterCommunicator.h"
#include "vtkRenderWindow.h"
#ifdef VTK_OPENGL2
# include "vtkOpenGLRenderUtilities.h"
#endif
#include "vtkOpenGLRenderWindow.h"
#include "vtkTextureObject.h"
#include "vtkPixelBufferObject.h"
......@@ -1622,7 +1625,7 @@ int vtkPSurfaceLICComposite::ExecuteShader(
fext[1]*2.0-1.0, fext[3]*2.0-1.0, 0.0f,
fext[0]*2.0-1.0, fext[3]*2.0-1.0, 0.0f};
vtkOpenGLRenderWindow::RenderQuad(verts, tcoords,
vtkOpenGLRenderUtilities::RenderQuad(verts, tcoords,
this->CompositeShader->Program, this->CompositeShader->VAO);
tex->Deactivate();
#else
......
......@@ -22,6 +22,7 @@
#include "vtkNew.h"
#include "vtkProperty.h"
#include "vtkTextureObject.h"
#include "vtkOpenGLRenderUtilities.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLShaderCache.h"
#include "vtkOpenGLVertexArrayObject.h"
......@@ -251,7 +252,7 @@ void vtkOpenGLRayCastImageDisplayHelper::RenderTextureInternal( vtkVolume *vol,
int sourceId = this->TextureObject->GetTextureUnit();
this->ShaderProgram->Program->SetUniformi("source",sourceId);
this->ShaderProgram->Program->SetUniformf("scale",this->PixelScale);
vtkOpenGLRenderWindow::RenderQuad(verts, tcoords, this->ShaderProgram->Program,
vtkOpenGLRenderUtilities::RenderQuad(verts, tcoords, this->ShaderProgram->Program,
this->ShaderProgram->VAO);
this->TextureObject->Deactivate();
......
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