/*public void UpdateTexture(int textureName) * { * GL.BindTexture(TextureTarget.Texture2D, textureName); * PixelBufferImpl.CVPixelBufferLockBaseAddress(_handle, CVPixelBufferLockFlags.kCVPixelBufferLock_ReadOnly); * GL.TexImage2D( * TextureTarget.Texture2D, * 0, * PixelInternalFormat.Rgba, * Width, * Height, * 0, * PixelFormat.Bgra, * PixelType.UnsignedByte, * PixelBufferImpl.CVPixelBufferGetBaseAddress(_handle)); * PixelBufferImpl.CVPixelBufferUnlockBaseAddress(_handle, CVPixelBufferLockFlags.kCVPixelBufferLock_ReadOnly); * }*/ public void UpdateTexture(int textureName, VideoHandle handle) { var width = Width; var height = Height; var bytesPerRow = BytesPerRow; var actualBytesPerRow = width * 4; PixelBufferImpl.CVPixelBufferLockBaseAddress(_handle, CVPixelBufferLockFlags.kCVPixelBufferLock_ReadOnly); var baseAddress = PixelBufferImpl.CVPixelBufferGetBaseAddress(_handle); var sourceAddress = baseAddress; var sourceOffset = 0; var destOffset = 0; for (int y = 0; y < height; y++) { sourceOffset = y * bytesPerRow; destOffset = y * actualBytesPerRow; sourceAddress = new IntPtr(baseAddress.ToInt64() + (Int64)sourceOffset); Marshal.Copy(sourceAddress, handle.Pixels, destOffset, actualBytesPerRow); } PixelBufferImpl.CVPixelBufferUnlockBaseAddress(_handle, CVPixelBufferLockFlags.kCVPixelBufferLock_ReadOnly); var pinnedArray = GCHandle.Alloc(handle.Pixels, GCHandleType.Pinned); _gl.BindTexture((int)TextureTarget.Texture2D, (int)textureName); if (width != handle.WidthCache || height != handle.HeightCache) { handle.WidthCache = width; handle.HeightCache = height; _gl.TexImage2D( (int)TextureTarget.Texture2D, 0, (int)PixelInternalFormat.Rgba, width, height, 0, (int)PixelFormat.Bgra, (int)PixelType.UnsignedByte, pinnedArray.AddrOfPinnedObject()); } else { _gl.TexSubImage2D( (int)TextureTarget.Texture2D, 0, 0, 0, width, height, (int)PixelFormat.Bgra, (int)PixelType.UnsignedByte, pinnedArray.AddrOfPinnedObject()); } pinnedArray.Free(); }
public static void BindTexture(GLTextureTarget target, GLTextureHandle texture) { _gl.BindTexture(target, texture); }
public void UpdateTexture(int textureHandle) { if (Width > 0 && Height > 0) { using (var dc = _drawingVisual.RenderOpen()) dc.DrawVideo(_mediaPlayer, new System.Windows.Rect(0, 0, Width, Height)); if (_renderTargetBitmap == null || (_widthCache != Width || _heightCache != Height)) { _renderTargetBitmap = new RenderTargetBitmap(Width, Height, 100, 100, PixelFormats.Pbgra32); } _renderTargetBitmap.Render(_drawingVisual); var stride = _renderTargetBitmap.PixelWidth * 4; var size = _renderTargetBitmap.PixelHeight * stride; if (_pixelBuffer == null || _pixelBuffer.Length != size) { _pixelBuffer = new byte[size]; } var pinnedBuffer = GCHandle.Alloc(_pixelBuffer, GCHandleType.Pinned); try { var pixelBufferPtr = pinnedBuffer.AddrOfPinnedObject(); _renderTargetBitmap.CopyPixels(Int32Rect.Empty, pixelBufferPtr, size, stride); _gl.BindTexture((int)TextureTarget.Texture2D, (int)textureHandle); if (_widthCache != Width || _heightCache != Height || _lastTextureHandle != textureHandle) { _widthCache = Width; _heightCache = Height; _lastTextureHandle = textureHandle; _gl.TexImage2D( (int)TextureTarget.Texture2D, 0, (int)PixelFormat.Bgra, Width, Height, 0, (int)PixelFormat.Bgra, (int)PixelType.UnsignedByte, pixelBufferPtr); } else { _gl.TexSubImage2D( (int)TextureTarget.Texture2D, 0, 0, 0, Width, Height, (int)PixelFormat.Bgra, (int)PixelType.UnsignedByte, pixelBufferPtr); } } finally { pinnedBuffer.Free(); } } }