1 module evael.graphics.DepthFrameBuffer; 2 3 import evael.graphics.GraphicsDevice; 4 import evael.graphics.Texture; 5 import evael.graphics.FrameBuffer; 6 7 /** 8 * DepthFrameBuffer. 9 */ 10 class DepthFrameBuffer : FrameBuffer 11 { 12 private uint m_depthBuffer; 13 14 /** 15 * DepthFrameBuffer constructor. 16 * Params: 17 * graphics : graphics device 18 * width : width 19 * height : height 20 */ 21 public this(GraphicsDevice graphics, in int width, in int height) nothrow 22 { 23 super(graphics, width, height); 24 25 gl.GenRenderbuffers(1, &this.m_depthBuffer); 26 27 this.m_texture = Texture.generateEmptyTexture(); 28 29 this.m_graphicsDevice.bindTexture(this.m_texture); 30 31 gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, null); 32 gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); 33 gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 34 gl.BindTexture(GL_TEXTURE_2D, 0); 35 36 gl.BindFramebuffer(GL_FRAMEBUFFER, this.m_id); 37 gl.BindRenderbuffer(GL_RENDERBUFFER, this.m_depthBuffer); 38 gl.RenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height); 39 40 // Attach it to currently bound framebuffer object 41 gl.FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, this.m_texture.id, 0); 42 gl.FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, this.m_depthBuffer); 43 44 gl.BindRenderbuffer(GL_RENDERBUFFER, 0); 45 } 46 47 /** 48 * DepthFrameBuffer destructor. 49 */ 50 @nogc 51 public override void dispose() const nothrow 52 { 53 super.dispose(); 54 gl.DeleteRenderbuffers(1, &this.m_depthBuffer); 55 } 56 57 }