medfall

A super great game engine
Log | Files | Refs

commit d744adf1adf247c5103688e468062d545621198c
parent bdbc2921098966d343f0a6b09363e8d32a4dbc0c
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Mon May 15 03:30:51 +0300

renderer_ub_easy

Diffstat:
renderer.h | 36++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+), 0 deletions(-)
diff --git a/renderer.h b/renderer.h @@ -202,3 +202,39 @@ void renderer_delete_texture( Texture texture ); Mesh renderer_new_mesh( MeshConfig config ); void renderer_draw_mesh( const Mesh & mesh, RenderState state ); void renderer_delete_mesh( const Mesh & mesh ); + +/* + * cheesy renderer_ub_data helper + */ + +// TODO: By the rules of std140, each vec3 must start on a 16-byte boundary. +// But vec3 does not consume 16 bytes of storage; it only consumes 12. And +// since float can start on a 4-byte boundary, a vec3 followed by a float will +// take up 16 bytes. + +template< typename T > +constexpr size_t renderer_ub_size() { + return sizeof( T ); +} + +template< typename S, typename T, typename... Rest > +constexpr size_t renderer_ub_size() { + return align4( sizeof( S ) ) + renderer_ub_size< T, Rest... >(); +} + +inline void renderer_ub_easy_helper( const char * buf ) { } + +template< typename T, typename... Rest > +inline void renderer_ub_easy_helper( char * buf, const T & first, Rest... rest ) { + memcpy( buf, &first, sizeof( first ) ); + renderer_ub_easy_helper( buf + align4( sizeof( first ) ), rest... ); +} + +template< typename... Rest > +inline void renderer_ub_easy( UB ub, Rest... rest ) { + constexpr size_t buf_size = renderer_ub_size< Rest... >(); + char buf[ buf_size ]; + memset( buf, 0, sizeof( buf ) ); + renderer_ub_easy_helper( buf, rest... ); + renderer_ub_data( ub, buf, sizeof( buf ) ); +}