Cut-out empty enum groups earlier (results in reordering of exports) and...
[cl-glfw/jecs.git] / lib / types.lisp
blobe5c87f48b4fac75159e5192080e61767f7b9873b
1 (defpackage #:cl-glfw-types
2 (:use #:cl #:cffi)
3 (:shadow #:boolean #:byte #:float #:char #:string)
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
8 #:char #:string
9 #:half))
11 (in-package #:cl-glfw-types)
13 (defctype enum :uint32)
14 (defctype boolean :uint8)
15 (defctype bitfield :uint32)
16 (defctype byte :int8)
17 (defctype short :int16)
18 (defctype int :int32)
19 (defctype sizei :int32)
20 (defctype ubyte :uint8)
21 (defctype ushort :uint16)
22 (defctype uint :uint32)
23 (defctype float :float)
24 (defctype clampf :float)
25 (defctype double :double)
26 (defctype clampd :double)
27 (defctype void :void)
29 #-cffi-features:no-long-long
30 (defctype uint64 :uint64)
31 #-cffi-features:no-long-long
32 (defctype int64 :int64)
34 ;; Find a CFFI integer type the same foreign-size as a pointer
35 (defctype intptr #.(find-symbol (format nil "INT~d" (* 8 (cffi:foreign-type-size :pointer))) (find-package '#:keyword)))
36 (defctype sizeiptr #.(find-symbol (format nil "INT~d" (* 8 (cffi:foreign-type-size :pointer))) (find-package '#:keyword)))
38 (defctype handle :unsigned-int)
40 (defctype char :char)
42 (defctype string :string)
44 (defctype half :unsigned-short) ; this is how glext.h defines it anyway
46 (defmethod cffi:expand-to-foreign (value (type (eql 'boolean)))
47 `(if ,value 1 0))
49 (defmethod cffi:expand-from-foreign (value (type (eql 'boolean)))
50 `(not (= ,value 0)))
52 (defmethod cffi:expand-to-foreign (value (type (eql 'clampf)))
53 `(coerce ,value 'single-float))
55 (defmethod cffi:expand-to-foreign (value (type (eql 'clampd)))
56 `(coerce ,value 'double-float))
58 (defmethod cffi:expand-to-foreign (value (type (eql 'float)))
59 `(coerce ,value 'single-float))
61 (defmethod cffi:expand-to-foreign (value (type (eql 'double)))
62 `(coerce ,value 'double-float))
64 ;; TODO: Maybe we can find/write a converter to a half? Does anyone want it?
65 ;; TODO: Might we want converters to integer types? What would it be? round, or floor (or even ceil)?