3dtrial/renderer1/raybuffer.go

47 lines
1.0 KiB
Go

package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
)
type RaylibBuffer struct {
Data []rl.Color
Width uint
Height uint
}
func NewRaylibBuffer(width uint, height uint) *RaylibBuffer {
return &RaylibBuffer{
Data: make([]rl.Color, width*height),
Width: width,
Height: height,
}
}
// Sure hope this gets inlined...
func (fb *RaylibBuffer) Set(x uint, y uint, r byte, g byte, b byte) {
if x >= fb.Width || y >= fb.Height {
return
}
fb.Data[x+y*fb.Width].R = r
fb.Data[x+y*fb.Width].G = g
fb.Data[x+y*fb.Width].B = b
}
func (fb *RaylibBuffer) Get(x uint, y uint) (byte, byte, byte) {
if x >= fb.Width || y >= fb.Height {
return 0, 0, 0
}
return fb.Data[x+y*fb.Width].R,
fb.Data[x+y*fb.Width].G,
fb.Data[x+y*fb.Width].B
}
func (fb *RaylibBuffer) GetUv(u float32, v float32) (byte, byte, byte) {
x := uint(float32(fb.Width)*u) & (fb.Width - 1)
y := uint(float32(fb.Height)*(1-v)) & (fb.Height - 1)
return fb.Data[x+y*fb.Width].R,
fb.Data[x+y*fb.Width].G,
fb.Data[x+y*fb.Width].B
}