/// <inheritdoc/> public override Surface2D CreateSurface(Rectangle region) { Contract.EnsureNotDisposed(this, Disposed); if (region.Left < 0 || region.Top < 0 || region.Right > Width || region.Bottom > Height || region.Width <= 0 || region.Height <= 0) { throw new ArgumentOutOfRangeException("region"); } var copysurf = new SDL2PlatformNativeSurface(region.Width, region.Height); var srcrect = new SDL_Rect() { x = region.X, y = region.Y, w = region.Width, h = region.Height }; var dstrect = new SDL_Rect() { x = 0, y = 0, w = region.Width, h = region.Height }; if (SDL_BlitSurface(nativesurf.NativePtr, &srcrect, copysurf.NativePtr, &dstrect) < 0) { throw new SDL2Exception(); } var options = SrgbEncoded ? SurfaceOptions.SrgbColor : SurfaceOptions.LinearColor; var result = new SDL2Surface2D(Ultraviolet, copysurf, options); return(result); }
/// <inheritdoc/> public override Texture2D CreateTexture(Boolean unprocessed) { Contract.EnsureNotDisposed(this, Disposed); if (unprocessed) { var options = TextureOptions.ImmutableStorage | (SrgbEncoded ? TextureOptions.SrgbColor : TextureOptions.LinearColor); return(Texture2D.CreateTexture((IntPtr)NativePtr->pixels, Width, Height, BytesPerPixel, options)); } else { using (var copysurf = new SDL2PlatformNativeSurface(Width, Height)) { if (SDL_BlitSurface(nativesurf.NativePtr, null, copysurf.NativePtr, null) < 0) { throw new SDL2Exception(); } copysurf.Flip(Ultraviolet.GetGraphics().Capabilities.FlippedTextures ? SurfaceFlipDirection.Vertical : SurfaceFlipDirection.None); var options = TextureOptions.ImmutableStorage | (SrgbEncoded ? TextureOptions.SrgbColor : TextureOptions.LinearColor); return(Texture2D.CreateTexture((IntPtr)copysurf.NativePtr->pixels, copysurf.Width, copysurf.Height, copysurf.BytesPerPixel, options)); } } }
/// <inheritdoc/> public override PlatformNativeSurface CreateCopy() { Contract.EnsureNotDisposed(this, Disposed); var copy = new SDL2PlatformNativeSurface(Width, Height); if (SDL_BlitSurface(ptr, null, copy.ptr, null) < 0) { throw new SDL2Exception(); } copy.isReadyForTextureExport = isReadyForTextureExport; copy.isFlippedVertically = isFlippedVertically; copy.isFlippedHorizontally = isFlippedHorizontally; copy.isAlphaPremultiplied = isAlphaPremultiplied; return(copy); }