From 54c2aed4a521cc7f6df34d7e18b77eb389d7c5fc Mon Sep 17 00:00:00 2001 From: Liam Galvin Date: Fri, 31 Aug 2018 20:01:27 +0100 Subject: [PATCH] fix render bugs --- gui/gui.go | 34 +++++++--------------------------- gui/renderer.go | 9 ++++++--- 2 files changed, 13 insertions(+), 30 deletions(-) diff --git a/gui/gui.go b/gui/gui.go index a99e288..eb4f30a 100644 --- a/gui/gui.go +++ b/gui/gui.go @@ -177,8 +177,6 @@ func (gui *GUI) Render() error { gl.Disable(gl.DEPTH_TEST) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST) - //glfw.SwapInterval(1) - gl.ClearColor( gui.config.ColourScheme.Background[0], gui.config.ColourScheme.Background[1], @@ -189,12 +187,9 @@ func (gui *GUI) Render() error { gui.terminal.AttachTitleChangeHandler(titleChan) gui.terminal.AttachDisplayChangeHandler(changeChan) - gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) - ticker := time.NewTicker(time.Second) defer ticker.Stop() - dirty := true defaultCell := buffer.NewBackgroundCell(gui.config.ColourScheme.Background) var lastCursorX uint @@ -202,6 +197,8 @@ func (gui *GUI) Render() error { for !gui.window.ShouldClose() { + dirty := false + select { case <-ticker.C: @@ -215,12 +212,9 @@ func (gui *GUI) Render() error { gl.UseProgram(program) - if dirty { - gui.window.SwapBuffers() - dirty = false - } + if dirty || gui.terminal.CheckDirty() { - if gui.terminal.CheckDirty() { + gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT) if gui.terminal.Modes().ShowCursor { cx := uint(gui.terminal.GetLogicalCursorX()) @@ -231,9 +225,6 @@ func (gui *GUI) Render() error { gui.renderState.SetDirty(lastCursorX, lastCursorY) dirty = true } - } else { - gui.renderState.SetDirty(lastCursorX, lastCursorY) - dirty = true } lines := gui.terminal.GetVisibleLines() @@ -244,7 +235,6 @@ func (gui *GUI) Render() error { for x := 0; x < int(colCount); x++ { cell := defaultCell - empty := true if y < len(lines) { cells := lines[y].Cells() @@ -253,14 +243,10 @@ func (gui *GUI) Render() error { if cell.Rune() == 0 { cell = defaultCell } - empty = false } } - if gui.renderState.RequiresRender(uint(x), uint(y), cell.Bg(), cell.Fg(), cell.Rune(), empty) { - gui.renderer.DrawCell(cell, uint(x), uint(y)) - dirty = true - } + gui.renderer.DrawCell(cell, uint(x), uint(y)) } } @@ -269,16 +255,10 @@ func (gui *GUI) Render() error { cx := uint(gui.terminal.GetLogicalCursorX()) cy := uint(gui.terminal.GetLogicalCursorY()) cy = cy + uint(gui.terminal.GetScrollOffset()) - - if lastCursorX != cx || lastCursorY != cy { - gui.renderer.DrawCursor(cx, cy, gui.config.ColourScheme.Cursor) - gui.renderState.SetDirty(lastCursorX, lastCursorY) - lastCursorX = cx - lastCursorY = cy - dirty = true - } + gui.renderer.DrawCursor(cx, cy, gui.config.ColourScheme.Cursor) } + gui.window.SwapBuffers() } //glfw.PollEvents() diff --git a/gui/renderer.go b/gui/renderer.go index 29da7d1..bd8eb91 100644 --- a/gui/renderer.go +++ b/gui/renderer.go @@ -66,6 +66,9 @@ func (r *OpenGLRenderer) newRectangle(x float32, y float32, colourAttr uint32) * colourAttr: colourAttr, prog: r.program, } + + gl.UseProgram(rect.prog) + // SHAPE gl.GenBuffers(1, &rect.vbo) gl.BindBuffer(gl.ARRAY_BUFFER, rect.vbo) @@ -158,6 +161,7 @@ func (r *OpenGLRenderer) SetFont(font *glfont.Font) { // @todo check for monospa r.termCols = uint(math.Floor(float64(float32(r.areaWidth) / r.cellWidth))) r.termRows = uint(math.Floor(float64(float32(r.areaHeight) / r.cellHeight))) r.calculatePositions() + r.rectangles = map[[2]uint]*rectangle{} } func (r *OpenGLRenderer) calculatePositions() { @@ -182,8 +186,6 @@ func (r *OpenGLRenderer) getRectangle(col uint, row uint) *rectangle { func (r *OpenGLRenderer) generateRectangle(col uint, line uint) *rectangle { - gl.UseProgram(r.program) - rect, ok := r.rectangles[[2]uint{col, line}] if ok { rect.Free() @@ -239,9 +241,10 @@ func (r *OpenGLRenderer) DrawCell(cell buffer.Cell, col uint, row uint) { panic(fmt.Sprintf("Missing position data for cell at %d,%d", col, row)) } - gl.UseProgram(r.program) rect := r.getRectangle(col, row) rect.setColour(bg) + + gl.UseProgram(r.program) gl.BindVertexArray(rect.vao) gl.DrawArrays(gl.TRIANGLES, 0, 6)