Tidy up opengl logging to prevent false bug reports (#176)

* add missing deps

* tidying
This commit is contained in:
Liam Galvin 2019-01-27 14:12:52 +00:00 committed by GitHub
parent a07ac1b469
commit 8cdbe2517d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 15 deletions

View File

@ -2,9 +2,9 @@ package gui
import ( import (
"fmt" "fmt"
"math"
"image" "image"
"image/png" "image/png"
"math"
"os" "os"
"os/exec" "os/exec"
"runtime" "runtime"
@ -13,6 +13,8 @@ import (
"sync" "sync"
"time" "time"
"unsafe"
"github.com/go-gl/gl/all-core/gl" "github.com/go-gl/gl/all-core/gl"
"github.com/go-gl/glfw/v3.2/glfw" "github.com/go-gl/glfw/v3.2/glfw"
"github.com/kbinani/screenshot" "github.com/kbinani/screenshot"
@ -21,7 +23,6 @@ import (
"github.com/liamg/aminal/terminal" "github.com/liamg/aminal/terminal"
"github.com/liamg/aminal/version" "github.com/liamg/aminal/version"
"go.uber.org/zap" "go.uber.org/zap"
"unsafe"
) )
type GUI struct { type GUI struct {
@ -131,7 +132,7 @@ func New(config *config.Config, terminal *terminal.Terminal, logger *zap.Sugared
logger: logger, logger: logger,
width: 800, width: 800,
height: 600, height: 600,
appliedWidth: 0, appliedWidth: 0,
appliedHeight: 0, appliedHeight: 0,
dpiScale: 1, dpiScale: 1,
terminal: terminal, terminal: terminal,
@ -250,8 +251,8 @@ func (gui *GUI) Render() error {
var err error var err error
gui.window, err = gui.createWindow() gui.window, err = gui.createWindow()
gui.RecalculateDpiScale() gui.RecalculateDpiScale()
gui.window.SetSize(int(float32(gui.width) * gui.dpiScale), gui.window.SetSize(int(float32(gui.width)*gui.dpiScale),
int(float32(gui.height) * gui.dpiScale)) int(float32(gui.height)*gui.dpiScale))
if err != nil { if err != nil {
return fmt.Errorf("Failed to create window: %s", err) return fmt.Errorf("Failed to create window: %s", err)
} }
@ -505,7 +506,7 @@ func (gui *GUI) redraw(defaultCell buffer.Cell) {
func (gui *GUI) createWindow() (*glfw.Window, error) { func (gui *GUI) createWindow() (*glfw.Window, error) {
if err := glfw.Init(); err != nil { if err := glfw.Init(); err != nil {
return nil, fmt.Errorf("Failed to initialise GLFW: %s", err) return nil, fmt.Errorf("failed to initialise GLFW: %s", err)
} }
glfw.WindowHint(glfw.Resizable, glfw.True) glfw.WindowHint(glfw.Resizable, glfw.True)
@ -529,9 +530,7 @@ func (gui *GUI) createWindow() (*glfw.Window, error) {
for _, v := range versions { for _, v := range versions {
var err error var err error
window, err = gui.createWindowWithOpenGLVersion(v[0], v[1]) window, err = gui.createWindowWithOpenGLVersion(v[0], v[1])
if err != nil { if err == nil {
gui.logger.Warnf("Failed to create window: %s. Will attempt older version...", err)
} else {
break break
} }
} }
@ -553,8 +552,8 @@ func (gui *GUI) createWindowWithOpenGLVersion(major int, minor int) (*glfw.Windo
glfw.WindowHint(glfw.ContextVersionMajor, major) glfw.WindowHint(glfw.ContextVersionMajor, major)
glfw.WindowHint(glfw.ContextVersionMinor, minor) glfw.WindowHint(glfw.ContextVersionMinor, minor)
window, err := glfw.CreateWindow(int(float32(gui.width) * gui.dpiScale), window, err := glfw.CreateWindow(int(float32(gui.width)*gui.dpiScale),
int(float32(gui.height) * gui.dpiScale), "Terminal", nil, nil) int(float32(gui.height)*gui.dpiScale), "Aminal", nil, nil)
if err != nil { if err != nil {
e := err.Error() e := err.Error()
if i := strings.Index(e, ", got version "); i > -1 { if i := strings.Index(e, ", got version "); i > -1 {
@ -569,7 +568,7 @@ func (gui *GUI) createWindowWithOpenGLVersion(major int, minor int) (*glfw.Windo
} }
} }
return nil, fmt.Errorf("Failed to create window using OpenGL v%d.%d: %s.", major, minor, err) return nil, fmt.Errorf("failed to create window using OpenGL v%d.%d: %s", major, minor, err)
} }
return window, nil return window, nil
@ -582,7 +581,7 @@ func (gui *GUI) onDebugMessage(source uint32, gltype uint32, id uint32, severity
// initOpenGL initializes OpenGL and returns an intiialized program. // initOpenGL initializes OpenGL and returns an intiialized program.
func (gui *GUI) createProgram() (uint32, error) { func (gui *GUI) createProgram() (uint32, error) {
if err := gl.Init(); err != nil { if err := gl.Init(); err != nil {
return 0, fmt.Errorf("Failed to initialise OpenGL: %s", err) return 0, fmt.Errorf("failed to initialise OpenGL: %s", err)
} }
gui.logger.Infof("OpenGL version %s", gl.GoStr(gl.GetString(gl.VERSION))) gui.logger.Infof("OpenGL version %s", gl.GoStr(gl.GetString(gl.VERSION)))
@ -640,8 +639,8 @@ func (gui *GUI) Screenshot(path string) {
x, y := gui.window.GetPos() x, y := gui.window.GetPos()
w, h := gui.window.GetSize() w, h := gui.window.GetSize()
img, err := screenshot.CaptureRect(image.Rectangle{ Min: image.Point{ X: x, Y: y }, img, err := screenshot.CaptureRect(image.Rectangle{Min: image.Point{X: x, Y: y},
Max: image.Point{ X: x + w, Y: y + h}}) Max: image.Point{X: x + w, Y: y + h}})
if err != nil { if err != nil {
panic(err) panic(err)
} }