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(); }
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; } }
//--------------------// #region Render /// <summary> /// Renders the content of a delegate to this texture /// </summary> /// <param name="render">The content to be rendered</param> internal void RenderTo(Action render) { #region Sanity checks if (Disposed) { throw new ObjectDisposedException(ToString()); } if (render == null) { throw new ArgumentNullException(nameof(render)); } #endregion // Don't initialise this earlier, would cause trouble with resetting the device if (_rtsHelper == null) { _rtsHelper = new RenderToSurface(_engine.Device, _rtsHelperSize.Width, _rtsHelperSize.Height, _engine.PresentParams.BackBufferFormat, _engine.PresentParams.AutoDepthStencilFormat); } using (new ProfilerEvent("Rendering to texture")) { _rtsHelper.BeginScene(Surface, Viewport); render(); _rtsHelper.EndScene(Filter.None); } }
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); } }
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(); }
public override void BeginRender() { // it looks like Direct3D creates a new surface. // so here we will create a new texture, and draw the current texture to it // then discard the old one. Texture t = new Texture(mDevice.Device, SurfaceWidth, SurfaceHeight, 1, Usage.None, Format.A8R8G8B8, Pool.Managed); Direct3D.Surface surfaceTarget = t.GetSurfaceLevel(0); mRenderToSurface = new RenderToSurface(mDevice.Device, SurfaceWidth, SurfaceHeight, Format.A8R8G8B8, false, DepthFormat.D16); Viewport vp = new Viewport(); vp.X = 0; vp.Y = 0; vp.Width = SurfaceWidth; vp.Height = SurfaceHeight; mRenderToSurface.BeginScene(surfaceTarget, vp); Display.Clear(); Draw(); mTexture.Dispose(); mTexture = new Ref <Texture>(t); }
private void Init(Device device) { System.Drawing.Size size = new System.Drawing.Size(device.PresentationParameters.BackBufferWidth / 4, device.PresentationParameters.BackBufferHeight / 4); occlusionRenderSurface = new RenderToSurface(device, size.Width, size.Height, Format.R32F, true, DepthFormat.D24S8); occlusionTexture = new Texture(device, size.Width, size.Height, 1, Usage.RenderTarget, Format.R32F, Pool.Default); occlusionSurface = occlusionTexture.GetSurfaceLevel(0); }
protected void CreateShaderResources(Device device) { if (qualityLevel != QualityLevelEnum.Low) { int textureSize = 512; // high quality if (qualityLevel == QualityLevelEnum.Medium) { textureSize = 256; // medium quality } if (renderHelper == null) { renderHelper = new RenderToSurface(device, textureSize, textureSize, device.PresentationParameters.BackBufferFormat, true, device.PresentationParameters.AutoDepthStencilFormat); } if (reflectionTexture == null) { reflectionTexture = new Texture(device, textureSize, textureSize, 1, Usage.RenderTarget, device.PresentationParameters.BackBufferFormat, Pool.Default); } if (reflectionSurface == null) { reflectionSurface = reflectionTexture.GetSurfaceLevel(0); } if (refractionTexture == null) { refractionTexture = new Texture(device, textureSize, textureSize, 1, Usage.RenderTarget, device.PresentationParameters.BackBufferFormat, Pool.Default); } if (refractionSurface == null) { refractionSurface = refractionTexture.GetSurfaceLevel(0); } } }
private void OnDeviceReset(object sender, EventArgs e) { Device dev = (Device)sender; m_Device = dev; m_Rts = new RenderToSurface(dev, RenderSurfaceSize, RenderSurfaceSize, Format.X8R8G8B8, true, DepthFormat.D16); }
/// <summary> /// Provede reinicializaci vsech vnitrnich objektu /// </summary> public void ReInit() { Dispose(); renderToSurface = new RenderToSurface(device, width, height, format, depthStencil, depthFormat); texture = new Texture(device, width, height, 1, Usage.RenderTarget, format, Pool.Default); surface = texture.GetSurfaceLevel(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); }
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); }
/// <summary> /// Clean up resources. /// </summary> private void CleanUp() { if (renderHelper != null) { renderHelper.Dispose(); renderHelper = null; } if (cubeTexture != null) { cubeTexture.Dispose(); cubeTexture = null; } }
} // initGfx() // ---] // [--- private void inicializarRenderizacaoNaTextura() { // Inicializa o Renderizador Renderizador = new RenderToSurface(device, superficie_ntam, superficie_ntam, Format.X8R8G8B8, true, DepthFormat.D16); // Cria uma textura alvo da renderização texturaAlvo = new Texture(device, superficie_ntam, superficie_ntam, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); // Acessa a superficie de dados da textura superficieAlvo = texturaAlvo.GetSurfaceLevel(0); // Cria uma sprite para a textura radar = new Sprite(device); }
/// <summary> /// Creates resources. /// </summary> private void Initialize() { if (Enabled) { if (cubeTexture == null) { cubeTexture = new TextureBase(256, true); } if (renderHelper == null) { renderHelper = new RenderToSurface(Framework.Instance.Device, 256, 256, Framework.Instance.Device.PresentationParameters.BackBufferFormat, true, Framework.Instance.Device.PresentationParameters.AutoDepthStencilFormat); } Invalidate(); } }
public RenderTarget(int width, int height, Device device) { _device = device; Width = width; Height = height; _viewport = new Viewport { X = 0, Y = 0, Width = width, Height = height }; InitializeRenderTarget(); _renderToSurface = new RenderToSurface(device, _surface.Description.Width, _surface.Description.Height, _surface.Description.Format, true, DepthFormat.D24S8); _renderToSurface.Reset += OnRenderToSurfaceReset; }
void m_Device_DeviceReset(object sender, EventArgs e) { m_Device.RenderState.CullMode = Cull.None; m_Device.RenderState.AlphaBlendEnable = true; m_ImageToTextures.Clear(); m_FontsToFonts.Clear(); Logger.WriteLine(Logger.Stage.INIT_GFX, "creating sprite..."); m_Sprite = new Sprite(m_Device); Logger.WriteLine(Logger.Stage.INIT_GFX, "creating text sprite..."); m_TextSprite = new Sprite(m_Device); Logger.WriteLine(Logger.Stage.INIT_GFX, "creating blank texture..."); m_BlankTexture = new Texture(m_Device, new Bitmap(@"Resources\Images\blank_texture.png"), 0, Pool.Managed); if (m_RenderTexture != null) { Logger.WriteLine(Logger.Stage.CLEAN_GFX, "disposing render texture..."); m_RenderTexture.Dispose(); m_RenderTexture = null; } Logger.WriteLine(Logger.Stage.INIT_GFX, "creating render texture..."); m_RenderTexture = new Texture(m_Device, RogueGame.CANVAS_WIDTH, RogueGame.CANVAS_HEIGHT, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default); m_RenderSurface = m_RenderTexture.GetSurfaceLevel(0); Logger.WriteLine(Logger.Stage.INIT_GFX, "creating render surface..."); m_RenderToSurface = new RenderToSurface(m_Device, RogueGame.CANVAS_WIDTH, RogueGame.CANVAS_HEIGHT, Format.A8R8G8B8, false, DepthFormat.Unknown); Logger.WriteLine(Logger.Stage.INIT_GFX, "creating minimap texture..."); const int numLevels = 1; // 0 = crash on some cards plus it means generate a bunch of mipmaps so bad anyway. m_MinimapTexture = new Texture(m_Device, RogueGame.MAP_MAX_WIDTH * RogueGame.MINITILE_SIZE, RogueGame.MAP_MAX_HEIGHT * RogueGame.MINITILE_SIZE, numLevels, Usage.SoftwareProcessing, Format.A8R8G8B8, Pool.Managed); Logger.WriteLine(Logger.Stage.INIT_GFX, "init done."); }
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; }
/// <summary> /// Constructor to initalize references and build the render targets. /// </summary> /// <param name="device">Copy of the rendering device.</param> /// <param name="effect">Copy of the effect class.</param> /// <param name="mesh">Reference of the list of models.</param> /// <param name="width">Width of the rendering panel.</param> /// <param name="height">Height of the rendering panel.</param> public Render(ref Device device, ref Effect effect, ref List <Model> mesh, ref GroundPlane groundPlane, int width, int height) { this.device = device; this.effect = effect; this.mesh = mesh; this.groundPlane = groundPlane; this.width = width; this.height = height; showLights = false; shadowMapSize = 512; blackMat = new Material(); whiteMat = new Material(); blackMat.Ambient = blackMat.Diffuse = blackMat.Emissive = Color.Black; whiteMat.Ambient = whiteMat.Diffuse = whiteMat.Emissive = Color.White; // Setup the RenderToSurface class and create the render target textures. 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); 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); //lightTexture = TextureLoader.FromFile(device, "lightbulb.png"); MemoryStream loMS = new MemoryStream(); global::ModelViewer.Properties.Resources.lightbulb.Save(loMS, System.Drawing.Imaging.ImageFormat.Png); loMS.Seek(0, 0); lightTexture = TextureLoader.FromStream(device, loMS); }
void ReloadGraphicResources() { resourceManager.EmptyTexture = new Texture(device, 1, 1, 1, Usage.None, Format.A8R8G8B8, Pool.Managed); SlimDX.DataRectangle dr = resourceManager.EmptyTexture.LockRectangle(0, LockFlags.Discard); dr.Data.Write <uint>(0x00000000); resourceManager.EmptyTexture.UnlockRectangle(0); emptyTexture = new Texture(device, 1, 1, 1, Usage.None, Format.A8R8G8B8, Pool.Managed); dr = emptyTexture.LockRectangle(0, LockFlags.Discard); dr.Data.Write <uint>(0xffffffff); emptyTexture.UnlockRectangle(0); spriteRenderer = new SlimDX.Direct3D9.Sprite(device); lineRenderer = new Line(device); loadingOverlay.Load(device); blendOverlay.Load(device); errorOverlay.Load(device); renderToSurface = new RenderToSurface(device, engine.GameResolution.x * renderScale, engine.GameResolution.y * renderScale, Format.X8R8G8B8); renderToTexture = new Texture(device, engine.GameResolution.x * renderScale, engine.GameResolution.y * renderScale, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); deviceReadyForRender = true; }
public void OnResetDevice() { int w = d3dDevice.PresentationParameters.BackBufferWidth; int h = d3dDevice.PresentationParameters.BackBufferHeight; fpsCamera.Aspect = ( float )w / ( float )h; SetupDeviceState(); if (rts == null /*&& RtsEnabled*/) { rts = new RenderToSurface(d3dDevice, surfWidth, surfHeight, Format.X8R8G8B8, true, DepthFormat.D24X8); rts.Reset += new EventHandler(rts_Reset); rts_Reset(this, null); } if (rte == null /*&& RteEnabled*/) { rte = new RenderToEnvironmentMap(d3dDevice, envSize, 1, Format.X8R8G8B8, true, DepthFormat.D24X8); rte.Reset += new EventHandler(rte_Reset); rte_Reset(this, null); } }
/// <summary> /// Initialize scene objects. /// </summary> protected override void InitializeDeviceObjects() { drawingFont.InitializeDeviceObjects(device); spaceSphere = new PositionedMesh(device, "SpaceSphere.x"); HullColors hullColor = HullColors.White; playerShip = new Ship(device, this, hullColor); if (playerShip.HostName == null) { playerShip.HostName = "Player"; } playerShip.State = ShipState.Normal; HullColors opponentHullColor; if (hullColor == HullColors.Red) { opponentHullColor = HullColors.White; } else { opponentHullColor = HullColors.Red; } opponentShip = new Ship(device, this, opponentHullColor); if (opponentShip.HostName == null) { opponentShip.HostName = "Opponent"; } opponentShip.State = ShipState.Normal; bgPointer = new BGPointer(device); vectorPanel = TextureLoader.FromFile(device, MediaUtilities.FindFile("vectorPanel.png")); rts = new RenderToSurface(device, 128, 128, Format.X8R8G8B8, true, DepthFormat.D16); }
private int width; // Width of the screen. #endregion Fields #region Constructors /// <summary> /// Constructor to initalize references and build the render targets. /// </summary> /// <param name="device">Copy of the rendering device.</param> /// <param name="effect">Copy of the effect class.</param> /// <param name="mesh">Reference of the list of models.</param> /// <param name="width">Width of the rendering panel.</param> /// <param name="height">Height of the rendering panel.</param> public Render(ref Device device, ref Effect effect, ref List<Model> mesh, ref GroundPlane groundPlane, int width, int height) { this.device = device; this.effect = effect; this.mesh = mesh; this.groundPlane = groundPlane; this.width = width; this.height = height; showLights = false; shadowMapSize = 512; blackMat = new Material(); whiteMat = new Material(); blackMat.Ambient = blackMat.Diffuse = blackMat.Emissive = Color.Black; whiteMat.Ambient = whiteMat.Diffuse = whiteMat.Emissive = Color.White; // Setup the RenderToSurface class and create the render target textures. 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); 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); //lightTexture = TextureLoader.FromFile(device, "lightbulb.png"); MemoryStream loMS = new MemoryStream(); global::ModelViewer.Properties.Resources.lightbulb.Save(loMS, System.Drawing.Imaging.ImageFormat.Png); loMS.Seek(0, 0); lightTexture = TextureLoader.FromStream(device, loMS); }
static void FillResources() { if (!Options.Option_Shaders) return; // Light camera depth map: RtsHelperLight = new RenderToSurface(device, ShadowMapSize, ShadowMapSize, Format.R16F, Format.D16); ShadowLightDepthMap = new Texture(device, ShadowMapSize, ShadowMapSize, 1, Usage.RenderTarget, Format.R16F, Pool.Default); ShadowLightDepthMapSurface = ShadowLightDepthMap.GetSurfaceLevel(0); // Light camera depth map: RtsHelperCamera = new RenderToSurface(device, device.Viewport.Width, device.Viewport.Height, Format.R16F, Format.D16); ShadowCameraDepthMap = new Texture(device, device.Viewport.Width, device.Viewport.Height, 1, Usage.RenderTarget, Format.R16F, Pool.Default); ShadowCameraDepthMapSurface = ShadowCameraDepthMap.GetSurfaceLevel(0); // Shadow maps RtsHelperShadow = new RenderToSurface(device, device.Viewport.Width, device.Viewport.Height, Format.A8R8G8B8, Format.D16); ShadowMapTexture[0] = new Texture(device, device.Viewport.Width, device.Viewport.Height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default); ShadowMapTexture[1] = new Texture(device, device.Viewport.Width, device.Viewport.Height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default); ShadowMapSurface[0] = ShadowMapTexture[0].GetSurfaceLevel(0); ShadowMapSurface[1] = ShadowMapTexture[1].GetSurfaceLevel(0); }
private void OnDeviceReset(object sender, EventArgs e) { Device dev = (Device) sender; m_Device = dev; m_Rts = new RenderToSurface(dev, RenderSurfaceSize, RenderSurfaceSize, Format.X8R8G8B8, true, DepthFormat.D16); }
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."); }
public bool Initialize(RenderForm Form) { direct3D = new Direct3D(); this.form = Form; int adapter = direct3D.AdapterCount - 1; // check window mode if (!direct3D.CheckDeviceType(adapter, DeviceType.Hardware, Format.R5G6B5, Format.R5G6B5, true)) { // not available System.Windows.Forms.MessageBox.Show("window mode not available"); } // fullscreen mode if (!direct3D.CheckDeviceType(adapter, DeviceType.Hardware, Format.R5G6B5, Format.R5G6B5, false)) { // not available System.Windows.Forms.MessageBox.Show("fullscreen not available"); } presentParams = new PresentParameters(); presentParams.BackBufferHeight = Form.ClientRectangle.Height; presentParams.BackBufferWidth = Form.ClientRectangle.Width; presentParams.DeviceWindowHandle = Form.Handle; presentParams.PresentationInterval = PresentInterval.One; presentParams.BackBufferCount = 1; presentParams.BackBufferFormat = Format.R5G6B5; // check back buffer format if (!direct3D.CheckDeviceFormat(adapter, DeviceType.Hardware, presentParams.BackBufferFormat, Usage.RenderTarget, ResourceType.Surface, Format.R5G6B5)) { // not available System.Windows.Forms.MessageBox.Show("back buffer not available"); } // check depth stencil format if (!direct3D.CheckDeviceFormat(adapter, DeviceType.Hardware, presentParams.BackBufferFormat, Usage.DepthStencil, ResourceType.Surface, Format.D16)) { // not available System.Windows.Forms.MessageBox.Show("depth stencil not available"); } // check depth stencil format match if (!direct3D.CheckDepthStencilMatch(adapter, DeviceType.Hardware, presentParams.BackBufferFormat, presentParams.BackBufferFormat, Format.D16)) { // not available System.Windows.Forms.MessageBox.Show("depth stencil match not available"); } presentParams.AutoDepthStencilFormat = Format.D16; presentParams.EnableAutoDepthStencil = true; presentParams.Windowed = !engine.FullScreen; if (!presentParams.Windowed) { presentParams.BackBufferWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; presentParams.BackBufferHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height; presentParams.SwapEffect = SwapEffect.Flip; Form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; engine.Resolution = new Vector2(presentParams.BackBufferWidth, presentParams.BackBufferHeight); Log.Info("Fullscreen: yes"); Log.Info("Resolution: " + presentParams.BackBufferWidth + "x" + presentParams.BackBufferHeight); } else { presentParams.SwapEffect = SwapEffect.Discard; Log.Info("Fullscreen: no"); Log.Info("Resolution: " + presentParams.BackBufferWidth + "x" + presentParams.BackBufferHeight); } Log.Info("Virtual resolution: " + engine.GameResolution.x + "x" + engine.GameResolution.y); Log.Info("Scale factor: " + engine.Scale.x.ToString("0.00") + "x" + engine.Scale.y.ToString("0.00")); Log.Info("Texture filter method: " + (engine.UseTextureFilter ? "GaussianQuad" : "NearestPoint")); device = new Device(direct3D, adapter, DeviceType.Hardware, Form.Handle, CreateFlags.SoftwareVertexProcessing | CreateFlags.Multithreaded, presentParams); renderToSurface = new RenderToSurface(device, engine.GameResolution.x * renderScale, engine.GameResolution.y * renderScale, Format.X8R8G8B8); renderToTexture = new Texture(device, engine.GameResolution.x * renderScale, engine.GameResolution.y * renderScale, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); loadingOverlay = new LoadingOverlay(engine, new Vector2(presentParams.BackBufferWidth, presentParams.BackBufferHeight)); blendOverlay = new BlendOverlay(new Vector2(presentParams.BackBufferWidth, presentParams.BackBufferHeight)); errorOverlay = new ErrorOverlay(engine, new Vector2(presentParams.BackBufferWidth, presentParams.BackBufferHeight)); ReloadGraphicResources(); DeviceReset += new EventHandler(RenderDevice_DeviceReset); DeviceLost += new EventHandler(RenderDevice_DeviceLost); return(true); }
/// <summary> /// Initialize scene objects. /// </summary> protected override void InitializeDeviceObjects() { drawingFont.InitializeDeviceObjects(device); spaceSphere = new PositionedMesh(device, "SpaceSphere.x"); playerShip = new Ship(device, this, hullColor); if (playerShip.HostName == null) playerShip.HostName = "Player"; playerShip.State = ShipState.Normal; HullColors opponentHullColor; if (hullColor == HullColors.Red) opponentHullColor = HullColors.White; else opponentHullColor = HullColors.Red; opponentShip = new Ship(device, this, opponentHullColor); if (opponentShip.HostName == null) opponentShip.HostName = "Opponent"; opponentShip.State = ShipState.Normal; bgPointer = new BGPointer(device); vectorPanel = TextureLoader.FromFile(device, MediaUtilities.FindFile("vectorPanel.png")); rts = new RenderToSurface(device, 128, 128, Format.X8R8G8B8, true, DepthFormat.D16); }
public void OnResetDevice(object sender, EventArgs e) { Device d3dDevice = (Device)sender; // Turn on the ZBuffer d3dDevice.RenderState.ZBufferEnable = true; d3dDevice.RenderState.CullMode = Cull.None; d3dDevice.RenderState.Lighting = true; // Enable alpha blending. d3dDevice.RenderState.AlphaBlendEnable = true; // Set the source blend state. d3dDevice.RenderState.SourceBlend = Blend.SourceAlpha; // Set the destination blend state. d3dDevice.RenderState.DestinationBlend = Blend.InvSourceAlpha; d3dDevice.RenderState.AlphaTestEnable = true; d3dDevice.RenderState.Ambient = Color.FromArgb(255, 100, 100, 100); //set up the lights d3dDevice.Lights[0].Type = LightType.Directional; d3dDevice.Lights[0].Diffuse = Color.White; d3dDevice.Lights[0].Direction = new Vector3(0, 0, 1); d3dDevice.Lights[0].Enabled = true; d3dDevice.Lights[1].Type = LightType.Directional; d3dDevice.Lights[1].Diffuse = Color.White; d3dDevice.Lights[1].Direction = new Vector3(0, -1, 0); d3dDevice.Lights[1].Enabled = true; //the device was reset m_bReset = true; //create the render to surface object rts = new RenderToSurface(d3dDevice, RenderSurfaceSize, RenderSurfaceSize, Format.A8R8G8B8, true, DepthFormat.D16); //create render texture renderTexture = new Texture(d3dDevice, RenderSurfaceSize, RenderSurfaceSize, 1,Usage.RenderTarget, Format.A8R8G8B8, Pool.Default); //create the rendesurface texture renderSurface = renderTexture.GetSurfaceLevel(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; }