Example #1
0
        public override void Apply(Graphics.IRenderContext context, System.Numerics.Matrix4x4 viewProjection, Assets.Material material, System.Numerics.Matrix4x4 world)
        {
            context.SetState(Engine.RenderStatePool.GetRenderState(new RenderStateInfo()
            {
                PrimitiveType = Graphics.PrimitiveType.TriangleList,
                Shader        = shader,
                Rasterizer    = rasterizerState,
                DepthStencil  = depthStencil
            }));
            context.SetTexture(shader, "picture", material.Texture.Handle);
            if (Engine.Settings.GraphicsAPI == GraphicsAPI.Direct3D11)
            {
                context.SetSampler(shader, "pictureSampler", sampler);
            }
            else if (Engine.Settings.GraphicsAPI == GraphicsAPI.OpenGL4)
            {
                context.SetSampler(shader, "picture", sampler);
            }

            GCHandle  handle;
            DataArray dataArray = DataArray.FromObject <Matrix4x4>(Matrix4x4.Transpose(world * viewProjection), out handle);

            try
            {
                context.UpdateContext.Update(constantBuffer, dataArray);
            }
            finally
            {
                handle.Free();
            }
            context.SetConstantBuffer(shader, constantBuffer);
        }
Example #2
0
        public IConstantBuffer CreateConstantBuffer <T>(T data, ResourceUsage usage) where T : struct
        {
            ConstantBuffer buffer = null;
            GCHandle       handle;
            DataArray      dataArray = DataArray.FromObject(data, out handle);

            try
            {
                buffer = new ConstantBuffer(graphicsDevice, usage, dataArray);
            }
            finally
            {
                handle.Free();
            }

            return(buffer);
        }
Example #3
0
        public IConstantBuffer CreateConstantBuffer <T>(T data, ResourceUsage usage) where T : struct
        {
            AssertCurrent();
            ConstantBuffer constantBuffer = null;
            GCHandle       handle;
            DataArray      dataArray = DataArray.FromObject <T>(data, out handle);

            try
            {
                constantBuffer = Register(new ConstantBuffer(graphicsDevice, usage, dataArray));
            }
            finally
            {
                handle.Free();
            }
            return(constantBuffer);
        }