private void CreateBuffers() { // Create color texture GL.GenTextures(1, out m_colorTextureHandle); GL.BindTexture(TextureTarget.Texture2D, m_colorTextureHandle); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, m_pixelWidth, m_pixelHeight, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero); //TODO: test for GL Error here (might be unsupported format) // prevent feedback, reading and writing to the same image is a bad idea GL.BindTexture(TextureTarget.Texture2D, 0); // Create depth Renderbuffer GL.GenRenderbuffers(1, out m_renderbufferHandle); GL.Ext.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, m_renderbufferHandle); GL.Ext.RenderbufferStorage(RenderbufferTarget.RenderbufferExt, (RenderbufferStorage)All.Depth24Stencil8, m_pixelWidth, m_pixelHeight); //TODO: test for GL Error here (might be unsupported format) // Create a FBO and attach the textures GL.Ext.GenFramebuffers(1, out m_fboHandle); GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, m_fboHandle); GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, m_colorTextureHandle, 0); GL.Ext.FramebufferRenderbuffer(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, RenderbufferTarget.RenderbufferExt, m_renderbufferHandle); GL.Ext.FramebufferRenderbuffer(FramebufferTarget.FramebufferExt, FramebufferAttachment.StencilAttachmentExt, RenderbufferTarget.RenderbufferExt, m_renderbufferHandle); GLEx.CheckFboStatus(); // return to visible framebuffer GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); // Allocate the occlusion query we're going to use for m_occlusionQueries = new int[64]; GL.GenQueries(m_occlusionQueries.Length, m_occlusionQueries); }
private void CreateCubemapBuffers() { CubemapFboHandle = new uint[6]; CubemapColorTexture = new uint[6]; CubemapDepthRenderbuffer = new uint[6]; cubemapDirections = new Vector3[6]; cubemapDirections[0] = new Vector3(0.0f, 0.0f, 1.0f); cubemapDirections[1] = new Vector3(0.0f, 0.0f, -1.0f); cubemapDirections[2] = new Vector3(0.0f, 1.0f, 0.0f); cubemapDirections[3] = new Vector3(0.0f, -1.0f, 0.0f); cubemapDirections[4] = new Vector3(1.0f, 0.0f, 0.0f); cubemapDirections[5] = new Vector3(-1.0f, 0.0f, 0.0f); cubemapUps = new Vector3[6]; cubemapUps[0] = Vector3.UnitY; cubemapUps[1] = Vector3.UnitY; cubemapUps[2] = Vector3.UnitZ; cubemapUps[3] = Vector3.UnitZ; cubemapUps[4] = Vector3.UnitY; cubemapUps[5] = Vector3.UnitY; cubemapColorBuffers = new RGB[6][]; for (int i = 0; i < 6; i++) { cubemapColorBuffers[i] = new RGB[CubemapWidth * CubemapHeight]; } cubemapDepthBuffers = new float[6][]; for (int i = 0; i < 6; i++) { cubemapDepthBuffers[i] = new float[CubemapWidth * CubemapHeight]; } cubemapProjections = new Matrix4[6]; // Create Color Texture GL.GenTextures(6, CubemapColorTexture); for (int i = 0; i < CubemapColorTexture.Length; i++) { GL.BindTexture(TextureTarget.Texture2D, CubemapColorTexture[i]); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, CubemapWidth, CubemapHeight, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero); } // test for GL Error here (might be unsupported format) GL.BindTexture(TextureTarget.Texture2D, 0); // prevent feedback, reading and writing to the same image is a bad idea // Create Depth Renderbuffer GL.Ext.GenRenderbuffers(6, CubemapDepthRenderbuffer); for (int i = 0; i < CubemapDepthRenderbuffer.Length; i++) { GL.Ext.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, CubemapDepthRenderbuffer[i]); GL.Ext.RenderbufferStorage(RenderbufferTarget.RenderbufferExt, (RenderbufferStorage)All.DepthComponent32, CubemapWidth, CubemapHeight); } // test for GL Error here (might be unsupported format) // Create a FBO and attach the textures GL.Ext.GenFramebuffers(6, CubemapFboHandle); for (int i = 0; i < CubemapFboHandle.Length; i++) { GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, CubemapFboHandle[i]); GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, CubemapColorTexture[i], 0); GL.Ext.FramebufferRenderbuffer(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, RenderbufferTarget.RenderbufferExt, CubemapDepthRenderbuffer[i]); } GLEx.CheckFboStatus(); GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); // return to visible framebuffer }