Example #1
0
        private void DrawGpuTextureWithOldDesc(Action <SKSurface, GRBackendTextureDesc> draw)
        {
            using (var ctx = CreateGlContext())
            {
                ctx.MakeCurrent();

                // create the texture
                var textureInfo = ctx.CreateTexture(new SKSizeI(100, 100));

                var oldInfo = new GRTextureInfoOld
                {
                    Id     = textureInfo.Id,
                    Target = textureInfo.Target
                };
                var textureHandle = GCHandle.Alloc(oldInfo, GCHandleType.Pinned);
                var textureDesc   = new GRBackendTextureDesc
                {
                    Width         = 100,
                    Height        = 100,
                    Config        = GRPixelConfig.Rgba8888,
                    Flags         = GRBackendTextureDescFlags.RenderTarget,
                    Origin        = GRSurfaceOrigin.BottomLeft,
                    SampleCount   = 0,
                    TextureHandle = textureHandle.AddrOfPinnedObject(),
                };

                // create the surface
                using (var grContext = GRContext.Create(GRBackend.OpenGL))
                    using (var surface = SKSurface.CreateAsRenderTarget(grContext, textureDesc))
                    {
                        Assert.NotNull(surface);

                        draw(surface, textureDesc);
                    }

                // clean up
                textureHandle.Free();
                ctx.DestroyTexture(textureInfo.Id);
            }
        }
Example #2
0
        public void CanConvertFromPointerToDescToTexture()
        {
            // the custom struct to contain the info
            var oldInfo = new GRTextureInfoOld
            {
                Id     = 123,
                Target = 456
            };

            // pin it for the native code
            var textureHandle = GCHandle.Alloc(oldInfo, GCHandleType.Pinned);

            // use the very old desc
            var textureDesc = new GRBackendTextureDesc
            {
                Width         = 100,
                Height        = 100,
                Config        = GRPixelConfig.Rgba8888,
                Flags         = GRBackendTextureDescFlags.RenderTarget,
                Origin        = GRSurfaceOrigin.BottomLeft,
                SampleCount   = 246,
                TextureHandle = textureHandle.AddrOfPinnedObject(),
            };

            // create the new texture
            var texture = new GRBackendTexture(textureDesc);

            // free up all resourcess
            textureHandle.Free();

            // make sure we kept the information
            Assert.Equal(100, texture.Width);
            Assert.Equal(100, texture.Height);
            var newInfo = texture.GetGlTextureInfo();

            Assert.Equal(oldInfo.Id, newInfo.Id);
            Assert.Equal(oldInfo.Target, newInfo.Target);
            Assert.Equal(GRPixelConfig.Rgba8888.ToGlSizedFormat(), newInfo.Format);
        }