use ptrdiff_t, not guesswork
[clinton/guile-figl.git] / figl / gl / types.scm
index 297ea5f..9b5da2e 100644 (file)
             GLclampd
 
             GLboolean-*
+            GLbyte-*
+            GLubyte-*
             GLchar-*
-            GLdouble-*
-            GLenum-*
-            GLfloat-*
+            GLshort-*
+            GLushort-*
             GLint-*
-            GLsizei-*
-            GLubyte-*
             GLuint-*
+            GLsizei-*
+            GLenum-*
+            GLfloat-*
+            GLclampf-*
+            GLdouble-*
+            GLclampd-*
             GLvoid-*
+            GLvoid-**
+
+            const-GLboolean-*
+            const-GLbyte-*
+            const-GLubyte-*
+            const-GLubyte*
             const-GLchar-*
             const-GLchar-**
-            const-GLclampf-*
-            const-GLdouble-*
-            const-GLenum-*
-            const-GLfloat-*
+            const-GLshort-*
+            const-GLushort-*
             const-GLint-*
-            const-GLsizei-*
-            const-GLubyte*
-            const-GLubyte-*
-            const-GLubyte-*
             const-GLuint-*
+            const-GLsizei-*
+            const-GLenum-*
+            const-GLfloat-*
+            const-GLclampf-*
+            const-GLdouble-*
+            const-GLclampd-*
             const-GLvoid-*
             const-GLvoid-**
             void-*))
 
-(define %ptr
-  (case (ffi:sizeof '*)
-    ((4) ffi:uint32)
-    ((8) ffi:uint64)
-    (else (error "unknown pointer size"))))
+;; TODO: Taken from Mesa headers for some types below.  Not clear what
+;; these types are on other platforms.
+(define %ptr ffi:ptrdiff_t)
 
 (define-simple-foreign-type void ffi:void)
 (define-simple-foreign-type GLboolean ffi:uint8)
 (define-simple-foreign-type GLbyte ffi:int8)
 (define-simple-foreign-type GLubyte ffi:uint8)
 (define-simple-foreign-type GLchar ffi:int8)
-(define-simple-foreign-type Glshort ffi:int16)
+(define-simple-foreign-type GLshort ffi:int16)
 (define-simple-foreign-type GLushort ffi:uint16)
 (define-simple-foreign-type GLint ffi:int32)
 (define-simple-foreign-type GLuint ffi:uint32)
 (define-simple-foreign-type void-* '*)
 (define-simple-foreign-type const-GLvoid-* '*)
 
-(define (array->pointer x)
-  (lambda (x)
-    (if x
-        (ffi:bytevector->pointer x)
-        ffi:%null-pointer)))
+(define (coerce-array-pointer x)
+  (cond
+   ((ffi:pointer? x)
+    x)
+   ((bytevector? x)
+    (ffi:bytevector->pointer x))
+   ;; TODO: (typed-array? x element-type)
+   ((not x)
+    ffi:%null-pointer)
+   (else
+    (error "unhandled array-pointer type" x))))
 
 (define-syntax define-array-foreign-type
   (syntax-rules ()
     ((_ name element-type)
      (define-foreign-type name '*
-       array->pointer
+       coerce-array-pointer
        (lambda (x) x)))))
 
 (define-array-foreign-type GLboolean-* GLboolean)
+(define-array-foreign-type GLbyte-* GLbyte)
+(define-array-foreign-type GLubyte-* GLubyte)
 (define-array-foreign-type GLchar-* GLchar)
-(define-array-foreign-type GLdouble-* GLdouble)
-(define-array-foreign-type GLenum-* GLenum)
-(define-array-foreign-type GLfloat-* GLfloat)
+(define-array-foreign-type GLshort-* GLshort)
+(define-array-foreign-type GLushort-* GLushort)
 (define-array-foreign-type GLint-* GLint)
-(define-array-foreign-type GLsizei-* GLsizei)
-(define-array-foreign-type GLubyte-* GLubyte)
 (define-array-foreign-type GLuint-* GLuint)
+(define-array-foreign-type GLsizei-* GLsizei)
+(define-array-foreign-type GLenum-* GLenum)
+(define-array-foreign-type GLfloat-* GLfloat)
+(define-array-foreign-type GLclampf-* GLclampf)
+(define-array-foreign-type GLdouble-* GLdouble)
+(define-array-foreign-type GLclampd-* GLclampd)
 
-(define-array-foreign-type const-GLclampf-* GLclampf)
-(define-array-foreign-type const-GLdouble-* GLdouble)
-(define-array-foreign-type const-GLenum-* GLenum)
-(define-array-foreign-type const-GLfloat-* GLfloat)
-(define-array-foreign-type const-GLint-* GLint)
-(define-array-foreign-type const-GLsizei-* GLsizei)
-(define-array-foreign-type const-GLubyte* GLubyte)
+(define-array-foreign-type const-GLboolean-* GLboolean)
+(define-array-foreign-type const-GLbyte-* GLbyte)
 (define-array-foreign-type const-GLubyte-* GLubyte)
+(define-array-foreign-type const-GLshort-* GLshort)
+(define-array-foreign-type const-GLushort-* GLushort)
+(define-array-foreign-type const-GLint-* GLint)
 (define-array-foreign-type const-GLuint-* GLuint)
+(define-array-foreign-type const-GLsizei-* GLsizei)
+(define-array-foreign-type const-GLenum-* GLenum)
+(define-array-foreign-type const-GLfloat-* GLfloat)
+(define-array-foreign-type const-GLclampf-* GLclampf)
+(define-array-foreign-type const-GLdouble-* GLdouble)
+(define-array-foreign-type const-GLclampd-* GLclampd)
 (define-array-foreign-type const-GLvoid-* GLvoid)
 
 (define-foreign-type const-GLchar-* '*
   ffi:pointer->string)
 
 ;; Functions with these types will need special help.
+(define-simple-foreign-type GLvoid-** '*)
 (define-simple-foreign-type const-GLchar-** '*)
 (define-simple-foreign-type const-GLvoid-** '*)
+
+;; TODO: Hacked for a typo in glGetString.xml.
+(define-array-foreign-type const-GLubyte* GLubyte)