static public void RenderFrame() { UpdateFramerate(); PrevTickCount = Environment.TickCount; device.ClearDepthStencilView(depthview, DepthStencilClearFlags.Depth, 1, 0); device.ClearRenderTargetView(renderview, Color.LightBlue); device.OutputMerger.DepthStencilState = depthstate; UpdateLight(); time += 0.01f; //EffectTechnique t = effect.GetTechniqueByName("Blinn"); //EffectTechnique t = effect.GetTechniqueByName("BlinnHeight"); EffectTechnique t = effect.GetTechniqueByName("POM"); M.Render(t); //L.Render(t); swapchain.Present(0, PresentFlags.None); //poczekaj EndTickCount = Environment.TickCount; while (Math.Abs(Environment.TickCount - PrevTickCount) < 16) { ; } Console.WriteLine("FPS {0:0.0} ; Light Pos: {1:0} {2:0} {3:0}", fps, LightPosition, LightPosition.Y, LightPosition.Z); Console.WriteLine("Rad {0:0.00}, Phi {1:0.00}, Theta {2:0.00}", radius, phi, theta); }
/// <summary> /// Presents the contents of the back buffer to the screen, and flips the front/back buffers. /// </summary> public override void Present() { //If resetting, return return return if (_resetting) { return; } _swapChain.Present(_interval, DXGI.PresentFlags.None); }
/// <summary> /// Our present hook that will grab a copy of the backbuffer when requested. Note: this supports multi-sampling (anti-aliasing) /// </summary> /// <param name="swapChainPtr"></param> /// <param name="syncInterval"></param> /// <param name="flags"></param> /// <returns>The HRESULT of the original method</returns> int PresentHook(IntPtr swapChainPtr, int syncInterval, SlimDX.DXGI.PresentFlags flags) { using (SlimDX.DXGI.SwapChain swapChain = SlimDX.DXGI.SwapChain.FromPointer(swapChainPtr)) { try { #region Screenshot Request if (this.Request != null) { this.DebugMessage("PresentHook: Request Start"); DateTime startTime = DateTime.Now; using (Texture2D texture = Texture2D.FromSwapChain <Texture2D>(swapChain, 0)) { #region Determine region to capture System.Drawing.Rectangle regionToCapture = new System.Drawing.Rectangle(0, 0, texture.Description.Width, texture.Description.Height); if (this.Request.RegionToCapture.Width > 0) { regionToCapture = this.Request.RegionToCapture; } #endregion var theTexture = texture; // If texture is multisampled, then we can use ResolveSubresource to copy it into a non-multisampled texture Texture2D textureResolved = null; if (texture.Description.SampleDescription.Count > 1) { this.DebugMessage("PresentHook: resolving multi-sampled texture"); // texture is multi-sampled, lets resolve it down to single sample textureResolved = new Texture2D(texture.Device, new Texture2DDescription() { CpuAccessFlags = CpuAccessFlags.None, Format = texture.Description.Format, Height = texture.Description.Height, Usage = ResourceUsage.Default, Width = texture.Description.Width, ArraySize = 1, SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0), // Ensure single sample BindFlags = BindFlags.None, MipLevels = 1, OptionFlags = texture.Description.OptionFlags }); // Resolve into textureResolved texture.Device.ImmediateContext.ResolveSubresource(texture, 0, textureResolved, 0, texture.Description.Format); // Make "theTexture" be the resolved texture theTexture = textureResolved; } // Create destination texture Texture2D textureDest = new Texture2D(texture.Device, new Texture2DDescription() { CpuAccessFlags = CpuAccessFlags.None, // CpuAccessFlags.Write | CpuAccessFlags.Read, Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm, // Supports BMP/PNG Height = regionToCapture.Height, Usage = ResourceUsage.Default, // ResourceUsage.Staging, Width = regionToCapture.Width, ArraySize = 1, //texture.Description.ArraySize, SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0), // texture.Description.SampleDescription, BindFlags = BindFlags.None, MipLevels = 1, //texture.Description.MipLevels, OptionFlags = texture.Description.OptionFlags }); // Copy the subresource region, we are dealing with a flat 2D texture with no MipMapping, so 0 is the subresource index theTexture.Device.ImmediateContext.CopySubresourceRegion(theTexture, 0, new ResourceRegion() { Top = regionToCapture.Top, Bottom = regionToCapture.Bottom, Left = regionToCapture.Left, Right = regionToCapture.Right, Front = 0, Back = 1 // Must be 1 or only black will be copied }, textureDest, 0, 0, 0, 0); // Note: it would be possible to capture multiple frames and process them in a background thread // Copy to memory and send back to host process on a background thread so that we do not cause any delay in the rendering pipeline Guid requestId = this.Request.RequestId; // this.Request gets set to null, so copy the RequestId for use in the thread ThreadPool.QueueUserWorkItem(delegate { //FileStream fs = new FileStream(@"c:\temp\temp.bmp", FileMode.Create); //Texture2D.ToStream(testSubResourceCopy, ImageFileFormat.Bmp, fs); DateTime startCopyToSystemMemory = DateTime.Now; using (MemoryStream ms = new MemoryStream()) { Texture2D.ToStream(textureDest.Device.ImmediateContext, textureDest, ImageFileFormat.Bmp, ms); ms.Position = 0; this.DebugMessage("PresentHook: Copy to System Memory time: " + (DateTime.Now - startCopyToSystemMemory).ToString()); DateTime startSendResponse = DateTime.Now; SendResponse(ms, requestId); this.DebugMessage("PresentHook: Send response time: " + (DateTime.Now - startSendResponse).ToString()); } // Free the textureDest as we no longer need it. textureDest.Dispose(); textureDest = null; this.DebugMessage("PresentHook: Full Capture time: " + (DateTime.Now - startTime).ToString()); }); // Prevent the request from being processed a second time this.Request = null; // Make sure we free up the resolved texture if it was created if (textureResolved != null) { textureResolved.Dispose(); textureResolved = null; } } this.DebugMessage("PresentHook: Copy BackBuffer time: " + (DateTime.Now - startTime).ToString()); this.DebugMessage("PresentHook: Request End"); } #endregion #region TODO: Draw overlay (after screenshot so we don't capture overlay as well) // Note: Direct3D 11 doesn't have font support, so I believe the approach is to use // a Direct3D 10.1 device with Direct2d, render to a texture, and then blend // this into the Direct3D 11 backbuffer - hmm sounds like fun. // http://forums.create.msdn.com/forums/t/38961.aspx // http://www.gamedev.net/topic/547920-how-to-use-d2d-with-d3d11/ #endregion } catch (Exception e) { // If there is an error we do not want to crash the hooked application, so swallow the exception this.DebugMessage("PresentHook: Exeception: " + e.GetType().FullName + ": " + e.Message); //return unchecked((int)0x8000FFFF); //E_UNEXPECTED } // As always we need to call the original method, note that EasyHook has already repatched the original method // so calling it here will not cause an endless recursion to this function return(swapChain.Present(syncInterval, flags).Code); } }
static public void RenderFrame() { device.ClearDepthStencilView(depthview, DepthStencilClearFlags.Depth, 1, 0); device.ClearRenderTargetView(renderview, Color.Blue); device.OutputMerger.DepthStencilState = depthstate; UpdateLight(); time += 0.001f; // if (count == 500) AddBox(); // if (count > 1000) { AddBall(); count = 0; } // count++; EffectTechnique t = effect.GetTechniqueByName("SimpleLight"); RasterizerStateDescription desc = new RasterizerStateDescription(); desc.CullMode = CullMode.None; desc.FillMode = FillMode.Wireframe; //dlaczego to nei dziala? effect.GetVariableByName("xDiffuseTexture").AsResource().SetResource(DiffuseResource); //byle co, i tak renderuje tylko boxy i plane'y effect.GetVariableByName("xMaxMass").AsScalar().Set(MaxMass); effect.GetVariableByName("xMass").AsScalar().Set(1); SetMatrices(Matrix.RotationX(-(float)Math.PI / 2) * Matrix.Scaling(10, 10, 10) * Matrix.Translation(0, -0.2f, 0)); Plane.Render(t); SetMatrices(Matrix.Scaling(10, 10, 10) * Matrix.Translation(0, 50f, -100)); Plane.Render(t); SetMatrices(Matrix.RotationY((float)Math.PI / 2) * Matrix.Scaling(10, 10, 10) * Matrix.Translation(-100f, 50f, 0)); Plane.Render(t); SetMatrices(Matrix.RotationY(-(float)Math.PI / 2) * Matrix.Scaling(10, 10, 10) * Matrix.Translation(100, 50f, 0)); Plane.Render(t); SetMatrices(Matrix.RotationY(-(float)Math.PI) * Matrix.Scaling(10, 10, 10) * Matrix.Translation(0, 50f, 100)); Plane.Render(t); SetMatrices(Matrix.RotationX((float)Math.PI / 2) * Matrix.Scaling(10, 10, 10) * Matrix.Translation(0, 100f, 0)); Plane.Render(t); effect.GetVariableByName("xDiffuseTexture").AsResource().SetResource(Diffuse2Resource); int i = 0; foreach (var M in BoxMatrices) { SetMatrices(M.Value); if (i < howManyBeginningActors) { SetMatrices(ScaleMatrixNoTranslation(M.Value, scale)); effect.GetVariableByName("xMass").AsScalar().Set(Engine.Actors[i + 7].Mass); } Boxes[i].Render(t); i++; } effect.GetVariableByName("xDiffuseTexture").AsResource().SetResource(Diffuse3Resource); i = 0; foreach (var M in BallMatrices) { SetMatrices(M.Value); Balls[i].Render(t); i++; } effect.GetVariableByName("xDiffuseTexture").AsResource().SetResource(Diffuse2Resource); foreach (var C in Engine.Scene.Cloths) { WavefrontLoader.WFOGeometry G = new WavefrontLoader.WFOGeometry(device, C, ClothGeometry); SetMatrices(Matrix.Identity); G.Render(device, t); } Engine.Step(); //dlaczego zmienia mi tutaj moje BoxMatrices? chyba w sumie musi zeby karta wiedziala co ma wyrenderowac swapchain.Present(0, PresentFlags.None); prevFrameX = curFrameX; prevFrameY = curFrameY; }
protected virtual void Draw() { device.ImmediateContext.ClearRenderTargetView(renderTarget, new Color4(1, 0, 0, 1)); swapChain.Present(0, Dxgi.PresentFlags.None); }
protected void RenderAll() //Slúži na opätované renderovanie objektu po úpravách { m_deviceContext.ClearRenderTargetView(m_renderTarget, new Color4(colorPozadie)); m_simpleBox.Render(m_device, m_worldMatrix, m_viewProjMatrix); m_swapChain.Present(0, DXGI.PresentFlags.None); }