Commit | Line | Data |
---|---|---|
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-* | |
78aa45b9 DH |
48 | GLbyte-* |
49 | GLubyte-* | |
00239761 | 50 | GLchar-* |
78aa45b9 DH |
51 | GLshort-* |
52 | GLushort-* | |
00239761 | 53 | GLint-* |
00239761 | 54 | GLuint-* |
78aa45b9 DH |
55 | GLsizei-* |
56 | GLenum-* | |
57 | GLfloat-* | |
58 | GLclampf-* | |
59 | GLdouble-* | |
60 | GLclampd-* | |
00239761 | 61 | GLvoid-* |
b002944d | 62 | GLvoid-** |
78aa45b9 DH |
63 | |
64 | const-GLboolean-* | |
65 | const-GLbyte-* | |
66 | const-GLubyte-* | |
00239761 AW |
67 | const-GLchar-* |
68 | const-GLchar-** | |
78aa45b9 DH |
69 | const-GLshort-* |
70 | const-GLushort-* | |
00239761 | 71 | const-GLint-* |
00239761 | 72 | const-GLuint-* |
78aa45b9 DH |
73 | const-GLsizei-* |
74 | const-GLenum-* | |
75 | const-GLfloat-* | |
76 | const-GLclampf-* | |
77 | const-GLdouble-* | |
78 | const-GLclampd-* | |
00239761 AW |
79 | const-GLvoid-* |
80 | const-GLvoid-** | |
81 | void-*)) | |
37a0c0f3 DH |
82 | |
83 | (define %ptr | |
93f72ad8 AW |
84 | (case (ffi:sizeof '*) |
85 | ((4) ffi:uint32) | |
86 | ((8) ffi:uint64) | |
37a0c0f3 DH |
87 | (else (error "unknown pointer size")))) |
88 | ||
93f72ad8 AW |
89 | (define-simple-foreign-type void ffi:void) |
90 | (define-simple-foreign-type GLboolean ffi:uint8) | |
91 | (define-simple-foreign-type GLbyte ffi:int8) | |
92 | (define-simple-foreign-type GLubyte ffi:uint8) | |
93 | (define-simple-foreign-type GLchar ffi:int8) | |
78aa45b9 | 94 | (define-simple-foreign-type GLshort ffi:int16) |
93f72ad8 AW |
95 | (define-simple-foreign-type GLushort ffi:uint16) |
96 | (define-simple-foreign-type GLint ffi:int32) | |
97 | (define-simple-foreign-type GLuint ffi:uint32) | |
98 | (define-simple-foreign-type GLsizei ffi:int32) | |
99 | (define-simple-foreign-type GLenum ffi:uint32) | |
100 | (define-simple-foreign-type GLintptr %ptr) | |
101 | (define-simple-foreign-type GLsizeiptr %ptr) | |
102 | (define-simple-foreign-type GLbitfield ffi:uint32) | |
103 | (define-simple-foreign-type GLfloat ffi:float) | |
104 | (define-simple-foreign-type GLclampf ffi:float) | |
105 | (define-simple-foreign-type GLdouble ffi:double) | |
106 | (define-simple-foreign-type GLclampd ffi:double) | |
93f72ad8 | 107 | (define-simple-foreign-type GLvoid-* '*) |
e40b2a3d | 108 | (define-simple-foreign-type void-* '*) |
93f72ad8 | 109 | (define-simple-foreign-type const-GLvoid-* '*) |
e40b2a3d | 110 | |
c9820ad6 AW |
111 | (define (array->pointer x) |
112 | (lambda (x) | |
113 | (if x | |
114 | (ffi:bytevector->pointer x) | |
115 | ffi:%null-pointer))) | |
116 | ||
e40b2a3d AW |
117 | (define-syntax define-array-foreign-type |
118 | (syntax-rules () | |
119 | ((_ name element-type) | |
120 | (define-foreign-type name '* | |
c9820ad6 | 121 | array->pointer |
e40b2a3d AW |
122 | (lambda (x) x))))) |
123 | ||
124 | (define-array-foreign-type GLboolean-* GLboolean) | |
78aa45b9 DH |
125 | (define-array-foreign-type GLbyte-* GLbyte) |
126 | (define-array-foreign-type GLubyte-* GLubyte) | |
e40b2a3d | 127 | (define-array-foreign-type GLchar-* GLchar) |
78aa45b9 DH |
128 | (define-array-foreign-type GLshort-* GLshort) |
129 | (define-array-foreign-type GLushort-* GLushort) | |
e40b2a3d | 130 | (define-array-foreign-type GLint-* GLint) |
e40b2a3d | 131 | (define-array-foreign-type GLuint-* GLuint) |
78aa45b9 DH |
132 | (define-array-foreign-type GLsizei-* GLsizei) |
133 | (define-array-foreign-type GLenum-* GLenum) | |
134 | (define-array-foreign-type GLfloat-* GLfloat) | |
135 | (define-array-foreign-type GLclampf-* GLclampf) | |
136 | (define-array-foreign-type GLdouble-* GLdouble) | |
137 | (define-array-foreign-type GLclampd-* GLclampd) | |
e40b2a3d | 138 | |
78aa45b9 DH |
139 | (define-array-foreign-type const-GLboolean-* GLboolean) |
140 | (define-array-foreign-type const-GLbyte-* GLbyte) | |
e40b2a3d | 141 | (define-array-foreign-type const-GLubyte-* GLubyte) |
78aa45b9 DH |
142 | (define-array-foreign-type const-GLshort-* GLshort) |
143 | (define-array-foreign-type const-GLushort-* GLushort) | |
144 | (define-array-foreign-type const-GLint-* GLint) | |
e40b2a3d | 145 | (define-array-foreign-type const-GLuint-* GLuint) |
78aa45b9 DH |
146 | (define-array-foreign-type const-GLsizei-* GLsizei) |
147 | (define-array-foreign-type const-GLenum-* GLenum) | |
148 | (define-array-foreign-type const-GLfloat-* GLfloat) | |
149 | (define-array-foreign-type const-GLclampf-* GLclampf) | |
150 | (define-array-foreign-type const-GLdouble-* GLdouble) | |
151 | (define-array-foreign-type const-GLclampd-* GLclampd) | |
e40b2a3d AW |
152 | (define-array-foreign-type const-GLvoid-* GLvoid) |
153 | ||
154 | (define-foreign-type const-GLchar-* '* | |
155 | ffi:string->pointer | |
156 | ffi:pointer->string) | |
157 | ||
158 | ;; Functions with these types will need special help. | |
b002944d | 159 | (define-simple-foreign-type GLvoid-** '*) |
e40b2a3d | 160 | (define-simple-foreign-type const-GLchar-** '*) |
93f72ad8 | 161 | (define-simple-foreign-type const-GLvoid-** '*) |