4
4
#include < glow/Program.h>
5
5
#include < glow/Shader.h>
6
6
#include < glow/Buffer.h>
7
- #include < glow/logging.h>
8
7
#include < glow/FrameBufferObject.h>
9
8
#include < glow/VertexArrayObject.h>
10
9
#include < glow/debugmessageoutput.h>
11
10
#include < glow/Texture.h>
12
11
13
- #include < glowutils/Timer.h>
14
12
#include < glowutils/AxisAlignedBoundingBox.h>
15
13
#include < glowutils/Icosahedron.h>
16
14
#include < glowutils/Camera.h>
17
- #include < glowutils/AdaptiveGrid.h>
18
15
#include < glowutils/AbstractCoordinateProvider.h>
19
16
#include < glowutils/WorldInHandNavigation.h>
20
- #include < glowutils/FlightNavigation.h>
21
17
#include < glowutils/glowutils.h>
22
18
#include < glowutils/StringTemplate.h>
23
19
#include < glowutils/ScreenAlignedQuad.h>
@@ -60,17 +56,22 @@ class EventHandler : public ExampleWindowEventHandler, glowutils::AbstractCoordi
60
56
61
57
gl::glClearColor (1 .0f , 1 .0f , 1 .0f , 0 .f );
62
58
63
- m_icosahedron = new glowutils::Icosahedron (2 );
64
-
65
- m_sphere = new glow::Program ();
66
- glowutils::StringTemplate* vertexShaderSource = new glowutils::StringTemplate (new glow::File (" data/gbuffers/sphere.vert" ));
67
- glowutils::StringTemplate* fragmentShaderSource = new glowutils::StringTemplate (new glow::File (" data/gbuffers/sphere.frag" ));
59
+ auto vertexShaderSource = new glowutils::StringTemplate (new glow::File (" data/gbuffers/sphere.vert" ));
60
+ auto fragmentShaderSource = new glowutils::StringTemplate (new glow::File (" data/gbuffers/sphere.frag" ));
61
+ auto postprocessingSource = new glowutils::StringTemplate (new glow::File (" data/gbuffers/postprocessing.frag" ));
62
+ auto gBufferChoiceSource = new glowutils::StringTemplate (new glow::File (" data/gbuffers/gbufferchoice.frag" ));
68
63
69
64
#ifdef MAC_OS
70
65
vertexShaderSource->replace (" #version 140" , " #version 150" );
71
66
fragmentShaderSource->replace (" #version 140" , " #version 150" );
67
+ postprocessingSource->replace (" #version 140" , " #version 150" );
68
+ gBufferChoiceSource ->replace (" #version 140" , " #version 150" );
72
69
#endif
73
-
70
+
71
+ m_icosahedron = new glowutils::Icosahedron (2 );
72
+
73
+ m_sphere = new glow::Program ();
74
+
74
75
m_sphere->attach (
75
76
new glow::Shader (gl::GL_VERTEX_SHADER, vertexShaderSource),
76
77
new glow::Shader (gl::GL_FRAGMENT_SHADER, fragmentShaderSource)
@@ -82,17 +83,11 @@ class EventHandler : public ExampleWindowEventHandler, glowutils::AbstractCoordi
82
83
m_geometryTexture = glow::Texture::createDefault (gl::GL_TEXTURE_2D);
83
84
84
85
m_sphereFBO = new glow::FrameBufferObject;
85
-
86
86
m_sphereFBO->attachTexture (gl::GL_COLOR_ATTACHMENT0, m_colorTexture);
87
87
m_sphereFBO->attachTexture (gl::GL_COLOR_ATTACHMENT1, m_normalTexture);
88
88
m_sphereFBO->attachTexture (gl::GL_COLOR_ATTACHMENT2, m_geometryTexture);
89
89
m_sphereFBO->attachTexture (gl::GL_DEPTH_ATTACHMENT, m_depthTexture);
90
-
91
- glowutils::StringTemplate* postprocessingSource = new glowutils::StringTemplate (new glow::File (" data/gbuffers/postprocessing.frag" ));
92
-
93
- #ifdef MAC_OS
94
- postprocessingSource->replace (" #version 140" , " #version 150" );
95
- #endif
90
+ m_sphereFBO->setDrawBuffers ({ gl::GL_COLOR_ATTACHMENT0, gl::GL_COLOR_ATTACHMENT1, gl::GL_COLOR_ATTACHMENT2 });
96
91
97
92
m_postprocessing = new glowutils::ScreenAlignedQuad (new glow::Shader (gl::GL_FRAGMENT_SHADER, postprocessingSource));
98
93
m_postprocessing->program ()->setUniform <gl::GLint>(" colorSource" , 0 );
@@ -103,14 +98,8 @@ class EventHandler : public ExampleWindowEventHandler, glowutils::AbstractCoordi
103
98
m_postprocessedTexture = glow::Texture::createDefault (gl::GL_TEXTURE_2D);
104
99
105
100
m_postprocessingFBO = new glow::FrameBufferObject;
106
-
107
101
m_postprocessingFBO->attachTexture (gl::GL_COLOR_ATTACHMENT0, m_postprocessedTexture);
108
-
109
- glowutils::StringTemplate* gBufferChoiceSource = new glowutils::StringTemplate (new glow::File (" data/gbuffers/gbufferchoice.frag" ));
110
-
111
- #ifdef MAC_OS
112
- gBufferChoiceSource ->replace (" #version 140" , " #version 150" );
113
- #endif
102
+ m_postprocessingFBO->setDrawBuffer (gl::GL_COLOR_ATTACHMENT0);
114
103
115
104
m_gBufferChoice = new glowutils::ScreenAlignedQuad (new glow::Shader (gl::GL_FRAGMENT_SHADER, gBufferChoiceSource ));
116
105
m_gBufferChoice->program ()->setUniform <gl::GLint>(" postprocessedSource" , 0 );
@@ -126,6 +115,8 @@ class EventHandler : public ExampleWindowEventHandler, glowutils::AbstractCoordi
126
115
m_gBufferChoice->program ()->setUniform <gl::GLfloat>(" farZ" , m_camera.zFar ());
127
116
128
117
window.addTimer (0 , 0 , false );
118
+
119
+ cameraChanged ();
129
120
}
130
121
131
122
virtual void finalize (Window &) override
@@ -142,26 +133,30 @@ class EventHandler : public ExampleWindowEventHandler, glowutils::AbstractCoordi
142
133
143
134
m_camera.setViewport (event.width (), event.height ());
144
135
136
+ cameraChanged ();
137
+
145
138
m_colorTexture->image2D (0 , gl::GL_RGBA8, event.width (), event.height (), 0 , gl::GL_RGBA, gl::GL_UNSIGNED_BYTE, nullptr );
146
139
m_normalTexture->image2D (0 , gl::GL_RGBA16F, event.width (), event.height (), 0 , gl::GL_RGBA, gl::GL_FLOAT, nullptr );
147
140
m_geometryTexture->image2D (0 , gl::GL_RGBA16F, event.width (), event.height (), 0 , gl::GL_RGBA, gl::GL_FLOAT, nullptr );
148
141
m_depthTexture->image2D (0 , gl::GL_DEPTH_COMPONENT, event.width (), event.height (), 0 , gl::GL_DEPTH_COMPONENT, gl::GL_FLOAT, nullptr );
149
142
m_postprocessedTexture->image2D (0 , gl::GL_RGBA8, event.width (), event.height (), 0 , gl::GL_RGBA, gl::GL_UNSIGNED_BYTE, nullptr );
150
143
}
151
144
145
+ void cameraChanged ()
146
+ {
147
+ m_sphere->setUniform (" transform" , m_camera.viewProjection ());
148
+ m_sphere->setUniform (" modelView" , m_camera.view ());
149
+ m_sphere->setUniform (" normalMatrix" , m_camera.normal ());
150
+ }
151
+
152
152
virtual void paintEvent (PaintEvent &) override
153
153
{
154
154
// Sphere Pass
155
155
156
156
m_sphereFBO->bind ();
157
- m_sphereFBO->setDrawBuffers ({ gl::GL_COLOR_ATTACHMENT0, gl::GL_COLOR_ATTACHMENT1, gl::GL_COLOR_ATTACHMENT2 });
158
157
159
158
gl::glClear (gl::GL_COLOR_BUFFER_BIT | gl::GL_DEPTH_BUFFER_BIT);
160
159
161
- m_sphere->setUniform (" transform" , m_camera.viewProjection ());
162
- m_sphere->setUniform (" modelView" , m_camera.view ());
163
- m_sphere->setUniform (" normalMatrix" , m_camera.normal ());
164
-
165
160
m_sphere->use ();
166
161
m_icosahedron->draw ();
167
162
m_sphere->release ();
@@ -171,7 +166,6 @@ class EventHandler : public ExampleWindowEventHandler, glowutils::AbstractCoordi
171
166
// Postprocessing Pass
172
167
173
168
m_postprocessingFBO->bind ();
174
- m_postprocessingFBO->setDrawBuffer (gl::GL_COLOR_ATTACHMENT0);
175
169
176
170
gl::glClear (gl::GL_COLOR_BUFFER_BIT);
177
171
@@ -191,7 +185,7 @@ class EventHandler : public ExampleWindowEventHandler, glowutils::AbstractCoordi
191
185
192
186
// GBuffer Choice Pass (including blitting)
193
187
194
- glow::FrameBufferObject::defaultFBO ()-> bind ();
188
+ // If no FBO is bound to GL_FRAMEBUFFER the default FBO is bound to GL_FRAMEBUFFER
195
189
196
190
gl::glClear (gl::GL_COLOR_BUFFER_BIT | gl::GL_DEPTH_BUFFER_BIT);
197
191
@@ -241,6 +235,7 @@ class EventHandler : public ExampleWindowEventHandler, glowutils::AbstractCoordi
241
235
m_camera.setCenter (vec3 ());
242
236
m_camera.setEye (vec3 (0 .f , 1 .f , 4 .0f ));
243
237
m_camera.setUp (vec3 (0 ,1 ,0 ));
238
+ cameraChanged ();
244
239
break ;
245
240
}
246
241
}
@@ -268,11 +263,13 @@ class EventHandler : public ExampleWindowEventHandler, glowutils::AbstractCoordi
268
263
case glowutils::WorldInHandNavigation::PanInteraction:
269
264
m_nav.panProcess (event.pos ());
270
265
event.accept ();
266
+ cameraChanged ();
271
267
break ;
272
268
273
269
case glowutils::WorldInHandNavigation::RotateInteraction:
274
270
m_nav.rotateProcess (event.pos ());
275
271
event.accept ();
272
+ cameraChanged ();
276
273
break ;
277
274
case glowutils::WorldInHandNavigation::NoInteraction:
278
275
break ;
@@ -302,6 +299,7 @@ class EventHandler : public ExampleWindowEventHandler, glowutils::AbstractCoordi
302
299
303
300
m_nav.scaleAtMouse (event.pos (), -event.offset ().y * 0 .1f );
304
301
event.accept ();
302
+ cameraChanged ();
305
303
}
306
304
307
305
virtual float depthAt (const ivec2 & windowCoordinates) const override
0 commit comments