mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +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/affine"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||||
emath "github.com/hajimehoshi/ebiten/internal/math"
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -407,36 +406,17 @@ type newImageCommand struct {
|
|||||||
height int
|
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 {
|
func (c *newImageCommand) String() string {
|
||||||
return fmt.Sprintf("new-image: result: %p, width: %d, height: %d", c.result, c.width, c.height)
|
return fmt.Sprintf("new-image: result: %p, width: %d, height: %d", c.result, c.width, c.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exec executes a newImageCommand.
|
// Exec executes a newImageCommand.
|
||||||
func (c *newImageCommand) Exec(indexOffsetInBytes int) error {
|
func (c *newImageCommand) Exec(indexOffsetInBytes int) error {
|
||||||
w := emath.NextPowerOf2Int(c.width)
|
i, err := opengl.NewImage(c.width, c.height)
|
||||||
h := emath.NextPowerOf2Int(c.height)
|
|
||||||
checkSize(w, h)
|
|
||||||
t, err := opengl.GetContext().NewTexture(w, h)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.result.image.Texture = t
|
c.result.image = i
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,11 +451,7 @@ func (c *newScreenFramebufferImageCommand) String() string {
|
|||||||
|
|
||||||
// Exec executes a newScreenFramebufferImageCommand.
|
// Exec executes a newScreenFramebufferImageCommand.
|
||||||
func (c *newScreenFramebufferImageCommand) Exec(indexOffsetInBytes int) error {
|
func (c *newScreenFramebufferImageCommand) Exec(indexOffsetInBytes int) error {
|
||||||
checkSize(c.width, c.height)
|
c.result.image = opengl.NewScreenFramebufferImage(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)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,11 +42,14 @@ func MaxImageSize() int {
|
|||||||
// Image represents an image that is implemented with OpenGL.
|
// Image represents an image that is implemented with OpenGL.
|
||||||
type Image struct {
|
type Image struct {
|
||||||
image *opengl.Image
|
image *opengl.Image
|
||||||
|
width int
|
||||||
|
height int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewImage(width, height int) *Image {
|
func NewImage(width, height int) *Image {
|
||||||
i := &Image{
|
i := &Image{
|
||||||
image: opengl.NewImage(width, height),
|
width: width,
|
||||||
|
height: height,
|
||||||
}
|
}
|
||||||
c := &newImageCommand{
|
c := &newImageCommand{
|
||||||
result: i,
|
result: i,
|
||||||
@ -59,7 +62,8 @@ func NewImage(width, height int) *Image {
|
|||||||
|
|
||||||
func NewScreenFramebufferImage(width, height int) *Image {
|
func NewScreenFramebufferImage(width, height int) *Image {
|
||||||
i := &Image{
|
i := &Image{
|
||||||
image: opengl.NewImage(width, height),
|
width: width,
|
||||||
|
height: height,
|
||||||
}
|
}
|
||||||
c := &newScreenFramebufferImageCommand{
|
c := &newScreenFramebufferImageCommand{
|
||||||
result: i,
|
result: i,
|
||||||
@ -78,7 +82,8 @@ func (i *Image) Dispose() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) Size() (int, int) {
|
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) {
|
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 {
|
func (i *Image) IsInvalidated() bool {
|
||||||
|
// i.image can be nil before initializing.
|
||||||
|
if i.image == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return i.image.IsInvalidated()
|
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
|
var texture Texture
|
||||||
if err := c.runOnContextThread(func() error {
|
if err := c.runOnContextThread(func() error {
|
||||||
var t uint32
|
var t uint32
|
||||||
|
@ -173,7 +173,7 @@ func (c *Context) BlendFunc(mode graphics.CompositeMode) {
|
|||||||
gl.Call("blendFunc", int(s2), int(d2))
|
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
|
gl := c.gl
|
||||||
t := gl.Call("createTexture")
|
t := gl.Call("createTexture")
|
||||||
if t == js.Null() {
|
if t == js.Null() {
|
||||||
|
@ -133,7 +133,7 @@ func (c *Context) BlendFunc(mode graphics.CompositeMode) {
|
|||||||
gl.BlendFunc(mgl.Enum(s2), mgl.Enum(d2))
|
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
|
gl := c.gl
|
||||||
t := gl.CreateTexture()
|
t := gl.CreateTexture()
|
||||||
if t.Value <= 0 {
|
if t.Value <= 0 {
|
||||||
|
@ -37,8 +37,8 @@ func newFramebufferFromTexture(texture Texture, width, height int) (*Framebuffer
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewScreenFramebuffer creates a framebuffer for the screen.
|
// newScreenFramebuffer creates a framebuffer for the screen.
|
||||||
func NewScreenFramebuffer(width, height int) *Framebuffer {
|
func newScreenFramebuffer(width, height int) *Framebuffer {
|
||||||
return &Framebuffer{
|
return &Framebuffer{
|
||||||
native: theContext.getScreenFramebuffer(),
|
native: theContext.getScreenFramebuffer(),
|
||||||
width: width,
|
width: width,
|
||||||
|
@ -15,9 +15,27 @@
|
|||||||
package opengl
|
package opengl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/math"
|
"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 {
|
type Image struct {
|
||||||
Texture Texture
|
Texture Texture
|
||||||
Framebuffer *Framebuffer
|
Framebuffer *Framebuffer
|
||||||
@ -25,11 +43,33 @@ type Image struct {
|
|||||||
height int
|
height int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewImage(width, height int) *Image {
|
func NewImage(width, height int) (*Image, error) {
|
||||||
return &Image{
|
i := &Image{
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
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) {
|
func (i *Image) Size() (int, int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user