fix render bugs

This commit is contained in:
Liam Galvin 2018-08-31 20:01:27 +01:00
parent 88528fc6b0
commit 54c2aed4a5
2 changed files with 13 additions and 30 deletions

View File

@ -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()

View File

@ -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)