1 USING: alien alien.syntax alien.parser combinators
2 kernel parser sequences system words namespaces hashtables init
3 math arrays assocs continuations lexer fry locals vocabs.parser ;
4 IN: opengl.gl.extensions
6 ERROR: unknown-gl-platform ;
8 { [ os windows? ] [ "opengl.gl.windows" ] }
9 { [ os macosx? ] [ "opengl.gl.macosx" ] }
10 { [ os unix? ] [ "opengl.gl.gtk" ] }
11 [ unknown-gl-platform ]
14 SYMBOL: +gl-function-counter+
15 SYMBOL: +gl-function-pointers+
17 : reset-gl-function-number-counter ( -- )
18 0 +gl-function-counter+ set-global ;
19 : reset-gl-function-pointers ( -- )
20 100 <hashtable> +gl-function-pointers+ set-global ;
22 STARTUP-HOOK: reset-gl-function-pointers
24 reset-gl-function-pointers
25 reset-gl-function-number-counter
27 : gl-function-counter ( -- n )
28 +gl-function-counter+ counter ;
30 : gl-function-pointer ( names n -- funptr )
31 gl-function-context 2array dup +gl-function-pointers+ get-global at
34 [ gl-function-address ] map [ ] find nip
35 dup [ "OpenGL function not available" throw ] unless
38 +gl-function-pointers+ get-global set-at
41 : indirect-quot ( function-ptr-quot return types abi -- quot )
42 '[ @ _ _ _ alien-indirect ] ;
44 :: define-indirect ( abi return function-name function-ptr-quot types names -- )
45 function-name create-function
46 function-ptr-quot return types abi indirect-quot
47 names return function-effect
50 : gl-function-calling-convention ( -- symbol )
51 os windows? [ stdcall ] [ cdecl ] if ;
54 gl-function-calling-convention
56 "{" expect "}" parse-tokens over suffix
57 gl-function-counter '[ _ _ gl-function-pointer ]
58 scan-c-args define-indirect ;