@@ -185,6 +185,7 @@ class Texture {
185185 * of Uint8Array if options.arrayLength is defined and greater than zero.
186186 * @param {boolean } [options.storage] - Defines if texture can be used as a storage texture by
187187 * a compute shader. Defaults to false.
188+ * @param {boolean } [options.immediate] - If set and true, the texture will be uploaded to the GPU immediately.
188189 * @example
189190 * // Create a 8x8x24-bit texture
190191 * const texture = new pc.Texture(graphicsDevice, {
@@ -267,7 +268,7 @@ class Texture {
267268
268269 this . _levels = options . levels ;
269270 if ( this . _levels ) {
270- this . upload ( ) ;
271+ this . upload ( options . immediate ?? false ) ;
271272 } else {
272273 this . _levels = this . _cubemap ? [ [ null , null , null , null , null , null ] ] : [ null ] ;
273274 }
@@ -878,8 +879,9 @@ class Texture {
878879 * @param {number } [mipLevel] - A non-negative integer specifying the image level of detail.
879880 * Defaults to 0, which represents the base image source. A level value of N, that is greater
880881 * than 0, represents the image source for the Nth mipmap reduction level.
882+ * @param {boolean } [immediate] - When set to true it forces an immediate upload upon assignment. Defaults to false.
881883 */
882- setSource ( source , mipLevel = 0 ) {
884+ setSource ( source , mipLevel = 0 , immediate = false ) {
883885 let invalid = false ;
884886 let width , height ;
885887
@@ -959,7 +961,7 @@ class Texture {
959961 this . _invalid = invalid ;
960962
961963 // reupload
962- this . upload ( ) ;
964+ this . upload ( immediate ) ;
963965 }
964966 }
965967
@@ -979,31 +981,33 @@ class Texture {
979981
980982 /**
981983 * Unlocks the currently locked mip level and uploads it to VRAM.
984+ * @param {boolean } [immediate] - When set to true it forces an immediate upload upon unlocking. Defaults to false.
982985 */
983- unlock ( ) {
986+ unlock ( immediate = false ) {
984987 if ( this . _lockedMode === TEXTURELOCK_NONE ) {
985988 Debug . warn ( "pc.Texture#unlock: Attempting to unlock a texture that is not locked." , this ) ;
986989 }
987990
988991 // Upload the new pixel data if locked in write mode (default)
989992 if ( this . _lockedMode === TEXTURELOCK_WRITE ) {
990- this . upload ( ) ;
993+ this . upload ( immediate ) ;
991994 }
992995 this . _lockedLevel = - 1 ;
993996 this . _lockedMode = TEXTURELOCK_NONE ;
994997 }
995998
996999 /**
9971000 * Forces a reupload of the textures pixel data to graphics memory. Ordinarily, this function
998- * is called by internally by {@link Texture#setSource} and {@link Texture#unlock}. However, it
1001+ * is called internally by {@link Texture#setSource} and {@link Texture#unlock}. However, it
9991002 * still needs to be called explicitly in the case where an HTMLVideoElement is set as the
10001003 * source of the texture. Normally, this is done once every frame before video textured
10011004 * geometry is rendered.
1005+ * @param {boolean } [immediate] - When set to true it forces an immediate upload. Defaults to false.
10021006 */
1003- upload ( ) {
1007+ upload ( immediate = false ) {
10041008 this . _needsUpload = true ;
10051009 this . _needsMipmapsUpload = this . _mipmaps ;
1006- this . impl . uploadImmediate ?. ( this . device , this ) ;
1010+ this . impl . uploadImmediate ( this . device , this , immediate ) ;
10071011 }
10081012
10091013 /**
0 commit comments