[Openmcl-devel] opengl macptr advice please

Arthur Cater arthur.cater at ucd.ie
Thu Mar 16 02:54:23 PDT 2017


Thank you for the response. Sorry your lisp crashed!
I’m about to leave for a few days, I’ll try your suggestions on my return.
Arthur

> On Mar 16, 2017, at 1:26 AM, R. Matthew Emerson <rme at acm.org> wrote:
> 
> 
>> On Mar 15, 2017, at 12:04 PM, Arthur Cater <arthur.cater at ucd.ie> wrote:
>> 
>> Hello,
>> I’ve gathered my Mac’s Open GL does not support glLineWidth > 1, but I don’t
>> understand what I need to do to use #_glGetFloatv to find out from gl info such as this.
>> I’d like to learn.
>> 
>> 
>> On finding I needed a MACPTR (rather than a raw lisp vector) I tried
>> 
>> (gui::execute-in-gui #'(lambda nil
>>                        (let ((v (make-array 2 :initial-element 0.0 :element-type 'single-float)))
>>                          (with-macptrs (v2 v) (#_glGetFloatv #$GL_ALIASED_LINE_WIDTH_RANGE v2))
>>                          v)))
>> but that gives a kernel error (10) through AltConsole.
> 
> Lisp data and foreign data live in two separate worlds, so you can't pass the address of a lisp array to foreign code.  (The gc might move the lisp array, and then the foreign pointer would become invalid.)
> 
> There's a macro called ccl:with-pointer-to-ivector that you could possibly use here.  I'm not a big fan of that macro, since it's body runs with the gc disabled.
> 
> You could also look up make-heap-ivector in the manual.
> 
> 
>> 
>> I also tried
>> (gui::execute-in-gui #'(lambda nil
>>                        (let ((v (make-array 2 :initial-element 0.0 :element-type 'single-float)))
>>                          (ccl::%stack-block ((v2 8))
>>                             (#_glGetFloatv #$GL_ALIASED_LINE_WIDTH_RANGE v2)
>>                             (ccl::%copy-ptr-to-ivector v2 0 v 0 8))
>>                          v)))
>> which gave #(0.0, 0.0)   — i.e. no change to v, where I’d hope for #(1.0, 1.0)
>> 
>> And I tried
>> (gui::execute-in-gui #'(lambda nil
>>                        (let ((v (make-array 2 :initial-element 130.0 :element-type 'single-float)))
>>                          (ccl::%stack-block ((v2 8))
>>                             (ccl::%copy-ivector-to-ptr v 0 v2 0 8)
>>                             (#_glGetFloatv #$GL_ALIASED_LINE_WIDTH_RANGE v2)
>>                             (ccl::%get-single-float v2 4)))))
>> which gave 130.0 (showing I think that the stack-allocated array is unchanged)
> 
> There are some primitive foreign memory accessors that you can use instead of messing around with the internal %copy-ivector-to-ptr or vice versa.
> 
> ccl:%stack-block gives to a pointer to some foreign memory on the stack.  In principle, you should be able to say 
> 
> (ccl:%stack-block ((params 8))
>  (#_glGetFloatv #$GL_ALIASED_LINE_WIDTH_RANGE params)
>  (values (%get-single-float params 0)
>  	  (%get-single-float params 4)))
> 
> Note, however, that when I tried this on my Mac, I crashed my lisp.  I don't know if I need to have an OpenGL context or something active before doing this or what.
> 
> Note that the rlet macro can be a little nicer to use.  The FFI's type system even has a notion of foreign arrays.  They are manipulated like so:
> 
> (rletz ((params (:array #>GLfloat 2)))
>    (setf (paref params (:* #>GLfloat) 0) 100.0)
>    (setf (paref params (:* #>GLfloat) 1) 200.0)
>    (values (paref params (:* #>GLfloat) 0)
>            (paref params (:* #>GLfloat) 1)))
> 
> If this doesn't get you unstuck, please post again.
> 
> 
> 




More information about the Openmcl-devel mailing list