private bool Equals(PixelFormatDescriptor other) { return(DrawingFormat == other.DrawingFormat && GLPixelInternalFormat == other.GLPixelInternalFormat && GLPixelFormat == other.GLPixelFormat && GLPixelType == other.GLPixelType); }
public StreamGLTextureReader(Stream input, int width, int height, PixelFormatDescriptor format) { _input = input; _width = width; _height = height; _format = format; }
public GLTexture(int id, int width, int height, PixelFormatDescriptor pixelFormat) { Id = id; Width = width; Height = height; PixelFormat = pixelFormat; }
public BitmapGLTextureReader(Bitmap bitmap, int width, int height, PixelFormatDescriptor format) { _bitmap = bitmap; _width = width; _height = height; _format = format; }
public byte[] GetManagedPixelsArray(PixelFormatDescriptor format) { byte[] result = new byte[Width * Height * format.BytesPerPixel]; using (GLService.AcquireContext()) { GL.BindTexture(TextureTarget.Texture2D, Id); GL.GetTexImage(TextureTarget.Texture2D, 0, format, format, result); return(result); } }
public SafeHGlobalHandle GetUnmanagedPixelsArray(PixelFormatDescriptor format) { SafeHGlobalHandle result = new SafeHGlobalHandle(Width * Height * format.BytesPerPixel); using (GLService.AcquireContext()) using (DisposableAction insurance = new DisposableAction(result.Dispose)) { GL.BindTexture(TextureTarget.Texture2D, Id); GL.GetTexImage(TextureTarget.Texture2D, 0, format, format, result.DangerousGetHandle()); insurance.Cancel(); } return(result); }
public static GLTexture HorizontalJoin(GLTexture left, GLTexture right) { Exceptions.CheckArgumentNull(left, "left"); Exceptions.CheckArgumentNull(right, "right"); if (left.Height != right.Height) { throw new ArgumentException("height"); } if (!left.PixelFormat.Equals(right.PixelFormat)) { throw new ArgumentException("pixelFormat"); } int height = left.Height; PixelFormatDescriptor format = left.PixelFormat; GLTexture texture = null; try { using (GLService.AcquireContext()) { texture = new GLTexture(GL.GenTexture(), left.Width + right.Width, height, format); GL.BindTexture(TextureTarget.Texture2D, texture.Id); GL.TexImage2D(TextureTarget.Texture2D, 0, format, texture.Width, texture.Height, 0, format, format, IntPtr.Zero); if (GLService.CheckVersion(4, 3)) { GL.CopyImageSubData(left.Id, ImageTarget.Texture2D, 0, 0, 0, 0, texture.Id, ImageTarget.Texture2D, 0, 0, 0, 0, left.Width, left.Height, 1); GL.CopyImageSubData(right.Id, ImageTarget.Texture2D, 0, 0, 0, 0, texture.Id, ImageTarget.Texture2D, 0, left.Width, 0, 0, right.Width, right.Height, 1); } else { using (GLFramebuffer framebuffer = GLFramebuffer.Create()) { GL.BindFramebuffer(FramebufferTarget.Framebuffer, framebuffer.Id); GL.FramebufferTexture2D(FramebufferTarget.DrawFramebuffer, FramebufferAttachment.ColorAttachment1, TextureTarget.Texture2D, texture.Id, 0); GL.FramebufferTexture2D(FramebufferTarget.ReadFramebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, left.Id, 0); GL.DrawBuffer(DrawBufferMode.ColorAttachment1); GL.BlitFramebuffer(0, 0, left.Width, height, 0, 0, left.Width, height, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Linear); GL.FramebufferTexture2D(FramebufferTarget.ReadFramebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, right.Id, 0); GL.DrawBuffer(DrawBufferMode.ColorAttachment1); GL.BlitFramebuffer(0, 0, left.Width, height, left.Width, 0, left.Width * 2, height, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Linear); } } GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); } } catch { texture.SafeDispose(); throw; } return(texture); }
public static async Task <GLTexture> FromBitmapAsync(CancellationToken cancelationToken, Bitmap bitmap, int width, int height, PixelFormatDescriptor format) { BitmapGLTextureReader reader = new BitmapGLTextureReader(bitmap, width, height, format); return(await reader.ReadTextureAsync(cancelationToken)); }
public static async Task <GLTexture> FromStreamAsync(CancellationToken cancelationToken, Stream input, int width, int height, PixelFormatDescriptor format) { StreamGLTextureReader reader = new StreamGLTextureReader(input, width, height, format); return(await reader.ReadTextureAsync(cancelationToken)); }
public static GLTexture FromBitmap(Bitmap bitmap, int width, int height, PixelFormatDescriptor format) { BitmapGLTextureReader reader = new BitmapGLTextureReader(bitmap, width, height, format); return(reader.ReadTexture()); }
public static GLTexture FromStream(Stream input, int width, int height, PixelFormatDescriptor format) { StreamGLTextureReader reader = new StreamGLTextureReader(input, width, height, format); return(reader.ReadTexture()); }
public static void HorizontalSplit(GLTexture layer, out GLTexture leftTexture, out GLTexture rightTexture) { Exceptions.CheckArgumentNull(layer, "layer"); if (layer.Width % 2 != 0) { throw new ArgumentException("layer.Width"); } int width = layer.Width / 2; int height = layer.Height; PixelFormatDescriptor format = layer.PixelFormat; leftTexture = null; rightTexture = null; try { using (GLService.AcquireContext()) { leftTexture = new GLTexture(GL.GenTexture(), width, height, format); rightTexture = new GLTexture(GL.GenTexture(), width, height, format); foreach (GLTexture texture in new[] { leftTexture, rightTexture }) { GL.BindTexture(TextureTarget.Texture2D, texture.Id); GL.TexImage2D(TextureTarget.Texture2D, 0, format, width, height, 0, format, format, IntPtr.Zero); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); } if (GLService.CheckVersion(4, 3)) { GL.CopyImageSubData(layer.Id, ImageTarget.Texture2D, 0, 0, 0, 0, leftTexture.Id, ImageTarget.Texture2D, 0, 0, 0, 0, width, height, 1); GL.CopyImageSubData(layer.Id, ImageTarget.Texture2D, 0, width, 0, 0, rightTexture.Id, ImageTarget.Texture2D, 0, 0, 0, 0, width, height, 1); } else { using (GLFramebuffer framebuffer = GLFramebuffer.Create()) { GL.BindFramebuffer(FramebufferTarget.Framebuffer, framebuffer.Id); GL.FramebufferTexture2D(FramebufferTarget.ReadFramebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, layer.Id, 0); GL.FramebufferTexture2D(FramebufferTarget.DrawFramebuffer, FramebufferAttachment.ColorAttachment1, TextureTarget.Texture2D, leftTexture.Id, 0); GL.DrawBuffer(DrawBufferMode.ColorAttachment1); GL.BlitFramebuffer(0, 0, width, height, 0, 0, width, height, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Linear); GL.FramebufferTexture2D(FramebufferTarget.DrawFramebuffer, FramebufferAttachment.ColorAttachment1, TextureTarget.Texture2D, rightTexture.Id, 0); GL.DrawBuffer(DrawBufferMode.ColorAttachment1); GL.BlitFramebuffer(width, 0, width * 2, height, 0, 0, width, height, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Linear); } } } } catch { leftTexture.SafeDispose(); rightTexture.SafeDispose(); throw; } }