mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-24 18:02:02 +01:00
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:
parent
f6927232f2
commit
3cf3b27729
@ -141,14 +141,14 @@ func (c *context) bindFramebuffer(f framebufferNative) {
|
|||||||
|
|
||||||
func (c *context) setViewport(f *framebuffer) {
|
func (c *context) setViewport(f *framebuffer) {
|
||||||
c.bindFramebuffer(f.native)
|
c.bindFramebuffer(f.native)
|
||||||
if c.lastViewportWidth == f.width && c.lastViewportHeight == f.height {
|
if c.lastViewportWidth == f.viewportWidth && c.lastViewportHeight == f.viewportHeight {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// On some environments, viewport size must be within the framebuffer size.
|
// On some environments, viewport size must be within the framebuffer size.
|
||||||
// e.g. Edge (#71), Chrome on GPD Pocket (#420), macOS Mojave (#691).
|
// e.g. Edge (#71), Chrome on GPD Pocket (#420), macOS Mojave (#691).
|
||||||
// Use the same size of the framebuffer here.
|
// 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.
|
// glViewport must be called at least at every frame on iOS.
|
||||||
// As the screen framebuffer is the last render target, next SetViewport should be
|
// 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.lastViewportWidth = 0
|
||||||
c.lastViewportHeight = 0
|
c.lastViewportHeight = 0
|
||||||
} else {
|
} else {
|
||||||
c.lastViewportWidth = f.width
|
c.lastViewportWidth = f.viewportWidth
|
||||||
c.lastViewportHeight = f.height
|
c.lastViewportHeight = f.viewportHeight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *context) newScreenFramebuffer(width, height int) *framebuffer {
|
func (c *context) newScreenFramebuffer(width, height int) *framebuffer {
|
||||||
return &framebuffer{
|
return &framebuffer{
|
||||||
native: c.screenFramebuffer,
|
native: c.screenFramebuffer,
|
||||||
width: width,
|
viewportWidth: width,
|
||||||
height: height,
|
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 nil, fmt.Errorf("opengl: creating framebuffer failed: unknown error")
|
||||||
}
|
}
|
||||||
return &framebuffer{
|
return &framebuffer{
|
||||||
native: framebufferNative(f),
|
native: framebufferNative(f),
|
||||||
width: width,
|
viewportWidth: width,
|
||||||
height: height,
|
viewportHeight: height,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,10 +37,9 @@ type Image struct {
|
|||||||
|
|
||||||
// framebuffer is a wrapper of OpenGL's framebuffer.
|
// framebuffer is a wrapper of OpenGL's framebuffer.
|
||||||
type framebuffer struct {
|
type framebuffer struct {
|
||||||
graphics *Graphics
|
native framebufferNative
|
||||||
native framebufferNative
|
viewportWidth int
|
||||||
width int
|
viewportHeight int
|
||||||
height int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) ID() graphicsdriver.ImageID {
|
func (i *Image) ID() graphicsdriver.ImageID {
|
||||||
@ -81,7 +80,7 @@ func (i *Image) ReadPixels(args []graphicsdriver.PixelsArgs) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) framebufferSize() (int, int) {
|
func (i *Image) viewportSize() (int, int) {
|
||||||
if i.screen {
|
if i.screen {
|
||||||
// The (default) framebuffer size can't be converted to a power of 2.
|
// 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
|
// On browsers, i.width and i.height are used as viewport size and
|
||||||
@ -96,11 +95,12 @@ func (i *Image) ensureFramebuffer() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
w, h := i.framebufferSize()
|
w, h := i.viewportSize()
|
||||||
if i.screen {
|
if i.screen {
|
||||||
i.framebuffer = i.graphics.context.newScreenFramebuffer(w, h)
|
i.framebuffer = i.graphics.context.newScreenFramebuffer(w, h)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := i.graphics.context.newFramebuffer(i.texture, w, h)
|
f, err := i.graphics.context.newFramebuffer(i.texture, w, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -118,7 +118,7 @@ func (i *Image) ensureStencilBuffer() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := i.graphics.context.newRenderbuffer(i.framebufferSize())
|
r, err := i.graphics.context.newRenderbuffer(i.viewportSize())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user