Update render

Hi,



I have two nodes, one attached to the rootNode with the spatials I want to be visible and the other not attached to the rootNode with the spatials invisible. When I move a spatial from one node to the other, I need to update the render, how could I do that in JME3? I’ve seen that in JME2 you could use:



display.getRenderer().draw(rootNode);

display.getRenderer().renderQueue();



but this methods are not available in JME3.





Thanks

Why do you need those calls? AFAIK by attaching one spatial to the node that is attached to the rootNode it will become visible automatically. The rootNode will be drawn per default during each update. Removing it from the node attached to the rootNode should make it invisible again. No manual updates should be required to do that I think.

If that’ s not what you are after, what is your problem exactly?

I need that because I want to do the following:



-Attach an spatial (lets call it “A”) to the visible node



-Count the pixels of “A” in the image



-Attach other spatials that may occlude “A” to the visible node



-Count the pixels of “A” that are not occluded



I want to obtain the percentage of pixels of “A” that is not occluded, and before I count the pixels I need to update the render





BTW, I count the pixels using:



[java]IntBuffer pixelBuf = ByteBuffer.allocateDirect((width*height)<<2).order(ByteOrder.nativeOrder()).asIntBuffer();

GL11.glReadPixels(0, 0, width, height, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, pixelBuf);[/java]

The rendermanager should be your place for such stuff, basically you could copy the render part of the simpleapplication two times in a row with your modifing code in the middle

Thanks! that’s what I needed, now i obtain the percentage without problems.



BTW, is there any more efficient way of counting pixels that using GL11.glReadPixels ?

You might be able to save one with a trick!



Do A* solid red

All others transparent green

(problem here might be rendering order depending on how the other objects are http://www.opengl.org/resources/faq/technical/transparency.htm)



Get all pixel then

and count the ones being only redchanel and the ones being red and green channel.

So you only need to do once then







EDIT: Just found while reading for myself:

Source:http://www.opengl.org/resources/faq/technical/performance.htm

22.070 Why are glDrawPixels() and glReadPixels() so slow?



While performance of the OpenGL 2D path (as its called) is acceptable on many higher-end UNIX workstation-class devices, some implementations (especially low-end inexpensive consumer-level graphics cards) never have had good 2D path performance. One can only expect that corners were cut on these devices or in the device driver to bring their cost down and decrease their time to market. When this was written (early 2000), if you purchase a graphics device for under $500, chances are the OpenGL 2D path performance will be unacceptably slow.



If your graphics system should have decent performance but doesn’t, there are some steps you can take to boost the performance.



First, all glPixelTransfer() state should be set to their default values. Also, glPixelStore() should be set to its default value, with the exception of GL_PACK_ALIGNMENT and GL_UNPACK_ALIGNMENT (whichever is relevant), which should be set to 8. Your data pointer will need to be correspondingly double- word aligned.



Second, examine the parameters to glDrawPixels() or glReadPixels(). Do they correspond to the framebuffer layout? Think about how the framebuffer is configured for your application. For example, if you know you’re rendering into a 24-bit framebuffer with eight bits of destination alpha, your type parameter should be GL_RGBA, and your format parameter should be GL_UNSIGNED_BYTE. If your type and format parameters don’t correspond to the framebuffer configuration, it’s likely you’ll suffer a performance hit due to the per pixel processing that’s required to translate your data between your parameter specification and the framebuffer format.



Finally, make sure you don’t have unrealistic expectations. Know your system bus and memory bandwidth limitations.

Thank you for the trick and the information. I’m trying what you said, I have used the following material for the others:



[java] matTrans = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

matTrans.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

matTrans.setColor(“Color”, ColorRGBA.Green);[/java]



But the spatial doesn`t look transparent.



I use this code to check the color of the pixels, but it gives me the RGB color so I think it won’t work for counting the pixels being red and green:



[java]

IntBuffer pixelBuf = ByteBuffer.allocateDirect((width*height)<<2).order(ByteOrder.nativeOrder()).asIntBuffer();

GL11.glReadPixels(0, 0, width, height, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, pixelBuf);



for (int x = 0; x < width; x++) {

for (int y = 0; y < height; y++) {

int pixel = pixelBuf.get((height-y-1) * width + x);

if(pixel == color)

count++;

}

}

[/java]

If you know in wich order the data is, and use a color format (like the bgra) you can calculate wich parts of it are for wich colorchanel.



Don’t ask me about transparency though I have not much expirience with that yet, I assume you need to set some alpha funtion ( add substract bla) for it to work but I don’t know.

You shouldn’t have to (and just shouldn’t) ever use any direct GL calls in jME3. The engine expects you not to do it and might break for you in the future if you do.

Is there any other way of counting pixels without using GL calls?

You should know in advance because you set up the textures or buffers to render to…

Normen this time you should probably read the whole thread…



I don’t see any way of doing what is asked without this. Also readpixel is a harmless call as it does not change any states.

EmpirePhoenix said:
Normen this time you should probably read the whole thread.... I don't see any way of doing what is asked without this.

Ok, I guess in this case the code has to be moved to a preview processor or a filter/material.

EmpirePhoenix said:
Also readpixel is a harmless call as it does not change any states.

Imagine a jME3 that has multiple threads doing the render update and does not really run the render() update on the OpenGL thread, in such an environment the calls would be sure to cause havoc. jME3 abstracts OpenGL to be able to use a simple API for advanced processing.
EmpirePhoenix said:
If you know in wich order the data is, and use a color format (like the bgra) you can calculate wich parts of it are for wich colorchanel.

Don't ask me about transparency though I have not much expirience with that yet, I assume you need to set some alpha funtion ( add substract bla) for it to work but I don't know.


Thank you very much! It's working, with a single render I can count the total pixels of the spatial and the visible ones.

The problem with transparency was that I was using BlendMode.Alpha and changing that to BlendMode.Color now when a pixel of the spatial is occluded by another spatial, the pixel have in his red and green channel data.