Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Icosphere mesh generation at compile time?

18 views
Skip to first unread message

bitrex

unread,
May 27, 2017, 10:50:18 AM5/27/17
to
Is there any way to use C++11 templates/recursion to adapt the following
algorithm for generating the index/face mesh of an "icosphere"
(icosahedron-derived sphere geometry) such that the structures are
populated for a given recursion depth at compile-time, rather than runtime?

<https://schneide.wordpress.com/2016/07/15/generating-an-icosphere-in-c/>

Rick C. Hodgin

unread,
May 27, 2017, 11:04:23 AM5/27/17
to
You could write a preprocessor, which takes prog1.cpp, runs it through
the preprocessor and sees a keyword like this: "ico<4>" and does the
compute part creating source code for the tesselation data at that
point, generating prog1_out.cpp, which is the version compiled.

It's how I would do it.

Thank you,
Rick C. Hodgin

David Brown

unread,
May 29, 2017, 5:05:09 AM5/29/17
to
I haven't looked at in detail, but your key is likely to use C++14, not
just C++11, and constexpr functions. (C++14 gives you a lot more
flexibility in constexpr functions.) This will be more efficient than
using recursive templates.

bitrex

unread,
May 29, 2017, 1:57:04 PM5/29/17
to
Thanks, I recall reading that C++14 does allow more flexibility, i.e.
constexpr functions can be more than essentially just a single "return
blah" statement.

Seems like the ability to simply jot down some recursive functions as
one would using regular runtime C++ but being able to just let the
compiler know to evaluate them at compile time as well (assuming the
arguments are say, template arguments known at compile-time) would be
really nice...
0 new messages