-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebGLRenderer: Enable subframe upload in copyTextureToTexture, align API to 3d version #28281
Changes from 13 commits
105488b
38c2f1d
8e3deaf
55a12e2
1e8b861
9f62ed6
67c1f1b
2944a86
f5c7761
7398afd
dc0a918
e6dade6
a23be2f
f4f22ae
2327394
37fe3b7
afc4869
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2371,10 +2371,25 @@ class WebGLRenderer { | |
|
||
}; | ||
|
||
this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0 ) { | ||
this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0, sourceBox = null ) { | ||
|
||
let width, height, minX, minY; | ||
if ( sourceBox !== null ) { | ||
|
||
width = sourceBox.max.x - sourceBox.min.x; | ||
height = sourceBox.max.y - sourceBox.min.y; | ||
minX = sourceBox.min.x; | ||
minY = sourceBox.min.y; | ||
|
||
} else { | ||
|
||
width = srcTexture.image.width; | ||
height = srcTexture.image.height; | ||
minX = 0; | ||
minY = 0; | ||
|
||
} | ||
|
||
const width = srcTexture.image.width; | ||
const height = srcTexture.image.height; | ||
const glFormat = utils.convert( dstTexture.format ); | ||
const glType = utils.convert( dstTexture.type ); | ||
|
||
|
@@ -2386,36 +2401,88 @@ class WebGLRenderer { | |
_gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha ); | ||
_gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment ); | ||
|
||
const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH ); | ||
const currentUnpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT ); | ||
const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS ); | ||
const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS ); | ||
const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES ); | ||
|
||
gkjohnson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image; | ||
|
||
_gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width ); | ||
_gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY ); | ||
|
||
if ( srcTexture.isDataTexture ) { | ||
|
||
_gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data ); | ||
_gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, width, height, glFormat, glType, image.data ); | ||
|
||
} else { | ||
|
||
if ( srcTexture.isCompressedTexture ) { | ||
|
||
_gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data ); | ||
_gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, image.width, image.height, glFormat, image.data ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One other discrepancy I noticed between the |
||
|
||
} else { | ||
|
||
_gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, glFormat, glType, srcTexture.image ); | ||
_gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, glFormat, glType, image ); | ||
|
||
} | ||
|
||
} | ||
|
||
_gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen ); | ||
_gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages ); | ||
|
||
// Generate mipmaps only when copying level 0 | ||
if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( _gl.TEXTURE_2D ); | ||
|
||
state.unbindTexture(); | ||
|
||
}; | ||
|
||
this.copyTextureToTexture3D = function ( sourceBox, position, srcTexture, dstTexture, level = 0 ) { | ||
this.copyTextureToTexture3D = function ( position, srcTexture, dstTexture, level = 0, sourceBox = null ) { | ||
|
||
// support previous signature with source box first | ||
if ( position.isBox3 === true ) { | ||
|
||
// @deprecated, r165 | ||
console.warn( 'WebGLRenderer: copyTextureToTexture3D function signature has changed.' ); | ||
|
||
sourceBox = arguments[ 0 ]; | ||
position = arguments[ 1 ]; | ||
srcTexture = arguments[ 2 ]; | ||
dstTexture = arguments[ 3 ]; | ||
level = arguments[ 4 ] || 0; | ||
|
||
} | ||
|
||
let width, height, depth, minX, minY, minZ; | ||
const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image; | ||
if ( sourceBox !== null ) { | ||
|
||
width = sourceBox.max.x - sourceBox.min.x; | ||
height = sourceBox.max.y - sourceBox.min.y; | ||
depth = sourceBox.max.z - sourceBox.min.z; | ||
minX = sourceBox.min.x; | ||
minY = sourceBox.min.y; | ||
minZ = sourceBox.min.z; | ||
|
||
} else { | ||
|
||
width = image.width; | ||
height = image.height; | ||
depth = image.depth; | ||
minX = 0; | ||
minY = 0; | ||
minZ = 0; | ||
|
||
} | ||
|
||
const width = sourceBox.max.x - sourceBox.min.x; | ||
const height = sourceBox.max.y - sourceBox.min.y; | ||
const depth = sourceBox.max.z - sourceBox.min.z; | ||
const glFormat = utils.convert( dstTexture.format ); | ||
const glType = utils.convert( dstTexture.type ); | ||
let glTarget; | ||
|
@@ -2441,19 +2508,17 @@ class WebGLRenderer { | |
_gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha ); | ||
_gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment ); | ||
|
||
const unpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH ); | ||
const unpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT ); | ||
const unpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS ); | ||
const unpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS ); | ||
const unpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES ); | ||
|
||
const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image; | ||
const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH ); | ||
const currentUnpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT ); | ||
const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS ); | ||
const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS ); | ||
const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES ); | ||
|
||
_gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width ); | ||
_gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, sourceBox.min.x ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, sourceBox.min.y ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, sourceBox.min.z ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, minZ ); | ||
|
||
if ( srcTexture.isDataTexture || srcTexture.isData3DTexture ) { | ||
|
||
|
@@ -2473,11 +2538,11 @@ class WebGLRenderer { | |
|
||
} | ||
|
||
_gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, unpackRowLen ); | ||
_gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, unpackImageHeight ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, unpackSkipPixels ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, unpackSkipRows ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, unpackSkipImages ); | ||
_gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen ); | ||
_gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows ); | ||
_gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages ); | ||
|
||
// Generate mipmaps only when copying level 0 | ||
if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( glTarget ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
srcRegion
is more clear and follows the rest of the parameter names.