mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
opengl: Unexport Texture
This commit is contained in:
parent
786b349579
commit
7bbc32ce0e
@ -66,7 +66,7 @@ type Context struct {
|
||||
locationCache *locationCache
|
||||
screenFramebuffer framebufferNative // This might not be the default frame buffer '0' (e.g. iOS).
|
||||
lastFramebuffer framebufferNative
|
||||
lastTexture Texture
|
||||
lastTexture textureNative
|
||||
lastViewportWidth int
|
||||
lastViewportHeight int
|
||||
lastCompositeMode graphics.CompositeMode
|
||||
@ -80,7 +80,7 @@ func GetContext() *Context {
|
||||
return theContext
|
||||
}
|
||||
|
||||
func (c *Context) bindTexture(t Texture) {
|
||||
func (c *Context) bindTexture(t textureNative) {
|
||||
if c.lastTexture == t {
|
||||
return
|
||||
}
|
||||
|
@ -29,14 +29,14 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
Texture uint32
|
||||
textureNative uint32
|
||||
framebufferNative uint32
|
||||
shader uint32
|
||||
program uint32
|
||||
buffer uint32
|
||||
)
|
||||
|
||||
var InvalidTexture Texture
|
||||
var InvalidTexture textureNative
|
||||
|
||||
type (
|
||||
uniformLocation int32
|
||||
@ -135,8 +135,8 @@ func (c *Context) BlendFunc(mode graphics.CompositeMode) {
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Context) newTexture(width, height int) (Texture, error) {
|
||||
var texture Texture
|
||||
func (c *Context) newTexture(width, height int) (textureNative, error) {
|
||||
var texture textureNative
|
||||
if err := c.runOnContextThread(func() error {
|
||||
var t uint32
|
||||
gl.GenTextures(1, &t)
|
||||
@ -145,7 +145,7 @@ func (c *Context) newTexture(width, height int) (Texture, error) {
|
||||
return errors.New("opengl: creating texture failed")
|
||||
}
|
||||
gl.PixelStorei(gl.UNPACK_ALIGNMENT, 4)
|
||||
texture = Texture(t)
|
||||
texture = textureNative(t)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return 0, err
|
||||
@ -190,14 +190,14 @@ func (c *Context) framebufferPixels(f *Framebuffer, width, height int) ([]byte,
|
||||
return pixels, nil
|
||||
}
|
||||
|
||||
func (c *Context) bindTextureImpl(t Texture) {
|
||||
func (c *Context) bindTextureImpl(t textureNative) {
|
||||
_ = c.runOnContextThread(func() error {
|
||||
gl.BindTexture(gl.TEXTURE_2D, uint32(t))
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Context) deleteTexture(t Texture) {
|
||||
func (c *Context) deleteTexture(t textureNative) {
|
||||
_ = c.runOnContextThread(func() error {
|
||||
tt := uint32(t)
|
||||
if !gl.IsTexture(tt) {
|
||||
@ -211,7 +211,7 @@ func (c *Context) deleteTexture(t Texture) {
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Context) isTexture(t Texture) bool {
|
||||
func (c *Context) isTexture(t textureNative) bool {
|
||||
r := false
|
||||
_ = c.runOnContextThread(func() error {
|
||||
r = gl.IsTexture(uint32(t))
|
||||
@ -220,7 +220,7 @@ func (c *Context) isTexture(t Texture) bool {
|
||||
return r
|
||||
}
|
||||
|
||||
func (c *Context) texSubImage2D(t Texture, p []byte, x, y, width, height int) {
|
||||
func (c *Context) texSubImage2D(t textureNative, p []byte, x, y, width, height int) {
|
||||
c.bindTexture(t)
|
||||
_ = c.runOnContextThread(func() error {
|
||||
gl.TexSubImage2D(gl.TEXTURE_2D, 0, int32(x), int32(y), int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(p))
|
||||
@ -232,7 +232,7 @@ func (c *Context) BeforeSwapping() {
|
||||
c.bindFramebuffer(c.screenFramebuffer)
|
||||
}
|
||||
|
||||
func (c *Context) newFramebuffer(texture Texture) (framebufferNative, error) {
|
||||
func (c *Context) newFramebuffer(texture textureNative) (framebufferNative, error) {
|
||||
var framebuffer framebufferNative
|
||||
var f uint32
|
||||
if err := c.runOnContextThread(func() error {
|
||||
|
@ -26,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
Texture js.Value
|
||||
textureNative js.Value
|
||||
framebufferNative js.Value
|
||||
shader js.Value
|
||||
buffer js.Value
|
||||
@ -40,7 +40,7 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
var InvalidTexture = Texture(js.Null())
|
||||
var InvalidTexture = textureNative(js.Null())
|
||||
|
||||
func getProgramID(p program) programID {
|
||||
return p.id
|
||||
@ -149,7 +149,7 @@ func Init() error {
|
||||
|
||||
func (c *Context) reset() error {
|
||||
c.locationCache = newLocationCache()
|
||||
c.lastTexture = Texture(js.Null())
|
||||
c.lastTexture = textureNative(js.Null())
|
||||
c.lastFramebuffer = framebufferNative(js.Null())
|
||||
c.lastViewportWidth = 0
|
||||
c.lastViewportHeight = 0
|
||||
@ -173,14 +173,14 @@ 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) (textureNative, error) {
|
||||
gl := c.gl
|
||||
t := gl.Call("createTexture")
|
||||
if t == js.Null() {
|
||||
return Texture(js.Null()), errors.New("opengl: glGenTexture failed")
|
||||
return textureNative(js.Null()), errors.New("opengl: glGenTexture failed")
|
||||
}
|
||||
gl.Call("pixelStorei", unpackAlignment, 4)
|
||||
c.bindTexture(Texture(t))
|
||||
c.bindTexture(textureNative(t))
|
||||
|
||||
gl.Call("texParameteri", texture2d, textureMagFilter, nearest)
|
||||
gl.Call("texParameteri", texture2d, textureMinFilter, nearest)
|
||||
@ -196,7 +196,7 @@ func (c *Context) newTexture(width, height int) (Texture, error) {
|
||||
// avoided.
|
||||
gl.Call("texImage2D", texture2d, 0, rgba, width, height, 0, rgba, unsignedByte, nil)
|
||||
|
||||
return Texture(t), nil
|
||||
return textureNative(t), nil
|
||||
}
|
||||
|
||||
func (c *Context) bindFramebufferImpl(f framebufferNative) {
|
||||
@ -220,28 +220,28 @@ func (c *Context) framebufferPixels(f *Framebuffer, width, height int) ([]byte,
|
||||
return pixels, nil
|
||||
}
|
||||
|
||||
func (c *Context) bindTextureImpl(t Texture) {
|
||||
func (c *Context) bindTextureImpl(t textureNative) {
|
||||
gl := c.gl
|
||||
gl.Call("bindTexture", texture2d, js.Value(t))
|
||||
}
|
||||
|
||||
func (c *Context) deleteTexture(t Texture) {
|
||||
func (c *Context) deleteTexture(t textureNative) {
|
||||
gl := c.gl
|
||||
if !gl.Call("isTexture", js.Value(t)).Bool() {
|
||||
return
|
||||
}
|
||||
if c.lastTexture == t {
|
||||
c.lastTexture = Texture(js.Null())
|
||||
c.lastTexture = textureNative(js.Null())
|
||||
}
|
||||
gl.Call("deleteTexture", js.Value(t))
|
||||
}
|
||||
|
||||
func (c *Context) isTexture(t Texture) bool {
|
||||
func (c *Context) isTexture(t textureNative) bool {
|
||||
gl := c.gl
|
||||
return gl.Call("isTexture", js.Value(t)).Bool()
|
||||
}
|
||||
|
||||
func (c *Context) texSubImage2D(t Texture, pixels []byte, x, y, width, height int) {
|
||||
func (c *Context) texSubImage2D(t textureNative, pixels []byte, x, y, width, height int) {
|
||||
c.bindTexture(t)
|
||||
gl := c.gl
|
||||
// void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
|
||||
@ -252,7 +252,7 @@ func (c *Context) texSubImage2D(t Texture, pixels []byte, x, y, width, height in
|
||||
p.Release()
|
||||
}
|
||||
|
||||
func (c *Context) newFramebuffer(t Texture) (framebufferNative, error) {
|
||||
func (c *Context) newFramebuffer(t textureNative) (framebufferNative, error) {
|
||||
gl := c.gl
|
||||
f := gl.Call("createFramebuffer")
|
||||
c.bindFramebuffer(framebufferNative(f))
|
||||
|
@ -26,14 +26,14 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
Texture mgl.Texture
|
||||
textureNative mgl.Texture
|
||||
framebufferNative mgl.Framebuffer
|
||||
shader mgl.Shader
|
||||
program mgl.Program
|
||||
buffer mgl.Buffer
|
||||
)
|
||||
|
||||
var InvalidTexture Texture
|
||||
var InvalidTexture textureNative
|
||||
|
||||
type (
|
||||
uniformLocation mgl.Uniform
|
||||
@ -43,7 +43,7 @@ type (
|
||||
type programID uint32
|
||||
|
||||
var (
|
||||
invalidTexture = Texture(mgl.Texture{})
|
||||
invalidTexture = textureNative(mgl.Texture{})
|
||||
invalidFramebuffer = framebufferNative(mgl.Framebuffer{(1 << 32) - 1})
|
||||
)
|
||||
|
||||
@ -133,14 +133,14 @@ 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) (textureNative, error) {
|
||||
gl := c.gl
|
||||
t := gl.CreateTexture()
|
||||
if t.Value <= 0 {
|
||||
return Texture{}, errors.New("opengl: creating texture failed")
|
||||
return textureNative{}, errors.New("opengl: creating texture failed")
|
||||
}
|
||||
gl.PixelStorei(mgl.UNPACK_ALIGNMENT, 4)
|
||||
c.bindTexture(Texture(t))
|
||||
c.bindTexture(textureNative(t))
|
||||
|
||||
gl.TexParameteri(mgl.TEXTURE_2D, mgl.TEXTURE_MAG_FILTER, mgl.NEAREST)
|
||||
gl.TexParameteri(mgl.TEXTURE_2D, mgl.TEXTURE_MIN_FILTER, mgl.NEAREST)
|
||||
@ -148,7 +148,7 @@ func (c *Context) newTexture(width, height int) (Texture, error) {
|
||||
gl.TexParameteri(mgl.TEXTURE_2D, mgl.TEXTURE_WRAP_T, mgl.CLAMP_TO_EDGE)
|
||||
gl.TexImage2D(mgl.TEXTURE_2D, 0, mgl.RGBA, width, height, mgl.RGBA, mgl.UNSIGNED_BYTE, nil)
|
||||
|
||||
return Texture(t), nil
|
||||
return textureNative(t), nil
|
||||
}
|
||||
|
||||
func (c *Context) bindFramebufferImpl(f framebufferNative) {
|
||||
@ -170,12 +170,12 @@ func (c *Context) framebufferPixels(f *Framebuffer, width, height int) ([]byte,
|
||||
return pixels, nil
|
||||
}
|
||||
|
||||
func (c *Context) bindTextureImpl(t Texture) {
|
||||
func (c *Context) bindTextureImpl(t textureNative) {
|
||||
gl := c.gl
|
||||
gl.BindTexture(mgl.TEXTURE_2D, mgl.Texture(t))
|
||||
}
|
||||
|
||||
func (c *Context) deleteTexture(t Texture) {
|
||||
func (c *Context) deleteTexture(t textureNative) {
|
||||
gl := c.gl
|
||||
if !gl.IsTexture(mgl.Texture(t)) {
|
||||
return
|
||||
@ -186,18 +186,18 @@ func (c *Context) deleteTexture(t Texture) {
|
||||
gl.DeleteTexture(mgl.Texture(t))
|
||||
}
|
||||
|
||||
func (c *Context) isTexture(t Texture) bool {
|
||||
func (c *Context) isTexture(t textureNative) bool {
|
||||
gl := c.gl
|
||||
return gl.IsTexture(mgl.Texture(t))
|
||||
}
|
||||
|
||||
func (c *Context) texSubImage2D(t Texture, p []byte, x, y, width, height int) {
|
||||
func (c *Context) texSubImage2D(t textureNative, p []byte, x, y, width, height int) {
|
||||
c.bindTexture(t)
|
||||
gl := c.gl
|
||||
gl.TexSubImage2D(mgl.TEXTURE_2D, 0, x, y, width, height, mgl.RGBA, mgl.UNSIGNED_BYTE, p)
|
||||
}
|
||||
|
||||
func (c *Context) newFramebuffer(texture Texture) (framebufferNative, error) {
|
||||
func (c *Context) newFramebuffer(texture textureNative) (framebufferNative, error) {
|
||||
gl := c.gl
|
||||
f := gl.CreateFramebuffer()
|
||||
if f.Value <= 0 {
|
||||
|
@ -25,7 +25,7 @@ type Framebuffer struct {
|
||||
}
|
||||
|
||||
// newFramebufferFromTexture creates a framebuffer from the given texture.
|
||||
func newFramebufferFromTexture(texture Texture, width, height int) (*Framebuffer, error) {
|
||||
func newFramebufferFromTexture(texture textureNative, width, height int) (*Framebuffer, error) {
|
||||
native, err := theContext.newFramebuffer(texture)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -37,10 +37,10 @@ func checkSize(width, height int) {
|
||||
}
|
||||
|
||||
type Image struct {
|
||||
Texture Texture
|
||||
Framebuffer *Framebuffer
|
||||
width int
|
||||
height int
|
||||
textureNative textureNative
|
||||
Framebuffer *Framebuffer
|
||||
width int
|
||||
height int
|
||||
}
|
||||
|
||||
func NewImage(width, height int) (*Image, error) {
|
||||
@ -55,7 +55,7 @@ func NewImage(width, height int) (*Image, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
i.Texture = t
|
||||
i.textureNative = t
|
||||
return i, nil
|
||||
}
|
||||
|
||||
@ -77,15 +77,15 @@ func (i *Image) Size() (int, int) {
|
||||
}
|
||||
|
||||
func (i *Image) IsInvalidated() bool {
|
||||
return !theContext.isTexture(i.Texture)
|
||||
return !theContext.isTexture(i.textureNative)
|
||||
}
|
||||
|
||||
func (i *Image) Delete() {
|
||||
if i.Framebuffer != nil {
|
||||
i.Framebuffer.delete()
|
||||
}
|
||||
if i.Texture != *new(Texture) {
|
||||
theContext.deleteTexture(i.Texture)
|
||||
if i.textureNative != *new(textureNative) {
|
||||
theContext.deleteTexture(i.textureNative)
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ func (i *Image) ensureFramebuffer() error {
|
||||
return nil
|
||||
}
|
||||
w, h := i.Size()
|
||||
f, err := newFramebufferFromTexture(i.Texture, math.NextPowerOf2Int(w), math.NextPowerOf2Int(h))
|
||||
f, err := newFramebufferFromTexture(i.textureNative, math.NextPowerOf2Int(w), math.NextPowerOf2Int(h))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -130,5 +130,5 @@ func (i *Image) ensureFramebuffer() error {
|
||||
}
|
||||
|
||||
func (i *Image) TexSubImage2D(p []byte, x, y, width, height int) {
|
||||
theContext.texSubImage2D(i.Texture, p, x, y, width, height)
|
||||
theContext.texSubImage2D(i.textureNative, p, x, y, width, height)
|
||||
}
|
||||
|
@ -267,11 +267,11 @@ func BufferSubData(vertices []float32, indices []uint16) {
|
||||
}
|
||||
|
||||
func UseProgram(proj []float32, src *Image, dstW, dstH, srcW, srcH int, colorM *affine.ColorM, filter graphics.Filter) {
|
||||
theOpenGLState.useProgram(proj, src.Texture, dstW, dstH, srcW, srcH, colorM, filter)
|
||||
theOpenGLState.useProgram(proj, src.textureNative, dstW, dstH, srcW, srcH, colorM, filter)
|
||||
}
|
||||
|
||||
// useProgram uses the program (programTexture).
|
||||
func (s *openGLState) useProgram(proj []float32, texture Texture, dstW, dstH, srcW, srcH int, colorM *affine.ColorM, filter graphics.Filter) {
|
||||
func (s *openGLState) useProgram(proj []float32, texture textureNative, dstW, dstH, srcW, srcH int, colorM *affine.ColorM, filter graphics.Filter) {
|
||||
c := GetContext()
|
||||
|
||||
var program program
|
||||
|
Loading…
Reference in New Issue
Block a user