gl01/internal/igwrap/imagewrap.go

79 lines
2.1 KiB
Go
Raw Normal View History

2022-02-10 19:58:51 +08:00
package igwrap
import (
"sync"
"edgaru089.ml/go/gl01/internal/util/itype"
"github.com/inkyblackness/imgui-go/v4"
)
// Image creates a ImGUI image based on the given texture.
// For *render.Texture, use tex.Handle().
//
// size is in pixels. texRange is in [0, 1].
func Image(tex uint32, size itype.Vec2f, texRange itype.Rectf) {
min, max := texRange.MinPoint(), texRange.MaxPoint()
imgui.ImageV(
imgui.TextureID(tex),
Vec2(size),
imgui.Vec2{X: min[0], Y: max[1]},
imgui.Vec2{X: max[0], Y: min[1]},
Color(255, 255, 255, 255),
imgui.Vec4{},
)
}
// ImageV creates a ImGUI image based on the given texture.
// For *render.Texture, use tex.Handle().
//
// size is in pixels. texRange is in [0, 1].
func ImageV(tex uint32, size itype.Vec2f, texRange itype.Rectf, texColor itype.Vec4f, borderColor itype.Vec4f) {
imgui.ImageV(
imgui.TextureID(tex),
Vec2(size),
Vec2(texRange.MinPoint()),
Vec2(texRange.MaxPoint()),
Vec4(texColor),
Vec4(borderColor),
)
}
type TextureFlag int
const (
TextureFlag_Red TextureFlag = 1 << iota // Renders the Red channel.
TextureFlag_Green // Renders the Green channel.
TextureFlag_Blue // Renders the Blue channel.
TextureFlag_Alpha // Renders the Alpha channel.
TextureFlag_Linear // Linear source data, requires gamma correction.
TextureFlag_ImGUIFont // This is a font texture from ImGUI, with a single red channel.
2022-02-10 19:58:51 +08:00
TextureFlag_RGB = TextureFlag_Red | TextureFlag_Green | TextureFlag_Blue
TextureFlag_RGBA = TextureFlag_Red | TextureFlag_Green | TextureFlag_Blue | TextureFlag_Alpha
)
var (
texflags map[uint32]TextureFlag = make(map[uint32]TextureFlag)
texflagslock sync.RWMutex
)
// SetTextureFlag changes the flag of a texture to the given flags combined.
func SetTextureFlag(tex uint32, flags ...TextureFlag) {
var f TextureFlag
for _, f0 := range flags {
f |= f0
}
texflagslock.Lock()
defer texflagslock.Unlock()
texflags[tex] = f
}
// TextureFlag returns the flags of a given texture.
func GetTextureFlag(tex uint32) TextureFlag {
texflagslock.RLock()
defer texflagslock.RUnlock()
return texflags[tex]
}