/// <summary> /// Initializes a new instance of the <see cref="FBO"/> class. /// </summary> /// <param name="size"></param> /// <exception cref="FBOException"> /// Given texture is null or texture dimensions do not match primary texture /// </exception> public CubeMapFBO(int size) { _size = size; // Create an FBO object GL.GenFramebuffers(1, out _fboHandle); Texture = new Texture(TextureTarget.TextureCubeMap); //Initialize empty textures in texture Texture.Activate(); for (int i = 0; i < 6; i++) { GL.TexImage2D(TextureTarget.TextureCubeMapPositiveX + i, 0, PixelInternalFormat.Rgba32f, size, size, 0, PixelFormat.Rgba, PixelType.Float, IntPtr.Zero); } Texture.Deactivate(); //Bind texture to framebuffer Activate(); for (int i = 0; i < 6; i++) { GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0 + i, TextureTarget.TextureCubeMapPositiveX + i, Texture.ID, 0); } string status = GetStatusMessage(); Deactivate(); if (!string.IsNullOrEmpty(status)) { throw new FBOException(status); } //Attach depth Activate(); _depth = new RenderBuffer(RenderbufferStorage.DepthComponent32, _size, _size); _depth.Attach(FramebufferAttachment.DepthAttachment); status = GetStatusMessage(); Deactivate(); if (!string.IsNullOrEmpty(status)) { throw new FBOException(status); } int linMin = (int)TextureMinFilter.LinearMipmapLinear; int linMag = (int)TextureMagFilter.Linear; int clampToEdge = (int)TextureWrapMode.ClampToEdge; Texture.Activate(); GL.TexParameterI(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, ref linMin); GL.TexParameterI(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, ref linMag); GL.TexParameterI(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, ref clampToEdge); GL.TexParameterI(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, ref clampToEdge); GL.TexParameterI(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, ref clampToEdge); Texture.Deactivate(); }