aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/OpenTKGameWindow.cs
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2016-02-15 14:59:02 +0100
committerjpbruyere <jp.bruyere@hotmail.com>2016-02-15 14:59:02 +0100
commit1a1b87d5505bd98321dfcab4fb00da3ee5767a1c (patch)
treedfd7c7ac18d70128681d1579d454dbc36df2fdd9 /src/OpenTKGameWindow.cs
parent7a0f22382979d7f8b205280aab3653b872f94839 (diff)
only upload to texture DirtyRect
Diffstat (limited to 'src/OpenTKGameWindow.cs')
-rw-r--r--src/OpenTKGameWindow.cs26
1 files 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 ();
}