internal/graphicsdriver/opengl: refactoring: rename variables

A framebuffer's width and height are unclear. Rename them to
viewportWidth and viewportHeight.
This commit is contained in:
Hajime Hoshi 2024-04-10 23:38:23 +09:00
parent f6927232f2
commit 3cf3b27729
2 changed files with 17 additions and 17 deletions

View File

@ -141,14 +141,14 @@ func (c *context) bindFramebuffer(f framebufferNative) {
func (c *context) setViewport(f *framebuffer) {
c.bindFramebuffer(f.native)
if c.lastViewportWidth == f.width && c.lastViewportHeight == f.height {
if c.lastViewportWidth == f.viewportWidth && c.lastViewportHeight == f.viewportHeight {
return
}
// On some environments, viewport size must be within the framebuffer size.
// e.g. Edge (#71), Chrome on GPD Pocket (#420), macOS Mojave (#691).
// Use the same size of the framebuffer here.
c.ctx.Viewport(0, 0, int32(f.width), int32(f.height))
c.ctx.Viewport(0, 0, int32(f.viewportWidth), int32(f.viewportHeight))
// glViewport must be called at least at every frame on iOS.
// As the screen framebuffer is the last render target, next SetViewport should be
@ -157,16 +157,16 @@ func (c *context) setViewport(f *framebuffer) {
c.lastViewportWidth = 0
c.lastViewportHeight = 0
} else {
c.lastViewportWidth = f.width
c.lastViewportHeight = f.height
c.lastViewportWidth = f.viewportWidth
c.lastViewportHeight = f.viewportHeight
}
}
func (c *context) newScreenFramebuffer(width, height int) *framebuffer {
return &framebuffer{
native: c.screenFramebuffer,
width: width,
height: height,
native: c.screenFramebuffer,
viewportWidth: width,
viewportHeight: height,
}
}
@ -346,9 +346,9 @@ func (c *context) newFramebuffer(texture textureNative, width, height int) (*fra
return nil, fmt.Errorf("opengl: creating framebuffer failed: unknown error")
}
return &framebuffer{
native: framebufferNative(f),
width: width,
height: height,
native: framebufferNative(f),
viewportWidth: width,
viewportHeight: height,
}, nil
}

View File

@ -37,10 +37,9 @@ type Image struct {
// framebuffer is a wrapper of OpenGL's framebuffer.
type framebuffer struct {
graphics *Graphics
native framebufferNative
width int
height int
native framebufferNative
viewportWidth int
viewportHeight int
}
func (i *Image) ID() graphicsdriver.ImageID {
@ -81,7 +80,7 @@ func (i *Image) ReadPixels(args []graphicsdriver.PixelsArgs) error {
return nil
}
func (i *Image) framebufferSize() (int, int) {
func (i *Image) viewportSize() (int, int) {
if i.screen {
// The (default) framebuffer size can't be converted to a power of 2.
// On browsers, i.width and i.height are used as viewport size and
@ -96,11 +95,12 @@ func (i *Image) ensureFramebuffer() error {
return nil
}
w, h := i.framebufferSize()
w, h := i.viewportSize()
if i.screen {
i.framebuffer = i.graphics.context.newScreenFramebuffer(w, h)
return nil
}
f, err := i.graphics.context.newFramebuffer(i.texture, w, h)
if err != nil {
return err
@ -118,7 +118,7 @@ func (i *Image) ensureStencilBuffer() error {
return err
}
r, err := i.graphics.context.newRenderbuffer(i.framebufferSize())
r, err := i.graphics.context.newRenderbuffer(i.viewportSize())
if err != nil {
return err
}