If I've got this stencilbuffer thingy right then geometries using the material above should not be rendered.
TestFunctions says the pixel should always fail the stencil test, but all the geometry still ends up on my screen.
I'm rendering to a FrameBuffer with a depth texture (Format.Depth) and there is no way for me to attach a stencil buffer and afaik the depthbuffer and stencil buffer is sharing space in hardware =S
@kwando said:
Great news! Does one have to enable stencil in the AppSettings? Noticed a setting for it there...
You only need to enable stencil there if you want to use it on the main framebuffer. If you want to use it on an FBO (as you mentioned in your post), you have to specify Format.Depth24Stencil8 in the FrameBuffer depth buffer setup.
Sure if this works correctly? Iācant create a Format.Depth24Stencil8 as a depth texture. Iām having a hard time thinking my Macbook Pro HD6750M GPU should not support this =S
Iām trying to use stencil with framebuffer (to mask light volume in a deferred rendering pass). And I also try to use TestFunction.Never to test āthe stencil testā. But witout success.
As a small sample I edit the sample jme3test.post.TestRenderToTexture with :
[java]
public Texture setupOffscreenView(){
ā¦
//setup framebuffer to use texture
offBuffer.setDepthBuffer(Format.Depth24Stencil8);
ā¦
Material material = assetManager.loadMaterial(āInterface/Logo/Logo.j3mā);
material.getAdditionalRenderState().setStencil(true,
StencilOperation.Keep, StencilOperation.Keep, StencilOperation.Keep,
StencilOperation.Keep, StencilOperation.Keep, StencilOperation.Keep,
TestFunction.Never, TestFunction.Never
);
ā¦
return offTex;
}
[/java]
full āmodifiedā source available at stencil and jme test Ā· GitHub
And expect to have the logo hidden (black or white), but stencil seems to have no impact.
What I did wrong ?
XxxRenderer doesnāt manage Depth24Stencil8.
To workaround the issue:
I copy LwjglRenderer and modify :
[java]
private int convertAttachmentSlot(int attachmentSlot) {
// can also add support for stencil here
if (attachmentSlot == -100) {
return GL_DEPTH_ATTACHMENT_EXT;
} else if (attachmentSlot == -101) {
return GL_DEPTH_STENCIL_ATTACHMENT;
} else if (attachmentSlot < 0 || attachmentSlot >= 16) {
throw new UnsupportedOperationException("Invalid FBO attachment slot: " + attachmentSlot);
}
return GL_COLOR_ATTACHMENT0_EXT + attachmentSlot;
}
[/java]
use refection to change the attachmentSlot
[java]
public static void setDepthStencilAttachment(FrameBuffer fb) {
Field field = FrameBuffer.class.getDeclaredField(ādepthBufā);
field.setAccessible(true);
RenderBuffer depthBuf = (RenderBuffer) field.get(fb);
depthBuf.slot = -101;
}
[/java]
@david.bernard.31 said:
@kwando, do you find a workaround for mac "unsupported image format 'Depth24Stencil8'" ? (2 users reported me the error)
2010 Macbook Pro with latest OSX
Macbook Pro (with Iris Pro GFX)
It will not work on Mac, because jME3 requires OpenGL 3.0+ for Depth24Stencil8 which is not exposed unless a core OpenGL 3.2 context is requested. The other option is to use EXT_packed_depth_stencil, but that one has somewhat different semantics and might be a bit too much work to support both ways. The alternative is to request jME3 to create a core 3.2 context via AppSettings.setRenderer(AppSettings.LWJGL_OPENGL3), but then all pre GLSL 1.5 shaders wonāt work.
I currently use a LwjglRendererCustom (a copy of LwjgRenderer + support for Stencil buffer like describe above in this thread). How to force OpenGL 3 I donāt see where the check opengl 3 requested / opengl 2 available is done. (I only used GLSL 1.5+)
@david.bernard.31 said:
From https://developer.apple.com/opengl/capabilities/ , mac 10.9 should support opengl 3.3 on every hardware.
I currently use a LwjglRendererCustom (a copy of LwjgRenderer + support for Stencil buffer like describe above in this thread). How to force OpenGL 3 I donāt see where the check opengl 3 requested / opengl 2 available is done. (I only used GLSL 1.5+)
ā
The alternative is to request jME3 to create a core 3.2 context via AppSettings.setRenderer(AppSettings.LWJGL_OPENGL3), but then all pre GLSL 1.5 shaders wonāt work.
I canāt use AppSettings.setRenderer(AppSettings.LWJGL_OPENGL3) because i use a custom renderer. My question is how with a custom renderer, where to look?