Пример #1
0
 public void TextureRenderTarget_Constructor_Test()
 {
     var rt = new TextureRenderTarget(Device, new Size(100, 100));
     Assert.IsNotNull(rt.Texture);
     Assert.IsNotNull(rt.TargetSurface);
     Assert.IsNotNull(rt.DepthStencilSurface);
 }
Пример #2
0
        public void Device_RenderTarget_Test()
        {
            var device = new Device(Window.Handle, Window.Width, Window.Height);
            var renderTarget = new TextureRenderTarget(device, new Size(100, 100));

            Assert.AreEqual(true, device.SetRenderTarget(renderTarget));
            Assert.AreEqual(renderTarget, device.RenderTarget);
        }
Пример #3
0
        bool IRenderable.Render(Camera camera, Light light)
        {
            if (IsEnabled == false)
                return true;

            if (this.textureRenderTarget == null ||
                this.textureRenderTarget.Size.Width != this.device.RenderTarget.Size.Width ||
                this.textureRenderTarget.Size.Height != this.device.RenderTarget.Size.Height)
            {
                this.textureRenderTarget = new TextureRenderTarget(this.device, this.device.RenderTarget.Size);
            }

            // Copy rendered buffer to our texture render target
            this.device.RawDevice.StretchRectangle(this.device.RenderTarget.TargetSurface, this.textureRenderTarget.TargetSurface, TextureFilter.None);

            this.device.RawDevice.SetRenderState(RenderState.ZEnable, false);
            this.device.RawDevice.SetRenderState(RenderState.ZWriteEnable, false);
            this.device.RawDevice.SetRenderState(RenderState.AlphaBlendEnable, false);

            this.device.RawDevice.VertexDeclaration = this.device.ScreenVertexDecl.RawDecl;

            if (this.device.RawDevice.SetStreamSource(0, this.device.ScreenVertexBuffer.RawBuffer, 0, this.device.ScreenVertexBuffer.ElementSize).IsFailure)
                return false;

            var windowSize = new Vector2(this.textureRenderTarget.Size.Width, this.textureRenderTarget.Size.Height);
            this.shader.Params["windowSize"].SetValue(windowSize);
            this.shader.Params["sceneMapTexture"].SetValue(this.textureRenderTarget.Texture);
            this.shader.Params["screenBorderFadeoutMapTexture"].SetValue(BorderTexture);

            bool ret = this.shader.RenderTechnique((pass) =>
            {
                return this.device.RawDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2).IsSuccess;
            }, "ScreenDarkenBorder");

            this.device.RawDevice.SetRenderState(RenderState.ZEnable, true);
            this.device.RawDevice.SetRenderState(RenderState.ZWriteEnable, true);

            return ret;
        }
Пример #4
0
        private void UpdateThumbnail()
        {
            TextureRenderTarget renderTarget = new TextureRenderTarget(this.framework.Device, thumbnailSize)
            {
                ClearBackGround = true,
                ClearColor = Color.Black,
                ClearOptions = D3D.ClearFlags.Target | D3D.ClearFlags.ZBuffer
            };

            if (RenderThumbnail(renderTarget) == false)
                return;

            this.thumbnail = new BitmapImage();
            this.thumbnail.BeginInit();
            this.thumbnail.CacheOption = BitmapCacheOption.OnLoad;
            this.thumbnail.StreamSource = renderTarget.Texture.ToJpgStream();
            this.thumbnail.EndInit();

            if (this.thumbnailMgr != null)
                this.thumbnailMgr.SetThumbnail(ThumbnailPath, this.thumbnail);

            OnPropertyChanged("Thumbnail");
        }
Пример #5
0
 private void CreateTextureRenderTargetIfRequired(ref TextureRenderTarget renderTarget, Size size)
 {
     if (renderTarget == null ||
         renderTarget.Size.Width != size.Width ||
         renderTarget.Size.Height != size.Height)
     {
         renderTarget = new TextureRenderTarget(this.device, size);
     }
 }
Пример #6
0
        private void CreateRenderTarget(Size size)
        {
            //if (this.renderTarget != null)
            //    this.renderTarget.Dispose();

            size.Width = Math.Max(1, size.Width);
            size.Height = Math.Max(1, size.Height);

            this.renderTarget = new TextureRenderTarget(this.framework.Device, size)
            {
                ClearBackGround = true,
                ClearColor = Color.Black
            };

            this.d3dImage.Lock();
            this.d3dImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, this.renderTarget.TargetSurface.ComPointer);
            this.d3dImage.Unlock();

            this.sceneManager.Camera.AspectRatio = (float)this.renderTarget.Size.Width / (float)this.renderTarget.Size.Height;

            SizeChanged(this, EventArgs.Empty);
        }