glCopyTexImage2D
does work with NPOT image.
NPT image (non-power of two) is limited supported by OpenGLES 2/OpenGL 1 or WebGL, In OpenGLES 3/OpenGL 2 or later it is fully supported.
If you want to copy color attachment of fbo
to newTexture
.
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, newTexture);
glTexImage2D(bindTarget, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glCopyTexSubImage2D(target, level, 0, 0, 0, 0, width, height);
NPT image will output black color in fragment shader sampling if texture mipmap, magnification filter and repeat mode setting is wrong.
glCopyTexImage2D
followed byglGetTexImage
yield the same result asglReadPixels
? (not recommended as a long-term solution for performance reasons, but as a troubleshoot step to see what's going on with the texture) – KerstinglTexImage2D
to allocate the texture with a power-of-2 size and passingNULL
for the data, thenglCopyTexSubImage2D
which allows non power-of-2 dimensions. – Kerstin