Trying to utilize directional shadow mapping on OpenGL. Need to generate a depth texture that isn't a renderbuffer (need to be able to read from it) it future passes. Keep getting GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT (as result of glCheckFramebufferStatus) when running on Android (don't get error when running on OSX).
Here's my code:
//Shadow
//gen tex
gl_shadow_bogus_texture_active_n = 7;
glActiveTexture(GL_TEXTURE0+gl_shadow_bogus_texture_active_n);
glGenTextures(1, &gl_shadow_bogus_texture_buff_id);
glBindTexture(GL_TEXTURE_2D, gl_shadow_bogus_texture_buff_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,tex_dim.x,tex_dim.y,0,GL_RGB,GL_UNSIGNED_BYTE,0);
//gen depth
gl_shadow_texture_active_n = 4;
glActiveTexture(GL_TEXTURE0+gl_shadow_texture_active_n);
glGenTextures(1, &gl_shadow_texture_buff_id);
glBindTexture(GL_TEXTURE_2D, gl_shadow_texture_buff_id);
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);
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT16,1024,1024,0,GL_DEPTH_COMPONENT,GL_FLOAT,0);
glGenFramebuffers(1, &gl_shadow_framebuffer_id); //gen fb
glBindFramebuffer(GL_FRAMEBUFFER, gl_shadow_framebuffer_id); //bind fb
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gl_shadow_bogus_texture_buff_id, 0); //attach tex
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, gl_shadow_texture_buff_id, 0); //attach depth
note that the whole gl_shadow_bogus_texture_buff_id
thing (the generation and binding of the color texture) is just an attempt to fill out the framebuffer, thus getting rid of the error. I don't actually care about the color data.
a further note is that the "color tex gen/bind" is not necessary on mac, and can be replaced with glDrawBuffer(GL_NONE)
and glReadBuffer(GL_NONE)
. But I can't compile with those in for android...