Skip to content

Commit 1964b27

Browse files
author
kevyuu
committed
Accept tesselation as uint16_t parameter
1 parent de02323 commit 1964b27

File tree

2 files changed

+10
-50
lines changed

2 files changed

+10
-50
lines changed

include/nbl/asset/utils/CGeometryCreator.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class NBL_API2 CGeometryCreator final : public core::IReferenceCounted
5858
\param colorCone color of the cone
5959
\return Generated mesh.
6060
*/
61-
core::vector<core::smart_refctd_ptr<ICPUPolygonGeometry>> createArrow(const uint32_t tesselationCylinder = 4,
62-
const uint32_t tesselationCone = 8, const float height = 1.f,
61+
core::vector<core::smart_refctd_ptr<ICPUPolygonGeometry>> createArrow(const uint16_t tesselationCylinder = 4,
62+
const uint16_t tesselationCone = 8, const float height = 1.f,
6363
const float cylinderHeight = 0.6f, const float widthCylinder = 0.05f,
6464
const float widthCone = 0.3f) const;
6565

@@ -85,7 +85,7 @@ class NBL_API2 CGeometryCreator final : public core::IReferenceCounted
8585
\return Generated mesh.
8686
*/
8787
core::smart_refctd_ptr<ICPUPolygonGeometry> createCylinder(float radius, float length,
88-
uint32_t tesselation,
88+
uint16_t tesselation,
8989
CQuantNormalCache* const quantNormalCacheOverride=nullptr) const;
9090

9191
//! Create a cone mesh.
@@ -98,7 +98,7 @@ class NBL_API2 CGeometryCreator final : public core::IReferenceCounted
9898
\param oblique (to be documented)
9999
\return Generated mesh.
100100
*/
101-
core::smart_refctd_ptr<ICPUPolygonGeometry> createCone(float radius, float length, uint32_t tesselation,
101+
core::smart_refctd_ptr<ICPUPolygonGeometry> createCone(float radius, float length, uint16_t tesselation,
102102
float oblique=0.f, CQuantNormalCache* const quantNormalCacheOverride=nullptr) const;
103103

104104
core::smart_refctd_ptr<ICPUPolygonGeometry> createRectangle(const hlsl::float32_t2 size={0.5f,0.5f}) const;

src/nbl/asset/utils/CGeometryCreator.cpp

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,13 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createSphere(float
493493

494494
core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createCylinder(
495495
float radius, float length,
496-
uint32_t tesselation, CQuantNormalCache* const quantNormalCacheOverride) const
496+
uint16_t tesselation, CQuantNormalCache* const quantNormalCacheOverride) const
497497
{
498498
using namespace hlsl;
499499

500500
CQuantNormalCache* const quantNormalCache = quantNormalCacheOverride == nullptr ? m_params.normalCache.get() : quantNormalCacheOverride;
501501

502-
const auto halfIx = static_cast<uint16_t>(tesselation);
502+
const auto halfIx = tesselation;
503503
const uint32_t u32_vertexCount = 2 * tesselation;
504504
if (u32_vertexCount > std::numeric_limits<uint16_t>::max())
505505
return nullptr;
@@ -585,7 +585,7 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createCylinder(
585585
}
586586

587587
core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createCone(
588-
float radius, float length, uint32_t tesselation,
588+
float radius, float length, uint16_t tesselation,
589589
float oblique, CQuantNormalCache* const quantNormalCacheOverride) const
590590
{
591591

@@ -690,8 +690,8 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createCone(
690690
}
691691

692692
core::vector<core::smart_refctd_ptr<ICPUPolygonGeometry>> CGeometryCreator::createArrow(
693-
const uint32_t tesselationCylinder,
694-
const uint32_t tesselationCone,
693+
const uint16_t tesselationCylinder,
694+
const uint16_t tesselationCone,
695695
const float height,
696696
const float cylinderHeight,
697697
const float width0,
@@ -880,7 +880,7 @@ class Icosphere
880880
public:
881881
using index_t = unsigned int;
882882

883-
Icosphere(float radius = 1.0f, int subdivision = 1, bool smooth = false) : radius(radius), subdivision(subdivision), smooth(smooth), interleavedStride(32)
883+
Icosphere(float radius = 1.0f, int subdivision = 1, bool smooth = false) : radius(radius), subdivision(subdivision), smooth(smooth)
884884
{
885885
if (smooth)
886886
buildVerticesSmooth();
@@ -909,12 +909,6 @@ class Icosphere
909909
const unsigned int* getIndices() const { return indices.data(); }
910910
const unsigned int* getLineIndices() const { return lineIndices.data(); }
911911

912-
// for interleaved vertices: V/N/T
913-
unsigned int getInterleavedVertexCount() const { return getPositionCount(); } // # of vertices
914-
unsigned int getInterleavedVertexSize() const { return (unsigned int)interleavedVertices.size() * sizeof(float); } // # of bytes
915-
int getInterleavedStride() const { return interleavedStride; } // should be 32 bytes
916-
const float* getInterleavedVertices() const { return interleavedVertices.data(); }
917-
918912
protected:
919913

920914
private:
@@ -1092,11 +1086,6 @@ class Icosphere
10921086
vertices[i] *= scale;
10931087
vertices[i + 1] *= scale;
10941088
vertices[i + 2] *= scale;
1095-
1096-
// for interleaved array
1097-
interleavedVertices[j] *= scale;
1098-
interleavedVertices[j + 1] *= scale;
1099-
interleavedVertices[j + 2] *= scale;
11001089
}
11011090
}
11021091

@@ -1260,9 +1249,6 @@ class Icosphere
12601249

12611250
// subdivide icosahedron
12621251
subdivideVerticesFlat();
1263-
1264-
// generate interleaved vertex array as well
1265-
buildInterleavedVertices();
12661252
}
12671253

12681254
/*
@@ -1485,8 +1471,6 @@ class Icosphere
14851471
// subdivide icosahedron
14861472
subdivideVerticesSmooth();
14871473

1488-
// generate interleaved vertex array as well
1489-
buildInterleavedVertices();
14901474
}
14911475
/*
14921476
divide a trinage into 4 sub triangles and repeat N times
@@ -1662,27 +1646,6 @@ class Icosphere
16621646
stride must be 32 bytes
16631647
*/
16641648

1665-
void buildInterleavedVertices()
1666-
{
1667-
core::vector<float>().swap(interleavedVertices);
1668-
1669-
std::size_t i, j;
1670-
std::size_t count = vertices.size();
1671-
for (i = 0, j = 0; i < count; i += 3, j += 2)
1672-
{
1673-
interleavedVertices.push_back(vertices[i]);
1674-
interleavedVertices.push_back(vertices[i + 1]);
1675-
interleavedVertices.push_back(vertices[i + 2]);
1676-
1677-
interleavedVertices.push_back(normals[i]);
1678-
interleavedVertices.push_back(normals[i + 1]);
1679-
interleavedVertices.push_back(normals[i + 2]);
1680-
1681-
interleavedVertices.push_back(texCoords[j]);
1682-
interleavedVertices.push_back(texCoords[j + 1]);
1683-
}
1684-
}
1685-
16861649
void addVertex(float x, float y, float z)
16871650
{
16881651
vertices.push_back(x);
@@ -1826,9 +1789,6 @@ class Icosphere
18261789
core::vector<uint32_t> lineIndices;
18271790
std::map<std::pair<float, float>, uint32_t> sharedIndices; // indices of shared vertices, key is tex coord (s,t)
18281791

1829-
// interleaved
1830-
core::vector<float> interleavedVertices;
1831-
uint32_t interleavedStride; // # of bytes to hop to the next vertex (should be 32 bytes)
18321792

18331793
};
18341794

0 commit comments

Comments
 (0)