vtkOpenGLVertexArrayObject.h 3.26 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*=========================================================================

  Program:   Visualization Toolkit

  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.

=========================================================================*/
Ken Martin's avatar
Ken Martin committed
14 15
#ifndef vtkOpenGLVertexArrayObject_h
#define vtkOpenGLVertexArrayObject_h
16

Ken Martin's avatar
Ken Martin committed
17 18
#include "vtkRenderingOpenGL2Module.h" // for export macro
#include "vtkObject.h"
19 20
#include <string> // For API.

21
class vtkShaderProgram;
Ken Martin's avatar
Ken Martin committed
22
class vtkOpenGLBufferObject;
23 24 25 26 27 28 29 30 31 32 33 34

/**
 * @brief The VertexArrayObject class uses, or emulates, vertex array objects.
 * These are extremely useful for setup/tear down of vertex attributes, and can
 * offer significant performance benefits when the hardware supports them.
 *
 * It should be noted that this object is very lightweight, and it assumes the
 * objects being used are correctly set up. Even without support for VAOs this
 * class caches the array locations, types, etc and avoids repeated look ups. It
 * it bound to a single ShaderProgram object.
 */

Ken Martin's avatar
Ken Martin committed
35
class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLVertexArrayObject : public vtkObject
36 37
{
public:
Ken Martin's avatar
Ken Martin committed
38 39 40
  static vtkOpenGLVertexArrayObject* New();
  vtkTypeMacro(vtkOpenGLVertexArrayObject, vtkObject)
  void PrintSelf(ostream& os, vtkIndent indent);
41 42 43 44 45

  void Bind();

  void Release();

46
  void ReleaseGraphicsResources();
47

48 49
  void ShaderProgramChanged();

Ken Martin's avatar
Ken Martin committed
50 51
  bool AddAttributeArray(vtkShaderProgram *program,
                         vtkOpenGLBufferObject *buffer,
52
                         const std::string &name, int offset, size_t stride,
53
                         int elementType, int elementTupleSize, bool normalize)
54
  {
55
    return this->AddAttributeArrayWithDivisor(program, buffer, name,
56
      offset,stride,elementType, elementTupleSize, normalize, 0, false);
57
  }
58

Ken Martin's avatar
Ken Martin committed
59 60
  bool AddAttributeArrayWithDivisor(vtkShaderProgram *program,
                         vtkOpenGLBufferObject *buffer,
61 62
                         const std::string &name, int offset, size_t stride,
                         int elementType, int elementTupleSize, bool normalize,
63
                         int divisor, bool isMatrix);
64

Ken Martin's avatar
Ken Martin committed
65 66
  bool AddAttributeMatrixWithDivisor(vtkShaderProgram *program,
                         vtkOpenGLBufferObject *buffer,
67 68 69
                         const std::string &name, int offset, size_t stride,
                         int elementType, int elementTupleSize, bool normalize,
                         int divisor);
70 71 72

  bool RemoveAttributeArray(const std::string &name);

Ken Martin's avatar
Ken Martin committed
73 74 75 76 77
  // Force this VAO to emulate a vertex aray object even if
  // the system supports VAOs. This can be useful in cases where
  // the vertex array object does not handle all extensions.
  void SetForceEmulation(bool val);

Ken Martin's avatar
Ken Martin committed
78 79 80 81
protected:
  vtkOpenGLVertexArrayObject();
  ~vtkOpenGLVertexArrayObject();

82
private:
Ken Martin's avatar
Ken Martin committed
83
  vtkOpenGLVertexArrayObject(
84
    const vtkOpenGLVertexArrayObject&) VTK_DELETE_FUNCTION;
85
  void operator=(const vtkOpenGLVertexArrayObject&) VTK_DELETE_FUNCTION;
86
  class Private;
Ken Martin's avatar
Ken Martin committed
87
  Private *Internal;
88 89
};

Ken Martin's avatar
Ken Martin committed
90
#endif // vtkOpenGLVertexArrayObject_h