use type maps in update-enumerations
authorDaniel Hartwig <mandyke@gmail.com>
Fri, 8 Feb 2013 11:21:49 +0000 (19:21 +0800)
committerDaniel Hartwig <mandyke@gmail.com>
Fri, 8 Feb 2013 11:21:49 +0000 (19:21 +0800)
* maint/update-enumerations (type-map, use-type-map): New procedures
  to set and use an appropriate type map.
  (bitfield?): Use type-map when possible.
  (write-scm, write-texi): Handle strip-bit failures gracefully.

* doc/low-level-gl-enums.texi:
* figl/gl/enums.scm: Regenerate, picking up more bitfields.

doc/low-level-gl-enums.texi
figl/gl/enums.scm
maint/update-enumerations

index 14a6d16..20299de 100644 (file)
@@ -105,14 +105,14 @@ known to this enumerated value form are:
 
 @end defmac
 
-@defmac clear-buffer-mask enum
-Enumerated value. The symbolic @var{enum}argument is replaced with its
-corresponding numeric value at compile-time. The symbolic arguments
-known to this enumerated value form are:
+@defmac clear-buffer-mask bit...
+Bitfield constructor. The symbolic @var{bit} arguments are replaced with
+their corresponding numeric values and combined with @code{logior} at
+compile-time. The symbolic arguments known to this bitfield constructor
+are:
 
-@code{depth-buffer-bit}, @code{accum-buffer-bit},
-@code{stencil-buffer-bit}, @code{color-buffer-bit},
-@code{coverage-buffer-bit-nv}.
+@code{depth-buffer}, @code{accum-buffer}, @code{stencil-buffer},
+@code{color-buffer}, @code{coverage-buffer-bit-nv}.
 
 @end defmac
 
@@ -1262,10 +1262,11 @@ known to this enumerated value form are:
 
 @end defmac
 
-@defmac ffd-mask-sgix enum
-Enumerated value. The symbolic @var{enum}argument is replaced with its
-corresponding numeric value at compile-time. The symbolic arguments
-known to this enumerated value form are:
+@defmac ffd-mask-sgix bit...
+Bitfield constructor. The symbolic @var{bit} arguments are replaced with
+their corresponding numeric values and combined with @code{logior} at
+compile-time. The symbolic arguments known to this bitfield constructor
+are:
 
 @code{texture-deformation-bit-sgix},
 @code{geometry-deformation-bit-sgix}.
index 7b1fd97..94ff5e5 100644 (file)
   (samples-3dfx 34484)
   (multisample-bit-3dfx 536870912))
 
-(define-enumeration
+(define-bitfield
   clear-buffer-mask
-  (depth-buffer-bit 256)
-  (accum-buffer-bit 512)
-  (stencil-buffer-bit 1024)
-  (color-buffer-bit 16384)
+  (depth-buffer 256)
+  (accum-buffer 512)
+  (stencil-buffer 1024)
+  (color-buffer 16384)
   (coverage-buffer-bit-nv 32768))
 
 (define-bitfield
   (copy-pixel-token 1798)
   (line-reset-token 1799))
 
-(define-enumeration
+(define-bitfield
   ffd-mask-sgix
   (texture-deformation-bit-sgix 1)
   (geometry-deformation-bit-sgix 2))
index df27fc5..68e9a58 100755 (executable)
@@ -6,6 +6,7 @@
              (ice-9 match)
              (sxml fold)
              ((srfi srfi-1) #:select (append-map))
+             (srfi srfi-69) ; alist->hash-table
              (texinfo serialize)
              (texinfo plain-text)
              (ice-9 pretty-print))
       (string->symbol (substring str 0 (- (string-length str) 5))))
      (else #f))))
 
+(define type-map-table (make-parameter #f))
+
+(define (use-type-map tm)
+  (type-map-table (alist->hash-table tm eq? hashq)))
+
+(define (type-map type)
+  (hash-table-ref/default (type-map-table) type #f))
+
+;; TODO: Some guesswork is applied here due to inconsistency between
+;; the various .spec and type map files.  Ideally, the type map can
+;; determine whether a type is a bitfield or enum.  However, some
+;; definitions in enum.spec use a different name to those in gl.spec
+;; and gl.tm.  For example, BufferAccessMask is known as
+;; ARB_map_buffer_range in enum.spec.
+;;
+;; Perhaps provide an additional map to translate these odd enum.spec
+;; names.
+
 (define (bitfield? enum)
-  (and-map (match-lambda ((name . value) (strip-bit name)))
-           (gl-enumeration-values enum)))
+  (let* ((type (make-gl-param-type (gl-enumeration-category enum)
+                                   'in
+                                   'value))
+         (mapped-type (type-map type)))
+    (if mapped-type
+        (eq? (gl-param-type-type mapped-type) 'GLbitfield)
+        ;; otherwise, resort to guesswork
+        (and-map (match-lambda ((name . value) (strip-bit name)))
+                 (gl-enumeration-values enum)))))
 
 (define (write-scm mod-name enums port)
   (display "\
       (if (bitfield? enum)
           `(define-bitfield ,(gl-enumeration-category enum)
              ,@(map (match-lambda
-                     ((name . value) (list (strip-bit name) value)))
+                     ((name . value) (list (or (strip-bit name) name)
+                                           value)))
                     (gl-enumeration-values enum)))
           `(define-enumeration ,(gl-enumeration-category enum)
              ,@(map (match-lambda
                   (para
                    ,@(list-intersperse
                       (map (lambda (name)
-                             `(code ,(symbol->string (strip-bit name))))
+                             `(code ,(symbol->string (or (strip-bit name)
+                                                         name))))
                            (map car (gl-enumeration-values enum)))
                      ", ")
                    "."))
       (write-texi mod-name enums port))))
 
 (define* (main arg0)
+  (use-type-map (parse-gl-type-map "gl.tm"))
   (write-enumerations 'gl (parse-gl-enumerations "enum.spec"))
+  (use-type-map (parse-gl-type-map "glx.tm"))
   (write-enumerations 'glx (parse-gl-enumerations "glxenum.spec")))
 
 (when (batch-mode?)