/// <summary> /// Creates new (set of) renderable Texture(s) /// </summary> /// <param name="width">The width in pixels of the Texture(s)</param> /// <param name="height">The height in pixels of the Texture(s)</param> /// <param name="depth">True if depthbuffer is required when rendering to the Texture(s)</param> /// <param name="components">The number of color components the Texture(s) have</param> /// <param name="format">The data format the Texture(s) shall use, default is 16bit Half</param> /// <param name="buffers">The number of Textures to use.</param> public RenderToTexture(int width, int height, bool depth, int components = 3, Type format = null, int buffers = 1) { _fbo = new FramebufferObject(); _textures = new Texture2D[buffers]; _bufs = new DrawBuffersEnum[buffers]; for (var i = 0; i < buffers; i++) _bufs[i] = DrawBuffersEnum.ColorAttachment0 + i; _fbo.Activate(); GL.DrawBuffers(_textures.Length, _bufs); Utilities.CheckGL(); _fbo.Finish(); GL.DrawBuffer(DrawBufferMode.Back); Utilities.CheckGL(); for (var i = 0; i < buffers; i++) { _textures[i] = new Texture2D(width, height, components, format ?? typeof(Half)); _fbo.SetTexture(_textures[i], i); } if (depth) { _rbo = new RenderbufferObject(); _fbo.Activate(); _rbo.SetSize(width, height); _fbo.Finish(); } _fbo.Check(); Utilities.CheckGL(); }
private RenderToTexture(int width, int height, bool depth, int buffers, Func<Texture2D> createTexture ) { _fbo = new FramebufferObject(); _textures = new Texture2D[buffers]; _bufs = new DrawBuffersEnum[buffers]; for (var i = 0; i < buffers; i++) _bufs[i] = DrawBuffersEnum.ColorAttachment0 + i; _fbo.Activate(); GL.DrawBuffers(_textures.Length, _bufs); Utilities.CheckGL(); _fbo.Finish(); GL.DrawBuffer(DrawBufferMode.Back); Utilities.CheckGL(); for (var i = 0; i < buffers; i++) { _textures[i] = createTexture(); _fbo.SetTexture(_textures[i], i); } if (depth) { _rbo = new RenderbufferObject(); _fbo.Activate(); _rbo.SetSize(width, height); _fbo.Finish(); } _fbo.Check(); Utilities.CheckGL(); }
private RenderToTexture(int width, int height, bool depth, int buffers, Func <Texture2D> createTexture) { _fbo = new FramebufferObject(); _textures = new Texture2D[buffers]; _bufs = new DrawBuffersEnum[buffers]; for (var i = 0; i < buffers; i++) { _bufs[i] = DrawBuffersEnum.ColorAttachment0 + i; } _fbo.Activate(); GL.DrawBuffers(_textures.Length, _bufs); Utilities.CheckGL(); _fbo.Finish(); GL.DrawBuffer(DrawBufferMode.Back); Utilities.CheckGL(); for (var i = 0; i < buffers; i++) { _textures[i] = createTexture(); _fbo.SetTexture(_textures[i], i); } if (depth) { _rbo = new RenderbufferObject(); _fbo.Activate(); _rbo.SetSize(width, height); _fbo.Finish(); } _fbo.Check(); Utilities.CheckGL(); }