Do dynamic lookup of OpenGL 1.2+ functions on all platforms. Use fallback extension names when the official name is not available, e.g., if glUseProgram is missing try glUseProgramObjectARB instead

db4
Joe Groff 2008-02-07 22:43:05 -08:00
parent a4a3ea3fa4
commit c906d26b13
8 changed files with 79 additions and 51 deletions

View File

@ -1,7 +1,7 @@
USING: help.syntax help.markup ; USING: help.syntax help.markup ;
IN: hash2 IN: hash2
ARTICLE: { "hash2" "intro" } ARTICLE: { "hash2" "intro" } "hash2 Vocabulary"
"The hash2 vocabulary specifies a simple minimal datastructure for hash tables with two integers as keys. These hash tables are fixed size and do not conform to the associative mapping protocol. Words used in creating and manipulating these hash tables include:" "The hash2 vocabulary specifies a simple minimal datastructure for hash tables with two integers as keys. These hash tables are fixed size and do not conform to the associative mapping protocol. Words used in creating and manipulating these hash tables include:"
{ $subsection <hash2> } { $subsection <hash2> }
{ $subsection hash2 } { $subsection hash2 }

View File

@ -0,0 +1,46 @@
USING: alien alien.syntax combinators kernel parser sequences
system words namespaces hashtables init math arrays assocs
sequences.lib continuations ;
<< {
{ [ windows? ] [ "opengl.gl.windows" ] }
{ [ macosx? ] [ "opengl.gl.macosx" ] }
{ [ unix? ] [ "opengl.gl.unix" ] }
{ [ t ] [ "Unknown OpenGL platform" throw ] }
} cond use+ >>
IN: opengl.gl.extensions
SYMBOL: +gl-function-number-counter+
SYMBOL: +gl-function-pointers+
: reset-gl-function-number-counter ( -- )
0 +gl-function-number-counter+ set-global ;
: reset-gl-function-pointers ( -- )
100 <hashtable> +gl-function-pointers+ set-global ;
[ reset-gl-function-pointers ] "opengl.gl init hook" add-init-hook
reset-gl-function-pointers
reset-gl-function-number-counter
: gl-function-number ( -- n )
+gl-function-number-counter+ get-global
dup 1+ +gl-function-number-counter+ set-global ;
: gl-function-pointer ( names n -- funptr )
gl-function-context 2array dup +gl-function-pointers+ get-global at
[ 2nip ] [
>r [ gl-function-address ] attempt-each
dup [ "OpenGL function not available" throw ] unless
dup r>
+gl-function-pointers+ get-global set-at
] if* ;
: GL-FUNCTION:
gl-function-calling-convention
scan
scan dup
scan drop "}" parse-tokens swap add*
gl-function-number
[ gl-function-pointer ] 2curry swap
";" parse-tokens [ "()" subseq? not ] subset
define-indirect
; parsing

View File

@ -3,8 +3,8 @@
! This file is based on the gl.h that comes with xorg-x11 6.8.2 ! This file is based on the gl.h that comes with xorg-x11 6.8.2
USING: alien alien.syntax kernel parser sequences system words ; USING: alien alien.syntax combinators kernel parser sequences
<< windows? "opengl.gl.windows" "opengl.gl.unix" ? use+ >> system words opengl.gl.extensions ;
IN: opengl.gl IN: opengl.gl
@ -1119,9 +1119,7 @@ FUNCTION: void glLoadName ( GLuint name ) ;
FUNCTION: void glPushName ( GLuint name ) ; FUNCTION: void glPushName ( GLuint name ) ;
FUNCTION: void glPopName ( ) ; FUNCTION: void glPopName ( ) ;
<< reset-gl-function-number-counter >>
! OpenGL extension functions
! OpenGL 1.2 ! OpenGL 1.2

View File

@ -0,0 +1,6 @@
USING: kernel alien ;
IN: opengl.gl.macosx
: gl-function-context ( -- context ) 0 ; inline
: gl-function-address ( name -- address ) "gl" load-library dlsym ; inline
: gl-function-calling-convention ( -- str ) "cdecl" ; inline

View File

@ -1,10 +1,6 @@
USING: alien.syntax alien.syntax.private kernel USING: kernel x11.glx ;
namespaces parser sequences syntax words ;
IN: opengl.gl.unix IN: opengl.gl.unix
: GL-FUNCTION: : gl-function-context ( -- context ) glXGetCurrentContext ; inline
scan "c-library" get scan : gl-function-address ( name -- address ) glXGetProcAddress ; inline
scan drop "}" parse-tokens drop : gl-function-calling-convention ( -- str ) "cdecl" ; inline
";" parse-tokens [ "()" subseq? not ] subset
define-function ; parsing

View File

@ -1,35 +1,6 @@
USING: alien alien.syntax arrays assocs hashtables init kernel USING: kernel windows.opengl32 ;
libc math namespaces parser sequences syntax system vectors
windows.opengl32 ;
IN: opengl.gl.windows IN: opengl.gl.windows
<PRIVATE : gl-function-context ( -- context ) wglGetCurrentContext alien-address ; inline
: gl-function-address ( name -- address ) wglGetProcAddress ; inline
SYMBOL: gl-function-number-counter : gl-function-calling-convention ( -- str ) "stdcall" ; inline
SYMBOL: gl-function-pointers
0 gl-function-number-counter set
[ 100 <hashtable> gl-function-pointers set ] "opengl.gl.windows init hook" add-init-hook
: gl-function-number ( -- n )
gl-function-number-counter get
dup 1+ gl-function-number-counter set ;
: gl-function-pointer ( name n -- funptr )
wglGetCurrentContext 2array dup gl-function-pointers get at
[ -rot 2drop ]
[ >r wglGetProcAddress dup r> gl-function-pointers get set-at ]
if* ;
PRIVATE>
: GL-FUNCTION:
"stdcall"
scan
scan
dup gl-function-number [ gl-function-pointer ] 2curry swap
scan drop "}" parse-tokens drop
";" parse-tokens [ "()" subseq? not ] subset
define-indirect
; parsing

View File

@ -1,6 +1,6 @@
USING: combinators.lib kernel sequences math namespaces assocs USING: combinators.lib kernel sequences math namespaces assocs
random sequences.private shuffle math.functions mirrors random sequences.private shuffle math.functions mirrors
arrays math.parser sorting strings ascii ; arrays math.parser math.private sorting strings ascii ;
IN: sequences.lib IN: sequences.lib
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@ -153,3 +153,14 @@ PRIVATE>
[ = [ ] [ drop f ] if ] curry [ = [ ] [ drop f ] if ] curry
2map 2map
[ ] subset ; [ ] subset ;
<PRIVATE
: (attempt-each-integer) ( i n quot -- result )
[
iterate-step roll
[ 3nip ] [ iterate-next (attempt-each-integer) ] if*
] [ 3drop f ] if-iterate? ; inline
PRIVATE>
: attempt-each ( seq quot -- result )
(each) iterate-prep (attempt-each-integer) ; inline