public void MainLoop(bool newScreen) { if (device != null) { //if (newScreen) //Texture seems to be destroyed after being displayed once { unsafe { DataRectangle drt = texture.Map(0, MapMode.WriteDiscard, SlimDX.Direct3D10.MapFlags.None); fixed(uint *screenPTR = screen) { imageScaler.PerformScale(screenPTR, (uint *)drt.Data.DataPointer); } texture.Unmap(0); } } device.ClearRenderTargetView(renderTargetView, new Color4(0.0f, 0.0f, 0.0f)); device.InputAssembler.SetInputLayout(inputLayout); device.InputAssembler.SetPrimitiveTopology(SlimDX.Direct3D10.PrimitiveTopology.TriangleStrip); device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, Marshal.SizeOf(typeof(Vertex)), 0)); pass.Apply(); device.Draw(4, 0); DrawMessageEvent(this, null); swapChain.Present(0, PresentFlags.None); } }
public void Render(DxCamera camera) { if (_vertexBuffer == null || _vertexCount == 0) { return; } _worldVar.SetMatrix(Matrix.Scaling(Scale, -Scale, Scale)); _eyePosWVar.Set(camera.Eye); _viewProjVar.SetMatrix(camera.View * camera.Projection); _fillColorVar.Set(_fillColor); _resVar.Set(new Vector2(_xRes, _yRes)); _focalLengthDepthVar.Set(_focalLengthDepth); _focalLengthImageVar.Set(_focalLengthImage); _depthToRgbVar.SetMatrix(_depthToRgb); _depthMapVar.SetResource(_depthMapBufferRV); _imageMapVar.SetResource(_imageTextureRV); _dxDevice.InputAssembler.SetInputLayout(_inputLayout); _dxDevice.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.PointList); _dxDevice.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_vertexBuffer, PointVertex.SizeOf, 0)); for (int p = 0; p < _renderTech.Description.PassCount; p++) { _renderTech.GetPassByIndex(p).Apply(); _dxDevice.Draw(_vertexCount, 0); } }
/// <summary> /// Draws non-indexed geometry. /// </summary> /// <param name="primType">Type of the primitives to draw</param> /// <param name="vertexCount">Number of vertices to draw</param> /// <param name="startVertex">Starting index in the vertex buffer at which to read vertices from.</param> public override void Draw(PrimitiveType primType, int vertexCount, int startVertex) { D3D10Helper.CheckDisposed(_graphicsDevice); if (vertexCount <= 0) { throw new ArgumentOutOfRangeException("vertexCount", "Vertex count must be greater than zero."); } //Send any remaining texture/sampler changes to the device. FlushStates(); _graphicsDevice.InputAssembler.SetInputLayout(_currentPass.InputLayoutMap.GetOrCreateLayout(_currentVertexBuffers, _currentVertexBufferCount)); _graphicsDevice.InputAssembler.SetPrimitiveTopology(D3D10Helper.ToD3DPrimitiveType(primType)); _graphicsDevice.Draw(vertexCount, startVertex); }
public void DrawProceduralEffect(EffectTechnique technique) { if (technique == null) { throw new ArgumentNullException("technique"); } if (!technique.IsValid) { throw new ArgumentException("Given technique is not valid.", "technique"); } device.InputAssembler.SetInputLayout(null); device.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip); for (int i = 0; i < technique.Description.PassCount; i++) { technique.GetPassByIndex(i).Apply(); device.Draw(3, 0); } }
public void Render(DxCamera camera) { // // Set constants. // _viewProjVar.SetMatrix(camera.View * camera.Projection); _gameTimeVar.Set(_gameTime); _timeStepVar.Set(_timeStep); _eyePosVar.Set(camera.Eye); _emitPosVar.Set(_emitPosW); _emitDirVar.Set(_emitDirW); _texArrayVar.SetResource(_texArrayRV); _randomTexVar.SetResource(_randomTexRV); // // Set IA stage. // _dxDevice.InputAssembler.SetInputLayout(_vertexLayout); _dxDevice.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.PointList); int stride = Marshal.SizeOf(typeof(ParticleVertex)); const int offset = 0; // On the first pass, use the initialization VB. Otherwise, use // the VB that contains the current particle list. _dxDevice.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_firstRun ? _initVB : _drawVB, stride, offset)); // // Draw the current particle list using stream output only to update // them. The updated vertices are streamed out to the target VB. // _dxDevice.StreamOutput.SetTargets( new StreamOutputBufferBinding(_streamOutVB, offset)); for (int p = 0; p < _streamOutTech.Description.PassCount; ++p) { _streamOutTech.GetPassByIndex(p).Apply(); if (_firstRun) { _dxDevice.Draw(1, 0); _firstRun = false; } else { _dxDevice.DrawAuto(); } } // done streaming out--unbind the vertex buffer _dxDevice.StreamOutput.SetTargets(null); // ping-pong the vertex buffers var tmpVB = _drawVB; _drawVB = _streamOutVB; _streamOutVB = tmpVB; // // Draw the updated particle system we just streamed out. // _dxDevice.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_drawVB, stride, offset)); for (int p = 0; p < _drawTech.Description.PassCount; ++p) { _drawTech.GetPassByIndex(p).Apply(); _dxDevice.DrawAuto(); } }
public virtual void Render(Device device, ShaderHelper shaderHelper) { if (vertexBuffer != null && Topology != PrimitiveTopology.Undefined) { device.InputAssembler.SetInputLayout(vertexLayout); device.InputAssembler.SetPrimitiveTopology(Topology); device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, Marshal.SizeOf(typeof(Vertex)), 0)); if (indexBuffer != null) device.InputAssembler.SetIndexBuffer(indexBuffer, Format.R32_UInt, 0); shaderHelper.ConstantBufferSet.World = World; shaderHelper.ConstantBufferSet.LocalRotation = RotationMatrix; shaderHelper.ConstantBufferSet.TextureIndex = TextureIndex; shaderHelper.ApplyEffects(); if (indexBuffer != null) device.DrawIndexed(Vertices.NumElements, 0, 0); else { device.Draw(Vertices.NumElements, 0); } } }
private void Render() { m_D3DDevice.ClearRenderTargetView(m_RenderTargetView, Color.Black); m_D3DDevice.ClearDepthStencilView(m_DepthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); m_D3DDevice.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip); m_D3DDevice.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(m_Vertices, InputStride, 0)); EffectTechnique technique = m_Effect.GetTechniqueByName("Render"); for (int i = 0; i < technique.Description.PassCount; i++) { EffectPass pass = technique.GetPassByIndex(i); var layout = new InputLayout(m_D3DDevice, pass.Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0), //new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0), }); m_Effect.GetVariableByName("View").AsMatrix().SetMatrix(Matrix.Translation(m_Window.Width / 2.0f, m_ScrollPos + m_Window.Height / 2.0f, 0) * Matrix.LookAtLH(new Vector3(0, 0, 4), Vector3.Zero, Vector3.UnitY)); m_Effect.GetVariableByName("Projection").AsMatrix().SetMatrix(Matrix.OrthoLH(m_Window.Width, m_Window.Height, 1, 10)); m_D3DDevice.InputAssembler.SetInputLayout(layout); ShaderResourceView resource_view = new ShaderResourceView(m_D3DDevice, m_Tex); m_Effect.GetVariableByName("tex2D").AsResource().SetResource(resource_view); for (int j = 0; j < 4; j++) { pass.Apply(); float imageAR = (float)m_Tex.Description.Width / m_Tex.Description.Height; float viewportAR = (float)m_Window.Width / m_Window.Height; if (m_CurrentViewState is ZoomingViewState && (m_CurrentViewState as ZoomingViewState).ZoomPhoto == j) { float lerp_factor = (m_CurrentViewState as ZoomingViewState).GetLerpFactor(DateTime.Now); bool zoom_in = (m_CurrentViewState as ZoomingViewState).ZoomIn; if (lerp_factor > 1) { m_CurrentViewState = (m_CurrentViewState as ZoomingViewState).NextState; lerp_factor = 1; } if (!zoom_in) { lerp_factor = 1 - lerp_factor; } //m_Effect.GetVariableByName("AspectRatio").AsScalar().Set(imageAR / (float)Math.Pow(viewportAR, lerp_factor)); m_Effect.GetVariableByName("AspectRatio").AsScalar().Set(Lerp(imageAR, imageAR / viewportAR, lerp_factor)); m_Effect.GetVariableByName("World").AsMatrix().SetMatrix(Matrix.Lerp(GetWorldTransform(j), GetZoomTransform(), lerp_factor)); } else if (m_CurrentViewState is ZoomedViewState && (m_CurrentViewState as ZoomedViewState).ZoomPhoto == j) { m_Effect.GetVariableByName("AspectRatio").AsScalar().Set(imageAR / viewportAR); m_Effect.GetVariableByName("World").AsMatrix().SetMatrix(GetZoomTransform()); } else { m_Effect.GetVariableByName("AspectRatio").AsScalar().Set(imageAR); m_Effect.GetVariableByName("World").AsMatrix().SetMatrix(GetWorldTransform(j)); } m_D3DDevice.Draw(4, 0); } } m_SwapChain.Present(1, PresentFlags.None); }