mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
opengl: Unexport NewTexture
This commit is contained in:
parent
bc7dd2f050
commit
531251d4ad
@ -19,7 +19,6 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
emath "github.com/hajimehoshi/ebiten/internal/math"
|
||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||
)
|
||||
|
||||
@ -407,36 +406,17 @@ type newImageCommand struct {
|
||||
height int
|
||||
}
|
||||
|
||||
func checkSize(width, height int) {
|
||||
if width < 1 {
|
||||
panic(fmt.Sprintf("graphics: width (%d) must be equal or more than 1.", width))
|
||||
}
|
||||
if height < 1 {
|
||||
panic(fmt.Sprintf("graphics: height (%d) must be equal or more than 1.", height))
|
||||
}
|
||||
m := MaxImageSize()
|
||||
if width > m {
|
||||
panic(fmt.Sprintf("graphics: width (%d) must be less than or equal to %d", width, m))
|
||||
}
|
||||
if height > m {
|
||||
panic(fmt.Sprintf("graphics: height (%d) must be less than or equal to %d", height, m))
|
||||
}
|
||||
}
|
||||
|
||||
func (c *newImageCommand) String() string {
|
||||
return fmt.Sprintf("new-image: result: %p, width: %d, height: %d", c.result, c.width, c.height)
|
||||
}
|
||||
|
||||
// Exec executes a newImageCommand.
|
||||
func (c *newImageCommand) Exec(indexOffsetInBytes int) error {
|
||||
w := emath.NextPowerOf2Int(c.width)
|
||||
h := emath.NextPowerOf2Int(c.height)
|
||||
checkSize(w, h)
|
||||
t, err := opengl.GetContext().NewTexture(w, h)
|
||||
i, err := opengl.NewImage(c.width, c.height)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.result.image.Texture = t
|
||||
c.result.image = i
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -471,11 +451,7 @@ func (c *newScreenFramebufferImageCommand) String() string {
|
||||
|
||||
// Exec executes a newScreenFramebufferImageCommand.
|
||||
func (c *newScreenFramebufferImageCommand) Exec(indexOffsetInBytes int) error {
|
||||
checkSize(c.width, c.height)
|
||||
// The (default) framebuffer size can't be converted to a power of 2.
|
||||
// On browsers, c.width and c.height are used as viewport size and
|
||||
// Edge can't treat a bigger viewport than the drawing area (#71).
|
||||
c.result.image.Framebuffer = opengl.NewScreenFramebuffer(c.width, c.height)
|
||||
c.result.image = opengl.NewScreenFramebufferImage(c.width, c.height)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -41,12 +41,15 @@ func MaxImageSize() int {
|
||||
|
||||
// Image represents an image that is implemented with OpenGL.
|
||||
type Image struct {
|
||||
image *opengl.Image
|
||||
image *opengl.Image
|
||||
width int
|
||||
height int
|
||||
}
|
||||
|
||||
func NewImage(width, height int) *Image {
|
||||
i := &Image{
|
||||
image: opengl.NewImage(width, height),
|
||||
width: width,
|
||||
height: height,
|
||||
}
|
||||
c := &newImageCommand{
|
||||
result: i,
|
||||
@ -59,7 +62,8 @@ func NewImage(width, height int) *Image {
|
||||
|
||||
func NewScreenFramebufferImage(width, height int) *Image {
|
||||
i := &Image{
|
||||
image: opengl.NewImage(width, height),
|
||||
width: width,
|
||||
height: height,
|
||||
}
|
||||
c := &newScreenFramebufferImageCommand{
|
||||
result: i,
|
||||
@ -78,7 +82,8 @@ func (i *Image) Dispose() {
|
||||
}
|
||||
|
||||
func (i *Image) Size() (int, int) {
|
||||
return i.image.Size()
|
||||
// i.image can be nil before initializing.
|
||||
return i.width, i.height
|
||||
}
|
||||
|
||||
func (i *Image) DrawImage(src *Image, vertices []float32, indices []uint16, clr *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter) {
|
||||
@ -112,5 +117,9 @@ func (i *Image) ReplacePixels(p []byte, x, y, width, height int) {
|
||||
}
|
||||
|
||||
func (i *Image) IsInvalidated() bool {
|
||||
// i.image can be nil before initializing.
|
||||
if i.image == nil {
|
||||
return false
|
||||
}
|
||||
return i.image.IsInvalidated()
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ func (c *Context) BlendFunc(mode graphics.CompositeMode) {
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Context) NewTexture(width, height int) (Texture, error) {
|
||||
func (c *Context) newTexture(width, height int) (Texture, error) {
|
||||
var texture Texture
|
||||
if err := c.runOnContextThread(func() error {
|
||||
var t uint32
|
||||
|
@ -173,7 +173,7 @@ func (c *Context) BlendFunc(mode graphics.CompositeMode) {
|
||||
gl.Call("blendFunc", int(s2), int(d2))
|
||||
}
|
||||
|
||||
func (c *Context) NewTexture(width, height int) (Texture, error) {
|
||||
func (c *Context) newTexture(width, height int) (Texture, error) {
|
||||
gl := c.gl
|
||||
t := gl.Call("createTexture")
|
||||
if t == js.Null() {
|
||||
|
@ -133,7 +133,7 @@ func (c *Context) BlendFunc(mode graphics.CompositeMode) {
|
||||
gl.BlendFunc(mgl.Enum(s2), mgl.Enum(d2))
|
||||
}
|
||||
|
||||
func (c *Context) NewTexture(width, height int) (Texture, error) {
|
||||
func (c *Context) newTexture(width, height int) (Texture, error) {
|
||||
gl := c.gl
|
||||
t := gl.CreateTexture()
|
||||
if t.Value <= 0 {
|
||||
|
@ -37,8 +37,8 @@ func newFramebufferFromTexture(texture Texture, width, height int) (*Framebuffer
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NewScreenFramebuffer creates a framebuffer for the screen.
|
||||
func NewScreenFramebuffer(width, height int) *Framebuffer {
|
||||
// newScreenFramebuffer creates a framebuffer for the screen.
|
||||
func newScreenFramebuffer(width, height int) *Framebuffer {
|
||||
return &Framebuffer{
|
||||
native: theContext.getScreenFramebuffer(),
|
||||
width: width,
|
||||
|
@ -15,9 +15,27 @@
|
||||
package opengl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/math"
|
||||
)
|
||||
|
||||
func checkSize(width, height int) {
|
||||
if width < 1 {
|
||||
panic(fmt.Sprintf("opengl: width (%d) must be equal or more than 1.", width))
|
||||
}
|
||||
if height < 1 {
|
||||
panic(fmt.Sprintf("opengl: height (%d) must be equal or more than 1.", height))
|
||||
}
|
||||
m := theContext.MaxTextureSize()
|
||||
if width > m {
|
||||
panic(fmt.Sprintf("opengl: width (%d) must be less than or equal to %d", width, m))
|
||||
}
|
||||
if height > m {
|
||||
panic(fmt.Sprintf("opengl: height (%d) must be less than or equal to %d", height, m))
|
||||
}
|
||||
}
|
||||
|
||||
type Image struct {
|
||||
Texture Texture
|
||||
Framebuffer *Framebuffer
|
||||
@ -25,11 +43,33 @@ type Image struct {
|
||||
height int
|
||||
}
|
||||
|
||||
func NewImage(width, height int) *Image {
|
||||
return &Image{
|
||||
func NewImage(width, height int) (*Image, error) {
|
||||
i := &Image{
|
||||
width: width,
|
||||
height: height,
|
||||
}
|
||||
w := math.NextPowerOf2Int(width)
|
||||
h := math.NextPowerOf2Int(height)
|
||||
checkSize(w, h)
|
||||
t, err := theContext.newTexture(w, h)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
i.Texture = t
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func NewScreenFramebufferImage(width, height int) *Image {
|
||||
checkSize(width, height)
|
||||
i := &Image{
|
||||
width: width,
|
||||
height: height,
|
||||
}
|
||||
// The (default) framebuffer size can't be converted to a power of 2.
|
||||
// On browsers, c.width and c.height are used as viewport size and
|
||||
// Edge can't treat a bigger viewport than the drawing area (#71).
|
||||
i.Framebuffer = newScreenFramebuffer(width, height)
|
||||
return i
|
||||
}
|
||||
|
||||
func (i *Image) Size() (int, int) {
|
||||
|
Loading…
Reference in New Issue
Block a user