imgui cleanup
This commit is contained in:
parent
90ce4409ce
commit
6c398bce8e
@ -21,6 +21,9 @@ var singleton struct {
|
||||
lastTime uint64
|
||||
fontTexture uint32
|
||||
context *imgui.Context
|
||||
|
||||
windowSize math.Vec2i
|
||||
bufferSize math.Vec2i
|
||||
}
|
||||
|
||||
func Init() error {
|
||||
@ -81,11 +84,14 @@ func Shutdown() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewFrame(windowSize math.Vec2i) error {
|
||||
func BeginFrame(windowSize, bufferSize math.Vec2i) error {
|
||||
if !singleton.isInit {
|
||||
return ErrWasNotInit
|
||||
}
|
||||
|
||||
singleton.windowSize = windowSize
|
||||
singleton.bufferSize = bufferSize
|
||||
|
||||
if singleton.fontTexture == 0 {
|
||||
singleton.fontTexture = createFontTexture()
|
||||
}
|
||||
@ -182,14 +188,16 @@ func ProcessEvent(event sdl.Event) (bool, error) {
|
||||
|
||||
// OpenGL2 Render function.
|
||||
// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL singleton 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 EndFrame() error {
|
||||
if !singleton.isInit {
|
||||
return ErrWasNotInit
|
||||
}
|
||||
|
||||
imgui.Render()
|
||||
drawData := imgui.RenderedDrawData()
|
||||
drawData.ScaleClipRects(imgui.Vec2{
|
||||
X: float32(fbSize.X) / float32(windowSize.X),
|
||||
Y: float32(fbSize.Y) / float32(windowSize.Y),
|
||||
X: float32(singleton.bufferSize.X) / float32(singleton.windowSize.X),
|
||||
Y: float32(singleton.bufferSize.Y) / float32(singleton.windowSize.Y),
|
||||
})
|
||||
|
||||
// We are using the OpenGL fixed pipeline to make the example code simpler to read!
|
||||
@ -221,11 +229,11 @@ func Render(windowSize, fbSize math.Vec2i, drawData imgui.DrawData) error {
|
||||
|
||||
// Setup viewport, orthographic projection matrix
|
||||
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayMin is typically (0,0) for single viewport apps.
|
||||
gl.Viewport(0, 0, int32(fbSize.X), int32(fbSize.Y))
|
||||
gl.Viewport(0, 0, int32(singleton.bufferSize.X), int32(singleton.bufferSize.Y))
|
||||
gl.MatrixMode(gl.PROJECTION)
|
||||
gl.PushMatrix()
|
||||
gl.LoadIdentity()
|
||||
gl.Ortho(0, float64(windowSize.X), float64(windowSize.Y), 0, -1, 1)
|
||||
gl.Ortho(0, float64(singleton.windowSize.X), float64(singleton.windowSize.Y), 0, -1, 1)
|
||||
gl.MatrixMode(gl.MODELVIEW)
|
||||
gl.PushMatrix()
|
||||
gl.LoadIdentity()
|
||||
@ -253,7 +261,7 @@ func Render(windowSize, fbSize math.Vec2i, drawData imgui.DrawData) error {
|
||||
command.CallUserCallback(commandList)
|
||||
} else {
|
||||
clipRect := command.ClipRect()
|
||||
gl.Scissor(int32(clipRect.X), int32(fbSize.Y)-int32(clipRect.W), int32(clipRect.Z-clipRect.X), int32(clipRect.W-clipRect.Y))
|
||||
gl.Scissor(int32(clipRect.X), int32(singleton.bufferSize.Y)-int32(clipRect.W), int32(clipRect.Z-clipRect.X), int32(clipRect.W-clipRect.Y))
|
||||
gl.BindTexture(gl.TEXTURE_2D, uint32(command.TextureID()))
|
||||
gl.DrawElements(gl.TRIANGLES, int32(command.ElementCount()), uint32(drawType), unsafe.Pointer(indexBufferOffset))
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package platform
|
||||
|
||||
import (
|
||||
imgui "github.com/FooSoft/imgui-go"
|
||||
"github.com/FooSoft/lazarus/math"
|
||||
"github.com/FooSoft/lazarus/platform/imgui_backend"
|
||||
"github.com/go-gl/gl/v2.1/gl"
|
||||
@ -94,22 +93,23 @@ func (w *Window) RenderTexture(texture *Texture, position math.Vec2i) {
|
||||
}
|
||||
|
||||
func (w *Window) advance() {
|
||||
size := w.displaySize()
|
||||
imgui_backend.NewFrame(size)
|
||||
w.sdlWindow.GLMakeCurrent(w.sdlGlContext)
|
||||
|
||||
gl.Viewport(0, 0, int32(size.X), int32(size.Y))
|
||||
displaySize := w.displaySize()
|
||||
bufferSize := w.bufferSize()
|
||||
imgui_backend.BeginFrame(displaySize, bufferSize)
|
||||
|
||||
gl.Viewport(0, 0, int32(displaySize.X), int32(displaySize.Y))
|
||||
gl.Clear(gl.COLOR_BUFFER_BIT)
|
||||
gl.MatrixMode(gl.PROJECTION)
|
||||
gl.LoadIdentity()
|
||||
gl.Ortho(0, float64(size.X), float64(size.Y), 0, -1, 1)
|
||||
gl.Ortho(0, float64(displaySize.X), float64(displaySize.Y), 0, -1, 1)
|
||||
gl.MatrixMode(gl.MODELVIEW)
|
||||
gl.LoadIdentity()
|
||||
|
||||
w.scene.Advance(w)
|
||||
|
||||
imgui.Render()
|
||||
imgui_backend.Render(w.displaySize(), w.bufferSize(), imgui.RenderedDrawData())
|
||||
|
||||
imgui_backend.EndFrame()
|
||||
w.sdlWindow.GLSwap()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user