Skip to content
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

Merged
merged 1 commit into from Aug 20, 2014
Merged

Conversation

henri-astre-msft
Copy link
Contributor

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

There should be no change in setTexture behavior.
@WestLangley
Copy link
Collaborator

Can you provide an example of the usage pattern for this new feature?

@henri-astre-msft
Copy link
Contributor Author

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,
--Henri

@@ -5610,108 +5610,114 @@ THREE.WebGLRenderer = function ( parameters ) {

};

this.setTexture = function ( texture, slot ) {
this.uploadTexture = function ( texture ) {
Copy link
Owner

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?

Copy link
Owner

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...

Copy link
Contributor Author

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep yep! Looks good! :)

mrdoob added a commit that referenced this pull request Aug 20, 2014
@mrdoob mrdoob merged commit 3c50ca7 into mrdoob:dev Aug 20, 2014
@mrdoob
Copy link
Owner

mrdoob commented Aug 20, 2014

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants