>>102054736
I went with some kind of batcher(with help from GPT) and it ended up looking like this.
flush :: proc(batch: ^BatchRenderer) {
if (batch.vertex_count == 0) {
return
}
gl.UseProgram(batch.shader_program)
gl.BindVertexArray(batch.vao)
gl.BindBuffer(gl.ARRAY_BUFFER, batch.vbo)
gl.BufferData(
gl.ARRAY_BUFFER,
batch.vertex_count * size_of(Vertex),
&batch.vertices[0],
gl.DYNAMIC_DRAW,
)
gl_primitive: u32
vertices_per_primitive: int
#partial switch batch.current_primitive {
case .Triangles:
gl_primitive = gl.TRIANGLES
vertices_per_primitive = 3
}
gl.DrawArrays(gl_primitive, 0, i32(batch.vertex_count))
batch.vertex_count = 0
}
// And batchrenderer is initialized like this
BatchRenderer :: struct {
vbo, vao: u32,
shader_program: u32,
vertices: [MAX_VERTICES]Vertex,
vertex_count: int,
current_primitive: PrimitiveType,
}
init_batch :: proc() -> BatchRenderer {
batch: BatchRenderer
gl.GenVertexArrays(1, &batch.vao)
gl.BindVertexArray(batch.vao)
gl.GenBuffers(1, &batch.vbo)
gl.BindBuffer(gl.ARRAY_BUFFER, batch.vbo)
gl.VertexAttribPointer(0, 3, gl.FLOAT, gl.FALSE, size_of(Vertex), 0)
gl.EnableVertexAttribArray(0)
gl.VertexAttribPointer(1, 3, gl.FLOAT, gl.FALSE, size_of(Vertex), 3 * size_of(f32))
gl.EnableVertexAttribArray(1)
triangle_shader := gl.load_shaders_file(
"tutorial/triangle.vs",
"tutorial/triangle.fs",
)
batch.shader_program = triangle_shader
batch.current_primitive = .Triangles
gl.BindVertexArray(0)
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
return batch
}
Also I think I'm gonna stop using AI in general. I don't feel good about this code, I get what it's trying to do but I didn't get there of my own accord so it feels shallow in a way.
>>102054828
thanks for this but like I said, I'm pretty lost.