graphicsdriver/opengl: Remove theContext

This commit is contained in:
Hajime Hoshi 2018-11-11 03:37:37 +09:00
parent 2f692d98c7
commit 734aeabc8d
5 changed files with 122 additions and 122 deletions

View File

@ -67,8 +67,6 @@ type context struct {
contextImpl contextImpl
} }
var theContext context
func (c *context) bindTexture(t textureNative) { func (c *context) bindTexture(t textureNative) {
if c.lastTexture == t { if c.lastTexture == t {
return return

View File

@ -15,6 +15,8 @@
package opengl package opengl
import ( import (
"fmt"
"github.com/hajimehoshi/ebiten/internal/affine" "github.com/hajimehoshi/ebiten/internal/affine"
"github.com/hajimehoshi/ebiten/internal/graphics" "github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/graphicsdriver" "github.com/hajimehoshi/ebiten/internal/graphicsdriver"
@ -29,6 +31,23 @@ func GetDriver() *Driver {
type Driver struct { type Driver struct {
state openGLState state openGLState
context context
}
func (d *Driver) 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 := d.context.getMaxTextureSize()
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))
}
} }
func (d *Driver) NewImage(width, height int) (graphicsdriver.Image, error) { func (d *Driver) NewImage(width, height int) (graphicsdriver.Image, error) {
@ -39,8 +58,8 @@ func (d *Driver) NewImage(width, height int) (graphicsdriver.Image, error) {
} }
w := math.NextPowerOf2Int(width) w := math.NextPowerOf2Int(width)
h := math.NextPowerOf2Int(height) h := math.NextPowerOf2Int(height)
checkSize(w, h) d.checkSize(w, h)
t, err := theContext.newTexture(w, h) t, err := d.context.newTexture(w, h)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -49,7 +68,7 @@ func (d *Driver) NewImage(width, height int) (graphicsdriver.Image, error) {
} }
func (d *Driver) NewScreenFramebufferImage(width, height int) graphicsdriver.Image { func (d *Driver) NewScreenFramebufferImage(width, height int) graphicsdriver.Image {
checkSize(width, height) d.checkSize(width, height)
i := &Image{ i := &Image{
driver: d, driver: d,
width: width, width: width,
@ -58,25 +77,25 @@ func (d *Driver) NewScreenFramebufferImage(width, height int) graphicsdriver.Ima
// The (default) framebuffer size can't be converted to a power of 2. // 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 // 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). // Edge can't treat a bigger viewport than the drawing area (#71).
i.framebuffer = newScreenFramebuffer(width, height) i.framebuffer = newScreenFramebuffer(&d.context, width, height)
return i return i
} }
// Reset resets or initializes the current OpenGL state. // Reset resets or initializes the current OpenGL state.
func (d *Driver) Reset() error { func (d *Driver) Reset() error {
return d.state.reset() return d.state.reset(&d.context)
} }
func (d *Driver) BufferSubData(vertices []float32, indices []uint16) { func (d *Driver) BufferSubData(vertices []float32, indices []uint16) {
bufferSubData(vertices, indices) bufferSubData(&d.context, vertices, indices)
} }
func (d *Driver) UseProgram(mode graphics.CompositeMode, colorM *affine.ColorM, filter graphics.Filter) error { func (d *Driver) UseProgram(mode graphics.CompositeMode, colorM *affine.ColorM, filter graphics.Filter) error {
return d.state.useProgram(mode, colorM, filter) return d.useProgram(mode, colorM, filter)
} }
func (d *Driver) DrawElements(len int, offsetInBytes int) { func (d *Driver) DrawElements(len int, offsetInBytes int) {
theContext.drawElements(len, offsetInBytes) d.context.drawElements(len, offsetInBytes)
// glFlush() might be necessary at least on MacBook Pro (a smilar problem at #419), // glFlush() might be necessary at least on MacBook Pro (a smilar problem at #419),
// but basically this pass the tests (esp. TestImageTooManyFill). // but basically this pass the tests (esp. TestImageTooManyFill).
// As glFlush() causes performance problems, this should be avoided as much as possible. // As glFlush() causes performance problems, this should be avoided as much as possible.
@ -84,9 +103,9 @@ func (d *Driver) DrawElements(len int, offsetInBytes int) {
} }
func (d *Driver) Flush() { func (d *Driver) Flush() {
theContext.flush() d.context.flush()
} }
func (d *Driver) MaxImageSize() int { func (d *Driver) MaxImageSize() int {
return theContext.getMaxTextureSize() return d.context.getMaxTextureSize()
} }

View File

@ -16,6 +16,7 @@ package opengl
// framebuffer is a wrapper of OpenGL's framebuffer. // framebuffer is a wrapper of OpenGL's framebuffer.
type framebuffer struct { type framebuffer struct {
driver *Driver
native framebufferNative native framebufferNative
proMatrix []float32 proMatrix []float32
width int width int
@ -23,8 +24,8 @@ type framebuffer struct {
} }
// newFramebufferFromTexture creates a framebuffer from the given texture. // newFramebufferFromTexture creates a framebuffer from the given texture.
func newFramebufferFromTexture(texture textureNative, width, height int) (*framebuffer, error) { func newFramebufferFromTexture(context *context, texture textureNative, width, height int) (*framebuffer, error) {
native, err := theContext.newFramebuffer(texture) native, err := context.newFramebuffer(texture)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -36,9 +37,9 @@ func newFramebufferFromTexture(texture textureNative, width, height int) (*frame
} }
// newScreenFramebuffer creates a framebuffer for the screen. // newScreenFramebuffer creates a framebuffer for the screen.
func newScreenFramebuffer(width, height int) *framebuffer { func newScreenFramebuffer(context *context, width, height int) *framebuffer {
return &framebuffer{ return &framebuffer{
native: theContext.getScreenFramebuffer(), native: context.getScreenFramebuffer(),
width: width, width: width,
height: height, height: height,
} }
@ -57,8 +58,8 @@ func (f *framebuffer) projectionMatrix() []float32 {
return f.proMatrix return f.proMatrix
} }
func (f *framebuffer) delete() { func (f *framebuffer) delete(context *context) {
if f.native != theContext.getScreenFramebuffer() { if f.native != context.getScreenFramebuffer() {
theContext.deleteFramebuffer(f.native) context.deleteFramebuffer(f.native)
} }
} }

View File

@ -15,27 +15,9 @@
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.getMaxTextureSize()
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 {
driver *Driver driver *Driver
textureNative textureNative textureNative textureNative
@ -45,15 +27,15 @@ type Image struct {
} }
func (i *Image) IsInvalidated() bool { func (i *Image) IsInvalidated() bool {
return !theContext.isTexture(i.textureNative) return !i.driver.context.isTexture(i.textureNative)
} }
func (i *Image) Delete() { func (i *Image) Delete() {
if i.framebuffer != nil { if i.framebuffer != nil {
i.framebuffer.delete() i.framebuffer.delete(&i.driver.context)
} }
if i.textureNative != *new(textureNative) { if i.textureNative != *new(textureNative) {
theContext.deleteTexture(i.textureNative) i.driver.context.deleteTexture(i.textureNative)
} }
} }
@ -65,7 +47,7 @@ func (i *Image) setViewport() error {
if err := i.ensureFramebuffer(); err != nil { if err := i.ensureFramebuffer(); err != nil {
return err return err
} }
theContext.setViewport(i.framebuffer) i.driver.context.setViewport(i.framebuffer)
return nil return nil
} }
@ -73,7 +55,7 @@ func (i *Image) Pixels() ([]byte, error) {
if err := i.ensureFramebuffer(); err != nil { if err := i.ensureFramebuffer(); err != nil {
return nil, err return nil, err
} }
p, err := theContext.framebufferPixels(i.framebuffer, i.width, i.height) p, err := i.driver.context.framebufferPixels(i.framebuffer, i.width, i.height)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -92,7 +74,7 @@ func (i *Image) ensureFramebuffer() error {
return nil return nil
} }
w, h := i.width, i.height w, h := i.width, i.height
f, err := newFramebufferFromTexture(i.textureNative, math.NextPowerOf2Int(w), math.NextPowerOf2Int(h)) f, err := newFramebufferFromTexture(&i.driver.context, i.textureNative, math.NextPowerOf2Int(w), math.NextPowerOf2Int(h))
if err != nil { if err != nil {
return err return err
} }
@ -103,8 +85,8 @@ func (i *Image) ensureFramebuffer() error {
func (i *Image) ReplacePixels(p []byte, x, y, width, height int) { func (i *Image) ReplacePixels(p []byte, x, y, width, height int) {
// glFlush is necessary on Android. // glFlush is necessary on Android.
// glTexSubImage2D didn't work without this hack at least on Nexus 5x and NuAns NEO [Reloaded] (#211). // glTexSubImage2D didn't work without this hack at least on Nexus 5x and NuAns NEO [Reloaded] (#211).
theContext.flush() i.driver.context.flush()
theContext.texSubImage2D(i.textureNative, p, x, y, width, height) i.driver.context.texSubImage2D(i.textureNative, p, x, y, width, height)
} }
func (i *Image) SetAsSource() { func (i *Image) SetAsSource() {

View File

@ -53,28 +53,28 @@ func (a *arrayBufferLayout) totalBytes() int {
} }
// newArrayBuffer creates OpenGL's buffer object for the array buffer. // newArrayBuffer creates OpenGL's buffer object for the array buffer.
func (a *arrayBufferLayout) newArrayBuffer() buffer { func (a *arrayBufferLayout) newArrayBuffer(context *context) buffer {
return theContext.newArrayBuffer(a.totalBytes() * graphics.IndicesNum) return context.newArrayBuffer(a.totalBytes() * graphics.IndicesNum)
} }
// enable binds the array buffer the given program to use the array buffer. // enable binds the array buffer the given program to use the array buffer.
func (a *arrayBufferLayout) enable(program program) { func (a *arrayBufferLayout) enable(context *context, program program) {
for _, p := range a.parts { for _, p := range a.parts {
theContext.enableVertexAttribArray(program, p.name) context.enableVertexAttribArray(program, p.name)
} }
total := a.totalBytes() total := a.totalBytes()
offset := 0 offset := 0
for _, p := range a.parts { for _, p := range a.parts {
theContext.vertexAttribPointer(program, p.name, p.num, float, total, offset) context.vertexAttribPointer(program, p.name, p.num, float, total, offset)
offset += float.SizeInBytes() * p.num offset += float.SizeInBytes() * p.num
} }
} }
// disable stops using the array buffer. // disable stops using the array buffer.
func (a *arrayBufferLayout) disable(program program) { func (a *arrayBufferLayout) disable(context *context, program program) {
// TODO: Disabling should be done in reversed order? // TODO: Disabling should be done in reversed order?
for _, p := range a.parts { for _, p := range a.parts {
theContext.disableVertexAttribArray(program, p.name) context.disableVertexAttribArray(program, p.name)
} }
} }
@ -146,8 +146,8 @@ const (
) )
// reset resets or initializes the OpenGL state. // reset resets or initializes the OpenGL state.
func (s *openGLState) reset() error { func (s *openGLState) reset(context *context) error {
if err := theContext.reset(); err != nil { if err := context.reset(); err != nil {
return err return err
} }
@ -162,51 +162,51 @@ func (s *openGLState) reset() error {
// However, it is not assumed that reset is called only when context lost happens. // However, it is not assumed that reset is called only when context lost happens.
// Let's delete them explicitly. // Let's delete them explicitly.
if s.programNearest != zeroProgram { if s.programNearest != zeroProgram {
theContext.deleteProgram(s.programNearest) context.deleteProgram(s.programNearest)
} }
if s.programLinear != zeroProgram { if s.programLinear != zeroProgram {
theContext.deleteProgram(s.programLinear) context.deleteProgram(s.programLinear)
} }
if s.programScreen != zeroProgram { if s.programScreen != zeroProgram {
theContext.deleteProgram(s.programScreen) context.deleteProgram(s.programScreen)
} }
// On browsers (at least Chrome), buffers are already detached from the context // On browsers (at least Chrome), buffers are already detached from the context
// and must not be deleted by DeleteBuffer. // and must not be deleted by DeleteBuffer.
if !web.IsBrowser() { if !web.IsBrowser() {
if s.arrayBuffer != zeroBuffer { if s.arrayBuffer != zeroBuffer {
theContext.deleteBuffer(s.arrayBuffer) context.deleteBuffer(s.arrayBuffer)
} }
if s.elementArrayBuffer != zeroBuffer { if s.elementArrayBuffer != zeroBuffer {
theContext.deleteBuffer(s.elementArrayBuffer) context.deleteBuffer(s.elementArrayBuffer)
} }
} }
shaderVertexModelviewNative, err := theContext.newShader(vertexShader, shaderStr(shaderVertexModelview)) shaderVertexModelviewNative, err := context.newShader(vertexShader, shaderStr(shaderVertexModelview))
if err != nil { if err != nil {
panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err)) panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
} }
defer theContext.deleteShader(shaderVertexModelviewNative) defer context.deleteShader(shaderVertexModelviewNative)
shaderFragmentNearestNative, err := theContext.newShader(fragmentShader, shaderStr(shaderFragmentNearest)) shaderFragmentNearestNative, err := context.newShader(fragmentShader, shaderStr(shaderFragmentNearest))
if err != nil { if err != nil {
panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err)) panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
} }
defer theContext.deleteShader(shaderFragmentNearestNative) defer context.deleteShader(shaderFragmentNearestNative)
shaderFragmentLinearNative, err := theContext.newShader(fragmentShader, shaderStr(shaderFragmentLinear)) shaderFragmentLinearNative, err := context.newShader(fragmentShader, shaderStr(shaderFragmentLinear))
if err != nil { if err != nil {
panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err)) panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
} }
defer theContext.deleteShader(shaderFragmentLinearNative) defer context.deleteShader(shaderFragmentLinearNative)
shaderFragmentScreenNative, err := theContext.newShader(fragmentShader, shaderStr(shaderFragmentScreen)) shaderFragmentScreenNative, err := context.newShader(fragmentShader, shaderStr(shaderFragmentScreen))
if err != nil { if err != nil {
panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err)) panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err))
} }
defer theContext.deleteShader(shaderFragmentScreenNative) defer context.deleteShader(shaderFragmentScreenNative)
s.programNearest, err = theContext.newProgram([]shader{ s.programNearest, err = context.newProgram([]shader{
shaderVertexModelviewNative, shaderVertexModelviewNative,
shaderFragmentNearestNative, shaderFragmentNearestNative,
}) })
@ -214,7 +214,7 @@ func (s *openGLState) reset() error {
return err return err
} }
s.programLinear, err = theContext.newProgram([]shader{ s.programLinear, err = context.newProgram([]shader{
shaderVertexModelviewNative, shaderVertexModelviewNative,
shaderFragmentLinearNative, shaderFragmentLinearNative,
}) })
@ -222,7 +222,7 @@ func (s *openGLState) reset() error {
return err return err
} }
s.programScreen, err = theContext.newProgram([]shader{ s.programScreen, err = context.newProgram([]shader{
shaderVertexModelviewNative, shaderVertexModelviewNative,
shaderFragmentScreenNative, shaderFragmentScreenNative,
}) })
@ -230,12 +230,12 @@ func (s *openGLState) reset() error {
return err return err
} }
s.arrayBuffer = theArrayBufferLayout.newArrayBuffer() s.arrayBuffer = theArrayBufferLayout.newArrayBuffer(context)
// Note that the indices passed to NewElementArrayBuffer is not under GC management // Note that the indices passed to NewElementArrayBuffer is not under GC management
// in opengl package due to unsafe-way. // in opengl package due to unsafe-way.
// See NewElementArrayBuffer in context_mobile.go. // See NewElementArrayBuffer in context_mobile.go.
s.elementArrayBuffer = theContext.newElementArrayBuffer(graphics.IndicesNum * 2) s.elementArrayBuffer = context.newElementArrayBuffer(graphics.IndicesNum * 2)
return nil return nil
} }
@ -253,18 +253,18 @@ func areSameFloat32Array(a, b []float32) bool {
return true return true
} }
func bufferSubData(vertices []float32, indices []uint16) { func bufferSubData(context *context, vertices []float32, indices []uint16) {
theContext.arrayBufferSubData(vertices) context.arrayBufferSubData(vertices)
theContext.elementArrayBufferSubData(indices) context.elementArrayBufferSubData(indices)
} }
// useProgram uses the program (programTexture). // useProgram uses the program (programTexture).
func (s *openGLState) useProgram(mode graphics.CompositeMode, colorM *affine.ColorM, filter graphics.Filter) error { func (d *Driver) useProgram(mode graphics.CompositeMode, colorM *affine.ColorM, filter graphics.Filter) error {
destination := s.destination destination := d.state.destination
if destination == nil { if destination == nil {
panic("destination image is not set") panic("destination image is not set")
} }
source := s.source source := d.state.source
if source == nil { if source == nil {
panic("source image is not set") panic("source image is not set")
} }
@ -279,89 +279,89 @@ func (s *openGLState) useProgram(mode graphics.CompositeMode, colorM *affine.Col
dstW := destination.width dstW := destination.width
srcW, srcH := source.width, source.height srcW, srcH := source.width, source.height
theContext.blendFunc(mode) d.context.blendFunc(mode)
var program program var program program
switch filter { switch filter {
case graphics.FilterNearest: case graphics.FilterNearest:
program = s.programNearest program = d.state.programNearest
case graphics.FilterLinear: case graphics.FilterLinear:
program = s.programLinear program = d.state.programLinear
case graphics.FilterScreen: case graphics.FilterScreen:
program = s.programScreen program = d.state.programScreen
default: default:
panic("not reached") panic("not reached")
} }
if s.lastProgram != program { if d.state.lastProgram != program {
theContext.useProgram(program) d.context.useProgram(program)
if s.lastProgram != zeroProgram { if d.state.lastProgram != zeroProgram {
theArrayBufferLayout.disable(s.lastProgram) theArrayBufferLayout.disable(&d.context, d.state.lastProgram)
} }
theArrayBufferLayout.enable(program) theArrayBufferLayout.enable(&d.context, program)
if s.lastProgram == zeroProgram { if d.state.lastProgram == zeroProgram {
theContext.bindBuffer(arrayBuffer, s.arrayBuffer) d.context.bindBuffer(arrayBuffer, d.state.arrayBuffer)
theContext.bindBuffer(elementArrayBuffer, s.elementArrayBuffer) d.context.bindBuffer(elementArrayBuffer, d.state.elementArrayBuffer)
theContext.uniformInt(program, "texture", 0) d.context.uniformInt(program, "texture", 0)
} }
s.lastProgram = program d.state.lastProgram = program
s.lastProjectionMatrix = nil d.state.lastProjectionMatrix = nil
s.lastColorMatrix = nil d.state.lastColorMatrix = nil
s.lastColorMatrixTranslation = nil d.state.lastColorMatrixTranslation = nil
s.lastSourceWidth = 0 d.state.lastSourceWidth = 0
s.lastSourceHeight = 0 d.state.lastSourceHeight = 0
} }
if !areSameFloat32Array(s.lastProjectionMatrix, proj) { if !areSameFloat32Array(d.state.lastProjectionMatrix, proj) {
theContext.uniformFloats(program, "projection_matrix", proj) d.context.uniformFloats(program, "projection_matrix", proj)
if s.lastProjectionMatrix == nil { if d.state.lastProjectionMatrix == nil {
s.lastProjectionMatrix = make([]float32, 16) d.state.lastProjectionMatrix = make([]float32, 16)
} }
// (*framebuffer).projectionMatrix is always same for the same framebuffer. // (*framebuffer).projectionMatrix is always same for the same framebuffer.
// It's OK to hold the reference without copying. // It's OK to hold the reference without copying.
s.lastProjectionMatrix = proj d.state.lastProjectionMatrix = proj
} }
esBody, esTranslate := colorM.UnsafeElements() esBody, esTranslate := colorM.UnsafeElements()
if !areSameFloat32Array(s.lastColorMatrix, esBody) { if !areSameFloat32Array(d.state.lastColorMatrix, esBody) {
theContext.uniformFloats(program, "color_matrix_body", esBody) d.context.uniformFloats(program, "color_matrix_body", esBody)
if s.lastColorMatrix == nil { if d.state.lastColorMatrix == nil {
s.lastColorMatrix = make([]float32, 16) d.state.lastColorMatrix = make([]float32, 16)
} }
// ColorM's elements are immutable. It's OK to hold the reference without copying. // ColorM's elements are immutable. It's OK to hold the reference without copying.
s.lastColorMatrix = esBody d.state.lastColorMatrix = esBody
} }
if !areSameFloat32Array(s.lastColorMatrixTranslation, esTranslate) { if !areSameFloat32Array(d.state.lastColorMatrixTranslation, esTranslate) {
theContext.uniformFloats(program, "color_matrix_translation", esTranslate) d.context.uniformFloats(program, "color_matrix_translation", esTranslate)
if s.lastColorMatrixTranslation == nil { if d.state.lastColorMatrixTranslation == nil {
s.lastColorMatrixTranslation = make([]float32, 4) d.state.lastColorMatrixTranslation = make([]float32, 4)
} }
// ColorM's elements are immutable. It's OK to hold the reference without copying. // ColorM's elements are immutable. It's OK to hold the reference without copying.
s.lastColorMatrixTranslation = esTranslate d.state.lastColorMatrixTranslation = esTranslate
} }
sw := emath.NextPowerOf2Int(srcW) sw := emath.NextPowerOf2Int(srcW)
sh := emath.NextPowerOf2Int(srcH) sh := emath.NextPowerOf2Int(srcH)
if s.lastSourceWidth != sw || s.lastSourceHeight != sh { if d.state.lastSourceWidth != sw || d.state.lastSourceHeight != sh {
theContext.uniformFloats(program, "source_size", []float32{float32(sw), float32(sh)}) d.context.uniformFloats(program, "source_size", []float32{float32(sw), float32(sh)})
s.lastSourceWidth = sw d.state.lastSourceWidth = sw
s.lastSourceHeight = sh d.state.lastSourceHeight = sh
} }
if program == s.programScreen { if program == d.state.programScreen {
scale := float32(dstW) / float32(srcW) scale := float32(dstW) / float32(srcW)
theContext.uniformFloat(program, "scale", scale) d.context.uniformFloat(program, "scale", scale)
} }
// We don't have to call gl.ActiveTexture here: GL_TEXTURE0 is the default active texture // We don't have to call gl.ActiveTexture here: GL_TEXTURE0 is the default active texture
// See also: https://www.opengl.org/sdk/docs/man2/xhtml/glActiveTexture.xml // See also: https://www.opengl.org/sdk/docs/man2/xhtml/glActiveTexture.xml
theContext.bindTexture(source.textureNative) d.context.bindTexture(source.textureNative)
s.source = nil d.state.source = nil
s.destination = nil d.state.destination = nil
return nil return nil
} }