/// <summary>
        /// Blits the surface onto the specified destination surface.
        /// </summary>
        /// <param name="src">The source surface.</param>
        /// <param name="srcRect">The area of this surface that will be copied to the destination surface.</param>
        /// <param name="dst">The destination surface.</param>
        /// <param name="dstRect">The area on the destination surface to which this surface will be copied.</param>
        private static void BlitInternal(OpenGLSurface2D src, Rectangle srcRect, OpenGLSurface2D dst, Rectangle dstRect)
        {
            var sdlSrcRect = new SDL_Rect()
            {
                x = srcRect.X, y = srcRect.Y, w = srcRect.Width, h = srcRect.Height
            };
            var sdlDstRect = new SDL_Rect()
            {
                x = dstRect.X, y = dstRect.Y, w = dstRect.Width, h = dstRect.Height
            };

            if (SDL.SetSurfaceBlendMode(src.nativesurf.Native, SDL_BlendMode.NONE) < 0)
            {
                throw new SDL2Exception();
            }

            if (srcRect.Width != dstRect.Width || srcRect.Height != dstRect.Height)
            {
                if (SDL.BlitScaled(src.nativesurf.Native, &sdlSrcRect, dst.nativesurf.Native, &sdlDstRect) < 0)
                {
                    throw new SDL2Exception();
                }
            }
            else
            {
                if (SDL.BlitSurface(src.nativesurf.Native, &sdlSrcRect, dst.nativesurf.Native, &sdlDstRect) < 0)
                {
                    throw new SDL2Exception();
                }
            }
        }
Beispiel #2
0
        /// <inheritdoc/>
        public override Texture2D Process(ContentManager manager, IContentProcessorMetadata metadata, SDL_Surface input)
        {
            var mdat = metadata.As <OpenGLTexture2DProcessorMetadata>();

            using (var surface = new OpenGLSurface2D(manager.Ultraviolet, input))
            {
                return(surface.CreateTexture(mdat.PremultiplyAlpha));
            }
        }
Beispiel #3
0
        /// <inheritdoc/>
        public override void ExportPreprocessed(ContentManager manager, IContentProcessorMetadata metadata, BinaryWriter writer, SDL_Surface input, Boolean delete)
        {
            var mdat = metadata.As <OpenGLTexture2DProcessorMetadata>();

            using (var surface = new OpenGLSurface2D(manager.Ultraviolet, input))
            {
                surface.PrepareForTextureExport(mdat.PremultiplyAlpha);

                using (var memstream = new MemoryStream())
                {
                    surface.SaveAsPng(memstream);
                    writer.Write((int)memstream.Length);
                    writer.Write(memstream.ToArray());
                }
            }
        }
        /// <summary>
        /// Blits the surface onto the specified destination surface.
        /// </summary>
        /// <param name="src">The source surface.</param>
        /// <param name="srcRect">The area of this surface that will be copied to the destination surface.</param>
        /// <param name="dst">The destination surface.</param>
        /// <param name="dstRect">The area on the destination surface to which this surface will be copied.</param>
        private static void BlitInternal(OpenGLSurface2D src, Rectangle srcRect, OpenGLSurface2D dst, Rectangle dstRect)
        {
            var sdlSrcRect = new SDL_Rect() { x = srcRect.X, y = srcRect.Y, w = srcRect.Width, h = srcRect.Height };
            var sdlDstRect = new SDL_Rect() { x = dstRect.X, y = dstRect.Y, w = dstRect.Width, h = dstRect.Height };

            if (SDL.SetSurfaceBlendMode(src.nativesurf.Native, SDL_BlendMode.NONE) < 0)
                throw new SDL2Exception();

            if (srcRect.Width != dstRect.Width || srcRect.Height != dstRect.Height)
            {
                if (SDL.BlitScaled(src.nativesurf.Native, &sdlSrcRect, dst.nativesurf.Native, &sdlDstRect) < 0)
                    throw new SDL2Exception();
            }
            else
            {
                if (SDL.BlitSurface(src.nativesurf.Native, &sdlSrcRect, dst.nativesurf.Native, &sdlDstRect) < 0)
                    throw new SDL2Exception();
            }
        }