Merge pull request #5410 from RoosterDragon/IDisposable

Disposable fixup
This commit is contained in:
Paul Chote
2014-06-11 10:55:44 +12:00
37 changed files with 248 additions and 260 deletions

View File

@@ -29,11 +29,12 @@ namespace OpenRA.Renderer.Sdl2
}
}
public class Sdl2GraphicsDevice : IGraphicsDevice
public sealed class Sdl2GraphicsDevice : IGraphicsDevice
{
Size size;
Sdl2Input input;
IntPtr context, window;
bool disposed;
public Size WindowSize { get { return size; } }
@@ -101,10 +102,21 @@ namespace OpenRA.Renderer.Sdl2
input = new Sdl2Input();
}
public virtual void Quit()
public void Dispose()
{
SDL.SDL_GL_DeleteContext(context);
SDL.SDL_DestroyWindow(window);
if (disposed)
return;
disposed = true;
if (context != IntPtr.Zero)
{
SDL.SDL_GL_DeleteContext(context);
context = IntPtr.Zero;
}
if (window != IntPtr.Zero)
{
SDL.SDL_DestroyWindow(window);
window = IntPtr.Zero;
}
SDL.SDL_Quit();
}

View File

@@ -106,18 +106,29 @@ namespace OpenRA.Renderer.Sdl2
public void SetData(Bitmap bitmap)
{
bool allocatedBitmap = false;
if (!Exts.IsPowerOf2(bitmap.Width) || !Exts.IsPowerOf2(bitmap.Height))
{
bitmap = new Bitmap(bitmap, bitmap.Size.NextPowerOf2());
allocatedBitmap = true;
}
try
{
size = new Size(bitmap.Width, bitmap.Height);
var bits = bitmap.LockBits(bitmap.Bounds(),
ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
size = new Size(bitmap.Width, bitmap.Height);
var bits = bitmap.LockBits(bitmap.Bounds(),
ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
PrepareTexture();
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, bits.Width, bits.Height,
0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bits.Scan0); // TODO: weird strides
ErrorHandler.CheckGlError();
bitmap.UnlockBits(bits);
PrepareTexture();
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, bits.Width, bits.Height,
0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bits.Scan0); // TODO: weird strides
ErrorHandler.CheckGlError();
bitmap.UnlockBits(bits);
}
finally
{
if (allocatedBitmap)
bitmap.Dispose();
}
}
public byte[] GetData()