Skip to content

Commit 054038f

Browse files
committed
add positions to geometry creator's grid for the polygon to be usable with GPU converter, encode to EF_A2R10G10B10_UNORM_PACK32, update examples_tests submodule
1 parent dbd2805 commit 054038f

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/nbl/asset/utils/CGeometryCreator.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,8 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createIcoSphere(fl
18911891

18921892
core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createGrid(const hlsl::uint16_t2 resolution) const
18931893
{
1894+
using namespace hlsl;
1895+
18941896
if (resolution.x < 2 || resolution.y < 2)
18951897
return nullptr;
18961898

@@ -1973,6 +1975,43 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createGrid(const h
19731975
else
19741976
return nullptr;
19751977

1978+
//! Create positions
1979+
const size_t vertexCount = resolution.x * resolution.y;
1980+
{
1981+
shapes::AABB<4, float32_t> aabb;
1982+
aabb.maxVx = float32_t4((resolution.x - 0.5f) / float(resolution.x), 0.5f, (resolution.y - 0.5f) / float(resolution.y), 1.f);
1983+
aabb.minVx = float32_t4(0.5f / float(resolution.x), 0.5f, 0.5f / float(resolution.y), 1.f);
1984+
1985+
const auto stride = getTexelOrBlockBytesize<EF_A2R10G10B10_UNORM_PACK32>();
1986+
const auto bytes = stride * vertexCount;
1987+
auto buffer = ICPUBuffer::create({ bytes, IBuffer::EUF_NONE });
1988+
ICPUPolygonGeometry::SDataView positionView = {
1989+
.composed = {
1990+
.encodedDataRange = {.f32 = aabb},
1991+
.stride = stride,
1992+
.format = EF_A2R10G10B10_UNORM_PACK32,
1993+
.rangeFormat = IGeometryBase::EAABBFormat::F32
1994+
},
1995+
.src = {.offset = 0,.size = buffer->getSize(),.buffer = core::smart_refctd_ptr(buffer)}
1996+
};
1997+
1998+
auto* packed = reinterpret_cast<uint32_t*>(buffer->getPointer());
1999+
for (uint32_t j = 0; j < resolution.y; ++j)
2000+
for (uint32_t i = 0; i < resolution.x; ++i)
2001+
{
2002+
const double u = (i + 0.5) / double(resolution.x);
2003+
const double v = (j + 0.5) / double(resolution.y);
2004+
2005+
float64_t4 rgbaunorm = { u, 0.5, v, 1.0 };
2006+
2007+
*packed = {};
2008+
encodePixels<asset::EF_A2R10G10B10_UNORM_PACK32, double>(packed, (double*)&rgbaunorm);
2009+
++packed;
2010+
}
2011+
2012+
retval->setPositionView(std::move(positionView));
2013+
}
2014+
19762015
CPolygonGeometryManipulator::recomputeContentHashes(retval.get());
19772016
return retval;
19782017
}

0 commit comments

Comments
 (0)