Exemplo n.º 1
0
        public void Render(DeviceContext context, Int2 screenResolution, UILineInstance[] lines, int start, int count)
        {
            //This assumes that rasterizer, blend, and depth states have been set appropriately for screenspace transparent rendering.
            context.InputAssembler.InputLayout = null;
            context.InputAssembler.SetIndexBuffer(indices);
            context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            context.VertexShader.Set(vertexShader);
            context.VertexShader.SetConstantBuffer(0, vertexConstants.Buffer);
            context.VertexShader.SetShaderResource(0, instances.SRV);
            var vertexConstantsData = new VertexConstants
            {
                //The packed minimum must permit subpixel locations. So, distribute the range 0 to 65535 over the pixel range 0 to resolution.
                PackedToScreenScale = new Vector2(screenResolution.X / 65535f, screenResolution.Y / 65535f),
                ScreenToNDCScale    = new Vector2(2f / screenResolution.X, -2f / screenResolution.Y),
            };

            vertexConstants.Update(context, ref vertexConstantsData);
            context.PixelShader.Set(pixelShader);

            while (count > 0)
            {
                var batchCount = Math.Min(instances.Capacity, count);
                instances.Update(context, lines, batchCount, start);
                context.DrawIndexed(batchCount * 6, 0, 0);
                count -= batchCount;
                start += batchCount;
            }
        }
Exemplo n.º 2
0
        public void Render(DeviceContext context, Camera camera, Int2 resolution, LineInstance[] instances, int start, int count)
        {
            var vertexConstantsData = new VertexConstants
            {
                ViewProjection   = Matrix.Transpose(camera.ViewProjection), //compensate for the shader packing.
                NDCToScreenScale = new Vector2(resolution.X / 2f, resolution.Y / 2f),
                CameraForward    = camera.Forward,
                TanAnglePerPixel = (float)Math.Tan(camera.FieldOfView / resolution.Y),
                CameraRight      = camera.Right,
                CameraPosition   = camera.Position,
            };

            vertexConstants.Update(context, ref vertexConstantsData);

            //This assumes that render states have been set appropriately for opaque rendering.
            context.InputAssembler.InputLayout = null;
            context.InputAssembler.SetIndexBuffer(indices);
            context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            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);
                context.DrawIndexed(batchCount * 36, 0, 0);
                count -= batchCount;
                start += batchCount;
            }
        }
Exemplo n.º 3
0
        public void Render(DeviceContext context, Font font, Int2 screenResolution, Span <GlyphInstance> glyphs)
        {
            var vertexConstantsData = new VertexConstants
            {
                //These first two scales could be uploaded once, but it would require another buffer. Not important enough.
                //The packed minimum must permit subpixel locations. So, distribute the range 0 to 65535 over the pixel range 0 to resolution.
                PackedToScreenScale    = new Vector2(screenResolution.X / 65535f, screenResolution.Y / 65535f),
                ScreenToNDCScale       = new Vector2(2f / screenResolution.X, -2f / screenResolution.Y),
                InverseAtlasResolution = new Vector2(1f / font.Content.Atlas.Width, 1f / font.Content.Atlas.Height)
            };

            vertexConstants.Update(context, ref vertexConstantsData);
            context.VertexShader.SetShaderResource(1, font.Sources.SRV);
            context.PixelShader.SetShaderResource(0, font.AtlasSRV);

            var count = glyphs.Length;
            var start = 0;

            while (count > 0)
            {
                var batchCount = Math.Min(instances.Capacity, count);
                instances.Update(context, glyphs.Slice(start, batchCount));
                context.DrawIndexed(batchCount * 6, 0, 0);
                count -= batchCount;
                start += batchCount;
            }
        }
Exemplo n.º 4
0
        public void Render(Font font, Int2 screenResolution, Span <GlyphInstance> glyphs)
        {
            font.Sources.Bind(1);
            GL.BindTexture(TextureTarget.Texture2D, font.Atlas);
            var vertexConstantsData = new VertexConstants {
                //These first two scales could be uploaded once, but it would require another buffer. Not important enough.
                //The packed minimum must permit subpixel locations. So, distribute the range 0 to 65535 over the pixel range 0 to resolution.
                PackedToScreenScale    = new Vector2(screenResolution.X / 65535f, screenResolution.Y / 65535f),
                ScreenToNDCScale       = new Vector2(2f / screenResolution.X, -2f / screenResolution.Y),
                InverseAtlasResolution = new Vector2(1f / font.Content.Atlas.Width, 1f / font.Content.Atlas.Height)
            };

            vertexConstants.Update(ref vertexConstantsData);
            var count = glyphs.Length;
            var start = 0;

            while (count > 0)
            {
                var batchCount = Math.Min(instances.Capacity, count);
                instances.Update(glyphs.Slice(start, batchCount));
                GL.DrawElements(PrimitiveType.Triangles, batchCount * 6, indices.Type, 0);
                count -= batchCount;
                start += batchCount;
            }
        }
Exemplo n.º 5
0
        public void Render(DeviceContext context, Camera camera, Int2 screenResolution, BoxInstance[] instances, int start, int count)
        {
            var vertexConstantsData = new VertexConstants
            {
                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.SetIndexBuffer(indices);
            context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            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);
                context.DrawIndexed(batchCount * 36, 0, 0);
                count -= batchCount;
                start += batchCount;
            }
        }