From 1a1b87d5505bd98321dfcab4fb00da3ee5767a1c Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Mon, 15 Feb 2016 14:59:02 +0100 Subject: [PATCH] only upload to texture DirtyRect --- src/OpenTKGameWindow.cs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index 140436b5..a2ca54d8 100644 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -244,10 +244,18 @@ namespace Crow shader.Enable (); - GL.TexSubImage2D (TextureTarget.Texture2D, 0, - 0, 0, ClientRectangle.Width, ClientRectangle.Height, - OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp); - + if (isDirty) { + byte[] tmp = new byte[4 * DirtyRect.Width * DirtyRect.Height]; + for (int y = 0; y < DirtyRect.Height; y++) { + Array.Copy(bmp, + ((DirtyRect.Top + y) * ClientRectangle.Width * 4) + DirtyRect.Left * 4, + tmp, y * DirtyRect.Width * 4, DirtyRect.Width *4); + } + GL.TexSubImage2D (TextureTarget.Texture2D, 0, + DirtyRect.Left, DirtyRect.Top, DirtyRect.Width, DirtyRect.Height, + OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, tmp); + isDirty = false; + } uiQuad.Render (PrimitiveType.TriangleStrip); GL.BindTexture(TextureTarget.Texture2D, 0); @@ -264,6 +272,9 @@ namespace Crow public Stopwatch drawingTime = new Stopwatch (); #endif + bool isDirty = false; + Rectangle DirtyRect; + #region update void update () { @@ -340,6 +351,13 @@ namespace Crow clipping.stroke (ctx, Color.Red.AdjustAlpha(0.5)); #endif + isDirty = true; + DirtyRect = clipping.Bounds; + DirtyRect.Left = Math.Max (0, DirtyRect.Left); + DirtyRect.Top = Math.Max (0, DirtyRect.Top); + DirtyRect.Width = Math.Min (ClientRectangle.Width - DirtyRect.Left, DirtyRect.Width); + DirtyRect.Height = Math.Min (ClientRectangle.Height - DirtyRect.Top, DirtyRect.Height); + clipping.Reset (); } -- 2.47.3