Hi all, I propose the following patch to implement the remaining state query functions (glGetInteger, glGetBoolean, etc) in CL-OPENGL. The interface is pretty straightforward, and the user can omit the number of values to return when the query is known to the library.
For example (from a running OpenGL program): CL-USER> (gl:get-float :viewport) #(0.0 0.0 640.0 480.0) CL-USER> (gl:get-float :texture-matrix) #(1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0) CL-USER> (gl:get-boolean :blend) T CL-USER> (gl:get-enum :depth-func 'gl::compare-func) :LESS I'm becoming fairly convinced that the separation of GLenum into discrete enum types based on context may not be a good idea. OpenGL doesn't make any distinction between different types of enums, and it feels as though we are going against the grain trying to separate them. There are a lot of duplicate definitions, and it also makes it hard to deal with a case like glGetInteger where you want to say, "this function returns a GLenum", because you don't know which CL-OPENGL enum type to use (hence the additional argument to GL:GET-ENUM in my implementation). I'd be willing to do the grunt work on a patch to move to one unified enum type---hopefully such a beast could be mostly machine generated from a header file or specification document (and updated by hand from then on). James
New patches: [Implement functions for querying non-string GL state. James Bielman <[EMAIL PROTECTED]>**20060823082148 - Define a new enumerated type QUERY-NAME that contains the valid queries. - The *QUERY-ENUM-SIZES* alist contains the expected number of values returned by each query. - The high-level Lisp interface automatically allocates a buffer of the appropriate size when the query parameter is known, returning it as either a vector or a single value. ] { hunk ./gl/enums.lisp 639 + +;;; Wrapper around DEFCENUM for defining the enumerated values for +;;; glGet*, as well as the expected number of values returned by each +;;; type of query. For queries with unknown and unspecified array +;;; sizes, use the largest known query size in hopes of minimizing +;;; segfaults. +(defmacro define-query-enums (name &body values) + (let ((max-size 0)) + `(progn + (defcenum (,name enum) + ,@(loop for (name value . rest) in values + collect `(,name ,@(if value (list value))))) + (defparameter *query-enum-sizes* + (list ,@(loop for (name value size . rest) in values + if size + collect `'(,name . ,size) + and do (when (> size max-size) + (setf max-size size))))) + (defparameter *query-max-size* ,max-size)))) + +;;; FIXME: I took these from the blue book for OpenGL 1.4 instead of +;;; the version 2.0 specification, as they were all listed together +;;; conveniently in the former. [JJB 2006/08/20] +(define-query-enums query-name + (:accum-alpha-bits #x0d58 1) + (:accum-blue-bits #x0d5a 1) + (:accum-clear-value #x0b80 4) + (:accum-green-bits #x0d59 1) + (:accum-red-bits #x0d58 1) + (:active-texture #x84e0 1) + (:aliased-point-size-range #x846d 2) + (:aliased-line-width-range #x846e 2) + (:alpha-bias #x0d1d 1) + (:alpha-bits #x0d55 1) + (:alpha-scale #x0d1c 1) + (:alpha-test #x0bc0 1) + (:alpha-test-func #x0bc1 1) + (:alpha-test-ref #x0bc2 1) + (:attrib-stack-depth #x0bb0 1) + (:auto-normal #x0d80 1) + (:aux-buffers #x0c00 1) + (:blend #x0be2 1) + (:blend-color #x8005 4) + (:blend-equation #x8009 1) + (:blue-bias #x0d1b 1) + (:blue-bits #x0d54 1) + (:blue-scale #x0d1a 1) + (:client-active-texture #x84e1 1) + (:client-attrib-stack-depth #x0bb1 1) + (:clip-plane0 #x3000 1) + (:clip-plane1 #x3001 1) + (:clip-plane2 #x3002 1) + (:clip-plane3 #x3003 1) + (:clip-plane4 #x3004 1) + (:clip-plane5 #x3005 1) + (:color-array #x8076 1) + (:color-array-size #x8081 1) + (:color-array-stride #x8083 1) + (:color-array-type #x8082 1) + (:color-clear-value #x0c22 4) + (:color-logic-op #x0bf2 1) + (:color-material #x0b57 1) + (:color-material-face #x0b55 1) + (:color-material-parameter #x0b56 1) + (:color-matrix #x80b1 16) + (:color-matrix-stack-depth #x80b2 1) + (:color-table #x80d0 1) + (:color-writemask #x0c23 4) + (:compressed-texture-formats #x86a3) + (:convolution-1d #x8010 1) + (:convolution-2d #x8011 1) + (:cull-face #x0b44 1) + (:cull-face-mode #x0b45 1) + (:current-color #x0b00 4) + (:current-index #x0b01 1) + (:current-normal #x0b02 3) + (:current-raster-color #x0b04 4) + (:current-raster-distance #x0b09 1) + (:current-raster-index #x0b05 1) + (:current-raster-position #x0b07 4) + (:current-raster-position-valid #x0b08 1) + (:current-raster-texture-coords #x0b06 4) + (:current-texture-coords #x0b03 4) + (:depth-bias #x0d1f 1) + (:depth-bits #x0d56 1) + (:depth-clear-value #x0b73 1) + (:depth-func #x0b74 1) + (:depth-range #x0b70 2) + (:depth-scale #x0d1e 1) + (:depth-test #x0b71 1) + (:depth-writemask #x0b72 1) + (:dither #x0bd0 1) + (:doublebuffer #x0c32 1) + (:draw-buffer #x0c01 1) + (:edge-flag #x0b43 1) + (:edge-flag-array #x8079 1) + (:edge-flag-array-stride #x808c 1) + (:feedback-buffer-size #x0df1 1) + (:feedback-buffer-type #x0df2 1) + (:fog #x0b60 1) + (:fog-color #x0b66 4) + (:fog-density #x0b62 1) + (:fog-end #x0b64 1) + (:fog-hint #x0c54 1) + (:fog-index #x0b61 1) + (:fog-mode #x0b65 1) + (:fog-start #x0b63 1) + (:front-face #x0b46 1) + (:generate-mipmap-hint #x8192 1) + (:green-bias #x0d19 1) + (:green-bits #x0d53 1) + (:green-scale #x0d18 1) + (:histogram #x8024 1) + (:index-array #x8077 1) + (:index-array-stride #x8086 1) + (:index-array-type #x8085 1) + (:index-bits #x0d51 1) + (:index-clear-value #x0c20 1) + (:index-logic-op #x0bf1 1) + (:index-mode #x0c30 1) + (:index-offset #x0d13 1) + (:index-shift #x0d12 1) + (:index-writemask #x0c21 1) + (:light0 #x4000 1) + (:light1 #x4001 1) + (:light2 #x4002 1) + (:light3 #x4003 1) + (:light4 #x4004 1) + (:light5 #x4005 1) + (:light6 #x4006 1) + (:light7 #x4007 1) + (:lighting #x0b50 1) + (:light-model-ambient #x0b53 4) + (:light-model-color-control #x81f8 1) + (:light-model-local-viewer #x0b51 1) + (:light-model-two-side #x0b52 1) + (:line-smooth #x0b20 1) + (:line-smooth-hint #x0c52 1) + (:line-stipple #x0b24 1) + (:line-stipple-pattern #x0b25 1) + (:line-stipple-repeat #x0b26 1) + (:line-width #x0b21 1) + (:line-width-granularity #x0b23 1) + (:line-width-range #x0b22 2) + (:list-base #x0b32 1) + (:list-index #x0b33 1) + (:list-mode #x0b30 1) + (:logic-op-mode #x0bf0 1) + (:map1-color-4 #x0d90 1) + (:map1-grid-domain #x0dd0 2) + (:map1-grid-segments #x0dd1 1) + (:map1-index #x0d91 1) + (:map1-normal #x0d92 1) + (:map1-texture-coord-1 #x0d93 1) + (:map1-texture-coord-2 #x0d94 1) + (:map1-texture-coord-3 #x0d95 1) + (:map1-texture-coord-4 #x0d96 1) + (:map1-vertex-3 #x0d97 1) + (:map1-vertex-4 #x0d98 1) + (:map2-color-4 #x0db0 1) + (:map2-grid-domain #x0dd2 4) + (:map2-grid-segments #x0dd3 2) + (:map2-index #x0db1 1) + (:map2-normal #x0db2 1) + (:map2-texture-coord-1 #x0db3 1) + (:map2-texture-coord-2 #x0db4 1) + (:map2-texture-coord-3 #x0db5 1) + (:map2-texture-coord-4 #x0db6 1) + (:map2-vertex-3 #x0db7 1) + (:map2-vertex-4 #x0db8 1) + (:map-color #x0d10 1) + (:map-stencil #x0d11 1) + (:matrix-mode #x0ba0 1) + (:max-3d-texture-size #x8073 1) + (:max-client-attrib-stack-depth #x0d3b 1) + (:max-attrib-stack-depth #x0d35 1) + (:max-clip-planes #x0d32 1) + (:max-color-matrix-stack-depth #x80b3 1) + (:max-cube-map-texture-size #x851c 1) + (:max-elements-indices #x80e9 1) + (:max-elements-vertices #x80e8 1) + (:max-eval-order #x0d30 1) + (:max-lights #x0d31 1) + (:max-list-nesting #x0b31 1) + (:max-modelview-stack-depth #x0d36 1) + (:max-name-stack-depth #x0d37 1) + (:max-pixel-map-table #x0d34 1) + (:max-projection-stack-depth #x0d38 1) + (:max-texture-size #x0d33 1) + (:max-texture-stack-depth #x0d39 1) + (:max-texture-units #x84e2 1) + (:max-viewport-dims #x0d3a 1) + (:minmax #x802e 1) + (:modelview-matrix #x0ba6 16) + (:modelview-stack-depth #x0ba3 1) + (:name-stack-depth #x0d70 1) + (:normal-array #x8075 1) + (:normal-array-stride #x807f 1) + (:normal-array-type #x807e 1) + (:normalize #x0ba1 1) + (:num-compressed-texture-format #x86a2 1) + (:pack-alignment #x0d05 1) + (:pack-image-height #x806c 1) + (:pack-lsb-first #x0d01 1) + (:pack-row-length #x0d02 1) + (:pack-skip-images #x806b 1) + (:pack-skip-pixels #x0d04 1) + (:pack-skip-rows #x0d03 1) + (:pack-swap-bytes #x0d00 1) + (:perspective-correction-hint #x0c50 1) + (:pixel-map-a-to-a-size #x0cb9 1) + (:pixel-map-b-to-b-size #x0cb8 1) + (:pixel-map-g-to-g-size #x0cb7 1) + (:pixel-map-i-to-a-size #x0cb5 1) + (:pixel-map-i-to-b-size #x0cb4 1) + (:pixel-map-i-to-g-size #x0cb3 1) + (:pixel-map-i-to-i-size #x0cb0 1) + (:pixel-map-i-to-r-size #x0cb2 1) + (:pixel-map-r-to-r-size #x0cb6 1) + (:pixel-map-s-to-s-size #x0cb1 1) + (:point-size #x0b11 1) + (:point-size-granularity #x0b13 1) + (:point-size-range #x0b12 2) + (:point-smooth #x0b10 1) + (:point-smooth-hint #x0c51 1) + (:polygon-mode #x0b40 2) + (:polygon-offset-factor #x8038 1) + (:polygon-offset-units #x2a00 1) + (:polygon-offset-fill #x8037 1) + (:polygon-offset-line #x2a02 1) + (:polygon-offset-point #x2a01 1) + (:polygon-smooth #x0b41 1) + (:polygon-smooth-hint #x0c53 1) + (:polygon-stipple #x0b42 1) + (:post-color-matrix-color-table #x80d2 1) + (:post-color-matrix-red-bias #x80b8 1) + (:post-color-matrix-green-bias #x80b9 1) + (:post-color-matrix-blue-bias #x80ba 1) + (:post-color-matrix-alpha-bias #x80bb 1) + (:post-color-matrix-red-scale #x801c 1) + (:post-color-matrix-green-scale #x801d 1) + (:post-color-matrix-blue-scale #x801e 1) + (:post-color-matrix-alpha-scale #x80b7 1) + (:post-convolution-color-table #x80d1 1) + (:post-convolution-red-bias #x8020 1) + (:post-convolution-green-bias #x8021 1) + (:post-convolution-blue-bias #x8022 1) + (:post-convolution-alpha-bias #x8023 1) + (:post-convolution-red-scale #x801c 1) + (:post-convolution-green-scale #x801d 1) + (:post-convolution-blue-scale #x801e 1) + (:post-convolution-alpha-scale #x801f 1) + (:projection-matrix #x0ba7 16) + (:projection-stack-depth #x0ba4 1) + (:read-buffer #x0c02 1) + (:red-bias #x0d15 1) + (:red-bits #x0d52 1) + (:red-scale #x0d14 1) + (:render-mode #x0c40 1) + (:rescale-normal #x803a 1) + (:rgba-mode #x0c31 1) + (:sample-buffers #x80a8 1) + (:sample-coverage-value #x80aa 1) + (:sample-coverage-invert #x80ab 1) + (:samples #x80a9 1) + (:scissor-box #x0c10 4) + (:scissor-test #x0c11 1) + (:selection-buffer-size #x0df4 1) + (:separable-2d #x8012 1) + (:shade-model #x0b54 1) + (:smooth-line-width-range #x0b22 2) + (:smooth-line-width-granularity #x0b23 1) + (:smooth-point-size-range #x0b12 2) + (:smooth-point-size-granularity #x0b13 1) + (:stencil-bits #x0d57 1) + (:stencil-clear-value #x0b91 1) + (:stencil-fail #x0b94 1) + (:stencil-func #x0b92 1) + (:stencil-pass-depth-fail #x0b95 1) + (:stencil-pass-depth-pass #x0b96 1) + (:stencil-ref #x0b97 1) + (:stencil-test #x0b90 1) + (:stencil-value-mask #x0b93 1) + (:stencil-writemask #x0b98 1) + (:stereo #x0c33 1) + (:subpixel-bits #x0d50 1) + (:texture-1d #x0de0 1) + (:texture-binding-1d #x8068 1) + (:texture-2d #x0de1 1) + (:texture-binding-2d #x8069 1) + (:texture-3d #x806f 1) + (:texture-binding-3d #x806a 1) + (:texture-binding-cube-map #x8514 1) + (:texture-compression-hint #x84ef 1) + (:texture-coord-array #x8078 1) + (:texture-coord-array-size #x8088 1) + (:texture-coord-array-stride #x808a 1) + (:texture-coord-array-type #x8089 1) + (:texture-cube-map #x8513 1) + (:texture-gen-q #x0c63 1) + (:texture-gen-r #x0c62 1) + (:texture-gen-s #x0c60 1) + (:texture-gen-t #x0c61 1) + (:texture-matrix #x0ba8 16) + (:texture-stack-depth #x0ba5 1) + (:transpose-color-matrix #x84e6 16) + (:transpose-modelview-matrix #x84e3 16) + (:transpose-projection-matrix #x84e4 16) + (:transpose-texture-matrix #x84e5 16) + (:unpack-alignment #x0cf5 1) + (:unpack-image-height #x806e 1) + (:unpack-lsb-first #x0cf1 1) + (:unpack-row-length #x0cf2 1) + (:unpack-skip-images #x806d 1) + (:unpack-skip-pixels #x0cf4 1) + (:unpack-skip-rows #x0cf3 1) + (:unpack-swap-bytes #x0cf0 1) + (:vertex-array #x8074 1) + (:vertex-array-size #x807a 1) + (:vertex-array-stride #x807c 1) + (:vertex-array-type #x807b 1) + (:viewport #x0ba2 4) + (:zoom-x #x0d16 1) + (:zoom-y #x0d17 1)) hunk ./gl/package.lisp 259 + #:get-boolean + #:get-integer + #:get-float + #:get-double + #:get-enum hunk ./gl/state.lisp 40 + +(defcfun ("glGetBooleanv" %glGetBooleanv) :void + (value query-name) + (data :pointer)) + +(defcfun ("glGetIntegerv" %glGetIntegerv) :void + (value query-name) + (data :pointer)) + +(defcfun ("glGetFloatv" %glGetFloatv) :void + (value query-name) + (data :pointer)) + +(defcfun ("glGetDoublev" %glGetDoublev) :void + (value query-name) + (data :pointer)) + +;;; Return the default array size for a state query enum. +(defun query-enum-size (value) + (or (cdr (assoc value *query-enum-sizes*)) *query-max-size*)) + +;;; Conversion function when querying OpenGL boolean states. +(defun nonzerop (x) + (not (zerop x))) + +(defmacro define-query-function (name fn type &optional (convert 'identity)) + `(defun ,name (value &optional (count (query-enum-size value))) + (with-foreign-object (buf ',type count) + (,fn value buf) + (if (> count 1) + (let ((result (make-array count))) + (dotimes (i count) + (setf (aref result i) (,convert (mem-aref buf ',type i)))) + result) + (,convert (mem-ref buf ',type)))))) + +;;; Define query functions for the basic types. +(define-query-function get-boolean %glGetBooleanv boolean nonzerop) +(define-query-function get-integer %glGetIntegerv int) +(define-query-function get-float %glGetFloatv float) +(define-query-function get-double %glGetDoublev double) + +;;; Wrapper around GET-INTEGER when the result should be interpreted +;;; as an enumerated constant. Since we've split up the constants +;;; into discrete types, we need to specify which enum to use to +;;; return the proper keyword (this is unfortunate IMHO). +(defun get-enum (value enum &optional (count (query-enum-size value))) + (let ((result (get-integer value count))) + (if (vectorp result) + (map 'vector (lambda (x) (foreign-enum-keyword enum x)) result) + (foreign-enum-keyword enum result)))) } Context: [Minor fix to glut/interface.lisp Luis Oliveira <[EMAIL PROTECTED]>**20060703224124] [CL-GLUT update Luis Oliveira <[EMAIL PROTECTED]>**20060624235928 - Fix foreign-symbol-pointer usage in glut/fonts.lisp. - Move enums next to the DEFCFUNs where they're used. - Rework the CL-GLUT CLOS interface. - Reorganize examples and rewrite them using the updated CLOS interface. ] [s/windows/cffi-features:windows Luis Oliveira <[EMAIL PROTECTED]>**20060425212810] [Convert array contents to floats in MAP1 and MAP2. James Bielman <[EMAIL PROTECTED]>**20060412015458] [Add evaluator constants to the ENABLE-CAP enum. James Bielman <[EMAIL PROTECTED]>**20060412015045] [New example: glut-teapot.lisp Luis Oliveira <[EMAIL PROTECTED]>**20060326211537 Also, fixed a typo in the README and added a README for the examples. ] [GLUT: add missing event and fix typo Luis Oliveira <[EMAIL PROTECTED]>**20060221054305 - Missing event: passive-motion. - fullscreen -> full-screen - move the (setf title) magic to a :before method. ] [Minor fixes to the examples Luis Oliveira <[EMAIL PROTECTED]>**20060221054151 - add ignore declarations to unused arguments. - use MOD! ] [Oops. Forgot to darcs add examples/mesademos/package.lisp Luis Oliveira <[EMAIL PROTECTED]>**20060219211853] [More examples Luis Oliveira <[EMAIL PROTECTED]>**20060218054241 - New examples: rb{6,7,8,9,10,11,12,13}. - Use with-new-list in mesademos/gears.lisp. - Add copyright notices to examples. - Fix example 4 which was drawing *halftone* twice. ] [with-new-list, with-primitive and call-lists Luis Oliveira <[EMAIL PROTECTED]>**20060218051830] [GLUT: use gl:ensure-double Luis Oliveira <[EMAIL PROTECTED]>**20060217231013] [Small change to with-opengl-sequence Luis Oliveira <[EMAIL PROTECTED]>**20060217224915 - Make it convert the sequence's elements to float or double when the type is gl:float or gl:double respectively. Breaks when type isn't constant, oops. ] [Tiny update to GLU Luis Oliveira <[EMAIL PROTECTED]>**20060217222227 - Mostly move files around. (remind not to create stub files again, ugh) - Added some new functions. ] [New types: gl:ensure-double and gl:ensure-float Luis Oliveira <[EMAIL PROTECTED]>**20060217221729 - Define and export ensure-double and ensure-float. (these need a recent CFFI) - Also export some types that'll be needed for GLU. Maybe a gl-types package would be a good idea? ] [Oops. Forgot darcs add. Luis Oliveira <[EMAIL PROTECTED]>**20060207034827] [New examples Luis Oliveira <[EMAIL PROTECTED]>**20060207032245 - New 5 examples from the redbook. - 2 GLU functions needed for the examples. - Added gl:polygon-stipple needed for one of the examples. - Fixed silly bugs in cl-glut's ascii-to-char type and the base-window initialize-instance. - Moved window's title initform to a special. ] [Preliminary CLOS interface to GLUT Luis Oliveira <[EMAIL PROTECTED]>**20060206182638 - Removed a german 'ss' from rasterization.lisp which was upsetting SBCL. - New macro WITH-PUSHED-MATRIX. WITH-MATRIX might be a better name? - New experimental CLOS-based interface to GLUT. - New example using the new CLOS interface. Moved old gears exmample to gears-raw.lisp. ] [Optimizations (needs recent CFFI again) Luis Oliveira <[EMAIL PROTECTED]>**20060203014020 - Add declarations in gears.lisp - Define the gl:* types to have no translation ] [Use internal-time-units-per-second Luis Oliveira <[EMAIL PROTECTED]>**20060202200413] [Add fps counter to examples/mesademos/gears.lisp Luis Oliveira <[EMAIL PROTECTED]>**20060202195354] [Texturing functions added. Oliver Markovic <[EMAIL PROTECTED]>**20060202185907 - Added preliminary support for glTexImage and glTexSubImage. I'm still not sure on how to handle the data. - Added glCopyTexImage and glCopyTexSubImage - Added glAreTexturesResident and glPrioritizeTextures along with TEXTURE-RESIDENT-P and PRIORITIZE-TEXTURE, which are hopefully less awkward to use than the direct translations. - Added glTexEnv. ] [Oops. Missing glut/main.lisp file. Luis Oliveira <[EMAIL PROTECTED]>**20060202190632] [GLUT update, less straw. Luis Oliveira <[EMAIL PROTECTED]>**20060202124342 (requires recent cffi patches fixing defcenum issue and implementing defbitfield) - add missing depends-on to funcs in cl-opengl.asd - complete glut bindings. next step: high level interface. ] [Add glutSetOption. Alexey Dvoychenkov <[EMAIL PROTECTED]>**20060202031904] [Big patch, lots of straw again. Luis Oliveira <[EMAIL PROTECTED]>**20060201164339 - GLU: added asd file and stub .lisp files. - Examples: - added cl-glut-examples.asd - new example: gears.lisp - GLUT: added asd file and implemented a few routines. (mostly those needed by the gears.lisp example) - Add my name to HEADER too. - 3 separate manuals is probably overkill? Use only one for now. - GL: - fixed enums, these should canonicalize to GLenum, not int. - renamed gl types from GLfoo to gl:foo (and exported them) - fixed erroneus check-type. - look for libGL.so.N if libGL.so isn't found. - removed some tabs from the files. - added missing space between ":constant-attenuation" and "linear-attenuation". - added missing (declare (ignore ..)) to avoid warnings. - fixed a small bug/typo where a foreign array was being accessed as if it were Lisp array. - change ;;;-comments to ;;-comments in package.lisp in order to indent well. ] [Add documentation structure. Luis Oliveira <[EMAIL PROTECTED]>**20060201013908 Just straw, no content. Taken from cffi mostly. ] [Minor changes Luis Oliveira <[EMAIL PROTECTED]>**20060131190956 - added HEADER file. - changed library.lisp to use BSD license. - removed tabs from state.lisp ] [Added examples directory. Oliver Markovic <[EMAIL PROTECTED]>**20060131120521] [Initial revision. Oliver Markovic <[EMAIL PROTECTED]>**20060131115438] Patch bundle hash: 5e6c8d5e8b6e65b845fa542c222f8a6908319ec9
_______________________________________________ cl-opengl-devel mailing list cl-opengl-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/cl-opengl-devel