GRIM: Formatted code and added an assert that checks that object-pointers and function-pointers are of the same size before casting.

This commit is contained in:
Joni Vähämäki 2011-05-20 03:12:48 +08:00 committed by Pawel Kolodziejski
parent 67487b8667
commit 22a5332a76

View file

@ -26,11 +26,6 @@
#undef ARRAYSIZE
#endif
#ifdef SDL_BACKEND
// We need SDL.h for SDL_GL_GetProcAddress.
#include "backends/platform/sdl/sdl-sys.h"
#endif
#include "common/endian.h"
#include "common/system.h"
@ -44,8 +39,13 @@
#include "engines/grim/bitmap.h"
#include "engines/grim/primitives.h"
#ifdef USE_OPENGL
#if defined(SDL_BACKEND)
// We need SDL.h for SDL_GL_GetProcAddress.
#include "backends/platform/sdl/sdl-sys.h"
// Extension functions needed for fragment programs.
PFNGLGENPROGRAMSARBPROC glGenProgramsARB;
PFNGLBINDPROGRAMARBPROC glBindProgramARB;
@ -54,8 +54,6 @@ PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB;
#endif
#ifdef USE_OPENGL
namespace Grim {
// Simple ARB fragment program that writes the value from a texture to the Z-buffer.
@ -119,6 +117,9 @@ void GfxOpenGL::initExtensions()
void* obj_ptr;
void (APIENTRY *func_ptr)();
} u;
// We're casting from an object pointer to a function pointer, the
// sizes need to be the same for this to work.
assert(sizeof(u.obj_ptr) == sizeof(u.func_ptr));
u.obj_ptr = SDL_GL_GetProcAddress("glGenProgramsARB");
glGenProgramsARB = (PFNGLGENPROGRAMSARBPROC)u.func_ptr;
u.obj_ptr = SDL_GL_GetProcAddress("glBindProgramARB");