Beispiel #1
0
func CreateIndexBuffer(data []uint16) IndexBuffer {
	return IndexBuffer{
		h: C.bgfx_create_index_buffer(
			// to keep things simple for now, we'll just copy
			C.bgfx_copy(unsafe.Pointer(&data[0]), C.uint32_t(len(data)*2)),
		),
	}
}
Beispiel #2
0
func CreateShader(data []byte) Shader {
	return Shader{
		h: C.bgfx_create_shader(
			// to keep things simple for now, we'll just copy
			C.bgfx_copy(unsafe.Pointer(&data[0]), C.uint32_t(len(data))),
		),
	}
}
Beispiel #3
0
func CreateTexture(data []byte, flags TextureFlags, skip uint8) (Texture, TextureInfo) {
	var ti C.bgfx_texture_info_t
	h := C.bgfx_create_texture(
		C.bgfx_copy(unsafe.Pointer(&data[0]), C.uint32_t(len(data))),
		C.uint32_t(flags),
		C.uint8_t(skip),
		&ti,
	)
	return Texture{h: h}, newTextureInfo(ti)
}
Beispiel #4
0
func CreateVertexBuffer(slice interface{}, decl VertexDecl) VertexBuffer {
	val := reflect.ValueOf(slice)
	if val.Kind() != reflect.Slice {
		panic(errors.New("bgfx: expected slice"))
	}
	size := uintptr(val.Len()) * val.Type().Elem().Size()
	return VertexBuffer{
		h: C.bgfx_create_vertex_buffer(
			// to keep things simple for now, we'll just copy
			C.bgfx_copy(unsafe.Pointer(val.Pointer()), C.uint32_t(size)),
			&decl.decl,
		),
	}
}
Beispiel #5
0
func CreateTextureCube(size, numMips int, format TextureFormat, flags TextureFlags, data []byte) Texture {
	var mem *C.bgfx_memory_t
	if data != nil {
		mem = C.bgfx_copy(unsafe.Pointer(&data[0]), C.uint32_t(len(data)))
	}
	h := C.bgfx_create_texture_cube(
		C.uint16_t(size),
		C.uint8_t(numMips),
		C.bgfx_texture_format_t(format),
		C.uint32_t(flags),
		mem,
	)
	return Texture{h: h}
}
Beispiel #6
0
func CreateTexture3D(width, height, depth, numMips int, format TextureFormat, flags TextureFlags, data []byte) Texture {
	var mem *C.bgfx_memory_t
	if data != nil {
		mem = C.bgfx_copy(unsafe.Pointer(&data[0]), C.uint32_t(len(data)))
	}
	h := C.bgfx_create_texture_3d(
		C.uint16_t(width),
		C.uint16_t(height),
		C.uint16_t(depth),
		C.uint8_t(numMips),
		C.bgfx_texture_format_t(format),
		C.uint32_t(flags),
		mem,
	)
	return Texture{h: h}
}
Beispiel #7
0
func UpdateTextureCube(t Texture, side, mip, x, y, width, height int, data []byte, pitch int) {
	if pitch == 0 {
		pitch = 0xffff
	}
	C.bgfx_update_texture_cube(
		t.h,
		C.uint8_t(side),
		C.uint8_t(mip),
		C.uint16_t(x),
		C.uint16_t(y),
		C.uint16_t(width),
		C.uint16_t(height),
		// to keep things simple and safe, just copy for now
		C.bgfx_copy(
			unsafe.Pointer(&data[0]),
			C.uint32_t(len(data)),
		),
		C.uint16_t(pitch),
	)
}