Problems using glFramebufferTexture2D() with Emscripten
Hi everyone, i am currently struggling to use the OpenGL ES function glFramebufferTexture2D() using Emscripten as my compiler. I thought that this library would just pass the call through to the Emscripten OpenGL ES (2) implementation, because it isn't part of the OpenGL 1.1 or 2.x standard, according to this page: https://docs.gl/es2/glFramebufferTexture2D Only newer desktop OpenGL versions >=3 should support it, which this library is not targeting.
Still, I found a lot of code in framebuffers.c that's executed, when this function is called, that might be the cause for my problems.
But I don't have enough OpenGL experience to tell what's exactly going wrong when i execute this:
// create a intermediate depth texture
GLuint depthTexture;
glGenTextures(1, &depthTexture);
glBindTexture(GL_TEXTURE_2D, depthTexture);
glTexImage2D(
GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
CheckAndPrintOpenGLErrors(__LINE__);
// setup framebuffer
GLuint framebuffer;
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
CheckAndPrintOpenGLErrors(__LINE__);
// this throws invalid operation (code 1282)!
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0);
CheckAndPrintOpenGLErrors(__LINE__);
// This assert surprisingly is true...
GLenum framebufferStatus;
framebufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
assert(framebufferStatus == GL_FRAMEBUFFER_COMPLETE);
I wonder where this invalid operation error comes from. To me, it looks like all the enums I passed are allowed by the spec and should also work in the browser.
According to mdn gl.INVALID_OPERATION should only occur in this cases:
A gl.INVALID_OPERATION error is thrown if texture isn't 0 or the name of an existing texture object.
Any ideas what i am doing wrong here?
Depth texture are tricky, and might not be supported. I think the error might comes from there. Do you need the depth texture or a renderbuffer can work?
Hey thanks for the quick response again ;) I haven't written the code myself, but we use a depth texture to store the values from the depth buffer in it. As you mention in the readme of this repo, it's not possible to read from the depth buffer directly with Gl4es or OpenGL ES in general, so this is the workaround that we are trying to implement...