[fpc-pascal] Next language feature for pas2js...
Michael Van Canneyt
michael at freepascal.org
Tue May 1 11:14:27 CEST 2018
On Tue, 1 May 2018, Mattias Gaertner wrote:
> On Tue, 1 May 2018 15:23:25 +0700
> Ryan Joseph <ryan at thealchemistguild.com> wrote:
>
>> [...]
>> what do we do for records then? We often need to pass arrays of specific types for functions such as glBufferData.
>>
>> type
>> TVec2f = record
>> x, y: GLfloat;
>> end;
>>
>> type
>> TVec2b = record
>> x, y: GLubyte;
>> end;
>>
>> var
>> verts: array[0..2] of TVec2f;
>> begin
>> glBufferData(GL_ARRAY_BUFFER, sizeof(TVec2f) * 3, @verts, GL_STATIC_DRAW); // pass an array of TVec2 but how does JS know this?
>
> Here is an JS example:
>
> ---JS-START---
> var vertices = [-0.5, 0.5, -0.5, -0.5, 0.0, -0.5,];
>
> // Create a new buffer object
> var vertex_buffer = gl.createBuffer();
>
> // Bind an empty array buffer to it
> gl.bindBuffer(gl.ARRAY_BUFFER, vertex_buffer);
>
> // Pass the vertices data to the buffer
> gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
So it does exist :)
Nice, I should have typed gl.bufferData instead of glbufferdata when
searching :-)
Michael.
More information about the fpc-pascal
mailing list