opengl: SetViewport no longer returns error

This commit is contained in:
Hajime Hoshi 2017-09-25 00:17:07 +09:00
parent b590005c7a
commit d455b9b8bb
6 changed files with 14 additions and 22 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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