diff options
Diffstat (limited to 'emulator/opengl/host/libs/Translator/include')
-rw-r--r-- | emulator/opengl/host/libs/Translator/include/GLcommon/GLutils.h | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/GLutils.h b/emulator/opengl/host/libs/Translator/include/GLcommon/GLutils.h index 2aed646..974b9be 100644 --- a/emulator/opengl/host/libs/Translator/include/GLcommon/GLutils.h +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/GLutils.h @@ -16,36 +16,37 @@ #ifndef GL_UTILS_H #define GL_UTILS_H -#include <inttypes.h> #include <assert.h> +#include <inttypes.h> -typedef enum{ - GLES_1_1 = 1, - GLES_2_0 = 2, - MAX_GLES_VERSION //Must be last - }GLESVersion; +typedef enum { + GLES_1_1 = 1, + GLES_2_0 = 2, + MAX_GLES_VERSION //Must be last +} GLESVersion; template <class T> void swap(T& x,T& y) { T temp; - temp=x; - x=y; - y=temp; + temp = x; + x = y; + y = temp; } bool isPowerOf2(int num); -inline -unsigned int ToTargetCompatibleHandle(uintptr_t hostHandle) -{ - // The host and target handles can have different sizes (e.g. 32-bit - // target handle for ARM, and 64-bit host handle on x86_64). - // This function checks that the input host handle value can be - // converted into a target handle one without losing any bits. - // - unsigned int targetHandle = (unsigned int)hostHandle; - assert(sizeof(targetHandle) == sizeof(hostHandle) || targetHandle == hostHandle); - return targetHandle; +// <EGL/egl.h> defines many types as 'void*' while they're really +// implemented as unsigned integers. These convenience template functions +// help casting between them safely without generating compiler warnings. +inline void* SafePointerFromUInt(unsigned int handle) { + return (void*)(uintptr_t)(handle); +} + +inline unsigned int SafeUIntFromPointer(const void* ptr) { + // Assertion error if the pointer contains a value that does not fit + // in an unsigned integer! + assert((uintptr_t)(ptr) == (unsigned int)(uintptr_t)(ptr)); + return (unsigned int)(uintptr_t)(ptr); } #endif |