Fix for callbacks under windows from Andrew Lyon.
[cl-glfw.git] / lib / types.lisp
blobdaa1f8dcb0e82bf7c7616a6b920905d2b5116e0f
1 (defpackage #:cl-glfw-types
2 (:use #:cl #:cffi)
3 (:shadow #:boolean #:byte #:float #:char #:string #:pointer)
4 (:export #:enum #:boolean #:bitfield #:byte #:short #:int #:sizei #:ubyte #:ushort #:uint
5 #:float #:clampf #:double #:clampd #:void #:uint64 #:int64
6 #:intptr #:sizeiptr
7 #:handle #:pointer
8 #:char
9 #:half))
11 (in-package #:cl-glfw-types)
13 (defmacro defgltype (type parser actual-type)
14 `(define-foreign-type ,type ()
16 (:actual-type ,actual-type)
17 (:simple-parser ,parser)))
19 (defgltype gl-enum enum :uint32)
20 (defgltype gl-boolean boolean :uint8)
21 (defgltype gl-bitfield bitfield :uint32)
22 (defgltype gl-byte byte :int8)
23 (defgltype gl-short short :int16)
24 (defgltype gl-int int :int32)
25 (defgltype gl-sizei sizei :int32)
26 (defgltype gl-ubyte ubyte :uint8)
27 (defgltype gl-ushort ushort :uint16)
28 (defgltype gl-uint uint :uint32)
29 (defgltype gl-float float :float)
30 (defgltype gl-clampf clampf :float)
31 (defgltype gl-double double :double)
32 (defgltype gl-clampd clampd :double)
33 (defgltype gl-void void :void)
35 #-cffi-features:no-long-long
36 (defgltype gl-uint64 uint64 :uint64)
37 #-cffi-features:no-long-long
38 (defgltype gl-int64 int64 :int64)
40 ;; Find a CFFI integer type the same foreign-size as a pointer
41 (defgltype gl-intprt intptr #.(find-symbol (format nil "INT~d" (* 8 (cffi:foreign-type-size :pointer))) (find-package '#:keyword)))
42 (defgltype gl-sizeiptr sizeiptr #.(find-symbol (format nil "INT~d" (* 8 (cffi:foreign-type-size :pointer))) (find-package '#:keyword)))
44 (defgltype gl-handle handle :unsigned-int)
45 (defgltype gl-char char :char)
46 ;;(defctype string :string)
47 (defgltype gl-half half :unsigned-short) ; this is how glext.h defines it anyway
48 (defctype pointer :pointer)
50 (defmethod cffi:expand-to-foreign (value (type gl-boolean))
51 `(if ,value 1 0))
53 (defmethod cffi:expand-from-foreign (value (type gl-boolean))
54 `(not (= ,value 0)))
56 (defmethod cffi:expand-to-foreign (value (type gl-clampf))
57 `(coerce ,value 'single-float))
59 (defmethod cffi:expand-to-foreign (value (type gl-clampd))
60 `(coerce ,value 'double-float))
62 (defmethod cffi:expand-to-foreign (value (type gl-float))
63 `(coerce ,value 'single-float))
65 (defmethod cffi:expand-to-foreign (value (type gl-double))
66 `(coerce ,value 'double-float))
68 ;; TODO: Maybe we can find/write a converter to a half? Does anyone want it?
69 ;; TODO: Might we want converters to integer types? What would it be? round, or floor (or even ceil)?