When using glTexImage2D
to attach textures to a Framebuffer Object (FBO), i recognized that the memory usage goes up in RAM. It looks like textures are allocated by OpenGL not only on the GPU but also in main memory.
Why is that happening?
Does it have any use?
Can memory allocation in main memory be prevented?
I am using the following GL-calls to attach a texture to an FBO:
auto internalformat = GL_RGBA32F;
auto format = GL_RGBA;
auto type = GL_FLOAT;
auto w = 1920;
auto h = 1080;
GLuint handle;
glGenTextures(1, &handle);
glTexImage2D(GL_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, nullptr);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, handle, 0);
The same happens when using glTexStorage2D
like follows (instead of the glTexImage2D
call):
glTexStorage2D(GL_TEXTURE_2D, 1, internalformat, w, h);
Why is this happening? I can't see why memory must be created in RAM and not only on the GPU. Are there better/other approaches?