From 4cebf2e874a219d785bd1f741bc3771884eab9f1 Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Fri, 27 Nov 2015 17:34:38 -0500 Subject: [PATCH] Clean up Compile-Time Type Info - Also added info about the metaprogramming helpers I added months ago --- doc/doc.tex | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/doc/doc.tex b/doc/doc.tex index 5db42515..bb77c02d 100644 --- a/doc/doc.tex +++ b/doc/doc.tex @@ -428,7 +428,7 @@ To gain a bit of performance, a programmer can define \verb|GLM_FORCE_INLINE| be #include \end{cppcode} -\subsection{Vector and Matrix Static Size} +\subsection{Compile-Time Type Info} The member function \verb|length()| returns the dimensionality (number of components) of any GLSL matrix or vector type. \begin{cppcode} @@ -479,11 +479,30 @@ void foo(glm::vec4 const & v) } \end{cppcode} +As of GLM 0.9.7.0, GLM also provides the \verb|GLM_META_PROG_HELPERS|, which enables \verb|static| members that provide information about vector, matrix, and quaternion types at compile time in a manner suitable for template metaprogramming. -\subsection{Disabling Default Constructor Initialization} +\begin{cppcode} +#define GLM_META_PROG_HELPERS +#include -By default, the nullary (zero-argument) constructors of vectors and matrices initialize their components to zero, as is required in the GLSL specification. Such behavior is reliable and convenient, but sometimes unnecessary. Disable it at compilation time by defining \verb|GLM_FORCE_NO_CTOR_INIT| before including any GLM headers. +template +void foo(VecT const & v) +{ + static_assert(VecT::components < 4, "4D doesn't make sense!"); + glm::vec2 something; + // vec2 with the same component type and precision as VecT +} + +template +void bar(MatT const & m) +{ + static_assert(MatT::rows == MatT::cols, "Square matrices only!"); +} +\end{cppcode} + + +\subsection{Disabling Default Initialization} GLM's default behavior: \begin{cppcode}