]> O.S.I.I.S - jp/crow.git/commitdiff
only upload to texture DirtyRect
authorjpbruyere <jp.bruyere@hotmail.com>
Mon, 15 Feb 2016 13:59:02 +0000 (14:59 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Mon, 15 Feb 2016 13:59:02 +0000 (14:59 +0100)
src/OpenTKGameWindow.cs

index 140436b52b10ad559c4dded63935802ca4d194d6..a2ca54d802392614ef00c604ca43caec9e285b08 100644 (file)
@@ -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 ();
                                        }