Пример #1
0
 private void AssetBrowserDocument_IsActiveChanged(object sender, EventArgs e)
 {
     if (!AssetBrowserDocument.IsActive)
     {
         ThumbnailCache.Write(true);
     }
 }
Пример #2
0
        unsafe void OnRenderModel()
        {
            if (mRenderer == null)
            {
                return;
            }

            mTarget.Clear();
            mTarget.Apply();

            var ctx = WorldFrame.Instance.GraphicsContext;
            var vp  = ctx.Viewport;

            ctx.Context.Rasterizer.SetViewport(new Viewport(0, 0, ImgWidth, ImgHeight, 0.0f, 1.0f));

            ctx.Context.VertexShader.SetConstantBuffer(0, mMatrixBuffer.Native);
            mRenderer.RenderPortrait();

            mTarget.Remove();
            ctx.Context.Rasterizer.SetViewport(vp);

            ctx.Context.ResolveSubresource(mTarget.Texture, 0, mResolveTexture, 0, Format.B8G8R8A8_UNorm);
            ctx.Context.CopyResource(mResolveTexture, mMapTexture);

            var box  = ctx.Context.MapSubresource(mMapTexture, 0, MapMode.Read, MapFlags.None);
            var bmp  = new Bitmap(ImgWidth, ImgHeight, PixelFormat.Format32bppArgb);
            var bmpd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly,
                                    PixelFormat.Format32bppArgb);
            byte *ptrDst = (byte *)bmpd.Scan0.ToPointer();
            byte *ptrSrc = (byte *)box.DataPointer.ToPointer();

            for (var i = 0; i < bmp.Height; ++i)
            {
                UnsafeNativeMethods.CopyMemory(ptrDst + i * bmp.Width * 4, ptrSrc + i * box.RowPitch, bmp.Width * 4);
            }

            bmp.UnlockBits(bmpd);
            ctx.Context.UnmapSubresource(mMapTexture, 0);

            //Cache thumbnail
            if (mThumbnailCaptureFrame > 0 && --mThumbnailCaptureFrame == 0)
            {
                renderTimer.Stop();

                Bitmap thumbnail = new Bitmap(ImgWidth, ImgHeight);
                using (var g = System.Drawing.Graphics.FromImage(thumbnail))
                {
                    g.Clear(Color.Black);
                    g.DrawImage(bmp, new PointF(0, 0));
                }

                ThumbnailCache.Cache(mRenderer.Model.FileName, thumbnail);
                if (mModels.Count > 0) //More models so render next
                {
                    LoadModel();
                }
            }
        }
Пример #3
0
 private void Window_Unloaded(object sender, RoutedEventArgs e)
 {
     ThumbnailCache.Write(true);
 }