-
Notifications
You must be signed in to change notification settings - Fork 21
/
vtkOpenGLShaderComputation.h
137 lines (107 loc) · 4.23 KB
/
vtkOpenGLShaderComputation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkOpenGLShaderComputation.h,v $
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 vtkOpenGLShaderComputation - OpenGL actor
// .SECTION Description
// vtkOpenGLShaderComputation is a way to perform GPU computations on vtk data.
// vtkOpenGLShaderComputation interfaces to the OpenGL rendering library.
#ifndef __vtkOpenGLShaderComputation_h
#define __vtkOpenGLShaderComputation_h
// VTK includes
#include "vtkAddon.h"
#include "vtkImageData.h"
#include "vtkRenderWindow.h"
#include "vtkVariant.h"
// STD includes
#include <map>
class VTK_ADDON_EXPORT vtkOpenGLShaderComputation : public vtkObject
{
protected:
public:
static vtkOpenGLShaderComputation *New();
vtkTypeMacro(vtkOpenGLShaderComputation,vtkObject);
void PrintSelf(ostream& os, vtkIndent indent) override;
/* Explicitly deleted functions belong in the public interface */
vtkOpenGLShaderComputation(const vtkOpenGLShaderComputation&) = delete;
void operator=(const vtkOpenGLShaderComputation&) = delete;
// Description:
// Loads the required extensions
void Initialize(vtkRenderWindow *renderWindow);
// Description:
// Checks the framebuffer and prints error if bad.
// Return true if framebuffer is complete.
bool FramebufferComplete();
// Description:
// Make this the target for OpenGL operations
void MakeCurrent();
// Description:
// Rebuild the shader program if needed
bool UpdateProgram();
// Description:
// Manage the OpenGL offscreen rendering framebuffer for computing
// Select this mode to render into a buffer that matches the ResultImageData
// and can be read back with ReadResult. Otherwise use
// vtkOpenGLTextureImage::AttachAsDrawTarget to set a texture
// as the draw target.
bool AcquireResultRenderbuffer();
void ReleaseResultRenderbuffer();
// Description:
// Perform the actual computation
// Updates the program if needed and then
// renders to the current framebuffer configuration
// Slice will be passed as a uniform float
void Compute(float slice=0.);
// Description:
// Add a uniform value TODO: support types other than float
void SetUniform(std::string name, float uniform);
// Description:
// Copy the framebuffer pixels into the result image
void ReadResult();
// Description:
// The strings defining the shaders
vtkGetStringMacro(VertexShaderSource);
vtkSetStringMacro(VertexShaderSource);
vtkGetStringMacro(FragmentShaderSource);
vtkSetStringMacro(FragmentShaderSource);
// Description:
// The results of the computation.
// Must be set with the desired dimensions before calling Compute.
vtkGetObjectMacro(ResultImageData, vtkImageData);
vtkSetObjectMacro(ResultImageData, vtkImageData);
// Description:
// Used internally to manage OpenGL context and extensions
vtkGetObjectMacro(RenderWindow, vtkRenderWindow);
vtkSetObjectMacro(RenderWindow, vtkRenderWindow);
// Description:
// Has the context been set up with a render window?
vtkGetMacro(Initialized, bool);
// Description:
// Has there been an error since the class was created.
// After an error, generally the cleanest thing to do is delete the class,
// and create a new instance.
vtkGetMacro(ErrorOccurred, bool);
protected:
vtkOpenGLShaderComputation();
~vtkOpenGLShaderComputation() override;
private:
bool Initialized;
bool ErrorOccurred;
char *VertexShaderSource;
char *FragmentShaderSource;
vtkImageData *ResultImageData;
vtkTypeUInt32 ProgramObject; // vtkTypeUInt32 same as GLuint: https://www.opengl.org/wiki/OpenGL_Type
unsigned long ProgramObjectMTime;
vtkTypeUInt32 FramebufferID;
vtkTypeUInt32 ColorRenderbufferID;
vtkTypeUInt32 DepthRenderbufferID;
vtkRenderWindow *RenderWindow;
std::map<std::string, vtkVariant> Uniforms;
};
#endif