mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
robust
This commit is contained in:
@@ -163,16 +163,17 @@ export default class TextureCube extends TextureBase {
|
||||
}
|
||||
}
|
||||
|
||||
public onLoaded () {
|
||||
this.mipmaps = this._mipmaps;
|
||||
}
|
||||
|
||||
protected _createTexture () {
|
||||
if (this._mipmaps.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._texture = this._getGlobalDevice().createTexture({
|
||||
const gfxDevice = this._getGlobalDevice();
|
||||
if (!gfxDevice) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._texture = gfxDevice.createTexture({
|
||||
type: GFXTextureType.TEX2D,
|
||||
/* tslint:disable:no-bitwise */
|
||||
usage: GFXTextureUsageBit.SAMPLED | GFXTextureUsageBit.TRANSFER_DST,
|
||||
@@ -196,7 +197,12 @@ export default class TextureCube extends TextureBase {
|
||||
return;
|
||||
}
|
||||
|
||||
this._textureView = this._getGlobalDevice().createTextureView({
|
||||
const gfxDevice = this._getGlobalDevice();
|
||||
if (!gfxDevice) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._textureView = gfxDevice.createTextureView({
|
||||
texture: this._texture,
|
||||
type: GFXTextureViewType.TV2D_ARRAY,
|
||||
format: this._getGfxFormat(),
|
||||
|
||||
@@ -51,6 +51,9 @@ export default class RenderTexture extends Texture2D {
|
||||
this.destroy();
|
||||
|
||||
const gfxDevice = this._getGlobalDevice();
|
||||
if (!gfxDevice) {
|
||||
return;
|
||||
}
|
||||
|
||||
const w = Math.floor(width || cc.visibleRect.width);
|
||||
const h = Math.floor(height || cc.visibleRect.height);
|
||||
@@ -179,11 +182,16 @@ export default class RenderTexture extends Texture2D {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const gfxDevice = this._getGlobalDevice();
|
||||
if (!gfxDevice) {
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedRect = normalizeRect2D(rect, this.width, this.height);
|
||||
|
||||
data = data || new Uint8Array(normalizedRect.width * normalizedRect.height * 4);
|
||||
|
||||
this._getGlobalDevice().copyFramebufferToBuffer(this._framebuffer, data.buffer, [{
|
||||
gfxDevice.copyFramebufferToBuffer(this._framebuffer, data.buffer, [{
|
||||
buffOffset: 0,
|
||||
buffStride: 0,
|
||||
buffTexHeight: 0,
|
||||
|
||||
@@ -175,16 +175,17 @@ export default class Texture2D extends TextureBase {
|
||||
}
|
||||
}
|
||||
|
||||
public onLoaded () {
|
||||
this.mipmaps = this._mipmaps;
|
||||
}
|
||||
|
||||
protected _createTexture () {
|
||||
if (this._mipmaps.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._texture = this._getGlobalDevice().createTexture({
|
||||
const gfxDevice = this._getGlobalDevice();
|
||||
if (!gfxDevice) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._texture = gfxDevice.createTexture({
|
||||
type: GFXTextureType.TEX2D,
|
||||
/* tslint:disable:no-bitwise */
|
||||
usage: GFXTextureUsageBit.SAMPLED | GFXTextureUsageBit.TRANSFER_DST,
|
||||
@@ -205,7 +206,12 @@ export default class Texture2D extends TextureBase {
|
||||
return;
|
||||
}
|
||||
|
||||
this._textureView = this._getGlobalDevice().createTextureView({
|
||||
const gfxDevice = this._getGlobalDevice();
|
||||
if (!gfxDevice) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._textureView = gfxDevice.createTextureView({
|
||||
texture: this._texture,
|
||||
type: GFXTextureViewType.TV2D,
|
||||
format: this._getGfxFormat(),
|
||||
|
||||
@@ -473,7 +473,12 @@ export default class TextureBase extends Asset {
|
||||
}
|
||||
}
|
||||
|
||||
protected _getGlobalDevice (): GFXDevice {
|
||||
public onLoaded () {
|
||||
this._updateSampler();
|
||||
this._recreateTexture();
|
||||
}
|
||||
|
||||
protected _getGlobalDevice (): GFXDevice | null {
|
||||
return cc.director.root.device;
|
||||
}
|
||||
|
||||
@@ -508,6 +513,11 @@ export default class TextureBase extends Asset {
|
||||
return;
|
||||
}
|
||||
|
||||
const gfxDevice = this._getGlobalDevice();
|
||||
if (!gfxDevice) {
|
||||
return;
|
||||
}
|
||||
|
||||
const region: GFXBufferTextureCopy = {
|
||||
buffOffset: 0,
|
||||
buffStride: 0,
|
||||
@@ -531,9 +541,9 @@ export default class TextureBase extends Asset {
|
||||
};
|
||||
|
||||
if (data instanceof HTMLElement) {
|
||||
this._getGlobalDevice().copyImageSourceToTexture(data, this._texture, [region]);
|
||||
gfxDevice.copyImageSourceToTexture(data, this._texture, [region]);
|
||||
} else {
|
||||
this._getGlobalDevice().copyBufferToTexture(data.buffer, this._texture, [region]);
|
||||
gfxDevice.copyBufferToTexture(data.buffer, this._texture, [region]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -568,7 +578,16 @@ export default class TextureBase extends Asset {
|
||||
}
|
||||
|
||||
private _updateSampler () {
|
||||
this._sampler = this._getGlobalDevice().createSampler({
|
||||
if (this._sampler) {
|
||||
this._sampler.destroy();
|
||||
}
|
||||
|
||||
const gfxDevice = this._getGlobalDevice();
|
||||
if (!gfxDevice) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._sampler = gfxDevice.createSampler({
|
||||
name: `Sampler of ${this.name}`,
|
||||
minFilter: toGfxFilterMode(this._minFilter),
|
||||
magFilter: toGfxFilterMode(this._magFilter),
|
||||
|
||||
Reference in New Issue
Block a user