mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
3ae5a37c24
A recent change made the OpenGL functions an interface of the functions required for the implementation of GPU, a renderer for Gio operations. That allowed for running Gio on external systems where OpenGL is available. However, to allow for non-OpenGL flavored backends such as Vulkan, Metal and Direct3D, this change introduces Backend for the high-level operations required by GPU. This change also adds a concrete backend to package gl. Type Backend is a first cut heavily based on OpenGL. Future changes will add more backends, where the Backend interface quite possibly will need refinement. Signed-off-by: Elias Naur <mail@eliasnaur.com>
93 lines
1.3 KiB
Go
93 lines
1.3 KiB
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package gpu
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type timers struct {
|
|
backend Backend
|
|
timers []*timer
|
|
}
|
|
|
|
type timer struct {
|
|
Elapsed time.Duration
|
|
backend Backend
|
|
timer Timer
|
|
state timerState
|
|
}
|
|
|
|
type timerState uint8
|
|
|
|
const (
|
|
timerIdle timerState = iota
|
|
timerRunning
|
|
timerWaiting
|
|
)
|
|
|
|
func newTimers(b Backend) *timers {
|
|
return &timers{
|
|
backend: b,
|
|
}
|
|
}
|
|
|
|
func (t *timers) newTimer() *timer {
|
|
if t == nil {
|
|
return nil
|
|
}
|
|
tt := &timer{
|
|
backend: t.backend,
|
|
timer: t.backend.NewTimer(),
|
|
}
|
|
t.timers = append(t.timers, tt)
|
|
return tt
|
|
}
|
|
|
|
func (t *timer) begin() {
|
|
if t == nil || t.state != timerIdle {
|
|
return
|
|
}
|
|
t.timer.Begin()
|
|
t.state = timerRunning
|
|
}
|
|
|
|
func (t *timer) end() {
|
|
if t == nil || t.state != timerRunning {
|
|
return
|
|
}
|
|
t.timer.End()
|
|
t.state = timerWaiting
|
|
}
|
|
|
|
func (t *timers) ready() bool {
|
|
if t == nil {
|
|
return false
|
|
}
|
|
for _, tt := range t.timers {
|
|
switch tt.state {
|
|
case timerIdle:
|
|
continue
|
|
case timerRunning:
|
|
return false
|
|
}
|
|
d, ok := tt.timer.Duration()
|
|
if !ok {
|
|
return false
|
|
}
|
|
tt.state = timerIdle
|
|
tt.Elapsed = d
|
|
}
|
|
return t.backend.IsTimeContinuous()
|
|
}
|
|
|
|
func (t *timers) release() {
|
|
if t == nil {
|
|
return
|
|
}
|
|
for _, tt := range t.timers {
|
|
tt.timer.Release()
|
|
}
|
|
t.timers = nil
|
|
}
|