-
Notifications
You must be signed in to change notification settings - Fork 14
/
gl_cu_interop_pingpong_st.h
150 lines (121 loc) · 3.52 KB
/
gl_cu_interop_pingpong_st.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
138
139
140
141
142
143
144
145
146
147
148
149
150
#pragma once
#include <nv_math/nv_math.h>
#include <nv_helpers/cameracontrol.hpp>
#include <nv_helpers_gl/WindowProfiler.hpp>
#include "helpers/cudaTools.hpp"
#include "helpers/ProgramGL.hpp"
#include "helpers/UniformGLUpdateExplicit.hpp"
#include <GL/glew.h>
#include <cuda.h>
using namespace nv_helpers_gl;
class Sample : public nv_helpers_gl::WindowProfiler
{
public:
Sample() : m_arrayBufferName(0)
, m_elementArrayBufferName(0)
, m_framebufferName(0)
, m_oContext(0)
, m_oDevice(0)
, m_volumeCoeff(1.0f)
, m_isRunning(true)
{}
// Main methods
bool begin();
void end();
void resize(int width, int height);
void think(double time);
void viewUpdate();
// Main supplementary UI methods
bool mouse_pos (int x, int y);
bool mouse_button (int button, int action);
bool mouse_wheel (int wheel);
bool key_button (int button, int action, int modifier);
// UI methods
void beginUI();
void endUI();
void renderUI();
void resizeUI(int width, int height);
static void _simStart(void* inst);
static void _simPause(void* inst);
static void _simReset(void* inst);
void simStart();
void simPause();
void simReset();
// Volume Render GL methods
void renderGLVolume(bool bOddStep);
void renderGLFrontface();
void initGL();
void initArrayBuffer();
void initPrograms();
void initFramebuffer();
void initFrontfaceInfoTexture();
void initVolumeTexture(unsigned int volumeTexSize);
void setVisualizationParameters();
void createSampleVolume( std::vector<float>& out, unsigned int volumeTexSize, float factor );
void setInitialVolumeData();
// Simulate CUDA methods
void simulateCUDA(float simDt);
void initCUDA();
void initCUDAEntryPoint( const std::string& ptxFile, const std::string& entryPointName );
void setCUDAVars();
void initCUDAArray();
void initCUDASurfTexReferences();
void bindCUDAReadWriteVolumes(bool bOddIter);
private:
enum
{
ULOC_MODEL2CLIP = 0,
ULOC_MODEL2WORLD = 1,
ULOC_EYEPOS = 4,
ULOC_VOLUMETEXDIMENSION = 5,
ULOC_VOLUMETEX = 6,
ULOC_BACKFACETEX = 7,
ULOC_VISRANGE = 8,
ULOC_COLLOW = 9,
ULOC_COLHIGH = 10,
ULOC_THICKNESSFACTOR = 11,
};
// View, projection
nv_math::mat4f m_projection;
nv_math::mat4f m_viewProjection;
nv_math::vec4f m_eyePos;
nv_math::vec4f m_lightDir;
nv_helpers::CameraControl m_control;
// Geometry stuff (volume cube)
GLsizei m_indexCount;
GLuint m_arrayBufferName;
GLuint m_elementArrayBufferName;
GLuint m_vaoName;
// Ping-pong texures
GLuint m_volumeTextureName[2];
GLuint m_volumeTexturePrevName;
GLuint m_volumeTextureCurName;
CUarray m_cudaArray[2];
CUgraphicsResource m_cuda_volumeTex[2];
CUsurfref m_surfWriteRef;
CUtexref m_surfReadRef;
// Frontface info FBO
GLuint m_framebufferName;
GLuint m_frontfaceInfoTextureName;
GLuint m_frontfaceInfoDepthTextureName;
// Simulation + Visualization related
unsigned int m_volumeTexDimension;
unsigned int m_volumeTexDimensionNonBoundary;
float m_volumeCoeff;
float m_alpha;
float m_cellWidth;
nv_math::vec3f m_colLow;
nv_math::vec3f m_colHigh;
float m_thicknessFactor;
bool m_isRunning;
// CUDA stuff
CUcontext m_oContext;
CUdevice m_oDevice;
CUmodule m_module;
CUfunction m_entryPoint;
// GLSL stuff
ProgramGL<Explicit>* m_glslFrontFace;
ProgramGL<Explicit>* m_glslVolume;
public:
nv_helpers_cuda::AsyncTimer* m_cudaTimer;
};