oframe / ogl

Minimal WebGL Library
https://oframe.github.io/ogl/examples
3.71k stars 211 forks source link

Add copy and clone methods in Program class #155

Open RAX7 opened 2 years ago

RAX7 commented 2 years ago

In some cases it is necessary to create programs with the same shader code but different uniforms (eg texture or color). The clone method creates a shallow copy of Program class. Copies all properties by reference except the uniforms. If uniform value has a clone method (eg Vec2, Mat4), it will be used, otherwise (eg Texture) the value is copied by reference.

Nam-Hai commented 1 year ago

what is the difference by using the Program in the multiple Mesh you need and then change Mesh.program.uniforms.uTexture by hand ? Or am I mission something

eXponenta commented 1 year ago

@Nam-Hai Yep, clone doings fullcopy of programm include a uniforms state. You should know all copies of programm if you want to change uniforms state for all of them.

This is why i did proposal use a Material wrapper that will have shared program/material state.

139