hi,
i’ve recently read that it is much better for performance to use immutable texture storages, allocated by glTexStorage2D(), rather than glTexImage2D()
for the framebuffer i need a texture that can be resized if the user resizes the window, but apparently that doesnt happen all the time
is it a good idea to use glTexStorage2D() for my framebuffer textures ?
another question:
i’ve problems using the depth texture, here’s how i’ve se it up
glBindTexture(GL_TEXTURE_2D, m_framebuffer.depth.ID());
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, m_framebuffer.size.x, m_framebuffer.size.y, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// ...
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_framebuffer.depth.ID(), 0);
here’s my fragment shader:
// used for postprocessing, both textures are the framebuffer attachments
#version 450
uniform vec2 DisplaySize = vec2(1200, 900);
uniform sampler2D scenecolortexture;
uniform sampler2D scenedepthtexture;
layout (location = 0) out vec4 FragmentColor0;
void main(void)
{
vec2 texcoords = gl_FragCoord.xy / DisplaySize;
// inversion
//FragmentColor0 = vec4(vec3(1.0 - texture(scenecolortexture, texcoords)), 1.0);
// grayscale
//vec4 color = texture(scenecolortexture, texcoords);
//float average = (color.r + color.g + color.b) / 3.0;
//FragmentColor0 = vec4(average, average, average, 1.0);
// depth
float depth = texture(scenedepthtexture, texcoords).r;
FragmentColor0 = vec4(depth, depth, depth, 1.0);
}
the screen appears completely gray, meaning that i’m not getting 0 as depth, but something between 0 and 1
how is it done right ?