Discussion:
[Opensg-users] OpenSG2: Accumulated changes... part 3: texture
Johannes Brunen
2017-01-18 10:58:12 UTC
Permalink
Hi,

on request of Carsten I have split up my 'accumulated changes' into smaller chunks so that it easier to look at them.

Currently, I'm working on shadow techniques. For these I do need texture arrays, especially cube map arrays. I have added support to the TexureObjChunk and to LayeredTextureBuffer and TextureBuffer.
The last two did have an 'unused' field named 'zoffset'. According to the specs of GL the correct parameter name is 'layer' and I have modified the Interface accordingly. See the .fcd files for that.

Additionally the Buffers work with the 'glFramebufferTextureLayer' API of OpenGL now.

Best,
Johannes
Carsten Neumann
2017-01-20 00:16:59 UTC
Permalink
Hello Johannes,
Post by Johannes Brunen
Currently, I'm working on shadow techniques. For these I do need texture
arrays, especially cube map arrays. I have added support to the
TexureObjChunk and to LayeredTextureBuffer and TextureBuffer.
I think this changes the semantics of LayeredTextureBuffer in an
incompatible way, so I'm not sure we can do this right away. See below
why I think this changes semantics.
Post by Johannes Brunen
The last two did have an 'unused' field named 'zoffset'. According to
the specs of GL the correct parameter name is 'layer' and I have
modified the Interface accordingly. See the .fcd files for that.
Additionally the Buffers work with the 'glFramebufferTextureLayer' API of OpenGL now.
My understanding of glFramebufferTextureLayer is that it is used to
attach a single face of a cubemap array texture as a framebuffer
attachment. While when using a cubemap array texture with
glFramebufferTexture3D this attaches all 6 faces of the cubemap as a
layered attachment point. Which of the layers a primitive is rendered to
is decided at runtime using a geometry shader that assigns to the
builtin variable gl_Layer.
Therefore (assuming the above is correct and I didn't misread the patch)
you are changing LayeredTextureBuffer from creating such a layered
attachment to a non-layered attachment.
I think the use of 'glFramebufferTextureLayer' should only be in
TextureBuffer, since that is used for non-layered framebuffer attachments.

Cheers,
Carsten
Johannes
2017-01-20 09:45:16 UTC
Permalink
Hello Carsten,

first off, I'm not an expert with textures. First I will show you how I
initialize my shadow maps in my plain OpenGL example. So that you
understand what I want to map into OpenSG land.

Example: [1]

Next the sources I have studied:
https://www.khronos.org/opengl/wiki/Framebuffer_Object
https://www.khronos.org/opengl/wiki/Geometry_Shader#Layered_rendering

https://www.opengl.org/sdk/docs/man/html/glFramebufferTextureLayer.xhtml
https://www.opengl.org/sdk/docs/man/html/glFramebufferTexture.xhtml


I have reread these articles and I now tend to agree with you wrt to the
LayeredTextureBuffer. However, the GL_TEXTURE_CUBE_MAP_ARRAY is missing
nevertheless (?)

This stuff is not easy to grasp. Most important for me is that I have
the OpenSG primitives at hand that I need to translate my plain OpenGL
shadow implementation into OpenSG land.

Best,
Johannes


[1]
void OpenGLWindow::InitializeShadowFBO()
{
if (_shadow_casters_point > 0)
{
glGenTextures(1, &_texture_shadow_array_point_id);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY,
_texture_shadow_array_point_id);

glTexImage3D(
GL_TEXTURE_CUBE_MAP_ARRAY,
0,
GL_DEPTH_COMPONENT,
SHADOW_WIDTH,
SHADOW_HEIGHT,
6 * _shadow_casters_point,
0,
GL_DEPTH_COMPONENT,
GL_FLOAT,
nullptr);

glTexParameteri (GL_TEXTURE_CUBE_MAP_ARRAY,
GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_CUBE_MAP_ARRAY,
GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_R,
GL_CLAMP_TO_EDGE);

for (unsigned int i = 0; i < _shadow_casters_point * 6; i++)
{
GLuint fbo_id;
glGenFramebuffers(1, &fbo_id);

glBindFramebuffer(GL_FRAMEBUFFER, fbo_id);
glFramebufferTextureLayer(GL_FRAMEBUFFER,
GL_DEPTH_ATTACHMENT, _texture_shadow_array_point_id, 0, i);

glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);

glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, 0);
}

if (_shadow_casters_dir > 0)
{
glGenTextures(1, &_texture_shadow_array_dir_id);
glBindTexture(GL_TEXTURE_2D_ARRAY, _texture_shadow_array_dir_id);

glTexImage3D(
GL_TEXTURE_2D_ARRAY,
0,
GL_DEPTH_COMPONENT,
SHADOW_WIDTH,
SHADOW_HEIGHT,
_shadow_casters_dir,
0,
GL_DEPTH_COMPONENT,
GL_FLOAT,
nullptr);

glTexParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_BORDER);
glTexParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_BORDER);

GLfloat borderColor[] = { 1.0, 1.0, 1.0, 1.0 };
glTexParameterfv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR,
borderColor);
glTexParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER,
GL_NEAREST);

for (unsigned int i = 0; i < _shadow_casters_dir; i++)
{
GLuint fbo_id;
glGenFramebuffers(1, &fbo_id);

glBindFramebuffer(GL_FRAMEBUFFER, fbo_id);
glFramebufferTextureLayer(GL_FRAMEBUFFER,
GL_DEPTH_ATTACHMENT, _texture_shadow_array_dir_id, 0, i);

glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);

glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
}
}
Carsten Neumann
2017-01-20 23:01:30 UTC
Permalink
Hello Johannes,
Post by Johannes
I have reread these articles and I now tend to agree with you wrt to the
LayeredTextureBuffer. However, the GL_TEXTURE_CUBE_MAP_ARRAY is missing
nevertheless (?)
yes, looks like it is missing. I think it should make use of
glFramebufferTexture for the cubemap array case though.
Post by Johannes
This stuff is not easy to grasp. Most important for me is that I have
the OpenSG primitives at hand that I need to translate my plain OpenGL
shadow implementation into OpenSG land.
I think OSG::TextureBuffer is the one that should use
glFramebufferTextureLayer (for cubemap array and similar cases) to make
non-layer attachments. To me that seems in line with it's other uses
where it binds a plain 2D image as the attachment.
Since you have a use case for these, you are likely in a much better
position to verify changes. Can you adjust the changes to
TextureBuffer/LayeredTextureBuffer to be in line with the above? Thanks!

Cheers,
Carsten
Johannes
2017-01-23 08:05:44 UTC
Permalink
Hello Carsten,
Can you adjust the changes to TextureBuffer/LayeredTextureBuffer
to be in line with the above? Thanks!
here we go :-)

Best Johannes
Carsten Neumann
2017-01-24 23:43:32 UTC
Permalink
Hello Johannes,
Post by Johannes
Can you adjust the changes to TextureBuffer/LayeredTextureBuffer
to be in line with the above? Thanks!
here we go :-)
thank you. It appears this in a small way depends on the GL changes in
part 5 though? I've added the missing function pointer type for
glFramebufferTextureLayer to OSGGLFuncProtos.h to make it independent of
that change. Thanks again,

Cheers,
Carsten

Loading...