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.Disable(gl.DEPTH_TEST)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
//glfw.SwapInterval(1)
gl.ClearColor( gl.ClearColor(
gui.config.ColourScheme.Background[0], gui.config.ColourScheme.Background[0],
gui.config.ColourScheme.Background[1], gui.config.ColourScheme.Background[1],
@ -189,12 +187,9 @@ func (gui *GUI) Render() error {
gui.terminal.AttachTitleChangeHandler(titleChan) gui.terminal.AttachTitleChangeHandler(titleChan)
gui.terminal.AttachDisplayChangeHandler(changeChan) gui.terminal.AttachDisplayChangeHandler(changeChan)
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
ticker := time.NewTicker(time.Second) ticker := time.NewTicker(time.Second)
defer ticker.Stop() defer ticker.Stop()
dirty := true
defaultCell := buffer.NewBackgroundCell(gui.config.ColourScheme.Background) defaultCell := buffer.NewBackgroundCell(gui.config.ColourScheme.Background)
var lastCursorX uint var lastCursorX uint
@ -202,6 +197,8 @@ func (gui *GUI) Render() error {
for !gui.window.ShouldClose() { for !gui.window.ShouldClose() {
dirty := false
select { select {
case <-ticker.C: case <-ticker.C:
@ -215,12 +212,9 @@ func (gui *GUI) Render() error {
gl.UseProgram(program) gl.UseProgram(program)
if dirty { if dirty || gui.terminal.CheckDirty() {
gui.window.SwapBuffers()
dirty = false
}
if gui.terminal.CheckDirty() { gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)
if gui.terminal.Modes().ShowCursor { if gui.terminal.Modes().ShowCursor {
cx := uint(gui.terminal.GetLogicalCursorX()) cx := uint(gui.terminal.GetLogicalCursorX())
@ -231,9 +225,6 @@ func (gui *GUI) Render() error {
gui.renderState.SetDirty(lastCursorX, lastCursorY) gui.renderState.SetDirty(lastCursorX, lastCursorY)
dirty = true dirty = true
} }
} else {
gui.renderState.SetDirty(lastCursorX, lastCursorY)
dirty = true
} }
lines := gui.terminal.GetVisibleLines() lines := gui.terminal.GetVisibleLines()
@ -244,7 +235,6 @@ func (gui *GUI) Render() error {
for x := 0; x < int(colCount); x++ { for x := 0; x < int(colCount); x++ {
cell := defaultCell cell := defaultCell
empty := true
if y < len(lines) { if y < len(lines) {
cells := lines[y].Cells() cells := lines[y].Cells()
@ -253,14 +243,10 @@ func (gui *GUI) Render() error {
if cell.Rune() == 0 { if cell.Rune() == 0 {
cell = defaultCell 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)) gui.renderer.DrawCell(cell, uint(x), uint(y))
dirty = true
}
} }
} }
@ -269,16 +255,10 @@ func (gui *GUI) Render() error {
cx := uint(gui.terminal.GetLogicalCursorX()) cx := uint(gui.terminal.GetLogicalCursorX())
cy := uint(gui.terminal.GetLogicalCursorY()) cy := uint(gui.terminal.GetLogicalCursorY())
cy = cy + uint(gui.terminal.GetScrollOffset()) cy = cy + uint(gui.terminal.GetScrollOffset())
if lastCursorX != cx || lastCursorY != cy {
gui.renderer.DrawCursor(cx, cy, gui.config.ColourScheme.Cursor) gui.renderer.DrawCursor(cx, cy, gui.config.ColourScheme.Cursor)
gui.renderState.SetDirty(lastCursorX, lastCursorY)
lastCursorX = cx
lastCursorY = cy
dirty = true
}
} }
gui.window.SwapBuffers()
} }
//glfw.PollEvents() //glfw.PollEvents()

View File

@ -66,6 +66,9 @@ func (r *OpenGLRenderer) newRectangle(x float32, y float32, colourAttr uint32) *
colourAttr: colourAttr, colourAttr: colourAttr,
prog: r.program, prog: r.program,
} }
gl.UseProgram(rect.prog)
// SHAPE // SHAPE
gl.GenBuffers(1, &rect.vbo) gl.GenBuffers(1, &rect.vbo)
gl.BindBuffer(gl.ARRAY_BUFFER, 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.termCols = uint(math.Floor(float64(float32(r.areaWidth) / r.cellWidth)))
r.termRows = uint(math.Floor(float64(float32(r.areaHeight) / r.cellHeight))) r.termRows = uint(math.Floor(float64(float32(r.areaHeight) / r.cellHeight)))
r.calculatePositions() r.calculatePositions()
r.rectangles = map[[2]uint]*rectangle{}
} }
func (r *OpenGLRenderer) calculatePositions() { 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 { func (r *OpenGLRenderer) generateRectangle(col uint, line uint) *rectangle {
gl.UseProgram(r.program)
rect, ok := r.rectangles[[2]uint{col, line}] rect, ok := r.rectangles[[2]uint{col, line}]
if ok { if ok {
rect.Free() 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)) panic(fmt.Sprintf("Missing position data for cell at %d,%d", col, row))
} }
gl.UseProgram(r.program)
rect := r.getRectangle(col, row) rect := r.getRectangle(col, row)
rect.setColour(bg) rect.setColour(bg)
gl.UseProgram(r.program)
gl.BindVertexArray(rect.vao) gl.BindVertexArray(rect.vao)
gl.DrawArrays(gl.TRIANGLES, 0, 6) gl.DrawArrays(gl.TRIANGLES, 0, 6)