Skip to content

Commit 86cc7dd

Browse files
author
devsh
committed
decouple CSimpleDebugRenderer from CGeometryCreatorScene
1 parent 20cc57e commit 86cc7dd

File tree

3 files changed

+70
-54
lines changed

3 files changed

+70
-54
lines changed

12_MeshLoaders/main.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
3737
}
3838

3939
//! cache results -- speeds up mesh generation on second run
40+
m_qnc = make_smart_refctd_ptr<CQuantNormalCache>();
4041
m_qnc->loadCacheFromFile<EF_R8G8B8_SNORM>(m_system.get(),sharedOutputCWD/"../../tmp/normalCache888.sse");
4142

4243
//
@@ -224,17 +225,29 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
224225
}
225226

226227
private:
228+
// TODO: standardise this across examples, and take from `argv`
229+
bool m_nonInteractiveTest = true;
230+
227231
inline bool reloadModel()
228232
{
229-
pfd::open_file file("Choose a supported Model File", "../../media", { "All Supported Formats", "*.ply *.stl *.serialized *.obj",
230-
"TODO (.ply)", "*.ply",
231-
"TODO (.stl)", "*.stl",
232-
"Mitsuba 0.6 Serialized (.serialized)", "*.serialized",
233-
"Wavefront Object (.obj)", "*.obj"
234-
});
235-
if (file.result().empty())
236-
return false;
237-
m_modelPath = file.result()[0];
233+
if (m_nonInteractiveTest) // TODO: maybe also take from argv and argc
234+
m_modelPath = (sharedInputCWD/"ply/Spanner-ply.ply").string();
235+
else
236+
{
237+
pfd::open_file file("Choose a supported Model File", sharedInputCWD.string(),
238+
{
239+
"All Supported Formats", "*.ply *.stl *.serialized *.obj",
240+
"TODO (.ply)", "*.ply",
241+
"TODO (.stl)", "*.stl",
242+
"Mitsuba 0.6 Serialized (.serialized)", "*.serialized",
243+
"Wavefront Object (.obj)", "*.obj"
244+
},
245+
false
246+
);
247+
if (file.result().empty())
248+
return false;
249+
m_modelPath = file.result()[0];
250+
}
238251

239252
// free up
240253
m_assetMgr->clearAllAssetCache();

common/include/nbl/examples/geometry/CGeometryCreatorScene.hpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ class CGeometryCreatorScene : public core::IReferenceCounted
4242
}
4343

4444

45-
core::vector<SNamedGeometry> namedGeometries;
45+
SInitParams init = {};
4646
core::vector<smart_refctd_ptr<const ICPUPolygonGeometry>> geometries;
4747
// create out geometries
4848
{
49-
auto addGeometry = [&namedGeometries,&geometries](const std::string_view name, smart_refctd_ptr<const ICPUPolygonGeometry>&& geom)->void
49+
auto addGeometry = [&init,&geometries](const std::string_view name, smart_refctd_ptr<const ICPUPolygonGeometry>&& geom)->void
5050
{
51-
namedGeometries.emplace_back().name = name;
51+
init.geometryNames.emplace_back(name);
5252
geometries.push_back(std::move(geom));
5353
};
5454

@@ -67,6 +67,7 @@ class CGeometryCreatorScene : public core::IReferenceCounted
6767
addGeometry("Rectangle",creator->createRectangle({1.5f,3.f}));
6868
addGeometry("Disk",creator->createDisk(2.f,30));
6969
}
70+
init.geometries.reserve(init.geometryNames.size());
7071

7172
// convert the geometries
7273
{
@@ -148,34 +149,37 @@ class CGeometryCreatorScene : public core::IReferenceCounted
148149
// assign outputs
149150
{
150151
auto inIt = reservation.getGPUObjects<ICPUPolygonGeometry>().data();
151-
for (auto outIt=namedGeometries.begin(); outIt!=namedGeometries.end(); inIt++)
152+
for (auto outIt=init.geometryNames.begin(); outIt!=init.geometryNames.end(); inIt++)
152153
{
153154
if (inIt->value)
154-
(outIt++)->geom = inIt->value;
155+
{
156+
init.geometries.push_back(inIt->value);
157+
outIt++;
158+
}
155159
else
156160
{
157-
logger->log("Failed to convert ICPUPolygonGeometry %s to GPU!",ILogger::ELL_ERROR,outIt->name.data());
158-
outIt = namedGeometries.erase(outIt);
161+
logger->log("Failed to convert ICPUPolygonGeometry %s to GPU!",ILogger::ELL_ERROR,outIt->c_str());
162+
outIt = init.geometryNames.erase(outIt);
159163
}
160164
}
161165
}
162166
}
163167

164-
return smart_refctd_ptr<CGeometryCreatorScene>(new CGeometryCreatorScene(std::move(namedGeometries)),dont_grab);
168+
return smart_refctd_ptr<CGeometryCreatorScene>(new CGeometryCreatorScene(std::move(init)),dont_grab);
165169
}
166170

167171
//
168-
struct SNamedGeometry
172+
struct SInitParams
169173
{
170-
std::string name = {};
171-
core::smart_refctd_ptr<video::IGPUPolygonGeometry> geom;
174+
core::vector<core::smart_refctd_ptr<const video::IGPUPolygonGeometry>> geometries;
175+
core::vector<std::string> geometryNames;
172176
};
173-
std::span<const SNamedGeometry> getGeometries() const {return m_geometries;}
177+
const SInitParams& getInitParams() const {return m_init;}
174178

175179
protected:
176-
inline CGeometryCreatorScene(core::vector<SNamedGeometry>&& _geometries) : m_geometries(std::move(_geometries)) {}
180+
inline CGeometryCreatorScene(SInitParams&& _init) : m_init(std::move(_init)) {}
177181

178-
core::vector<SNamedGeometry> m_geometries;
182+
SInitParams m_init;
179183
#undef EXPOSE_NABLA_NAMESPACES
180184
};
181185

common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted
7979
};
8080

8181
//
82-
static inline core::smart_refctd_ptr<CSimpleDebugRenderer> create(asset::IAssetManager* assMan, video::IGPURenderpass* renderpass, const uint32_t subpassIX, const CGeometryCreatorScene* scene)
82+
static inline core::smart_refctd_ptr<CSimpleDebugRenderer> create(asset::IAssetManager* assMan, video::IGPURenderpass* renderpass, const uint32_t subpassIX, const std::span<const video::IGPUPolygonGeometry* const> geometries)
8383
{
8484
EXPOSE_NABLA_NAMESPACES;
8585

@@ -88,10 +88,7 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted
8888
auto device = const_cast<ILogicalDevice*>(renderpass->getOriginDevice());
8989
auto logger = device->getLogger();
9090

91-
if (!assMan || !scene)
92-
return nullptr;
93-
const auto namedGeoms = scene->getGeometries();
94-
if (namedGeoms.empty())
91+
if (!assMan || geometries.empty())
9592
return nullptr;
9693

9794
// load shader
@@ -154,33 +151,26 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted
154151
init.layout = device->createPipelineLayout(ranges,smart_refctd_ptr<const IGPUDescriptorSetLayout>(init.ds->getLayout()));
155152

156153
// create pipelines
157-
enum PipelineType : uint8_t
158-
{
159-
BasicTriangleList,
160-
BasicTriangleFan,
161-
Cone,
162-
Count
163-
};
164-
smart_refctd_ptr<IGPUGraphicsPipeline> pipelines[PipelineType::Count] = {};
154+
using pipeline_e = SInitParams::PipelineType;
165155
{
166-
IGPUGraphicsPipeline::SCreationParams params[PipelineType::Count] = {};
167-
params[PipelineType::BasicTriangleList].vertexShader = {.shader=shader.get(),.entryPoint="BasicVS"};
168-
params[PipelineType::BasicTriangleList].fragmentShader = {.shader=shader.get(),.entryPoint="BasicFS"};
169-
params[PipelineType::BasicTriangleFan].vertexShader = {.shader=shader.get(),.entryPoint="BasicVS"};
170-
params[PipelineType::BasicTriangleFan].fragmentShader = {.shader=shader.get(),.entryPoint="BasicFS"};
171-
params[PipelineType::Cone].vertexShader = {.shader=shader.get(),.entryPoint="ConeVS"};
172-
params[PipelineType::Cone].fragmentShader = {.shader=shader.get(),.entryPoint="ConeFS"};
173-
for (auto i=0; i< PipelineType::Count; i++)
156+
IGPUGraphicsPipeline::SCreationParams params[pipeline_e::Count] = {};
157+
params[pipeline_e::BasicTriangleList].vertexShader = {.shader=shader.get(),.entryPoint="BasicVS"};
158+
params[pipeline_e::BasicTriangleList].fragmentShader = {.shader=shader.get(),.entryPoint="BasicFS"};
159+
params[pipeline_e::BasicTriangleFan].vertexShader = {.shader=shader.get(),.entryPoint="BasicVS"};
160+
params[pipeline_e::BasicTriangleFan].fragmentShader = {.shader=shader.get(),.entryPoint="BasicFS"};
161+
params[pipeline_e::Cone].vertexShader = {.shader=shader.get(),.entryPoint="ConeVS"};
162+
params[pipeline_e::Cone].fragmentShader = {.shader=shader.get(),.entryPoint="ConeFS"};
163+
for (auto i=0; i<pipeline_e::Count; i++)
174164
{
175165
params[i].layout = init.layout.get();
176166
// no vertex input
177167
auto& primitiveAssembly = params[i].cached.primitiveAssembly;
178168
auto& rasterization = params[i].cached.rasterization;
179169
auto& blend = params[i].cached.blend;
180-
const auto type = static_cast<PipelineType>(i);
170+
const auto type = static_cast<pipeline_e>(i);
181171
switch (type)
182172
{
183-
case PipelineType::BasicTriangleFan:
173+
case pipeline_e::BasicTriangleFan:
184174
primitiveAssembly.primitiveType = E_PRIMITIVE_TOPOLOGY::EPT_TRIANGLE_FAN;
185175
break;
186176
default:
@@ -193,7 +183,7 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted
193183
params[i].cached.subpassIx = subpassIX;
194184
params[i].renderpass = renderpass;
195185
}
196-
if (!device->createGraphicsPipelines(nullptr,params,pipelines))
186+
if (!device->createGraphicsPipelines(nullptr,params,init.pipelines))
197187
{
198188
logger->log("Could not create Graphics Pipelines!",ILogger::ELL_ERROR);
199189
return nullptr;
@@ -212,25 +202,21 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted
212202
return retval;
213203
};
214204

215-
for (const auto& entry : namedGeoms)
205+
for (const auto geom : geometries)
216206
{
217-
const auto* geom = entry.geom.get();
218207
// could also check device origin on all buffers
219208
if (!geom->valid())
220209
continue;
221210
auto& out = init.geoms.emplace_back();
222211
switch (geom->getIndexingCallback()->knownTopology())
223212
{
224213
case E_PRIMITIVE_TOPOLOGY::EPT_TRIANGLE_FAN:
225-
out.pipeline = pipelines[PipelineType::BasicTriangleFan];
214+
out.pipeline = init.pipelines[pipeline_e::BasicTriangleFan];
226215
break;
227216
default:
228-
out.pipeline = pipelines[PipelineType::BasicTriangleList];
217+
out.pipeline = init.pipelines[pipeline_e::BasicTriangleList];
229218
break;
230219
}
231-
// special case
232-
if (entry.name=="Cone")
233-
out.pipeline = pipelines[PipelineType::Cone];
234220
if (const auto& view=geom->getIndexView(); view)
235221
{
236222
out.indexBuffer.offset = view.src.offset;
@@ -275,12 +261,25 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted
275261
//
276262
struct SInitParams
277263
{
264+
enum PipelineType : uint8_t
265+
{
266+
BasicTriangleList,
267+
BasicTriangleFan,
268+
Cone, // special case
269+
Count
270+
};
271+
278272
core::smart_refctd_ptr<video::IGPUDescriptorSet> ds;
279273
core::smart_refctd_ptr<video::IGPUPipelineLayout> layout;
274+
core::smart_refctd_ptr<video::IGPUGraphicsPipeline> pipelines[PipelineType::Count];
280275
core::vector<SPackedGeometry> geoms;
281276
};
282277
inline const SInitParams& getInitParams() const {return m_params;}
283278

279+
//
280+
inline auto& getGeometry(const uint32_t ix) {return m_params.geoms[ix];}
281+
inline const auto& getGeometry(const uint32_t ix) const {return m_params.geoms[ix];}
282+
284283
//
285284
inline void render(video::IGPUCommandBuffer* cmdbuf, const SViewParams& viewParams) const
286285
{

0 commit comments

Comments
 (0)