Hello,
I am trying to cast a seq[GLfloat_t] to an openArray[Vertex] where:
type
Vertex* = object
x*, y*, z*: GLfloat_t I have tried the following but these do not compile:
let vp: seq[Vertex] = ...
let t1 = cast[openArray[Vertex]](vp.addr)
let t2 = cast[openArray[Vertex]](addr(vp[0]))
let t3 = cast[openArray[GLfloat_t]](addr(vp[0])) The following works for ptr Vertex:
var t0 = cast[ptr Vertex](vp.addr)
var t1 = cast[ptr Vertex](addr(vp[0])) But I cannot seem t use these as arguments to:
proc vertices_vbo(vertices: openArray[Vertex]): GLuint_t = ... What am I missing here?
TIA
Go it to compile with:
let vpv = cast[ptr UncheckedArray[Vertex]](vp[0].addr)
doAssert vp.len mod 3 == 0
let points_vbo = vertices_vbo(vpv.toOpenArray(0, vp.len div 3 - 1))
let vao: GLuint_t = vao_of(points_vbo) My search also led me to a use:
type
Vertex* {.bycopy, packed.} = object
x*, y*, z*: GLfloat_t
static:
assert sizeof(Vertex) == 3 * sizeof(GLfloat_t) Seems to be working. I just don't know if that .bcopy. is critical, but seeing as I am using a C API, I think it is best to use it.