VoxelBlur
Depth-of-field volume rendering
 All Classes Files Functions Variables Enumerations Enumerator
volumerenderer_private.h
Go to the documentation of this file.
1 #ifndef VOLUMERENDERER_PRIVATE_H
2 #define VOLUMERENDERER_PRIVATE_H
3 
4 #include "volumerenderer.h"
5 #include "volumeloader.h"
6 #include "geometry.h"
7 
14 //these are the only functions that we use that are not in GL 3.3
15 //instead of using the whole 4.2 context, we just import this one function manually
16 extern PFNGLBINDIMAGETEXTUREPROC __glBindImageTexture;
17 extern PFNGLDISPATCHCOMPUTEPROC __glDispatchCompute;
18 
19 #define glBindImageTexture __glBindImageTexture
20 #define glDispatchCompute __glDispatchCompute
21 
22 //vertex attribute positions
23 #define ATTRPOS_VERTEX 0
24 #define ATTRPOS_COLOR 1
25 
26 //tex unit positions
27 #define TEXUNIT_VOLUME 0
28 #define TEXUNIT_TRANSFUNC 1
29 //these are only temporarily used while loading the volume
30 #define TEXUNIT_INTENSITY 2
31 #define TEXUNIT_SMOOTH 3
32 
33 //current slice texture
34 #define TEXUNIT_SLICE 4
35 //previous eye/intermediate buffer
36 #define TEXUNIT_PREVIOUS 5
37 //final intermediate buffer (for merging)
38 #define TEXUNIT_INTERMEDIATE 6
39 
40 //image units (for shader-writable textures)
41 #define IMGUNIT_VOLUME 0
42 #define IMGUNIT_SMOOTH 1
43 
44 //the maximal number of intersection points of a plane with a cube is 6, + 1 centroid vertex, +1 repeated vertex
45 #define SLICEBUFFER_STRIDE 8
46 //the buffer has storage for this amount of slices (i.e. is of size SLICEBUFFER_STRIDE * 3(xyz) * 4(float) * SLICEBUFFER_SLICECOUNT bytes in total)
47 #define SLICEBUFFER_SLICECOUNT 2048
48 
49 //1s sync timeout
50 #define SYNC_TIMEOUT 1000000
51 
56 {
57  VolumeLoader* volLoader;
58  QOpenGLDebugLogger* glLogger;
59 
60  Cube bBox;
61  bool volumeLoaded,fixSlicingMatrix,renderBB,smoothVolume,showLightDir;
62  VolumeMetaData currentVolume;
63  QByteArray currentVolumeData; //this is only filled after loadVolume and before update() has finished
64 
65  QVector2D window;
66  //light dir vector, and halfway vector
67  QVector3D lightVec,halfVec;
68 
69  VolumeRenderer::ProjectionType projType;
70  QMatrix4x4 mProj, view, mvp, mSlicing;
71 
72  int sliceCount,renderedSlices;
73 
74  bool doDOF;
75  float focalPlaneDist,blurAmount;
76 
77  int winWidth,winHeight;
78 
79  /*
80  This is the offset in the SLICE BUFFER, not the Z offset of the current slice!
81  The value lies in [0, SLICEBUFFER_SLICECOUNT)
82  */
83  int currentSliceOffset;
84  GLsync sliceSync[SLICEBUFFER_SLICECOUNT];
85 
86  QList<QString> glExtensions;
87 
88 
89  float rotX,rotY,distance,sliceDelta;
90  float lightAz,lightAngle;
91  float gaussSigma;
92 
93  QElapsedTimer timer;
94  qint64 frametime;
95  struct
96  {
97  QOpenGLShaderProgram* blur;
98  QOpenGLShaderProgram* merge;
99  QOpenGLShaderProgram* transform;
100  QOpenGLShaderProgram* color;
101  QOpenGLShaderProgram* bBox;
102  QOpenGLShaderProgram* slice;
103  QOpenGLShaderProgram* gaussian;
104  QOpenGLShaderProgram* gradient;
105  } shaders;
106  struct
107  {
108  //QOpenGLBuffer* uniformBuffer;
109  QOpenGLBuffer* vBuffer;
110  QOpenGLBuffer* lineBuffer;
111  QOpenGLBuffer* sliceVBuffer;
112  QOpenGLBuffer* iBuffer;
113  size_t triangleIndexOffset, lineIndexOffset, sliceIndexOffset;
114  } buffers;
115  struct
116  {
117  QOpenGLVertexArrayObject* box;
118  QOpenGLVertexArrayObject* line;
119  QOpenGLVertexArrayObject* slice;
120  } vaos;
121 
122  struct
123  {
124  QOpenGLFramebufferObject* slice;
125  QOpenGLFramebufferObject* eye[2];
126  QOpenGLFramebufferObject* intermediate[2];
127  uint eDraw,eRead;
128  uint iDraw,iRead;
129  } fbos;
130 
131  struct
132  {
133  QOpenGLTexture* volume;
134  } textures;
135 
137  : distance(2.0f),rotX(0),rotY(0),projType(VolumeRenderer::ProjectionType::Perspective),
138  renderBB(true),sliceDelta(0.01f),window(0.0f,1.0f),frametime(0),volumeLoaded(false),fixSlicingMatrix(false),showLightDir(false),smoothVolume(true),lightAz(180.0f),lightAngle(15.0f),gaussSigma(0.6f),
139  currentSliceOffset(0), focalPlaneDist(0.5f), blurAmount(0.5f), doDOF(true), sliceCount(0), renderedSlices(0)
140  {
141  fbos.slice = nullptr;
142  fbos.eye[0] = fbos.eye[1] = nullptr;
143  fbos.intermediate[0] = fbos.intermediate[1] = nullptr;
144  fbos.eDraw = fbos.iDraw = 0;
145  fbos.eRead = fbos.iRead = 1;
146 
147  for(int i =0;i<SLICEBUFFER_SLICECOUNT;++i)
148  {
149  sliceSync[i] = nullptr;
150  }
151  }
152 };
153 
154 #endif
Class for loading volume meta data (VolumeMetaData) as well as the raw volume data itself...
Definition: volumeloader.h:86
This includes the public VolumeRenderer class.
Contains private data of the volume renderer.
Definition: volumerenderer_private.h:55
Describes a equilateral cube, centered on the origin.
Definition: geometry.h:15
This file includes the VolumeLoader class, as well as the VolumeMetaData structure.
This class contains metadata for volumes, like dimensions and the file where the data can be found...
Definition: volumeloader.h:14
Contains general-purpose geometric helpers, like the Cube structure and Line-Plane intersection algor...