source: trunk/src/lib/gl.cc @ 167

Last change on this file since 167 was 167, checked in by epyon, 12 years ago
  • freetype2 - using new function loading method
  • gl - using new function loading method
File size: 2.0 KB
RevLine 
[5]1// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
2// http://chaosforge.org/
3//
4// This file is part of NV Libraries.
5// For conditions of distribution and use, see copyright notice in nv.hh
6
[20]7#include "nv/common.hh"
[5]8#include "nv/lib/gl.hh"
9
10#if defined( NV_GL_DYNAMIC )
11
12#include "nv/library.hh"
13
14#if defined( NV_SDL_GL )
15#       include "nv/lib/sdl12.hh"
16#endif
17
[167]18#define NV_GL_FUN( rtype, fname, fparams ) rtype (NV_GL_APIENTRY *fname) fparams = nullptr;
19#define NV_GL_FUN_EXT NV_GL_FUN
20#include <nv/lib/detail/gl_functions.inc>
21#undef NV_GL_FUN_EXT
22#undef NV_GL_FUN
[5]23
24bool nv::load_gl_library( const char* path )
25{
26#if defined( NV_SDL_GL )
27#               define NV_GL_LOAD( symbol ) *(void **) (&symbol) = SDL_GL_GetProcAddress(#symbol);
28#               define NV_GL_LOAD_EXT( symbol ) *(void **) (&symbol) = SDL_GL_GetProcAddress(#symbol);
29#else
[109]30        static nv::library gl_library;
31        if ( gl_library.is_open() ) return true;
32        gl_library.open( path );
33
[5]34        void * (NV_GL_APIENTRY *ext_loader) (const char* proc) = nullptr;
35#       if NV_PLATFORM == NV_WINDOWS
36#               define NV_GL_LOAD( symbol ) *(void **) (&symbol) = gl_library.get(#symbol);
37                *(void **) (&ext_loader) = gl_library.get("wglGetProcAddress");
38#               define NV_GL_LOAD_EXT( symbol ) *(void **) (&symbol) = ext_loader(#symbol);
39#       elif NV_PLATFORM == NV_LINUX
40#               define NV_GL_LOAD( symbol ) *(void **) (&symbol) = gl_library.get(#symbol);
41                *(void **) (&ext_loader) = gl_library.get("glXGetProcAddress");
42#               define NV_GL_LOAD_EXT( symbol ) *(void **) (&symbol) = ext_loader(#symbol);
43#       else
44#               define NV_GL_LOAD( symbol ) *(void **) (&symbol) = gl_library.get(#symbol);
45#               define NV_GL_LOAD_EXT( symbol ) *(void **) (&symbol) = gl_library.get(#symbol);
46#       endif
47#endif
48
[167]49#       define NV_GL_FUN( rtype, fname, fparams ) NV_GL_LOAD( fname )
50#       define NV_GL_FUN_EXT( rtype, fname, fparams ) NV_GL_LOAD_EXT( fname )
51#       include <nv/lib/detail/gl_functions.inc>
52#       undef NV_GL_FUN_EXT
53#       undef NV_GL_FUN
[5]54
55#       undef NV_GL_LOAD
56#       undef NV_GL_LOAD_EXT
57        return true;
58}
59
[20]60#endif
Note: See TracBrowser for help on using the repository browser.