On 27 June 2013 10:30, kilon <[email protected]> wrote:
> I also tried
>
> gl shaderSource_shader: shader count: 1  string: (NBExternalAddress
> fromString: shaderString)  length: (NBExternalObject null) .
>
> still getting "Error during FFI call : NIL" .
>
> This is the full method :
>
> createShader: shaderType string: shaderString
>         " create shader using its source and compile it , return shader"
>
>         | shader |
>         shader := gl createShader: shaderType .
>         gl shaderSource_shader: shader count: 1  string: (NBExternalAddress
> fromString: shaderString)  length: (NBExternalObject null) .
>         gl compileShader: shader.
>         ^ shader
>

i think it fails because you passing strange (NBExternalObject null)
as length parameter.
i guess you meant  NBExternalAddress null instead.

here the function prototype:

void glShaderSource ( GLuint shader , GLsizei count , GLchar** string
, long* length )

so, length and string is both pointers, and NB marshalling knows only that
(it doesn't knows if there are arrays of strings, ints or whatever).
So, to make it happy you must pass instances of NBExternalAddress as
both of there parameters.

And code will look like:

assume that you have an array of strings, holding the shader sources,
lets call it sources.

sources := #( ' this is first'  'this is second' 'etc' ).

sizeOfPointer := NBExternalType sizeOf: 'void*'.

"allocate buffer for array of pointers"

externalArrayOfPointers := NativeBoost allocate: sizeOfPointer * sources size.

"allocate strings and copy them to external heap"
sourcesOnHeap := sources collect: [:each | NBExternalAddress fromString: each ].

"copy string pointers to external array"
sourcesOnHeap withIndexDo: [:ptr :i |
   "using nbUInt32AtOffset because we know pointer is 4 bytes :) "
    externalArrayOfPointers nbUInt32AtOffset: (i-1)*4 put: ptr value
]

and now you can call that function

 gl shaderSource_shader: shader count:  sources size  string:
externalArrayOfPointers
   length: (NBExternalAddress null) .

but after, don't forget to free the memory:

sourcesOnHeap do: [:each | each free].
externalArrayOfPointers free.


> . I also use gl getError to get any possible opengl error in my part , It
> reports that there is no such error.I am continuing investigating
> Nativeboost
>
>
>
> --
> View this message in context: 
> http://forum.world.st/Understanding-NBOpenGL-tp4686514p4695575.html
> Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
>



-- 
Best regards,
Igor Stasenko.

Reply via email to