From d455b9b8bb38ae6f14f48083993973dee5f11239 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 25 Sep 2017 00:17:07 +0900 Subject: [PATCH] opengl: SetViewport no longer returns error --- internal/graphics/command.go | 15 ++++++--------- internal/graphics/framebuffer.go | 4 ++-- internal/opengl/context.go | 7 ++----- internal/opengl/context_desktop.go | 4 ++-- internal/opengl/context_js.go | 3 +-- internal/opengl/context_mobile.go | 3 +-- 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/internal/graphics/command.go b/internal/graphics/command.go index cc633c588..5949a4256 100644 --- a/internal/graphics/command.go +++ b/internal/graphics/command.go @@ -197,9 +197,8 @@ func (c *fillCommand) Exec(indexOffsetInBytes int) error { if err != nil { return err } - if err := f.setAsViewport(); err != nil { - return err - } + f.setAsViewport() + cr, cg, cb, ca := c.color.R, c.color.G, c.color.B, c.color.A const max = math.MaxUint8 r := float64(cr) / max @@ -235,9 +234,8 @@ func (c *drawImageCommand) Exec(indexOffsetInBytes int) error { if err != nil { return err } - if err := f.setAsViewport(); err != nil { - return err - } + f.setAsViewport() + opengl.GetContext().BlendFunc(c.mode) n := c.quadsNum() @@ -302,9 +300,8 @@ func (c *replacePixelsCommand) Exec(indexOffsetInBytes int) error { if err != nil { return err } - if err := f.setAsViewport(); err != nil { - return err - } + f.setAsViewport() + // Filling with non black or white color is required here for glTexSubImage2D. // Very mysterious but this actually works (Issue #186). // This is needed even after fixing a shader bug at f537378f2a6a8ef56e1acf1c03034967b77c7b51. diff --git a/internal/graphics/framebuffer.go b/internal/graphics/framebuffer.go index 2c3e0ef57..acd47631f 100644 --- a/internal/graphics/framebuffer.go +++ b/internal/graphics/framebuffer.go @@ -93,9 +93,9 @@ func (f *framebuffer) viewportSize() (int, int) { } // setAsViewport sets the framebuffer as the current viewport. -func (f *framebuffer) setAsViewport() error { +func (f *framebuffer) setAsViewport() { w, h := f.viewportSize() - return opengl.GetContext().SetViewport(f.native, w, h) + opengl.GetContext().SetViewport(f.native, w, h) } // projectionMatrix returns a projection matrix of the framebuffer. diff --git a/internal/opengl/context.go b/internal/opengl/context.go index 95fccba5b..5478f4a2b 100644 --- a/internal/opengl/context.go +++ b/internal/opengl/context.go @@ -69,16 +69,13 @@ func (c *Context) bindFramebuffer(f Framebuffer) { c.lastFramebuffer = f } -func (c *Context) SetViewport(f Framebuffer, width, height int) error { +func (c *Context) SetViewport(f Framebuffer, width, height int) { c.bindFramebuffer(f) if c.lastViewportWidth != width || c.lastViewportHeight != height { - if err := c.setViewportImpl(width, height); err != nil { - return nil - } + c.setViewportImpl(width, height) c.lastViewportWidth = width c.lastViewportHeight = height } - return nil } func (c *Context) ScreenFramebuffer() Framebuffer { diff --git a/internal/opengl/context_desktop.go b/internal/opengl/context_desktop.go index 8815d8231..16ea2923f 100644 --- a/internal/opengl/context_desktop.go +++ b/internal/opengl/context_desktop.go @@ -274,8 +274,8 @@ func (c *Context) NewFramebuffer(texture Texture) (Framebuffer, error) { return framebuffer, nil } -func (c *Context) setViewportImpl(width, height int) error { - return c.runOnContextThread(func() error { +func (c *Context) setViewportImpl(width, height int) { + _ = c.runOnContextThread(func() error { gl.Viewport(0, 0, int32(width), int32(height)) return nil }) diff --git a/internal/opengl/context_js.go b/internal/opengl/context_js.go index 764b657a5..d20573db2 100644 --- a/internal/opengl/context_js.go +++ b/internal/opengl/context_js.go @@ -254,10 +254,9 @@ func (c *Context) NewFramebuffer(t Texture) (Framebuffer, error) { return Framebuffer{f}, nil } -func (c *Context) setViewportImpl(width, height int) error { +func (c *Context) setViewportImpl(width, height int) { gl := c.gl gl.Viewport(0, 0, width, height) - return nil } func (c *Context) FillFramebuffer(r, g, b, a float64) error { diff --git a/internal/opengl/context_mobile.go b/internal/opengl/context_mobile.go index de5c9e532..96d2da0a5 100644 --- a/internal/opengl/context_mobile.go +++ b/internal/opengl/context_mobile.go @@ -215,10 +215,9 @@ func (c *Context) NewFramebuffer(texture Texture) (Framebuffer, error) { return Framebuffer(f), nil } -func (c *Context) setViewportImpl(width, height int) error { +func (c *Context) setViewportImpl(width, height int) { gl := c.gl gl.Viewport(0, 0, width, height) - return nil } func (c *Context) FillFramebuffer(r, g, b, a float64) error {