-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
clampToMaxSize function in WebGLTextures may need type check #13454
Comments
You mean this error, right? |
Yes, you are right! |
I guess this would fix the issue. We only use function clampToMaxSize( image, maxSize ) {
if ( image.width > maxSize || image.height > maxSize ) {
var scale = maxSize / Math.max( image.width, image.height );
if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof ImageBitmap ) {
// Warning: Scaling through the canvas will only work with images that use
// premultiplied alpha.
var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
canvas.width = Math.max( Math.floor( image.width * scale ), 1 );
canvas.height = Math.max( Math.floor( image.height * scale ), 1 );
var context = canvas.getContext( '2d' );
context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
return canvas;
} else {
var width = Math.max( Math.floor( image.width * scale ), 1 );
var height = Math.max( Math.floor( image.height * scale ), 1 );
console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + width + 'x' + height, image );
image.width = width;
image.height = height;
}
}
return image;
} |
Does three.js/src/renderers/webgl/WebGLTextures.js Lines 48 to 68 in 23be4d6
Currently it only deals with HTMLImageElement, HTMLCanvasElement and ImageBitmap. |
Maybe. @WestLangley @mrdoob What do you think about this? |
So the problem is that |
|
POT is only required for mipmapping. DataTextures are typically neither mipmapped nor resized -- right?. So I do not understand what the issue is... |
@WestLangley Well , thank you for pointing out that the DataTextures do not need power-of-two process. So you can take care of the first three comments of this issue and ignore others. The issue is about Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)' |
I do not think DataTextures should ever be resized. |
@WestLangley Even the DataTextures are larger than WebGL: INVALID_VALUE: texImage2D: width or height out of range |
Resizing a DataTexture would destroy the data. If the DataTexture is too big, then that is a user error. |
It's not just a warning, My suggestion was to add at least a more robust version of |
Closing. If more users complain, we can still make |
That sounds good to me 👍 |
Okay, i'll make a PR then 😊 |
Description of the problem
In
uploadTexture
function forWebGLTextures
three.js/src/renderers/webgl/WebGLTextures.js
Lines 429 to 435 in 23be4d6
clampToMaxSize
is called for any texture on texture.image.I've figure out the texture type could only be one of
CanvasTexture
,VideoTexture
andDataTexture
foruploadTexture
.So the logic problem comes here,
clampToMaxSize
function given anDataTexture.image
( an object withwidth
,height
,data
properties ) will cause error ondrawImage
if the size is larger thancapabilities.maxTextureSize
.three.js/src/renderers/webgl/WebGLTextures.js
Lines 18 to 33 in 23be4d6
The example for SkinnedMesh in doc will go to
clampToMaxSize
withDataTexture.image
as image argument but its size is not larger thancapabilities.maxTextureSize
which makes it not trigger the error.Maybe it is not practical to set extreme large number of bones, but I think logically this should be fixed.
makePowerOfTwo
function do this well.Three.js version
Any thoughts?
The text was updated successfully, but these errors were encountered: