X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=util.cpp;h=1e66c30b573e51ef419146d5149c32ed9e53e7d3;hp=8162f712d02eed8f5b47b7f481b977b827f56f8f;hb=6aff20a0932dc9b668b77981390539dd710cf06d;hpb=f3591ae239781d0587a141e14633e172ba9e376b diff --git a/util.cpp b/util.cpp index 8162f71..1e66c30 100644 --- a/util.cpp +++ b/util.cpp @@ -9,6 +9,14 @@ #include "init.h" #include "util.h" +#if defined(__DARWIN__) +#include +#elif defined(WIN32) +#include +#else +#include +#endif + using namespace std; namespace movit { @@ -220,4 +228,28 @@ unsigned div_round_up(unsigned a, unsigned b) return (a + b - 1) / b; } +// Algorithm from http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2. +unsigned next_power_of_two(unsigned v) +{ + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v++; + return v; +} + +void *get_gl_context_identifier() +{ +#if defined(__DARWIN__) + return (void *)CGLGetCurrentContext(); +#elif defined(WIN32) + return (void *)wglGetCurrentContext(); +#else + return (void *)glXGetCurrentContext(); +#endif +} + } // namespace movit