From: jpbruyere Date: Mon, 15 Feb 2016 13:59:02 +0000 (+0100) Subject: only upload to texture DirtyRect X-Git-Tag: v0.4~127^2~18 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=1a1b87d5505bd98321dfcab4fb00da3ee5767a1c;p=jp%2Fcrow.git only upload to texture DirtyRect --- 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 (); }