[fpc-pascal] Next language feature for pas2js...

Mattias Gaertner nc-gaertnma at netcologne.de
Tue May 1 11:10:00 CEST 2018


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);

// Unbind the buffer
gl.bindBuffer(gl.ARRAY_BUFFER, null);
---JS-END---

In pas2js it will probably look similar to this:

var vertices: array of glfloat = (-0.5, 0.5, -0.5, -0.5, 0.0, -0.5);
var vertex_buffer: TInsertNameHere;
begin
  // Create a new buffer object
  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, Float32Array.new(vertices), gl.STATIC_DRAW);

  // Unbind the buffer
  gl.bindBuffer(gl.ARRAY_BUFFER, nil);
end;


Mattias




More information about the fpc-pascal mailing list