Having some trouble understanding multi pointers

I have done some C programming and I’m currently writing a very simple game engine with odin and sdl3 primarily to learn more. pigeon-collective/pax: A simple game engine built using Odin & SDL3 - Codeberg.org

Im just getting started and I’ve run into an area where I don’t think I have an understanding of whats happening. The context of this code is that I am creating an sdl3 graphics pipeline and describing the vertex attributes inside the vertex buffer.

	// a_position
	vertex_attributes: [^]sdl3.GPUVertexAttribute = make([^]sdl3.GPUVertexAttribute, 2)
	vertex_attributes[0] = sdl3.GPUVertexAttribute{}
	vertex_attributes[0].buffer_slot = 0
	vertex_attributes[0].location = 0
	vertex_attributes[0].format = .FLOAT3
	vertex_attributes[0].offset = 0

	// a_color
	vertex_attributes[1] = sdl3.GPUVertexAttribute{}
	vertex_attributes[1].buffer_slot = 0
	vertex_attributes[1].location = 1
	vertex_attributes[1].format = .FLOAT4
	vertex_attributes[1].offset = size_of(f32) * 3

	// Tell the pipeline (vertex input state) everything we know about our vertex attributes
	pipeline_info.vertex_input_state.num_vertex_attributes = 2
	pipeline_info.vertex_input_state.vertex_attributes = vertex_attributes

This vertex_attributes variable is of type
vertex_attributes: [^]sdl3.GPUVertexAttribute

Looking at the odin docs, this is a multi pointer type, which is something designed to be similar to a C array pointer. The trouble I’m having is that I’d really like to avoid heap allocating this variable as such

	vertex_attributes: [^]sdl3.GPUVertexAttribute = make([^]sdl3.GPUVertexAttribute, 2)

The option I have would be to make this an odin array literal, ie

	vertex_attributes: [2]sdl3.GPUVertexAttribute = {}

But then in order to set this on my pipeline, the pipeline object expects the multi pointer type.

	pipeline_info.vertex_input_state.vertex_attributes = vertex_attributes

Here pipeline_info.vertex_input_state.vertex_attributes is a multi pointer. Is there an easy way to convert between these so I don’t have to heap allocate with a make() call? Ideally I’d like a stack allocated static array. I’m new to odin, so apologies if I’m missing something obvious :slight_smile: Thanks in advance for any help

Given vertex_attributes: [2]sdl3.GPUVertexAttribute, the raw_data builtin can get you a multi-pointer from an array with raw_data(&vertex_attributes), or a regular pointer will also implicitly convert to a multi-pointer so &vertex_attributes[0] would work too.

1 Like

Just set up the pipeline this way and it works! I tried the raw_data function prior, but I was doingraw_data(vertex_attributes) instead of raw_data(&vertex_attributes). Cheers, thank you! @Barinzaya