private void Build(int width, int height, bool mipMap, RSurfaceFormat preferredFormat, RDepthFormat preferredDepthFormat, int preferredMultiSampleCount, bool shared) { var depth = 0; var stencil = 0; BackBuffer = new RTexture2D(); BackBuffer.Create(width, height, RPixelFormat.Rgba, preferredFormat); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, BackBuffer.Id, 0); if (preferredDepthFormat != RDepthFormat.None) { DepthBuffer = new RTexture2D(); if (preferredDepthFormat == RDepthFormat.Depth24Stencil8 || preferredDepthFormat == RDepthFormat.Depth32Stencil8) { DepthBuffer.CreateDepth(width, height, RPixelFormat.DepthStencil, preferredDepthFormat); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthStencilAttachment, TextureTarget.Texture2D, DepthBuffer.Id, 0); } else { DepthBuffer.CreateDepth(width, height, RPixelFormat.DepthComponent, preferredDepthFormat); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, TextureTarget.Texture2D, DepthBuffer.Id, 0); } REngine.CheckGLError(); } if (GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer) != FramebufferErrorCode.FramebufferComplete) { throw new Exception("Error creating frame buffer: framebuffer is not complete"); } }
public void CreateDepth(int width, int height, RPixelFormat format, RDepthFormat depthFormat) { GL.GenTextures(1, out Id); textureTarget = TextureTarget.Texture2D; GL.BindTexture(textureTarget, Id); REngine.CheckGLError(); GL.TexImage2D(textureTarget, 0, GetPixelInternalForDepth(depthFormat), width, height, 0, (PixelFormat)format, GetPixelTypeForDepth(depthFormat), IntPtr.Zero); REngine.CheckGLError(); CreateProperties(textureTarget, false); REngine.CheckGLError(); }
PixelType GetPixelTypeForDepth(RDepthFormat depthFormat) { switch (depthFormat) { case RDepthFormat.Depth16: case RDepthFormat.Depth24: return(PixelType.UnsignedInt); case RDepthFormat.Depth24Stencil8: case RDepthFormat.Depth32Stencil8: return(PixelType.UnsignedInt248); default: return(PixelType.UnsignedInt); } }
public RFrameBuffer(int width, int height, bool mipMap, RSurfaceFormat preferredFormat, RDepthFormat preferredDepthFormat, int preferredMultiSampleCount, bool shared) { Width = width; Height = height; DepthStencilFormat = preferredDepthFormat; SurfaceFormat = preferredFormat; MultiSampleCount = preferredMultiSampleCount; var id = 0; GL.GenFramebuffers(1, out id); REngine.CheckGLError(); Id = id; Bind(); Build(width, height, mipMap, preferredFormat, preferredDepthFormat, preferredMultiSampleCount, shared); Unbind(); }
PixelInternalFormat GetPixelInternalForDepth(RDepthFormat depthFormat) { switch (depthFormat) { case RDepthFormat.Depth16: return(PixelInternalFormat.DepthComponent16); case RDepthFormat.Depth24: return(PixelInternalFormat.DepthComponent24); case RDepthFormat.Depth24Stencil8: return(PixelInternalFormat.Depth24Stencil8); case RDepthFormat.Depth32Stencil8: return(PixelInternalFormat.Depth32fStencil8); default: return(PixelInternalFormat.DepthStencil); } }
public RFrameBuffer(int width, int height, bool mipMap, RSurfaceFormat preferredFormat, RDepthFormat preferredDepthFormat) : this(width, height, mipMap, preferredFormat, preferredDepthFormat, 0) { }
public RFrameBuffer(int width, int height, bool mipMap, RSurfaceFormat preferredFormat, RDepthFormat preferredDepthFormat, int preferredMultiSampleCount) : this(width, height, mipMap, preferredFormat, preferredDepthFormat, preferredMultiSampleCount, false) { }