瀏覽代碼

Simulate WebGL behaviour on sampler wrap u/v/r when calling _bindTexture and not _setTexture

Popov72 4 年之前
父節點
當前提交
9fe5815d85
共有 1 個文件被更改,包括 17 次插入1 次删除
  1. 17 1
      src/Engines/webgpuEngine.ts

+ 17 - 1
src/Engines/webgpuEngine.ts

@@ -168,6 +168,9 @@ export class WebGPUEngine extends Engine {
     private _textureHelper: WebGPUTextureHelper;
     private _bufferManager: WebGPUBufferManager;
     private _emptyVertexBuffer: VertexBuffer;
+    private _lastCachedWrapU: number;
+    private _lastCachedWrapV: number;
+    private _lastCachedWrapR: number;
     private _counters: {
         numPipelineDescriptorCreation: number;
         numBindGroupsCreation: number;
@@ -1662,14 +1665,17 @@ export class WebGPUEngine extends Engine {
 
                 if (internalTexture._cachedWrapU !== texture.wrapU) {
                     internalTexture._cachedWrapU = texture.wrapU;
+                    this._lastCachedWrapU = texture.wrapU;
                 }
 
                 if (internalTexture._cachedWrapV !== texture.wrapV) {
                     internalTexture._cachedWrapV = texture.wrapV;
+                    this._lastCachedWrapV = texture.wrapV;
                 }
 
                 if (internalTexture.is3D && internalTexture._cachedWrapR !== texture.wrapR) {
                     internalTexture._cachedWrapR = texture.wrapR;
+                    this._lastCachedWrapR = texture.wrapR;
                 }
 
                 this._setAnisotropicLevel(0, internalTexture, texture.anisotropicFilteringLevel);
@@ -1712,7 +1718,17 @@ export class WebGPUEngine extends Engine {
         }
 
         if (texture) {
-            texture._associatedChannel = channel;
+            if (this._lastCachedWrapU !== null && texture._cachedWrapU !== this._lastCachedWrapU) {
+                texture._cachedWrapU = this._lastCachedWrapU;
+            }
+
+            if (this._lastCachedWrapV !== null && texture._cachedWrapV !== this._lastCachedWrapV) {
+                texture._cachedWrapV = this._lastCachedWrapV;
+            }
+
+            if (this._lastCachedWrapR !== null && texture._cachedWrapR !== this._lastCachedWrapR) {
+                texture._cachedWrapR = this._lastCachedWrapR;
+            }
         }
 
         this._setInternalTexture(name, texture);