utils

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2025 License: MIT Imports: 3 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ptr

func Ptr(data interface{}) unsafe.Pointer

Ptr takes a slice or pointer (to a singular scalar value or the first element of an array or slice) and returns its GL-compatible address.

For example:

var data []uint8
...
gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))

func PtrToSlice added in v1.4.0

func PtrToSlice[T any](x *T, length int) []T

PtrToSlice in short is an equvalent to `unsafe.Slice(x, length)`. It allows to restore imgui data presented in form of a pointer to a Go slice. Reference issue: https://github.com/AllenDang/cimgui-go/issues/160#issuecomment-2768647950 Example usage:

Consider you have sortSpecs := imgui.TableGetSortSpecs()
Now, because sortSpecs is of type *imgui.TableSortSpecs, you can't directly convert it to the slice (this is NOT supposed to be slice - this is a pointer to the GO type).
You need to extract raw C pointer which is sortSpecs.CData.
After calling PtrToSLice(imgui.TableSortSpecs.CData, int(sortSpecs.Count)), you will need to call NewTableSortSpecsFromC on every element to get something useful.

func SliceToPtr

func SliceToPtr[T any](slice []T) *T

SliceToPtr takes a slice and returns its C-compatible pointer.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL