mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
graphics: Fix viewport sizes for Edge (#71)
This commit is contained in:
parent
da48712cf3
commit
d30f8a2bbf
@ -381,6 +381,8 @@ func (c *newScreenFramebufferImageCommand) Exec(indexOffsetInBytes int) error {
|
|||||||
f := &framebuffer{
|
f := &framebuffer{
|
||||||
native: opengl.GetContext().ScreenFramebuffer(),
|
native: opengl.GetContext().ScreenFramebuffer(),
|
||||||
flipY: true,
|
flipY: true,
|
||||||
|
width: c.width,
|
||||||
|
height: c.height,
|
||||||
offsetX: c.offsetX,
|
offsetX: c.offsetX,
|
||||||
offsetY: c.offsetY,
|
offsetY: c.offsetY,
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ package graphics
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||||
|
"github.com/hajimehoshi/ebiten/internal/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
func orthoProjectionMatrix(left, right, bottom, top int) []float32 {
|
func orthoProjectionMatrix(left, right, bottom, top int) []float32 {
|
||||||
@ -36,39 +37,50 @@ type framebuffer struct {
|
|||||||
native opengl.Framebuffer
|
native opengl.Framebuffer
|
||||||
flipY bool
|
flipY bool
|
||||||
proMatrix []float32
|
proMatrix []float32
|
||||||
|
width int
|
||||||
|
height int
|
||||||
offsetX float64
|
offsetX float64
|
||||||
offsetY float64
|
offsetY float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFramebufferFromTexture(texture *texture) (*framebuffer, error) {
|
func newFramebufferFromTexture(texture *texture, width, height int) (*framebuffer, error) {
|
||||||
native, err := opengl.GetContext().NewFramebuffer(opengl.Texture(texture.native))
|
native, err := opengl.GetContext().NewFramebuffer(opengl.Texture(texture.native))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &framebuffer{
|
return &framebuffer{
|
||||||
native: native,
|
native: native,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const viewportSize = 4096
|
const defaultViewportSize = 4096
|
||||||
|
|
||||||
|
func (f *framebuffer) viewportSize() (int, int) {
|
||||||
|
if web.IsEdgeBrowser() {
|
||||||
|
return f.width, f.height
|
||||||
|
}
|
||||||
|
return defaultViewportSize, defaultViewportSize
|
||||||
|
}
|
||||||
|
|
||||||
func (f *framebuffer) setAsViewport() error {
|
func (f *framebuffer) setAsViewport() error {
|
||||||
width := viewportSize
|
w, h := f.viewportSize()
|
||||||
height := viewportSize
|
return opengl.GetContext().SetViewport(f.native, w, h)
|
||||||
return opengl.GetContext().SetViewport(f.native, width, height)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *framebuffer) projectionMatrix(height int) []float32 {
|
func (f *framebuffer) projectionMatrix(height int) []float32 {
|
||||||
if f.proMatrix != nil {
|
if f.proMatrix != nil {
|
||||||
return f.proMatrix
|
return f.proMatrix
|
||||||
}
|
}
|
||||||
m := orthoProjectionMatrix(0, viewportSize, 0, viewportSize)
|
w, h := f.viewportSize()
|
||||||
|
m := orthoProjectionMatrix(0, w, 0, h)
|
||||||
if f.flipY {
|
if f.flipY {
|
||||||
m[4*1+1] *= -1
|
m[4*1+1] *= -1
|
||||||
m[4*3+1] += float32(height) / float32(viewportSize) * 2
|
m[4*3+1] += float32(height) / float32(h) * 2
|
||||||
}
|
}
|
||||||
m[4*3+0] += float32(f.offsetX) / float32(viewportSize) * 2
|
m[4*3+0] += float32(f.offsetX) / float32(w) * 2
|
||||||
m[4*3+1] += float32(f.offsetY) / float32(viewportSize) * 2
|
m[4*3+1] += float32(f.offsetY) / float32(h) * 2
|
||||||
f.proMatrix = m
|
f.proMatrix = m
|
||||||
return f.proMatrix
|
return f.proMatrix
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ type Image struct {
|
|||||||
height int
|
height int
|
||||||
}
|
}
|
||||||
|
|
||||||
const MaxImageSize = viewportSize
|
const MaxImageSize = defaultViewportSize
|
||||||
|
|
||||||
func NewImage(width, height int, filter opengl.Filter) *Image {
|
func NewImage(width, height int, filter opengl.Filter) *Image {
|
||||||
i := &Image{
|
i := &Image{
|
||||||
@ -132,7 +132,7 @@ func (i *Image) createFramebufferIfNeeded() (*framebuffer, error) {
|
|||||||
if i.framebuffer != nil {
|
if i.framebuffer != nil {
|
||||||
return i.framebuffer, nil
|
return i.framebuffer, nil
|
||||||
}
|
}
|
||||||
f, err := newFramebufferFromTexture(i.texture)
|
f, err := newFramebufferFromTexture(i.texture, math.NextPowerOf2Int(i.width), math.NextPowerOf2Int(i.height))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user