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
@ -1273,7 +1271,7 @@ GL-FUNCTION: void glTexSubImage3D { glTexSubImage3DEXT } ( GLenum target, GLint
: GL_DOT3_RGBA HEX: 86AF ; inline : GL_DOT3_RGBA HEX: 86AF ; inline
: GL_MULTISAMPLE_BIT HEX: 20000000 ; inline : GL_MULTISAMPLE_BIT HEX: 20000000 ; inline
GL-FUNCTION: void glActiveTexture { glActiveTextureARB }( GLenum texture ) ; GL-FUNCTION: void glActiveTexture { glActiveTextureARB } ( GLenum texture ) ;
GL-FUNCTION: void glClientActiveTexture { glClientActiveTextureARB } ( GLenum texture ) ; GL-FUNCTION: void glClientActiveTexture { glClientActiveTextureARB } ( GLenum texture ) ;
GL-FUNCTION: void glCompressedTexImage1D { glCompressedTexImage1DARB } ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, GLvoid* data ) ; GL-FUNCTION: void glCompressedTexImage1D { glCompressedTexImage1DARB } ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, GLvoid* data ) ;
GL-FUNCTION: void glCompressedTexImage2D { glCompressedTexImage2DARB } ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, GLvoid* data ) ; GL-FUNCTION: void glCompressedTexImage2D { glCompressedTexImage2DARB } ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, GLvoid* data ) ;
@ -1607,7 +1605,7 @@ GL-FUNCTION: void glGetVertexAttribdv { glGetVertexAttribdvARB } ( GLuint index,
GL-FUNCTION: void glGetVertexAttribfv { glGetVertexAttribfvARB } ( GLuint index, GLenum pname, GLfloat* params ) ; GL-FUNCTION: void glGetVertexAttribfv { glGetVertexAttribfvARB } ( GLuint index, GLenum pname, GLfloat* params ) ;
GL-FUNCTION: void glGetVertexAttribiv { glGetVertexAttribivARB } ( GLuint index, GLenum pname, GLint* params ) ; GL-FUNCTION: void glGetVertexAttribiv { glGetVertexAttribivARB } ( GLuint index, GLenum pname, GLint* params ) ;
GL-FUNCTION: GLboolean glIsProgram { glIsProgramARB } ( GLuint program ) ; GL-FUNCTION: GLboolean glIsProgram { glIsProgramARB } ( GLuint program ) ;
GL-FUNCTION: GLboolean glIsShader { glIsShaderARB }( GLuint shader ) ; GL-FUNCTION: GLboolean glIsShader { glIsShaderARB } ( GLuint shader ) ;
GL-FUNCTION: void glLinkProgram { glLinkProgramARB } ( GLuint program ) ; GL-FUNCTION: void glLinkProgram { glLinkProgramARB } ( GLuint program ) ;
GL-FUNCTION: void glShaderSource { glShaderSourceARB } ( GLuint shader, GLsizei count, GLchar** strings, GLint* lengths ) ; GL-FUNCTION: void glShaderSource { glShaderSourceARB } ( GLuint shader, GLsizei count, GLchar** strings, GLint* lengths ) ;
GL-FUNCTION: void glStencilFuncSeparate { glStencilFuncSeparateATI } ( GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask ) ; GL-FUNCTION: void glStencilFuncSeparate { glStencilFuncSeparateATI } ( GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask ) ;

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

View File

@ -42,7 +42,7 @@ FUNCTION: GLXContext glXCreateContext ( Display* dpy, XVisualInfo* vis, GLXConte
FUNCTION: GLXPixmap glXCreateGLXPixmap ( Display* dpy, XVisualInfo* vis, Pixmap pixmap ) ; FUNCTION: GLXPixmap glXCreateGLXPixmap ( Display* dpy, XVisualInfo* vis, Pixmap pixmap ) ;
FUNCTION: void glXDestroyContext ( Display* dpy, GLXContext ctx ) ; FUNCTION: void glXDestroyContext ( Display* dpy, GLXContext ctx ) ;
FUNCTION: void glXDestroyGLXPixmap ( Display* dpy, GLXPixmap pix ) ; FUNCTION: void glXDestroyGLXPixmap ( Display* dpy, GLXPixmap pix ) ;
FUNCTION: int glXGetConfig ( Display* dpy, XVisualInfo* vis, int attrib, int* value) ; FUNCTION: int glXGetConfig ( Display* dpy, XVisualInfo* vis, int attrib, int* value ) ;
FUNCTION: GLXContext glXGetCurrentContext ( ) ; FUNCTION: GLXContext glXGetCurrentContext ( ) ;
FUNCTION: GLXDrawable glXGetCurrentDrawable ( ) ; FUNCTION: GLXDrawable glXGetCurrentDrawable ( ) ;
FUNCTION: bool glXIsDirect ( Display* dpy, GLXContext ctx ) ; FUNCTION: bool glXIsDirect ( Display* dpy, GLXContext ctx ) ;