include more low-level bindings
[clinton/guile-figl.git] / figl / gl / types.scm
CommitLineData
37a0c0f3
DH
1;;; figl
2;;; Copyright (C) 2013 Daniel Hartwig <mandyke@gmail.com>
3;;;
4;;; Figl is free software: you can redistribute it and/or modify it
5;;; under the terms of the GNU Lesser General Public License as
6;;; published by the Free Software Foundation, either version 3 of the
7;;; License, or (at your option) any later version.
8;;;
9;;; Figl is distributed in the hope that it will be useful, but WITHOUT
10;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11;;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
12;;; Public License for more details.
13;;;
14;;; You should have received a copy of the GNU Lesser General Public
15;;; License along with this program. If not, see
16;;; <http://www.gnu.org/licenses/>.
17
18;;; Commentary:
19;;
20;; Mappings from OpenGL to FFI types.
21;;
22;;; Code:
23
7ec693ed 24(define-module (figl gl types)
93f72ad8 25 #:use-module (figl runtime)
e40b2a3d 26 #:use-module (rnrs bytevectors)
93f72ad8
AW
27 #:use-module ((system foreign) #:renamer (symbol-prefix-proc 'ffi:))
28 #:export (void
29 GLboolean
37a0c0f3
DH
30 GLbyte
31 GLubyte
32 GLchar
33 GLshort
34 GLushort
35 GLint
36 GLuint
37 GLsizei
38 GLenum
39 GLintptr
40 GLsizeiptr
41 GLbitfield
42 GLfloat
43 GLclampf
44 GLdouble
00239761
AW
45 GLclampd
46
47 GLboolean-*
48 GLchar-*
49 GLdouble-*
50 GLenum-*
51 GLfloat-*
52 GLint-*
53 GLsizei-*
54 GLubyte-*
55 GLuint-*
56 GLvoid-*
b002944d 57 GLvoid-**
00239761
AW
58 const-GLchar-*
59 const-GLchar-**
60 const-GLclampf-*
61 const-GLdouble-*
62 const-GLenum-*
63 const-GLfloat-*
64 const-GLint-*
65 const-GLsizei-*
66 const-GLubyte*
67 const-GLubyte-*
68 const-GLubyte-*
69 const-GLuint-*
70 const-GLvoid-*
71 const-GLvoid-**
72 void-*))
37a0c0f3
DH
73
74(define %ptr
93f72ad8
AW
75 (case (ffi:sizeof '*)
76 ((4) ffi:uint32)
77 ((8) ffi:uint64)
37a0c0f3
DH
78 (else (error "unknown pointer size"))))
79
93f72ad8
AW
80(define-simple-foreign-type void ffi:void)
81(define-simple-foreign-type GLboolean ffi:uint8)
82(define-simple-foreign-type GLbyte ffi:int8)
83(define-simple-foreign-type GLubyte ffi:uint8)
84(define-simple-foreign-type GLchar ffi:int8)
85(define-simple-foreign-type Glshort ffi:int16)
86(define-simple-foreign-type GLushort ffi:uint16)
87(define-simple-foreign-type GLint ffi:int32)
88(define-simple-foreign-type GLuint ffi:uint32)
89(define-simple-foreign-type GLsizei ffi:int32)
90(define-simple-foreign-type GLenum ffi:uint32)
91(define-simple-foreign-type GLintptr %ptr)
92(define-simple-foreign-type GLsizeiptr %ptr)
93(define-simple-foreign-type GLbitfield ffi:uint32)
94(define-simple-foreign-type GLfloat ffi:float)
95(define-simple-foreign-type GLclampf ffi:float)
96(define-simple-foreign-type GLdouble ffi:double)
97(define-simple-foreign-type GLclampd ffi:double)
93f72ad8 98(define-simple-foreign-type GLvoid-* '*)
e40b2a3d 99(define-simple-foreign-type void-* '*)
93f72ad8 100(define-simple-foreign-type const-GLvoid-* '*)
e40b2a3d 101
c9820ad6
AW
102(define (array->pointer x)
103 (lambda (x)
104 (if x
105 (ffi:bytevector->pointer x)
106 ffi:%null-pointer)))
107
e40b2a3d
AW
108(define-syntax define-array-foreign-type
109 (syntax-rules ()
110 ((_ name element-type)
111 (define-foreign-type name '*
c9820ad6 112 array->pointer
e40b2a3d
AW
113 (lambda (x) x)))))
114
115(define-array-foreign-type GLboolean-* GLboolean)
116(define-array-foreign-type GLchar-* GLchar)
117(define-array-foreign-type GLdouble-* GLdouble)
118(define-array-foreign-type GLenum-* GLenum)
119(define-array-foreign-type GLfloat-* GLfloat)
120(define-array-foreign-type GLint-* GLint)
121(define-array-foreign-type GLsizei-* GLsizei)
122(define-array-foreign-type GLubyte-* GLubyte)
123(define-array-foreign-type GLuint-* GLuint)
124
125(define-array-foreign-type const-GLclampf-* GLclampf)
126(define-array-foreign-type const-GLdouble-* GLdouble)
127(define-array-foreign-type const-GLenum-* GLenum)
128(define-array-foreign-type const-GLfloat-* GLfloat)
129(define-array-foreign-type const-GLint-* GLint)
130(define-array-foreign-type const-GLsizei-* GLsizei)
131(define-array-foreign-type const-GLubyte* GLubyte)
132(define-array-foreign-type const-GLubyte-* GLubyte)
133(define-array-foreign-type const-GLuint-* GLuint)
134(define-array-foreign-type const-GLvoid-* GLvoid)
135
136(define-foreign-type const-GLchar-* '*
137 ffi:string->pointer
138 ffi:pointer->string)
139
140;; Functions with these types will need special help.
b002944d 141(define-simple-foreign-type GLvoid-** '*)
e40b2a3d 142(define-simple-foreign-type const-GLchar-** '*)
93f72ad8 143(define-simple-foreign-type const-GLvoid-** '*)