Control#render() vs Control#update(tpf)

In a com.jme3.scene.control.AbstractControl there is two methods, controlUpdate(tpf) and controlRender().



What are the semantics of them? When is it better to stick code in one over another?

One is called during render and one during update :wink: The latter is also not called when the spatial is culled. Note that most things that are scene graph-related should be done in update(). Render() is special and for things like debug or getting stuff out of the GPU and similar and should normally not modify things.

Thanks! Then controlRender is the one I’m gonna use :slight_smile:

@normen said:
One is called during render and one during update ;) The latter is also not called when the spatial is culled. Note that most things that are scene graph-related should be done in update(). Render() is special and for things like debug or getting stuff out of the GPU and similar and should normally not modify things.

to be clear it's controlRender() that is not called when the spatial is culled, controlUpdate() is always called unless the control is disabled

I guess update shader uniforms is a good fit for the controlRender method so I’ll use that :slight_smile:

@kwando said:
I guess update shader uniforms is a good fit for the controlRender method so I'll use that :)

No exactly not. That is changing something, right? :)

Why? Since the object is culled there is no need to update the shader uniforms? =S

@kwando said:
Why? Since the object is culled there is no need to update the shader uniforms? =S

Huh? You are not supposed to do anything that changes something in render().

yeah be careful with that, you are potentially changing a material.

Objects are sorted according to their material during the update loop (after your controlUpdate), by changing something on the material during the render loop, you may produce some shader switches that will slow down the rendering process.

You’d better do it in the update, that’s not gonna kill the perfs.

I’m sorry, you are talking to a tree again :stuck_out_tongue: I’l move the code to update(tpf) instead :slight_smile:

@nehon, going through the rendering code I can tell that runControlRender(this, vp) is called during the geometry queueing. Sorting is done after that so shader switches should not be a problem, if I’m getting it right…

mhhh true, you’re right. Actually the queues are sorted later.

So i guess it’s ok as long as you don’t change the scene graph itself (anyway you’ll have an exception if you do).