2 ;;; Copyright (C) 2013 Daniel Hartwig <mandyke@gmail.com>
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.
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.
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/>.
20 ;; Mappings from OpenGL to FFI types.
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:))
84 ;; TODO: Taken from Mesa headers for some types below. Not clear what
85 ;; these types are on other platforms.
86 (define %ptr ffi:ptrdiff_t)
88 (define-simple-foreign-type void ffi:void)
89 (define-simple-foreign-type GLbyte ffi:int8)
90 (define-simple-foreign-type GLubyte ffi:uint8)
91 (define-simple-foreign-type GLchar ffi:int8)
92 (define-simple-foreign-type GLshort ffi:int16)
93 (define-simple-foreign-type GLushort ffi:uint16)
94 (define-simple-foreign-type GLint ffi:int32)
95 (define-simple-foreign-type GLuint ffi:uint32)
96 (define-simple-foreign-type GLsizei ffi:int32)
97 (define-simple-foreign-type GLenum ffi:uint32)
98 (define-simple-foreign-type GLintptr %ptr)
99 (define-simple-foreign-type GLsizeiptr %ptr)
100 (define-simple-foreign-type GLbitfield ffi:uint32)
101 (define-simple-foreign-type GLfloat ffi:float)
102 (define-simple-foreign-type GLclampf ffi:float)
103 (define-simple-foreign-type GLdouble ffi:double)
104 (define-simple-foreign-type GLclampd ffi:double)
105 (define-simple-foreign-type GLvoid-* '*)
106 (define-simple-foreign-type void-* '*)
107 (define-simple-foreign-type const-GLvoid-* '*)
112 (define-foreign-type GLboolean ffi:uint8
113 (lambda (x) (if x GL_TRUE GL_FALSE))
114 (lambda (x) (eqv? x GL_TRUE)))
116 (define (coerce-array-pointer x)
121 (ffi:bytevector->pointer x))
122 ;; TODO: (typed-array? x element-type)
126 (error "unhandled array-pointer type" x))))
128 (define-syntax define-array-foreign-type
130 ((_ name element-type)
131 (define-foreign-type name '*
135 (define-array-foreign-type GLboolean-* GLboolean)
136 (define-array-foreign-type GLbyte-* GLbyte)
137 (define-array-foreign-type GLubyte-* GLubyte)
138 (define-array-foreign-type GLchar-* GLchar)
139 (define-array-foreign-type GLshort-* GLshort)
140 (define-array-foreign-type GLushort-* GLushort)
141 (define-array-foreign-type GLint-* GLint)
142 (define-array-foreign-type GLuint-* GLuint)
143 (define-array-foreign-type GLsizei-* GLsizei)
144 (define-array-foreign-type GLenum-* GLenum)
145 (define-array-foreign-type GLfloat-* GLfloat)
146 (define-array-foreign-type GLclampf-* GLclampf)
147 (define-array-foreign-type GLdouble-* GLdouble)
148 (define-array-foreign-type GLclampd-* GLclampd)
150 (define-array-foreign-type const-GLboolean-* GLboolean)
151 (define-array-foreign-type const-GLbyte-* GLbyte)
152 (define-array-foreign-type const-GLubyte-* GLubyte)
153 (define-array-foreign-type const-GLshort-* GLshort)
154 (define-array-foreign-type const-GLushort-* GLushort)
155 (define-array-foreign-type const-GLint-* GLint)
156 (define-array-foreign-type const-GLuint-* GLuint)
157 (define-array-foreign-type const-GLsizei-* GLsizei)
158 (define-array-foreign-type const-GLenum-* GLenum)
159 (define-array-foreign-type const-GLfloat-* GLfloat)
160 (define-array-foreign-type const-GLclampf-* GLclampf)
161 (define-array-foreign-type const-GLdouble-* GLdouble)
162 (define-array-foreign-type const-GLclampd-* GLclampd)
163 (define-array-foreign-type const-GLvoid-* GLvoid)
165 (define-foreign-type const-GLchar-* '*
169 ;; Functions with these types will need special help.
170 (define-simple-foreign-type GLvoid-** '*)
171 (define-simple-foreign-type const-GLchar-** '*)
172 (define-simple-foreign-type const-GLvoid-** '*)
174 ;; TODO: Hacked for a typo in glGetString.xml.
175 (define-array-foreign-type const-GLubyte* GLubyte)