1d144500ae538371f5e4efceacd62c52b71a7db6
[clinton/guile-figl.git] / figl / gl / types.scm
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
24 (define-module (figl gl types)
25 #:use-module (figl runtime)
26 #:use-module (rnrs bytevectors)
27 #:use-module ((system foreign) #:renamer (symbol-prefix-proc 'ffi:))
28 #:export (void
29 GLboolean
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
45 GLclampd
46
47 GLboolean-*
48 GLbyte-*
49 GLubyte-*
50 GLchar-*
51 GLshort-*
52 GLushort-*
53 GLint-*
54 GLuint-*
55 GLsizei-*
56 GLenum-*
57 GLfloat-*
58 GLclampf-*
59 GLdouble-*
60 GLclampd-*
61 GLvoid-*
62 GLvoid-**
63
64 const-GLboolean-*
65 const-GLbyte-*
66 const-GLubyte-*
67 const-GLubyte*
68 const-GLchar-*
69 const-GLchar-**
70 const-GLshort-*
71 const-GLushort-*
72 const-GLint-*
73 const-GLuint-*
74 const-GLsizei-*
75 const-GLenum-*
76 const-GLfloat-*
77 const-GLclampf-*
78 const-GLdouble-*
79 const-GLclampd-*
80 const-GLvoid-*
81 const-GLvoid-**
82 void-*))
83
84 (define %ptr
85 (case (ffi:sizeof '*)
86 ((4) ffi:uint32)
87 ((8) ffi:uint64)
88 (else (error "unknown pointer size"))))
89
90 (define-simple-foreign-type void ffi:void)
91 (define-simple-foreign-type GLboolean ffi:uint8)
92 (define-simple-foreign-type GLbyte ffi:int8)
93 (define-simple-foreign-type GLubyte ffi:uint8)
94 (define-simple-foreign-type GLchar ffi:int8)
95 (define-simple-foreign-type GLshort ffi:int16)
96 (define-simple-foreign-type GLushort ffi:uint16)
97 (define-simple-foreign-type GLint ffi:int32)
98 (define-simple-foreign-type GLuint ffi:uint32)
99 (define-simple-foreign-type GLsizei ffi:int32)
100 (define-simple-foreign-type GLenum ffi:uint32)
101 (define-simple-foreign-type GLintptr %ptr)
102 (define-simple-foreign-type GLsizeiptr %ptr)
103 (define-simple-foreign-type GLbitfield ffi:uint32)
104 (define-simple-foreign-type GLfloat ffi:float)
105 (define-simple-foreign-type GLclampf ffi:float)
106 (define-simple-foreign-type GLdouble ffi:double)
107 (define-simple-foreign-type GLclampd ffi:double)
108 (define-simple-foreign-type GLvoid-* '*)
109 (define-simple-foreign-type void-* '*)
110 (define-simple-foreign-type const-GLvoid-* '*)
111
112 (define (array->pointer x)
113 (lambda (x)
114 (if x
115 (ffi:bytevector->pointer x)
116 ffi:%null-pointer)))
117
118 (define-syntax define-array-foreign-type
119 (syntax-rules ()
120 ((_ name element-type)
121 (define-foreign-type name '*
122 array->pointer
123 (lambda (x) x)))))
124
125 (define-array-foreign-type GLboolean-* GLboolean)
126 (define-array-foreign-type GLbyte-* GLbyte)
127 (define-array-foreign-type GLubyte-* GLubyte)
128 (define-array-foreign-type GLchar-* GLchar)
129 (define-array-foreign-type GLshort-* GLshort)
130 (define-array-foreign-type GLushort-* GLushort)
131 (define-array-foreign-type GLint-* GLint)
132 (define-array-foreign-type GLuint-* GLuint)
133 (define-array-foreign-type GLsizei-* GLsizei)
134 (define-array-foreign-type GLenum-* GLenum)
135 (define-array-foreign-type GLfloat-* GLfloat)
136 (define-array-foreign-type GLclampf-* GLclampf)
137 (define-array-foreign-type GLdouble-* GLdouble)
138 (define-array-foreign-type GLclampd-* GLclampd)
139
140 (define-array-foreign-type const-GLboolean-* GLboolean)
141 (define-array-foreign-type const-GLbyte-* GLbyte)
142 (define-array-foreign-type const-GLubyte-* GLubyte)
143 (define-array-foreign-type const-GLshort-* GLshort)
144 (define-array-foreign-type const-GLushort-* GLushort)
145 (define-array-foreign-type const-GLint-* GLint)
146 (define-array-foreign-type const-GLuint-* GLuint)
147 (define-array-foreign-type const-GLsizei-* GLsizei)
148 (define-array-foreign-type const-GLenum-* GLenum)
149 (define-array-foreign-type const-GLfloat-* GLfloat)
150 (define-array-foreign-type const-GLclampf-* GLclampf)
151 (define-array-foreign-type const-GLdouble-* GLdouble)
152 (define-array-foreign-type const-GLclampd-* GLclampd)
153 (define-array-foreign-type const-GLvoid-* GLvoid)
154
155 (define-foreign-type const-GLchar-* '*
156 ffi:string->pointer
157 ffi:pointer->string)
158
159 ;; Functions with these types will need special help.
160 (define-simple-foreign-type GLvoid-** '*)
161 (define-simple-foreign-type const-GLchar-** '*)
162 (define-simple-foreign-type const-GLvoid-** '*)
163
164 ;; TODO: Hacked for a typo in glGetString.xml.
165 (define-array-foreign-type const-GLubyte* GLubyte)