On Tue, 1 May 2018, Ryan Joseph wrote:



On May 1, 2018, at 3:17 PM, Mattias Gaertner <nc-gaert...@netcologne.de> wrote:

JS only knows double for numbers.

At compile time you can use almost all the normal types: byte,
word, longint, etc.
pas2js has an alias single, but because internally it is a double this
gives warnings.

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?

Arrays are arrays in JS. 'records' in JS are (literal) objects.

Note that the above call does not exist in webGL. But if something like it 
existed, it would probably be
simply

glBufferData(verts, GL_STATIC_DRAW);

defined as
glBufferData(data : JSValue; aType : int);

The WebGL API would then presumably internally inspect the data, and if it is
an array, convert the Javascript array of objects to something the underlying 
GL understands.

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to