Exemple #1
0
        void OnResize(object sender, EventArgs args)
        {
            var texDesc = new Texture2DDescription
            {
                ArraySize         = 1,
                BindFlags         = BindFlags.None,
                CpuAccessFlags    = CpuAccessFlags.None,
                Format            = Format.B8G8R8A8_UNorm,
                Height            = ClientSize.Height,
                Width             = ClientSize.Width,
                Usage             = ResourceUsage.Default,
                SampleDescription = new SampleDescription(1, 0),
                OptionFlags       = ResourceOptionFlags.None,
                MipLevels         = 1
            };

            if (mResolveTexture != null)
            {
                mResolveTexture.Dispose();
            }

            mResolveTexture = new Texture2D(WorldFrame.Instance.GraphicsContext.Device, texDesc);

            if (mMapTexture != null)
            {
                mMapTexture.Dispose();
            }

            texDesc.CpuAccessFlags = CpuAccessFlags.Read;
            texDesc.Usage          = ResourceUsage.Staging;
            mMapTexture            = new Texture2D(WorldFrame.Instance.GraphicsContext.Device, texDesc);

            mTarget.Resize(ClientSize.Width, ClientSize.Height, true);
            mCamera.SetAspect((float)ClientSize.Width / ClientSize.Height);
        }
Exemple #2
0
        public ThumbnailCapture(int Width, int Height)
        {
            ImgWidth  = Width;
            ImgHeight = Height;

            if (WorldFrame.Instance == null || WorldFrame.Instance.GraphicsContext == null)
            {
                return;
            }

            mTarget       = new RenderTarget(WorldFrame.Instance.GraphicsContext);
            mMatrixBuffer = new ConstantBuffer(WorldFrame.Instance.GraphicsContext);

            mCamera                    = new PerspectiveCamera();
            mCamera.ViewChanged       += delegate { mMatrixBuffer.UpdateData(mCamera.ViewProjection); };
            mCamera.ProjectionChanged += delegate { mMatrixBuffer.UpdateData(mCamera.ViewProjection); };
            mCamera.SetClip(0.2f, 1000.0f);
            mCamera.SetParameters(new Vector3(10, 0, 0), Vector3.Zero, Vector3.UnitZ, Vector3.UnitY);

            renderTimer          = new Timer();
            renderTimer.Interval = 10;
            renderTimer.Tick    += OnRenderTimerTick;

            var texDesc = new Texture2DDescription
            {
                ArraySize         = 1,
                BindFlags         = BindFlags.None,
                CpuAccessFlags    = CpuAccessFlags.None,
                Format            = Format.B8G8R8A8_UNorm,
                Height            = ImgWidth,
                Width             = ImgWidth,
                Usage             = ResourceUsage.Default,
                SampleDescription = new SampleDescription(1, 0),
                OptionFlags       = ResourceOptionFlags.None,
                MipLevels         = 1
            };

            if (mResolveTexture != null)
            {
                mResolveTexture.Dispose();
            }

            mResolveTexture = new Texture2D(WorldFrame.Instance.GraphicsContext.Device, texDesc);

            if (mMapTexture != null)
            {
                mMapTexture.Dispose();
            }

            texDesc.CpuAccessFlags = CpuAccessFlags.Read;
            texDesc.Usage          = ResourceUsage.Staging;
            mMapTexture            = new Texture2D(WorldFrame.Instance.GraphicsContext.Device, texDesc);

            mTarget.Resize(ImgWidth, ImgHeight, true);
            mCamera.SetAspect((float)ImgWidth / ImgHeight);
        }