Determining whether the current thread is the OpenGL thread

Hey, I have a method that will be called both out and into the OpenGL thread (in a AppState.update() call) and its code must be run in the OpenGL thread because it changes the transform of some objects. When I call it outside the OpenGL thread I have to enqueue a Callable in the Application with the code inside the call() method, otherwise I can run the code directly which is lighter. I want for the code to look like this:



[java]

public void setButtonPosition(final String clientName, final float x, final float y)

{

if(isOpenGLThread())

{

Spatial child = rootNode.getChild(“button”+clientName);

if (child != null)

child.setLocalTranslation(new Vector3f(x, child.getLocalTranslation().y, y));

}

else

{

enqueue(new Callable() {

public Void call() throws Exception {

Spatial child = rootNode.getChild(“button”+clientName);

if (child != null)

child.setLocalTranslation(new Vector3f(x, child.getLocalTranslation().y, y));

return null;

}

});

}

}

[/java]



Thanks in advance,

In jME3 there can be multiple OpenGL threads. Application could get a method to check if you’re on “its” opengl thread… But generally you should better know when you are on the opengl thread and when not because of code logic :wink: