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

Ryan Joseph ryan at thealchemistguild.com
Tue May 1 11:59:39 CEST 2018



> On May 1, 2018, at 4:37 PM, Michael Van Canneyt <michael at freepascal.org> wrote:
> 
> What's wrong with the above code ?
> 
> It obviously works well enough, otherwise they wouldn't have made the API so.
> 
> The float32 array is a Javascript type that encapsulates a memory buffer.
> I assu

It’s difficult to work with. With OpenGL what you have is a record with all the fields that are the data for vertex (positions, colors, normals etc…) and you tell OpenGL at what offset and stride the data starts. If you use to just array literals like that it would be very messy.

    void vertexAttribPointer(GLuint index, GLint size, GLenum type,
                             GLboolean normalized, GLsizei stride, GLintptr offset);

That’s what I would expect not using WebGL before. Getting that down to typed arrays using wrapper functions would be a mess though. Ouch. No idea how that’s supposed to look in WebGL.

// array of TVertex 
[
  // vertex 1
  [
  [0, 0], // position (vec2f)
  [255, 255, 255], // color (vec4b)
  [0, 1], // texture coord (vec2f)
  ],
  
  // vertex 2
  [
  [0, 0], // position (vec2f)
  [255, 255, 255], // color (vec4b)
  [0, 1], // texture coord (vec2f)
  ],

  // vertex 3
  [
  [0, 0], // position (vec2f)
  [255, 255, 255], // color (vec4b)
  [0, 1], // texture coord (vec2f)
  ]
]

type
  TVertex = record
    pos: TVec2f;
    color: TVec4b;
    texCoord: TVec2f;
  end;

verts: array[0..2] of TVertex;

The parser could break down records into those arrays but it would be complicated I suspect.

Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list