示例#1
0
        private void Initialize()
        {
            if (!_engine.IsDisposed)
            {
                // Use the engine's default viewport if selected
                Viewport = (Size == Size.Empty) ? _engine.RenderViewport : new Viewport {
                    Width = Size.Width, Height = Size.Height, MaxZ = 1
                };

                // Dispose the _rtsHelper if it already exists but the size has changed
                new Size(Viewport.Width, Viewport.Height).To(ref _rtsHelperSize, delegate
                {
                    if (_rtsHelper != null)
                    {
                        _rtsHelper.Dispose();
                        _rtsHelper = null;
                    }
                });

                // Reset the _rtsHelper if it already exists and is still valid
                _rtsHelper?.OnResetDevice();

                // Create the target texture and surface
                Texture = new Texture(_engine.Device, Viewport.Width, Viewport.Height, 1,
                                      Usage.RenderTarget, _engine.PresentParams.BackBufferFormat, Pool.Default);
                Surface = Texture.GetSurfaceLevel(0);
            }
        }
示例#2
0
 protected void DeleteShaderResources()
 {
     if (reflectionTexture != null)
     {
         reflectionTexture.Dispose();
         reflectionTexture = null;
     }
     if (reflectionSurface != null)
     {
         reflectionSurface.Dispose();
         reflectionSurface = null;
     }
     if (refractionTexture != null)
     {
         refractionTexture.Dispose();
         refractionTexture = null;
     }
     if (refractionSurface != null)
     {
         refractionSurface.Dispose();
         refractionSurface = null;
     }
     if (renderHelper != null)
     {
         renderHelper.Dispose();
         renderHelper = null;
     }
 }
示例#3
0
        public SDX_Surface(Size size)
        {
            mSrcRect = new Rectangle(new Point(0, 0), size);

            mDisplay = Display.Impl as SDX_Display;
            mDevice  = mDisplay.D3D_Device;

            mTexture = new Ref <Texture>(new Texture(mDevice.Device, size.Width, size.Height, 1, Usage.None,
                                                     Format.A8R8G8B8, Pool.Managed));

            RenderToSurface render = new RenderToSurface(mDevice.Device, size.Width, size.Height,
                                                         Format.A8R8G8B8, Format.D16);

            Viewport v = new Viewport(0, 0, size.Width, size.Height);

            render.BeginScene(mTexture.Value.GetSurfaceLevel(0), v);
            mDevice.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0, 0).ToArgb(), 1.0f, 0);
            render.EndScene(Filter.None);

            render.Dispose();
            render = null;

            mTextureSize = mSrcRect.Size;

            InitVerts();
        }
示例#4
0
        public MDX1_Surface(Size size)
        {
            mSrcRect = new Rectangle(new Point(0, 0), size);

            mDisplay = Display.Impl as MDX1_Display;
            mDevice  = mDisplay.D3D_Device;

            /*
             * Bitmap bitmap = new Bitmap(size.Width, size.Height);
             * Graphics g = Graphics.FromImage(bitmap);
             * g.Clear(Color.FromArgb(0, 0, 0, 0));
             * g.Dispose();
             */
            //mTexture = Texture.FromBitmap(mDevice, bitmap, Usage.None, Pool.Managed);
            mTexture = new Ref <Texture>(new Texture(mDevice.Device, size.Width, size.Height, 1, Usage.None,
                                                     Format.A8R8G8B8, Pool.Managed));

            mRenderToSurface = new RenderToSurface(mDevice.Device, size.Width, size.Height,
                                                   Format.A8R8G8B8, true, DepthFormat.D16);

            mRenderToSurface.BeginScene(mTexture.Value.GetSurfaceLevel(0));
            mDevice.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0, 0).ToArgb(), 1.0f, 0);
            mRenderToSurface.EndScene(Filter.None);

            mRenderToSurface.Dispose();
            mRenderToSurface = null;

            mTextureSize = mSrcRect.Size;

            InitVerts();
        }
示例#5
0
        /// <summary>
        /// Rebuilds the render targets after resizing.
        /// </summary>
        /// <param name="width">The new width of the rendering panel.</param>
        /// <param name="height">The new height of the rendering panel.</param>
        public void RebuildRenderTargets(int width, int height)
        {
            surfRender.Dispose();
            renderedGlow.Dispose();
            renderedScene.Dispose();

            surfRender    = new RenderToSurface(device, width, height, Format.X8R8G8B8, true, DepthFormat.D16);
            renderedGlow  = new Texture(device, width, height, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);
            renderedScene = new Texture(device, width, height, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);
        }
示例#6
0
        public void RebuildShadowMaps(int shadowMapSize)
        {
            shadowHelp.Dispose();
            shadowMap.Dispose();
            shadowMap2.Dispose();
            shadowMap3.Dispose();

            shadowHelp = new RenderToSurface(device, shadowMapSize, shadowMapSize, Format.X8R8G8B8, true, DepthFormat.D16);
            shadowMap  = new Texture(device, shadowMapSize, shadowMapSize, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);
            shadowMap2 = new Texture(device, shadowMapSize, shadowMapSize, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);
            shadowMap3 = new Texture(device, shadowMapSize, shadowMapSize, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);
        }
示例#7
0
 /// <summary>
 /// Clean up resources.
 /// </summary>
 private void CleanUp()
 {
     if (renderHelper != null)
     {
         renderHelper.Dispose();
         renderHelper = null;
     }
     if (cubeTexture != null)
     {
         cubeTexture.Dispose();
         cubeTexture = null;
     }
 }
        /// <summary>
        /// Uvolni objekty
        /// </summary>
        public void Dispose()
        {
            if (renderToSurface != null && !renderToSurface.Disposed)
            {
                renderToSurface.Dispose();
            }

            if (surface != null && !surface.Disposed)
            {
                surface.Dispose();
            }

            if (texture != null && !texture.Disposed)
            {
                texture.Dispose();
            }
        }
示例#9
0
        void UnloadGraphicResources()
        {
            deviceReadyForRender = false;

            resourceManager.ReleaseAll();

            resourceManager.EmptyTexture.Dispose();
            emptyTexture.Dispose();

            spriteRenderer.Dispose();
            lineRenderer.Dispose();

            loadingOverlay.Unload();
            blendOverlay.Unload();
            errorOverlay.Unload();

            renderToSurface.Dispose();
            renderToTexture.Dispose();
        }
        public void Dispose()
        {
            m_Initialized = false;
            if (m_Device != null)
            {
                m_Device.DeviceReset -= new EventHandler(OnDeviceReset);
            }

            if (m_Rts != null && !m_Rts.Disposed)
            {
                m_Rts.Dispose();
            }
            lock (m_RootSurfaceTiles.SyncRoot)
            {
                foreach (SurfaceTile st in m_RootSurfaceTiles)
                {
                    st.Dispose();
                }
            }
        }
示例#11
0
        public void Draw()
        {           // draw particles in _screenTexture
            RenderToSurface rts     = new RenderToSurface(_Device, _width, _height, _screenTexture.GetLevelDescription(0).Format);
            Surface         surface = _screenTexture.GetSurfaceLevel(0);

            rts.BeginScene(surface, new SharpDX.Viewport(0, 0, _width, _height, 0, 1));
            drawTexture(_backGroundTexture, _particles.Fade);
            DrawQuadParticles();
            rts.EndScene(Filter.None);
            surface.Dispose();
            rts.Dispose();

            //draw screenTexture in screen
            _Device.Viewport = new SharpDX.Viewport(0, 0, canvasWidth, canvasHeight, 0, 1);
            _Device.BeginScene();
            //
            _Device.Clear(ClearFlags.Target, new SharpDX.ColorBGRA(0.0f, 0.0f, 0.0f, 1.0f), 0.0f, 1);
            _Device.SetRenderState(RenderState.AlphaBlendEnable, true);
            _Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);             //SourceColor SourceAlpha SourceAlpha*
            _Device.SetRenderState(RenderState.DestinationBlend, Blend.DestinationAlpha);   //DestinationAlpha SourceColor  DestinationColor*

            if (_pointBool)
            {
                drawTexture(_earthTexture, 1.0f);
            }
            else
            {
                drawTexture(_earthWhite, 1.0f);
            }

            drawTexture(_screenTexture, 1.0f);
            _Device.SetRenderState(RenderState.AlphaBlendEnable, false);
            _Device.EndScene();
            _Device.Present();

            Texture temp = _backGroundTexture;

            _backGroundTexture = _screenTexture;
            _screenTexture     = temp;
        }
示例#12
0
        private void Dispose(bool disposing)
        {
            if (disposing)
            { // This block will only be executed on manual disposal, not by Garbage Collection
                // Unhook device events
                _engine.DeviceLost  -= OnLostDevice;
                _engine.DeviceReset -= Initialize;

                if (_engine == null || _engine.IsDisposed)
                {
                    return;
                }
                _rtsHelper?.Dispose();
                Surface?.Dispose();
                Texture?.Dispose();
            }
            else
            { // This block will only be executed on Garbage Collection, not by manual disposal
                Log.Error("Forgot to call Dispose on " + this);
#if DEBUG
                throw new InvalidOperationException("Forgot to call Dispose on " + this);
#endif
            }
        }
示例#13
0
        private void updateParticles()
        {
            int             particleRes = _particles.getParticleStateResolution();
            RenderToSurface rts         = new RenderToSurface(_Device, particleRes, particleRes, _stateParticleTexture1.GetLevelDescription(0).Format);
            Surface         surface     = _stateParticleTexture1.GetSurfaceLevel(0);

            rts.BeginScene(surface, new SharpDX.Viewport(0, 0, particleRes, particleRes, 0, 1));

            /*set parametres shader*/
            _updateParticleShader.SetTexture("d_wind", _windTexture);
            _Device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Clamp);
            _Device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Clamp);
            _Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear);
            _Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);

            _updateParticleShader.SetTexture("d_particles", _stateParticleTexture0);
            _Device.SetSamplerState(1, SamplerState.AddressU, TextureAddress.Clamp);
            _Device.SetSamplerState(1, SamplerState.AddressV, TextureAddress.Clamp);
            _Device.SetSamplerState(1, SamplerState.MinFilter, TextureFilter.Point);
            _Device.SetSamplerState(1, SamplerState.MagFilter, TextureFilter.Point);

            //parametros JSON
            _updateParticleShader.SetValue("d_rand_seed", (float)new Random().NextDouble());
            _updateParticleShader.SetValue("d_wind_resolution", new float[] { _windData.width, _windData.height });
            _updateParticleShader.SetValue("d_wind_min", new float[] { _windData.uMin, _windData.vMin });
            _updateParticleShader.SetValue("d_wind_max", new float[] { _windData.uMax, _windData.vMax });
            _updateParticleShader.SetValue("d_particles_res", particleRes);
            _updateParticleShader.SetValue("d_particles_min", min_range);
            _updateParticleShader.SetValue("d_particles_max", max_range);

            //parametros Menu
            _updateParticleShader.SetValue("d_speed_factor", _particles.SpeedFactor);

            //correction texture inverse
            _updateParticleShader.SetValue("d_miPixX", -0.5f / _stateParticleTexture0.GetLevelDescription(0).Width);
            _updateParticleShader.SetValue("d_miPixY", -0.5f / _stateParticleTexture0.GetLevelDescription(0).Height);

            if (_particles.IsWave)
            {
                _updateParticleShader.Technique = "Wave";
            }
            else
            {
                _updateParticleShader.Technique = "Default";
            }

            /************************/
            _updateParticleShader.SetValue("d_ParticulesByBlock", _particlesPerBlock);
            _updateParticleShader.SetValue("d_delta", dx);
            /************************/

            _updateParticleShader.Begin();
            _updateParticleShader.BeginPass(0);
            UtilDraw.drawInQuad(_Device);
            _updateParticleShader.EndPass();
            _updateParticleShader.End();

            rts.EndScene(Filter.None);
            surface.Dispose();
            rts.Dispose();

            /*Change index for fading and reset*/
            updateIndexReset();

            /*exchange texture*/
            _tempTexture           = _stateParticleTexture0;
            _stateParticleTexture0 = _stateParticleTexture1;
            _stateParticleTexture1 = _tempTexture;
        }
        void DisposeD3D()
        {
            Logger.WriteLine(Logger.Stage.CLEAN_GFX, "disposing...");

            foreach (Texture t in m_ImageToTextures.Values)
            {
                t.Dispose();
            }
            m_ImageToTextures.Clear();

            foreach (DXFont f in m_FontsToFonts.Values)
            {
                f.Dispose();
            }
            m_FontsToFonts.Clear();

            if (m_BlankTexture != null)
            {
                Logger.WriteLine(Logger.Stage.CLEAN_GFX, "disposing blank texture...");
                m_BlankTexture.Dispose();
                m_BlankTexture = null;
            }

            if (m_MinimapTexture != null)
            {
                Logger.WriteLine(Logger.Stage.CLEAN_GFX, "disposing minimap texture...");
                m_MinimapTexture.Dispose();
                m_MinimapTexture = null;
            }

            if (m_Sprite != null)
            {
                Logger.WriteLine(Logger.Stage.CLEAN_GFX, "disposing sprite...");
                m_Sprite.Dispose();
                m_Sprite = null;
            }

            if (m_TextSprite != null)
            {
                Logger.WriteLine(Logger.Stage.CLEAN_GFX, "disposing text sprite...");
                m_TextSprite.Dispose();
                m_TextSprite = null;
            }

            if (m_RenderToSurface != null)
            {
                Logger.WriteLine(Logger.Stage.CLEAN_GFX, "disposing render surface...");
                m_RenderToSurface.Dispose();
                m_RenderToSurface = null;
            }

            if (m_RenderTexture != null)
            {
                Logger.WriteLine(Logger.Stage.CLEAN_GFX, "disposing render texture...");
                m_RenderTexture.Dispose();
                m_RenderTexture = null;
            }

            if (m_Device != null)
            {
                Logger.WriteLine(Logger.Stage.CLEAN_GFX, "disposing device...");
                m_Device.Dispose();
                m_Device = null;
            }

            Logger.WriteLine(Logger.Stage.CLEAN_GFX, "disposing done.");
        }