create error constants, hookup imgui_backend init and shutdown
This commit is contained in:
parent
dd39ca8b8d
commit
6736cc5067
@ -18,9 +18,14 @@ var (
|
|||||||
imguiContext *imgui.Context
|
imguiContext *imgui.Context
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrAlreadyInit = errors.New("imgui backend is already initialized")
|
||||||
|
ErrWasNotInit = errors.New("imgui backend was not initialized")
|
||||||
|
)
|
||||||
|
|
||||||
func Init() error {
|
func Init() error {
|
||||||
if imguiIsInit {
|
if imguiIsInit {
|
||||||
return errors.New("imgui backend is already initialized")
|
return ErrAlreadyInit
|
||||||
}
|
}
|
||||||
|
|
||||||
imguiContext = imgui.CreateContext(nil)
|
imguiContext = imgui.CreateContext(nil)
|
||||||
@ -56,14 +61,14 @@ func Init() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
imguiFontTexture = createFontTexture()
|
imguiFontTexture = createFontTexture()
|
||||||
|
|
||||||
imguiIsInit = true
|
imguiIsInit = true
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Shutdown() error {
|
func Shutdown() error {
|
||||||
if !imguiIsInit {
|
if !imguiIsInit {
|
||||||
return errors.New("imgui backend was not initialized")
|
return ErrWasNotInit
|
||||||
}
|
}
|
||||||
|
|
||||||
imguiIsInit = false
|
imguiIsInit = false
|
||||||
@ -79,7 +84,7 @@ func Shutdown() error {
|
|||||||
|
|
||||||
func NewFrame(windowSize math.Vec2i) error {
|
func NewFrame(windowSize math.Vec2i) error {
|
||||||
if !imguiIsInit {
|
if !imguiIsInit {
|
||||||
return errors.New("imgui backend was not initialized")
|
return ErrWasNotInit
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup display size (every frame to accommodate for window resizing)
|
// Setup display size (every frame to accommodate for window resizing)
|
||||||
@ -116,7 +121,7 @@ func NewFrame(windowSize math.Vec2i) error {
|
|||||||
// If you have multiple SDL events and some of them are not meant to be used by dear imgui, you may need to filter events based on their windowID field.
|
// If you have multiple SDL events and some of them are not meant to be used by dear imgui, you may need to filter events based on their windowID field.
|
||||||
func ProcessEvent(event sdl.Event) (bool, error) {
|
func ProcessEvent(event sdl.Event) (bool, error) {
|
||||||
if !imguiIsInit {
|
if !imguiIsInit {
|
||||||
return false, errors.New("imgui backend was not initialized")
|
return false, ErrWasNotInit
|
||||||
}
|
}
|
||||||
|
|
||||||
switch io := imgui.CurrentIO(); event.GetType() {
|
switch io := imgui.CurrentIO(); event.GetType() {
|
||||||
@ -176,7 +181,7 @@ func ProcessEvent(event sdl.Event) (bool, error) {
|
|||||||
// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly, in order to be able to run within any OpenGL engine that doesn't do so.
|
// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly, in order to be able to run within any OpenGL engine that doesn't do so.
|
||||||
func Render(windowSize, fbSize math.Vec2i, drawData imgui.DrawData) error {
|
func Render(windowSize, fbSize math.Vec2i, drawData imgui.DrawData) error {
|
||||||
if !imguiIsInit {
|
if !imguiIsInit {
|
||||||
return errors.New("imgui backend was not initialized")
|
return ErrWasNotInit
|
||||||
}
|
}
|
||||||
|
|
||||||
drawData.ScaleClipRects(imgui.Vec2{
|
drawData.ScaleClipRects(imgui.Vec2{
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/FooSoft/lazarus/platform/imgui_backend"
|
||||||
"github.com/go-gl/gl/v2.1/gl"
|
"github.com/go-gl/gl/v2.1/gl"
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
)
|
)
|
||||||
@ -14,9 +15,14 @@ var (
|
|||||||
platformWindows []Window
|
platformWindows []Window
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrAlreadyInit = errors.New("platform is already initialized")
|
||||||
|
ErrWasNotInit = errors.New("platform was not initialized")
|
||||||
|
)
|
||||||
|
|
||||||
func Init() error {
|
func Init() error {
|
||||||
if platformIsInit {
|
if platformIsInit {
|
||||||
return errors.New("platform is already initialized")
|
return ErrAlreadyInit
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
@ -29,13 +35,38 @@ func Init() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := imgui_backend.Init(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
platformIsInit = true
|
platformIsInit = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Shutdown() error {
|
||||||
|
if !platformIsInit {
|
||||||
|
return ErrWasNotInit
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, w := range platformWindows {
|
||||||
|
if err := w.Destroy(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := imgui_backend.Shutdown(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
platformWindows = nil
|
||||||
|
platformIsInit = false
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func ProcessEvents() error {
|
func ProcessEvents() error {
|
||||||
if !platformIsInit {
|
if !platformIsInit {
|
||||||
return errors.New("platform was not initialized")
|
return ErrWasNotInit
|
||||||
}
|
}
|
||||||
|
|
||||||
var terminate bool
|
var terminate bool
|
||||||
@ -54,26 +85,9 @@ func ProcessEvents() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Shutdown() error {
|
|
||||||
if !platformIsInit {
|
|
||||||
return errors.New("platform was not initialized")
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, w := range platformWindows {
|
|
||||||
if err := w.Destroy(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
platformWindows = nil
|
|
||||||
platformIsInit = false
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func CreateWindow(title string, width, height int) (Window, error) {
|
func CreateWindow(title string, width, height int) (Window, error) {
|
||||||
if !platformIsInit {
|
if !platformIsInit {
|
||||||
return nil, errors.New("platform was not initialized")
|
return nil, ErrWasNotInit
|
||||||
}
|
}
|
||||||
|
|
||||||
window, err := newWindow(title, width, height)
|
window, err := newWindow(title, width, height)
|
||||||
|
Loading…
Reference in New Issue
Block a user