protected override void OnRender(RenderContext context, DeviceContextProxy deviceContext) { if (CreateCubeMapResources()) { InvalidateRenderer(); return; // Skip this frame if texture resized to reduce latency. } context.IsInvertCullMode = true; #if TEST for (int index = 0; index < 6; ++index) #else Parallel.For(0, 6, (index) => #endif { var ctx = contextPool.Get(); ctx.DeviceContext.ClearRenderTargetView(cubeRTVs[index], context.RenderHost.ClearColor); ctx.DeviceContext.ClearDepthStencilView(cubeDSVs[index], DepthStencilClearFlags.Depth, 1, 0); ctx.DeviceContext.OutputMerger.SetRenderTargets(cubeDSVs[index], cubeRTVs[index]); ctx.DeviceContext.Rasterizer.SetViewport(viewport); ctx.DeviceContext.Rasterizer.SetScissorRectangle(0, 0, FaceSize, FaceSize); var transforms = new GlobalTransformStruct(); transforms.Projection = cubeFaceCameras.Cameras[index].Projection; transforms.View = cubeFaceCameras.Cameras[index].View; transforms.Viewport = new Vector4(FaceSize, FaceSize, 1/FaceSize, 1/FaceSize); transforms.ViewProjection = transforms.View * transforms.Projection; ModelConstBuffer.UploadDataToBuffer(ctx, ref transforms); var frustum = new BoundingFrustum(transforms.ViewProjection); //Render opaque for (int i = 0; i < context.RenderHost.PerFrameOpaqueNodes.Count; ++i) { var node = context.RenderHost.PerFrameOpaqueNodes[i]; if (node.GUID != this.GUID && !IgnoredGuid.Contains(node.GUID) && node.TestViewFrustum(ref frustum)) { node.Render(context, ctx); } } //Render particle for (int i = 0; i < context.RenderHost.PerFrameParticleNodes.Count; ++i) { var node = context.RenderHost.PerFrameParticleNodes[i]; if (node.GUID != this.GUID && !IgnoredGuid.Contains(node.GUID) && node.TestViewFrustum(ref frustum)) { node.Render(context, ctx); } } commands[index] = ctx.DeviceContext.FinishCommandList(false); contextPool.Put(ctx); } #if !TEST ); #endif context.IsInvertCullMode = false; for (int i = 0; i < commands.Length; ++i) { Device.ImmediateContext.ExecuteCommandList(commands[i], true); commands[i].Dispose(); } deviceContext.DeviceContext.GenerateMips(CubeMap); context.UpdatePerFrameData(true, false); }
/// <summary> /// Called when [render]. /// </summary> /// <param name="context">The context.</param> /// <param name="deviceContext">The device context.</param> protected override void OnRender(IRenderContext context, DeviceContextProxy deviceContext) { bool succ = duplicationResource.Initialize(); if (!succ) { InvalidateRenderer(); return; } context.RenderHost.RenderConfiguration = config; FrameData data; bool isTimeOut; bool accessLost; if (duplicationResource.GetFrame(Output, out data, ref pointer, out isTimeOut, out accessLost)) { if (data.FrameInfo.TotalMetadataBufferSize > 0) { frameProcessor.ProcessFrame(ref data, deviceContext); } invalidRender = true; } if (frameProcessor.SharedTexture != null && !accessLost) { if (clearTarget) { clearTarget = false; context.RenderHost.ClearRenderTarget(deviceContext, true, false); } bool cursorValid = false; if (pointer.Visible) { Vector4 rect; if (frameProcessor.ProcessCursor(ref pointer, deviceContext, out rect)) { GetCursorVertexBound((int)context.ActualWidth, (int)context.ActualHeight, frameProcessor.TextureWidth, frameProcessor.TextureHeight, ref rect); invalidRender = true; cursorValid = true; } } if (invalidRender) { ModelConstBuffer.UploadDataToBuffer(deviceContext, ref modelStruct); DefaultShaderPass.BindShader(deviceContext); DefaultShaderPass.BindStates(deviceContext, StateType.BlendState | StateType.DepthStencilState | StateType.RasterState); deviceContext.DeviceContext.InputAssembler.PrimitiveTopology = global::SharpDX.Direct3D.PrimitiveTopology.TriangleStrip; DefaultShaderPass.GetShader(ShaderStage.Pixel).BindSampler(deviceContext, samplerBindSlot, textureSampler); int left = (int)(context.ActualWidth * Math.Abs(modelStruct.TopLeft.X + 1) / 2); int top = (int)(context.ActualHeight * Math.Abs(modelStruct.TopLeft.Y - 1) / 2); deviceContext.DeviceContext.Rasterizer.SetScissorRectangle(left, top, (int)context.ActualWidth - left, (int)context.ActualHeight - top); using (var textureView = new global::SharpDX.Direct3D11.ShaderResourceView(deviceContext.DeviceContext.Device, frameProcessor.SharedTexture)) { DefaultShaderPass.GetShader(ShaderStage.Pixel).BindTexture(deviceContext, textureBindSlot, textureView); deviceContext.DeviceContext.Draw(4, 0); } if (ShowMouseCursor && cursorValid) { DrawCursor(ref pointer, deviceContext); } invalidRender = false; } } if (isTimeOut) { } else if (accessLost) { throw new SharpDXException(ResultCode.AccessLost); } else { duplicationResource.ReleaseFrame(); } InvalidateRenderer(); }