public void Render(DeviceContext context, Camera camera, Int2 screenResolution, Span <TInstance> instances, int start, int count)
        {
            var vertexConstantsData = new RasterizedVertexConstants
            {
                Projection     = Matrix.Transpose(camera.Projection), //compensate for the shader packing.
                CameraPosition = camera.Position,
                CameraRight    = camera.Right,
                CameraUp       = camera.Up,
                CameraBackward = camera.Backward,
            };

            vertexConstants.Update(context, ref vertexConstantsData);

            //This assumes that render states have been set appropriately for opaque rendering.
            context.InputAssembler.InputLayout       = null;
            context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            OnDrawSetup(context);
            context.VertexShader.Set(vertexShader);
            context.VertexShader.SetConstantBuffer(0, vertexConstants.Buffer);
            context.VertexShader.SetShaderResource(0, this.instances.SRV);
            context.PixelShader.Set(pixelShader);

            while (count > 0)
            {
                var batchCount = Math.Min(this.instances.Capacity, count);
                this.instances.Update(context, instances, batchCount, start);
                OnBatchDraw(context, batchCount);
                count -= batchCount;
                start += batchCount;
            }
        }
        public void Render(Camera camera, Int2 screenResolution, Span <TInstance> instances, int start, int count)
        {
            Use();
            vertexConstants.Bind(0);
            this.instances.Bind(0);
            OnDrawSetup();

            var vertexConstantsData = new RasterizedVertexConstants
            {
                Projection     = camera.Projection,
                CameraPosition = camera.Position,
                CameraRight    = camera.Right,
                CameraUp       = camera.Up,
                CameraBackward = camera.Backward,
            };

            vertexConstants.Update(ref vertexConstantsData);

            while (count > 0)
            {
                var batchCount = Math.Min(this.instances.Capacity, count);
                this.instances.Update(instances, batchCount, start);
                OnBatchDraw(batchCount);
                count -= batchCount;
                start += batchCount;
            }
        }