[SOLVED-ish] See if a mesh has been changed?

I have an appstate that inside the update loop is searching for geometries in the scene, and when one is found i wish to see if its mesh has been changed (i.e. vertexbuffers content has been changed) since the last update.
There is something i could use as a reference value to accomplish this without comparing the buffers?

Unfortunately no. It’s one of those longstanding issues which I had to deal with when I implemented VAOs in the experimental branch.

The only way is to check VertexBuffer.isUpdateNeeded() for all VBs on the mesh, every frame.

1 Like

Thanks for the reply.
This is what i am doing


    protected boolean isMeshUpdateNeeded(Mesh m){
        for(VertexBuffer b:m.getBufferList()){
            if(b.isUpdateNeeded()){
                log.log(logLevel, "VertexBuffer {0} need update", b.getBufferType());
                return true;
            }else{
                log.log(logLevel, "VertexBuffer {0} is updated", b.getBufferType());
            }
        }
        return false;        
    }

but for some reasons isUpdateNeeded always return true for the Normal buffer.

Is the usage set to CpuOnly? It might be ignored for rendering.

Doesn’t seem so

VertexBuffer Normal need update. Usage Static

EDIT:
Updated code

    protected boolean isMeshUpdateNeeded(Mesh m){
        for(VertexBuffer b:m.getBufferList()){
            if(b.isUpdateNeeded()&&b.getUsage()!=Usage.CpuOnly){
                log.log(logLevel, "VertexBuffer {0} need update. Usage {1}", new Object[]{b.getBufferType(),b.getUsage()});
                return true;
            }else{
                log.log(logLevel, "VertexBuffer {0} is updated. Usage {1}", new Object[]{b.getBufferType(),b.getUsage()});
            }
        }
        return false;        
    }
    

EDIT2: I’m making a testcase < done

So if that’s the case that means every time that mesh is rendered, the normal buffer is uploaded to the GPU. What model are you seeing this happen on?

It’s a scene loaded with blenderloader, but for testing purpose i’ve just made this:

My output:

############# isMeshUpdateNeeded #############
VertexBuffer Position  is updated. Usage Static
VertexBuffer Normal need update. Usage Static
VertexBuffer TexCoord need update. Usage Static
VertexBuffer Index  is updated. Usage Static
############# /isMeshUpdateNeeded #############

Note for posterity:

It turned out that there is no straightforward way to determine that.
The isUpdateNeeded method is not a reliable because it could return the wrong result when the vertexbuffer is not used by any material (but still present in the mesh).
And the engine doesn’t provide anything neither for determine the case above.

I didn’t manage to propose a good enough solution to fix this in the core, so instead of that i made a workaround based on an appstate.

Might I ask the question how an Mesh does change without you actually telling it in your code to do so?

It doesn’t.
But i like to keep the source as modular as possible, so having a bunch of appstates with methods that need to be called each time a mesh is modified defeats a bit the purpose of my design.

With my solution i can make an appstate that is standalone and add it to my applications and i won’t need to care about anything else.

Hm have you thought about using an Eventbus for this kinds of behaviours?
Eg your places where you modify the mesh throw only the event, and the other parts consume it.

That way only the eventbus needs to be known.