- function TShadowFbo.Generate(Attachments: Integer): Boolean;
- var
- i: Integer;
- FBOState: TuInt32;
- begin
- SetLength(tex, Attachments);
- for I := 0 to Attachments - 1 do
- begin
- // Try to use a texture depth component
- glGenTextures(1, @tex[i]);
- glBindTexture(GL_TEXTURE_2D, tex[i]);
- // GL_LINEAR does not make sense for depth texture. However, next tutorial shows usage of GL_LINEAR and PCF
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- // No need to force GL_DEPTH_COMPONENT24, drivers usually give you the max precision if available
- glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, Height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
- end;
- glBindTexture(GL_TEXTURE_2D, 0);
- // create a framebuffer object
- glGenFramebuffersEXT(1, @container);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, container);
- // Instruct openGL that we won't bind a color texture with the currently binded FBO
- glDrawBuffer(GL_NONE);
- glReadBuffer(GL_NONE);
- // attach the texture to FBO depth attachment point
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, tex[i], 0);
- // check FBO status
- FBOState := glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
- if FBOState<> GL_FRAMEBUFFER_COMPLETE_EXT then
- result:=false
- else Result:=True;
- // switch back to window-system-provided framebuffer
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- end;