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
add uploadTexture to WebGLRenderer #5208
Conversation
There should be no change in setTexture behavior.
Can you provide an example of the usage pattern for this new feature? |
Let me know if this example is enough: //Fake viewer
var viewer = new function() {
var _renderer; //WebGLRenderer
var _textureToUpload = [];
this.loadTexture = function(tex) {
_textureToUpload.push(tex);
};
function onFrameUpdate() { //callback fired by window.requestAnimationFrame
var startTime = Date.now();
//upload textures in the queue to GPU within the time budget
while (_textureToUpload.length > 0) {
var tex = _textureToUpload.shift();
_renderer.uploadTexture(tex);
if (Date.now()-startTime > 7) //max total upload time = ~7ms
return;
}
}
};
//Usage
//Download img content, then create a texture object
var tex = new THREE.Texture(img);
tex.needsUpdate = false;
tex.onUpdate = function() {
//triggered when the texture has been uploaded to GPU
};
//submit the texture to the queue of texture to be uploaded
viewer.loadTexture(tex); Thanks, |
@@ -5610,108 +5610,114 @@ THREE.WebGLRenderer = function ( parameters ) { | |||
|
|||
}; | |||
|
|||
this.setTexture = function ( texture, slot ) { | |||
this.uploadTexture = function ( texture ) { |
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.
There are other calls to this.setTexture
in WebGLRenderer
itself which also rely in the slot
parameter. Do you mind taking a look?
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.
Ah wait. Ignore that, just saw that the setTexture is still there...
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.
Yes, the diff is hard to read in github due to the new tab indent. But the change is actually very minimal. I'm just exposing uploadTexture() and the behavior of setTexture() is left unchanged.
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.
Yep yep! Looks good! :)
add uploadTexture to WebGLRenderer
Thanks! |
Hi,
The goal of this PR is to provide a manual way of uploading texture.
The default behavior (needsUpdate=true) is well suited for gaming were all resources are loaded at start time.
But for a streaming solution (like in Photosynth2) this is actually hurting performance.
In Photosynth2 textures are uploaded in a loop which is suppose to not exceed ~7ms per frame, remaining textures are uploaded in consecutive frames.
Exposing this method let the user decide of his own strategy on when to upload texture.
Let me know if you find this useful or if there is any bug.
The diff is hard to read due to the new indentation but the change is actually pretty minimal.
Thanks,
--Henri