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

WebGLRenderer: Remove program reference from materials. #19839

Merged
merged 1 commit into from Jul 15, 2020

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Jul 14, 2020

This PR ensures that Material.program is not set by the renderer anymore. If the renderer needs access to the current material's program, the following approach should be used:

const materialProperties = properties.get( material );
const program = materialProperties.program;

The refactoring makes the code more clear since the instance of WebGLProgram is now retrieved in a single way. Besides, it does not leak in materials and thus is no part of the public API anymore. It's also necessary to remove Material.program for solving #15047 anyway.

The only place that was necessary to change was WebGLRenderLists.

@mrdoob
Copy link
Owner

mrdoob commented Jul 14, 2020

Sweet! This definitely needs to happen.

Not sure properties.get( material ) will solve the actual problem though.

We may need something like:

programs.get( mesh );

If a material is reused by a Mesh and a InstancedMesh, two different programs would be produced, so we need to be able to get the program from a higher level.

Happy to merge this but I don't see how the new API could transition to a more suitable one without breaking again.

@mrdoob mrdoob added this to the r119 milestone Jul 14, 2020
@Mugen87
Copy link
Collaborator Author

Mugen87 commented Jul 15, 2020

Not sure properties.get( material ) will solve the actual problem though.

Yes, that's true. I'm currently trying a few things out to solve #15047 and I thought this small refactoring is something we can do now. The usage of Material.program just feels irritating since at first glance you wonder why a reference to WebGLProgram is stored at two places. Besides, the material is public and I don't think users should have access to a program property.

programs.get( mesh );

The signature probably needs scene and renderer as additional arguments too since the program also depends on scene and renderer parameters. Since solving #15047 will be a big change for WebGLRenderer, I would prefer to implement it gradually. Meaning preparing the code base for the "big" PR (in the hope that it will be fairly small 😇 ).

@mrdoob
Copy link
Owner

mrdoob commented Jul 15, 2020

The usage of Material.program just feels irritating since at first glance you wonder why a reference to WebGLProgram is stored at two places. Besides, the material is public and I don't think users should have access to a program property.

Definitely, it was a mistake to make it public.

Since solving #15047 will be a big change for WebGLRenderer, I would prefer to implement it gradually. Meaning preparing the code base for the "big" PR (in the hope that it will be fairly small 😇 ).

Yeah... Okay, if anything, this change will let us see how many people rely on material.program.

@mrdoob mrdoob merged commit 7047adf into mrdoob:dev Jul 15, 2020
@mrdoob
Copy link
Owner

mrdoob commented Jul 15, 2020

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

2 participants