public void DrawPrimitive(GeometricPrimitive primitive)
 {
     if (ActiveMaterial != primitive.MaterialShader)
     {
         ActiveMaterial = primitive.MaterialShader;
         ActiveMaterial.Begin();
     }
     ActiveMaterial.SetBuffers(primitive);
     primitive.Draw(Context);
 }
 /// <summary>
 /// Fills the buffer by semantics
 /// </summary>
 public void FillBuffer(DeviceContext Context, GeometricPrimitive primitive)
 {
     FillBuffer(Context, primitive.MatrixWorld);
 }
 public void SetBuffers(GeometricPrimitive Primitive, DeviceContext Context)
 {
     if (Primitive is SkinnedMeshPrimitive)
     {
         if (VertexShader_Skinning == null)
             return;
         else
             Context.VertexShader.Set(VertexShader_Skinning);
     }
     foreach (ConstantBufferWrapper cbuffer in ConstantBuffers)
     {
         cbuffer.FillBuffer(Context, Primitive);
         if (cbuffer.ShaderType == ShaderType.VertexShader)
             Context.VertexShader.SetConstantBuffer(cbuffer.CBuffer, cbuffer.ResourceSlot);
         if (cbuffer.ShaderType == ShaderType.PixelShader)
             Context.PixelShader.SetConstantBuffer(cbuffer.CBuffer, cbuffer.ResourceSlot);
     }
     if (Primitive is SkinnedMeshPrimitive)
     {
         if ((Primitive as SkinnedMeshPrimitive).IsPlaying == false)
             (Primitive as SkinnedMeshPrimitive).PlayAnimation(0, true);
         (Primitive as SkinnedMeshPrimitive).StepAnimation(0.002f);
         (Primitive as SkinnedMeshPrimitive).SetBoneMatrices(Renderer);
         Context.VertexShader.SetConstantBuffer((Primitive as SkinnedMeshPrimitive).BoneBuffer, 1);
     }
     for (int i = 0; i < Samplers.Count; i++)
     {
         Context.PixelShader.SetSampler(Samplers[i], i);
     }
     for (int i = 0; i < ShaderResources.Count; i++)
     {
         Context.PixelShader.SetShaderResource(ShaderResources[i], i);
     }
 }
 public void SetBuffers(GeometricPrimitive Primitive)
 {
     SetBuffers(Primitive, Renderer.Context);
 }
        public void Draw(GeometricPrimitive Primitive, DeviceContext Context)
        {
            Context.InputAssembler.PrimitiveTopology = Topology;
            if (Primitive is SkinnedMeshPrimitive)
                Context.InputAssembler.InputLayout = SkinnedMeshInputLayout;
            else
                Context.InputAssembler.InputLayout = StaticMeshInputLayout;
            Context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(Primitive.GeometryData.VertexBuffer, Primitive.GeometryData.VertexStride, 0));
            Context.InputAssembler.SetIndexBuffer(Primitive.GeometryData.IndexBuffer, Format.R16_UInt, 0);

            Context.DrawIndexed(Primitive.GeometryData.IndexCount, 0, 0);
        }
 public void Draw(GeometricPrimitive Primitive)
 {
     Draw(Primitive, Renderer.Context);
 }
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
            this.SizeChanged += Viewport_SizeChanged;

            ImageContainer = new D3DImageSource();
            ImageContainer.IsFrontBufferAvailableChanged += OnIsFrontBufferAvailableChanged;

            Renderer = new Renderer((int)this.ActualWidth, (int)this.ActualHeight);
            tri = new TestTriangle(Renderer.Device);
            prim2 = new PlanePrimitive(Renderer, 2000, 2000, 10, 10);
            prim2.MatrixWorld = SlimDX.Matrix.Translation(new Vector3(0, -1, 1));
            prim3 = new SpherePrimitive(Renderer, 0.1f, 16);
            prim = new SpherePrimitive(Renderer, 1f, 32);
            Renderer.Camera = new Camera(CameraProjectionType.Perspective, CameraViewType.Orbital);
            Renderer.Camera.Offset = 15;
            Renderer.Camera.zNear = 0.001f;
            Renderer.Camera.zFar = 1000f;
            Renderer.Camera.Rotation = new Vector3(MathHelper.PiOver2*1.5f, MathHelper.PiOver2*0.75f, 0);
            Renderer.LightingSystem.Lights.Add(new PointLight()
                {
                    Position = new Vector3(1,3,1),
                    Color = new Vector3(1,1,1),
                    Radius = 15,
                });
            prim3.MatrixWorld = SlimDX.Matrix.Translation(Renderer.LightingSystem.Lights[0].Position);
            MaterialShader ms;
            using (Texture2D tex = ContentHelper.TextureFromColor(Renderer.Device, new Color4(1, 1, 1, 0)))
                ms = MaterialShader.BasicMaterial(Renderer, tex);
            prim3.MaterialShader = ms;
            ImageContainer.SetBackBufferSlimDX(Renderer.SharedTexture);
            Timer = new Stopwatch();
            MouseWheel += ViewportFrame_MouseWheel;
            BeginRenderingScene();
        }