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).
//
// 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
// InternalImageSize returns a nearest appropriate size as an internal image.
@ -34,13 +34,3 @@ func InternalImageSize(x int) int {
}
return r
}
func isInternalImageSize(x int) bool {
if x <= 0 {
return false
}
if x < minInternalImageSize {
return false
}
return (x & (x - 1)) == 0
}

View File

@ -31,11 +31,13 @@ const (
// Image represents an image that is implemented with OpenGL.
type Image struct {
image driver.Image
width int
height int
screen bool
lastCommand lastCommand
image driver.Image
width int
height int
internalWidth int
internalHeight int
screen bool
lastCommand lastCommand
}
// NewImage returns a new image.
@ -43,8 +45,10 @@ type Image struct {
// Note that the image is not initialized yet.
func NewImage(width, height int) *Image {
i := &Image{
width: width,
height: height,
width: width,
height: height,
internalWidth: graphics.InternalImageSize(width),
internalHeight: graphics.InternalImageSize(height),
}
c := &newImageCommand{
result: i,
@ -57,9 +61,11 @@ func NewImage(width, height int) *Image {
func NewScreenFramebufferImage(width, height int) *Image {
i := &Image{
width: width,
height: height,
screen: true,
width: width,
height: height,
internalWidth: graphics.InternalImageSize(width),
internalHeight: graphics.InternalImageSize(height),
screen: true,
}
c := &newScreenFramebufferImageCommand{
result: i,
@ -82,6 +88,10 @@ func (i *Image) Size() (int, int) {
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) {
if src.screen {
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 bool
w2 int
h2 int
// priority indicates whether the image is restored in high priority when context-lost happens.
priority bool
}
@ -234,12 +231,7 @@ func (i *Image) Size() (int, int) {
// internalSize returns the size of the internal texture.
func (i *Image) internalSize() (int, int) {
if i.w2 == 0 || i.h2 == 0 {
w, h := i.image.Size()
i.w2 = graphics.InternalImageSize(w)
i.h2 = graphics.InternalImageSize(h)
}
return i.w2, i.h2
return i.image.InternalSize()
}
func (i *Image) PutVertex(vs []float32, dx, dy, sx, sy float32, bx0, by0, bx1, by1 float32, cr, cg, cb, ca float32) {