public override void DidOutputSampleBuffer (AVCaptureOutput captureOutput, MonoTouch.CoreMedia.CMSampleBuffer sampleBuffer, AVCaptureConnection connection) { try { using (var pixelBuffer = sampleBuffer.GetImageBuffer () as CVPixelBuffer){ int width = pixelBuffer.Width; int height = pixelBuffer.Height; if (container.ripple == null || width != textureWidth || height != textureHeight){ textureWidth = width; textureHeight = height; container.SetupRipple (textureWidth, textureHeight); } CleanupTextures (); // Y-plane GL.ActiveTexture (All.Texture0); All re = (All) 0x1903; // GL_RED_EXT, RED component from ARB OpenGL extension CVReturn status; lumaTexture = container.videoTextureCache.TextureFromImage (pixelBuffer, true, re, textureWidth, textureHeight, re, DataType.UnsignedByte, 0, out status); if (lumaTexture == null){ Console.WriteLine ("Error creating luma texture: {0}", status); return; } GL.BindTexture ((All)lumaTexture.Target, lumaTexture.Name); GL.TexParameter (All.Texture2D, All.TextureWrapS, (int) All.ClampToEdge); GL.TexParameter (All.Texture2D, All.TextureWrapT, (int) All.ClampToEdge); // UV Plane GL.ActiveTexture (All.Texture1); re = (All) 0x8227; // GL_RG_EXT, RED GREEN component from ARB OpenGL extension chromaTexture = container.videoTextureCache.TextureFromImage (pixelBuffer, true, re, textureWidth/2, textureHeight/2, re, DataType.UnsignedByte, 1, out status); if (chromaTexture == null){ Console.WriteLine ("Error creating chroma texture: {0}", status); return; } GL.BindTexture ((All) chromaTexture.Target, chromaTexture.Name); GL.TexParameter (All.Texture2D, All.TextureWrapS, (int)All.ClampToEdge); GL.TexParameter (All.Texture2D, All.TextureWrapT, (int) All.ClampToEdge); } } finally { sampleBuffer.Dispose (); } }