Procházet zdrojové kódy

Create OpenGL state when creating a window

Daniel Salvadori před 6 roky
rodič
revize
48abed3aa8
3 změnil soubory, kde provedl 21 přidání a 8 odebrání
  1. 2 7
      util/application/application.go
  2. 17 1
      window/glfw.go
  3. 2 0
      window/window.go

+ 2 - 7
util/application/application.go

@@ -161,13 +161,8 @@ func Create(ops Options) (*Application, error) {
 	}
 	win.SetPos(posx, posy)
 	app.win = win
+	app.gl = win.Gls()
 
-	// Create OpenGL state
-	gl, err := gls.New()
-	if err != nil {
-		return nil, err
-	}
-	app.gl = gl
 	// Checks OpenGL errors
 	app.gl.SetCheckErrors(!*app.noglErrors)
 
@@ -210,7 +205,7 @@ func Create(ops Options) (*Application, error) {
 	app.guiroot.SetColor(math32.NewColor("silver"))
 
 	// Creates renderer
-	app.renderer = renderer.NewRenderer(gl)
+	app.renderer = renderer.NewRenderer(app.gl)
 	err = app.renderer.AddDefaultShaders()
 	if err != nil {
 		return nil, fmt.Errorf("Error from AddDefaulShaders:%v", err)

+ 17 - 1
window/glfw.go

@@ -9,6 +9,7 @@ import (
 
 	"bytes"
 	"github.com/g3n/engine/core"
+	"github.com/g3n/engine/gls"
 	"github.com/g3n/engine/gui/assets"
 	"github.com/go-gl/glfw/v3.2/glfw"
 	"image"
@@ -223,6 +224,7 @@ type glfwManager struct {
 // glfwWindow describes one glfw window
 type glfwWindow struct {
 	core.Dispatcher              // Embedded event dispatcher
+	gls             *gls.GLS     // Associated OpenGL State
 	win             *glfw.Window // Pointer to native glfw window
 	mgr             *glfwManager // Pointer to window manager
 	fullScreen      bool
@@ -321,7 +323,7 @@ func (m *glfwManager) SetSwapInterval(interval int) {
 	glfw.SwapInterval(interval)
 }
 
-// Terminate destroys any remainding window, cursors and other related objects.
+// Terminate destroys any remaining window, cursors and other related objects.
 func (m *glfwManager) Terminate() {
 
 	glfw.Terminate()
@@ -486,9 +488,23 @@ func (m *glfwManager) CreateWindow(width, height int, title string, fullscreen b
 	if fullscreen {
 		w.SetFullScreen(true)
 	}
+
+	// Create OpenGL state
+	gl, err := gls.New()
+	if err != nil {
+		return nil, err
+	}
+	w.gls = gl
+
 	return w, nil
 }
 
+// Gls returns the associated OpenGL state
+func (w *glfwWindow) Gls() *gls.GLS {
+
+	return w.gls
+}
+
 // Manager returns the window manager and satisfies the IWindow interface
 func (w *glfwWindow) Manager() IWindowManager {
 

+ 2 - 0
window/window.go

@@ -8,6 +8,7 @@ package window
 
 import (
 	"github.com/g3n/engine/core"
+	"github.com/g3n/engine/gls"
 )
 
 // IWindowManager is the interface for all window managers
@@ -25,6 +26,7 @@ type IWindowManager interface {
 // IWindow is the interface for all windows
 type IWindow interface {
 	core.IDispatcher
+	Gls() *gls.GLS
 	Manager() IWindowManager
 	MakeContextCurrent()
 	FramebufferSize() (width int, height int)