예제 #1
0
        /// <summary>
        /// Releases a render target and puts it back into the pool for future reuse.
        /// </summary>
        /// <param name="renderTarget">The render target.</param>
        public void Recycle(RenderTargetCube renderTarget)
        {
            if (renderTarget == null || renderTarget.IsDisposed)
            {
                return;
            }

            if (Enabled)
            {
                if ((GlobalSettings.ValidationLevelInternal & GlobalSettings.ValidationLevelUserHighExpensive) != 0)
                {
                    if (RenderTargetsCube.Contains(renderTarget))
                    {
                        throw new InvalidOperationException("Cannot recycle render target because it is already in the render target pool.");
                    }
                }

                RenderTargetsCube.Add(renderTarget);
                CountersCube.Add(0);
            }
            else
            {
                renderTarget.Dispose();
            }
        }
        public void ShouldClearRenderTargetAndGetData(int size)
        {
            var dataSize         = size * size;
            var renderTargetCube = new RenderTargetCube(gd, size, false, SurfaceFormat.Color, DepthFormat.Depth16);

            var colors = new[]
            {
                Color.BlanchedAlmond,
                Color.BlueViolet,
                Color.DarkSeaGreen,
                Color.ForestGreen,
                Color.IndianRed,
                Color.LightGoldenrodYellow
            };

            for (var i = 0; i < 6; i++)
            {
                gd.SetRenderTarget(renderTargetCube, (CubeMapFace)i);
                gd.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, colors[i], 1.0f, 0);
                gd.SetRenderTarget(null, (CubeMapFace)i);
            }

            for (var i = 0; i < 6; i++)
            {
                var readData = new Color[dataSize];
                renderTargetCube.GetData((CubeMapFace)i, readData);

                for (var j = 0; j < dataSize; j++)
                {
                    Assert.AreEqual(colors[i], readData[j]);
                }
            }

            renderTargetCube.Dispose();
        }
예제 #3
0
        public void ContentLostResources()
        {
            // https://blogs.msdn.microsoft.com/shawnhar/2007/12/12/virtualizing-the-graphicsdevice-in-xna-game-studio-2-0/

            var rt  = new RenderTarget2D(gdm.GraphicsDevice, 5, 5);
            var vb  = new DynamicVertexBuffer(gd, VertexPositionColor.VertexDeclaration, 1, BufferUsage.None);
            var ib  = new DynamicIndexBuffer(gd, IndexElementSize.SixteenBits, 1, BufferUsage.None);
            var rtc = new RenderTargetCube(gd, 1, false, SurfaceFormat.Color, DepthFormat.Depth16);

            gd.Reset();

            Assert.IsTrue(rt.IsContentLost);
            Assert.IsFalse(rt.IsDisposed);

            Assert.IsTrue(vb.IsContentLost);
            Assert.IsFalse(vb.IsDisposed);

            Assert.IsTrue(ib.IsContentLost);
            Assert.IsFalse(ib.IsDisposed);

            Assert.IsTrue(rtc.IsContentLost);
            Assert.IsFalse(rtc.IsDisposed);

            rt.Dispose();
            vb.Dispose();
            ib.Dispose();
            rtc.Dispose();
        }
예제 #4
0
 public void CleanUp(PloobsEngine.Engine.GraphicFactory factory)
 {
     ForwardEnvironmentShader.Cleanup(factory);
     if (RenderTargetCube != null && !RenderTargetCube.IsDisposed)
     {
         RenderTargetCube.Dispose();
     }
 }
예제 #5
0
 public void Dispose()
 {
     if (shadowMap != null)
     {
         shadowMap.Dispose();
     }
     mo        = null;
     shadowMap = null;
 }
 public void NullDeviceShouldThrowArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         var renderTarget = new RenderTargetCube(null, 16, false, SurfaceFormat.Color, DepthFormat.None);
         renderTarget.Dispose();
     });
     GC.GetTotalMemory(true); // collect uninitialized renderTarget
 }
 public void Die(Game1 game)
 {
     ShadowCube.Dispose();
     ShadowCube2.Dispose();
     NeedShadows = true;
 }