graphicscommand: Refactoring

This commit is contained in:
Hajime Hoshi 2019-06-25 23:18:00 +09:00
parent 09d473ea1b
commit 93c31654da
3 changed files with 22 additions and 30 deletions

View File

@ -17,7 +17,7 @@ package graphics
// minInternalImageSize is the minimum size of internal images (texture/framebuffer). // minInternalImageSize is the minimum size of internal images (texture/framebuffer).
// //
// For example, the image size less than 15 is not supported on some iOS devices. // For example, the image size less than 15 is not supported on some iOS devices.
// See also: https://stackoverflow.com/questions/15935651/certain-framebuffer-sizes-fail-on-ios-devices-gl-framebuffer-unsupported // See also: https://stackoverflow.com/questions/15935651
const minInternalImageSize = 16 const minInternalImageSize = 16
// InternalImageSize returns a nearest appropriate size as an internal image. // InternalImageSize returns a nearest appropriate size as an internal image.
@ -34,13 +34,3 @@ func InternalImageSize(x int) int {
} }
return r return r
} }
func isInternalImageSize(x int) bool {
if x <= 0 {
return false
}
if x < minInternalImageSize {
return false
}
return (x & (x - 1)) == 0
}

View File

@ -34,6 +34,8 @@ type Image struct {
image driver.Image image driver.Image
width int width int
height int height int
internalWidth int
internalHeight int
screen bool screen bool
lastCommand lastCommand lastCommand lastCommand
} }
@ -45,6 +47,8 @@ func NewImage(width, height int) *Image {
i := &Image{ i := &Image{
width: width, width: width,
height: height, height: height,
internalWidth: graphics.InternalImageSize(width),
internalHeight: graphics.InternalImageSize(height),
} }
c := &newImageCommand{ c := &newImageCommand{
result: i, result: i,
@ -59,6 +63,8 @@ func NewScreenFramebufferImage(width, height int) *Image {
i := &Image{ i := &Image{
width: width, width: width,
height: height, height: height,
internalWidth: graphics.InternalImageSize(width),
internalHeight: graphics.InternalImageSize(height),
screen: true, screen: true,
} }
c := &newScreenFramebufferImageCommand{ c := &newScreenFramebufferImageCommand{
@ -82,6 +88,10 @@ func (i *Image) Size() (int, int) {
return i.width, i.height return i.width, i.height
} }
func (i *Image) InternalSize() (int, int) {
return i.internalWidth, i.internalHeight
}
func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16, clr *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, address graphics.Address) { func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16, clr *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, address graphics.Address) {
if src.screen { if src.screen {
panic("graphicscommand: the screen image cannot be the rendering source") panic("graphicscommand: the screen image cannot be the rendering source")

View File

@ -108,9 +108,6 @@ type Image struct {
// screen indicates whether the image is used as an actual screen. // screen indicates whether the image is used as an actual screen.
screen bool screen bool
w2 int
h2 int
// priority indicates whether the image is restored in high priority when context-lost happens. // priority indicates whether the image is restored in high priority when context-lost happens.
priority bool priority bool
} }
@ -234,12 +231,7 @@ func (i *Image) Size() (int, int) {
// internalSize returns the size of the internal texture. // internalSize returns the size of the internal texture.
func (i *Image) internalSize() (int, int) { func (i *Image) internalSize() (int, int) {
if i.w2 == 0 || i.h2 == 0 { return i.image.InternalSize()
w, h := i.image.Size()
i.w2 = graphics.InternalImageSize(w)
i.h2 = graphics.InternalImageSize(h)
}
return i.w2, i.h2
} }
func (i *Image) PutVertex(vs []float32, dx, dy, sx, sy float32, bx0, by0, bx1, by1 float32, cr, cg, cb, ca float32) { func (i *Image) PutVertex(vs []float32, dx, dy, sx, sy float32, bx0, by0, bx1, by1 float32, cr, cg, cb, ca float32) {