Esempio n. 1
0
 public void Render(DeviceContext context, vsBuffer vsBuffer, psBuffer psBuffer)
 {
     foreach (Model model in models)
     {
         model.Render(context, vsBuffer, psBuffer);
     }
 }
Esempio n. 2
0
        public void Render(DeviceContext context, vsBuffer vsBuffer, psBuffer psBuffer)
        {
            context.InputAssembler.InputLayout = layout;
            if (isTesselated)
            {
                context.InputAssembler.PrimitiveTopology = PrimitiveTopology.PatchListWith3ControlPoints;
            }
            else
            {
                context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            }
            context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(mesh.vertexBuffer, mesh._vertexStream.vertexType.SizeOf(), 0));
            context.InputAssembler.SetIndexBuffer(mesh.indexBuffer, SharpDX.DXGI.Format.R16_UInt, 0);
            context.VertexShader.Set(_shaderSolution.vs);
            for (int i = 0; i < _shaderSolution.shaders_buffers[Shaders.VertexShader].Length; i++)
            {
                context.VertexShader.SetConstantBuffer(i, _shaderSolution.shaders_buffers[Shaders.VertexShader][i]);

            }
            context.PixelShader.Set(_shaderSolution.ps);
            for (int i = 0; i < _shaderSolution.shaders_buffers[Shaders.PixelShader].Length; i++)
            {
                context.PixelShader.SetConstantBuffer(i, _shaderSolution.shaders_buffers[Shaders.PixelShader][i]);
            }
            if (this.isTesselated)
            {
                context.HullShader.Set(_shaderSolution.hs);
                for (int i = 0; i < _shaderSolution.shaders_buffers[Shaders.HullShader].Length; i++)
                {
                    context.HullShader.SetConstantBuffer(i, _shaderSolution.shaders_buffers[Shaders.HullShader][i]);
                }
                context.DomainShader.Set(_shaderSolution.ds);
                for (int i = 0; i < _shaderSolution.shaders_buffers[Shaders.DomainShader].Length; i++)
                {
                    context.DomainShader.SetConstantBuffer(i, _shaderSolution.shaders_buffers[Shaders.DomainShader][i]);
                }
                context.UpdateSubresource(ref vsBuffer, _shaderSolution.shaders_buffers[Shaders.DomainShader][0]);
            }
            else
            {
                context.HullShader.Set(null);
                context.DomainShader.Set(null);
            }
            for(int i = 0; i<material.textures.Count; i++)
            {
                context.PixelShader.SetShaderResource(i, material.textures[i]);
            }
            context.UpdateSubresource(ref vsBuffer, _shaderSolution.shaders_buffers[Shaders.VertexShader][0]);

            // !!!!!!!!!!!!!!!!!!!!!!! not normal (be careful of shader being optimized and stripped of unused constant buffer)
            //context.UpdateSubresource(ref psBuffer, _shaderSolution.shaders_buffers[Shaders.PixelShader][0]);
            context.PixelShader.SetSampler(0, sampler);
            context.DrawIndexed(mesh._indexStream.getIndexCount(), 0, 0);
        }