@@ -82,6 +82,7 @@ void validateVertexAttributes(const renderer::IntrospectProgram & aProgram)
8282}
8383
8484
85+ const unsigned int gCircleResolution = 32 ;
8586const std::filesystem::path gProgramPath = " programs/ch10_area_lights_TessellateSphere.prog" ;
8687// const std::filesystem::path gProgramPath = "programs/WrapLighting.prog";
8788const std::filesystem::path gLightProgramPath = " programs/TessSphere_PlainColor.prog" ;
@@ -105,6 +106,20 @@ void describe(T_witness aWitness, Scene::TessellationControl & aValue)
105106 aValue.mInnerLevel = math::min (aValue.mInnerLevel , maxTess.xy ());
106107}
107108
109+ LineDrawer::LineDrawer (renderer::IntrospectProgram aLineProgram) :
110+ mProgram {std::move (aLineProgram)}
111+ {
112+ auto vertices = renderer::makeRoundSegment (gCircleResolution );
113+ auto verticesSpan = std::span{vertices};
114+ mVerticesCount = vertices.size ();
115+ glBindBuffer (mVertices .GLTarget_v , mVertices );
116+ glBufferData (mVertices .GLTarget_v , verticesSpan.size_bytes (), verticesSpan.data (), GL_STATIC_DRAW);
117+
118+ glBindVertexArray (mVao );
119+ glEnableVertexAttribArray (0 );
120+ glBindBuffer (mVertices .GLTarget_v , mVertices );
121+ glVertexAttribPointer (0 , 3 , GL_FLOAT, GL_FALSE, 0 , 0 );
122+ }
108123
109124Scene::Scene (graphics::AppInterface & aAppInterface, const imguiui::ImguiUi & aImgui) :
110125 mVertexSpecification {},
@@ -115,7 +130,7 @@ Scene::Scene(graphics::AppInterface & aAppInterface, const imguiui::ImguiUi & aI
115130 graphics::BufferHint::StaticDraw)},
116131 mSurfaceProgram {mEngine .loadProgram (renderer::ReferencePath{gProgramPath })},
117132 mLightProgram {mEngine .loadProgram (renderer::ReferencePath{gLightProgramPath })},
118- mLineProgram {mEngine .loadProgram (renderer::ReferencePath{gLineProgramPath })}
133+ mLineDrawer {mEngine .loadProgram (renderer::ReferencePath{gLineProgramPath })}
119134{
120135 graphics::attachIndexBuffer (mIndexBuffer , mVertexSpecification .mVertexArray );
121136
@@ -159,7 +174,7 @@ void Scene::loadPrograms()
159174 mEngine .loadProgram (renderer::ReferencePath{ gProgramPath });
160175 mLightProgram =
161176 mEngine .loadProgram (renderer::ReferencePath{ gLightProgramPath });
162- mLineProgram =
177+ mLineDrawer . mProgram =
163178 mEngine .loadProgram (renderer::ReferencePath{ gLineProgramPath });
164179}
165180
@@ -279,29 +294,33 @@ void Scene::render(math::Size<2, int> aRenderResolution)
279294 sphereCount,
280295 0 );
281296
282- // Render point lights as sphere
283- validateVertexAttributes (mLightProgram );
284- glUseProgram (mLightProgram );
285- glDrawElementsInstancedBaseInstance (
286- GL_PATCHES,
287- mIndicesCount ,
288- graphics::MappedGL_v<scenic::Index>,
289- 0 ,
290- mLights .mPointCount ,
291- sphereCount);
297+ if (mFrameControl .mShowPunctualLights )
298+ {
299+ // Render point lights as sphere
300+ validateVertexAttributes (mLightProgram );
301+ glUseProgram (mLightProgram );
302+ glDrawElementsInstancedBaseInstance (
303+ GL_PATCHES,
304+ mIndicesCount ,
305+ graphics::MappedGL_v<scenic::Index>,
306+ 0 ,
307+ mLights .mPointCount ,
308+ sphereCount);
309+ }
292310
293311 // Render tube lights as fat lines
294312 {
295313 glDisable (GL_CULL_FACE);
296- graphics::setUniform (mLineProgram , " u_FramebufferSize" , aRenderResolution);
314+ graphics::setUniform (mLineDrawer . mProgram , " u_FramebufferSize" , aRenderResolution);
297315 {
298316 // Binds to the general binding point, in addition to binding index 8
299- glBindBufferBase (GL_SHADER_STORAGE_BUFFER, 8 , mLinesSsbo );
317+ glBindBufferBase (GL_SHADER_STORAGE_BUFFER, 8 , mLineDrawer . mLinesSsbo );
300318 std::span<renderer::LineSegment_glsl> lines{ mLines .mSegments };
301319 glBufferData (GL_SHADER_STORAGE_BUFFER, lines.size_bytes (), lines.data (), GL_STREAM_DRAW);
302320 }
303- glUseProgram (mLineProgram );
304- glDrawArrays (GL_TRIANGLE_STRIP, 0 , 4 );
321+ glBindVertexArray (mLineDrawer .mVao );
322+ glUseProgram (mLineDrawer .mProgram );
323+ glDrawArrays (GL_TRIANGLES, 0 , mLineDrawer .mVerticesCount );
305324 glEnable (GL_CULL_FACE);
306325 }
307326}
@@ -330,6 +349,8 @@ void Scene::presentUi(bool * aOpen)
330349 FrameControl::gPolygonModes .end (),
331350 [](auto aModeIt){return graphics::to_string (*aModeIt);});
332351
352+ ImGui::Checkbox (" Show Punctual Lights" , &mFrameControl .mShowPunctualLights );
353+
333354 DearImguiWitness witness;
334355
335356 ImGui::Spacing ();
0 commit comments