vtkOpenGLRenderTimer.h 2.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkOpenGLRenderTimer.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.

=========================================================================*/

16 17 18 19 20 21 22 23 24 25 26 27
/**
 * @class   vtkOpenGLRenderTimer
 * @brief   Asynchronously measures GPU execution time.
 *
 *
 * This class posts events to the OpenGL server to measure execution times
 * of GPU processes. The queries are asynchronous and multiple
 * vtkOpenGLRenderTimers may overlap / be nested.
 *
 * This uses GL_TIMESTAMP rather than GL_ELAPSED_TIME, since only one
 * GL_ELAPSED_TIME query may be active at a time.
*/
28 29 30 31 32 33 34 35 36 37 38 39 40

#ifndef vtkOpenGLRenderTimer_h
#define vtkOpenGLRenderTimer_h

#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkType.h" // For vtkTypeUint64, etc

class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLRenderTimer
{
public:
  vtkOpenGLRenderTimer();
  ~vtkOpenGLRenderTimer();

41 42 43
  /**
   * Clear out any previous results and prepare for a new query.
   */
44 45
  void Reset();

46 47 48
  /**
   * Mark the start of a timed event.
   */
49 50
  void Start();

51 52 53
  /**
   * Mark the end of a timed event.
   */
54 55
  void Stop();

56 57 58
  /**
   * Returns true if the timer has been started. The query may not be ready yet.
   */
59 60
  bool Started();

61 62 63
  /**
   * Returns true if the timer has been stopped. The query may not be ready yet.
   */
64 65
  bool Stopped();

66 67 68
  /**
   * Returns true when the timing results are available.
   */
69 70
  bool Ready();

71 72 73 74
  //@{
  /**
   * If Ready() returns true, get the elapsed time in the requested units.
   */
75 76 77
  float GetElapsedSeconds();
  float GetElapsedMilliseconds();
  vtkTypeUInt64 GetElapsedNanoseconds();
78
  //@}
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

protected:
  bool StartReady;
  bool EndReady;

  vtkTypeUInt32 StartQuery;
  vtkTypeUInt32 EndQuery;

  vtkTypeUInt64 StartTime;
  vtkTypeUInt64 EndTime;

private:
  vtkOpenGLRenderTimer(const vtkOpenGLRenderTimer&) VTK_DELETE_FUNCTION;
  void operator=(const vtkOpenGLRenderTimer&) VTK_DELETE_FUNCTION;
};

#endif // vtkOpenGLRenderTimer_h

// VTK-HeaderTest-Exclude: vtkOpenGLRenderTimer.h