Example #1
0
    private void CreateIndexBuffer()
    {
        // 12 tris are needed to fill the space between two discs
        // which comes down to 15 * 12 = 180 tris overall, each needing
        // 3 indices
        Span <ushort> indices = stackalloc ushort[TriCount * 3];
        int           i       = 0;

        for (var disc = 0; disc < 15; ++disc)
        {
            var discFirst     = disc * 6;       // Index of first vertex in the current disc
            var nextDiscFirst = (disc + 1) * 6; // Index of first vertex in the next disc

            for (var segment = 0; segment < 5; ++segment)
            {
                indices[i++] = (ushort)(discFirst + segment);
                indices[i++] = (ushort)(discFirst + segment + 1);
                indices[i++] = (ushort)(nextDiscFirst + segment + 1);
                indices[i++] = (ushort)(discFirst + segment);
                indices[i++] = (ushort)(nextDiscFirst + segment + 1);
                indices[i++] = (ushort)(nextDiscFirst + segment);
            }

            // The last segment of this disc wraps back around
            // and connects to the first segment
            indices[i++] = (ushort)(discFirst + 5);
            indices[i++] = (ushort)(discFirst);
            indices[i++] = (ushort)(nextDiscFirst);
            indices[i++] = (ushort)(discFirst + 5);
            indices[i++] = (ushort)(nextDiscFirst);
            indices[i++] = (ushort)(nextDiscFirst + 5);
        }

        mIndexBuffer = mDevice.CreateIndexBuffer(indices);
    }
    public PickerAreaRenderer(RenderingDevice device)
    {
        _device           = device;
        _fanIndexBuffer   = device.CreateIndexBuffer(FanIndices);
        _fanVertexBuffer  = device.CreateEmptyVertexBuffer(IntgameVertex.Size * 39, debugName: "PickerAreaFan");
        _fanBufferBinding = device.CreateMdfBufferBinding().Ref();
        _fanBufferBinding.Resource.AddBuffer <IntgameVertex>(_fanVertexBuffer.Resource, 0)
        .AddElement(VertexElementType.Float4, VertexElementSemantic.Position)
        .AddElement(VertexElementType.Float4, VertexElementSemantic.Normal)
        .AddElement(VertexElementType.Color, VertexElementSemantic.Color)
        .AddElement(VertexElementType.Float2, VertexElementSemantic.TexCoord);

        _ringIndexBuffer   = device.CreateIndexBuffer(RingIndices);
        _ringVertexBuffer  = device.CreateEmptyVertexBuffer(IntgameVertex.Size * 76, debugName: "PickerAreaRing");
        _ringBufferBinding = device.CreateMdfBufferBinding().Ref();
        _ringBufferBinding.Resource.AddBuffer <IntgameVertex>(_ringVertexBuffer.Resource, 0)
        .AddElement(VertexElementType.Float4, VertexElementSemantic.Position)
        .AddElement(VertexElementType.Float4, VertexElementSemantic.Normal)
        .AddElement(VertexElementType.Color, VertexElementSemantic.Color)
        .AddElement(VertexElementType.Float2, VertexElementSemantic.TexCoord);
    }
Example #3
0
    public RectangleRenderer(RenderingDevice device)
    {
        _device             = device;
        _innerIndexBuffer   = device.CreateIndexBuffer(InnerIndices);
        _innerVertexBuffer  = device.CreateEmptyVertexBuffer(IntgameVertex.Size * 22, debugName: "RectangleInner");
        _innerBufferBinding = device.CreateMdfBufferBinding().Ref();
        _innerBufferBinding.Resource.AddBuffer <IntgameVertex>(_innerVertexBuffer.Resource, 0)
        .AddElement(VertexElementType.Float4, VertexElementSemantic.Position)
        .AddElement(VertexElementType.Float4, VertexElementSemantic.Normal)
        .AddElement(VertexElementType.Color, VertexElementSemantic.Color)
        .AddElement(VertexElementType.Float2, VertexElementSemantic.TexCoord);

        _outerIndexBuffer   = device.CreateIndexBuffer(OuterIndices);
        _outerVertexBuffer  = device.CreateEmptyVertexBuffer(IntgameVertex.Size * 52, debugName: "RectangleOuter");
        _outerBufferBinding = device.CreateMdfBufferBinding().Ref();
        _outerBufferBinding.Resource.AddBuffer <IntgameVertex>(_outerVertexBuffer.Resource, 0)
        .AddElement(VertexElementType.Float4, VertexElementSemantic.Position)
        .AddElement(VertexElementType.Float4, VertexElementSemantic.Normal)
        .AddElement(VertexElementType.Color, VertexElementSemantic.Color)
        .AddElement(VertexElementType.Float2, VertexElementSemantic.TexCoord);
    }
Example #4
0
    public SpellPointerRenderer(RenderingDevice device)
    {
        _device       = device;
        _indexBuffer  = device.CreateIndexBuffer(Indices);
        _vertexBuffer = device.CreateEmptyVertexBuffer(IntgameVertex.Size * 4, debugName: "SpellPointer");

        _bufferBinding = device.CreateMdfBufferBinding().Ref();
        _bufferBinding.Resource.AddBuffer <IntgameVertex>(_vertexBuffer.Resource, 0)
        .AddElement(VertexElementType.Float4, VertexElementSemantic.Position)
        .AddElement(VertexElementType.Float4, VertexElementSemantic.Normal)
        .AddElement(VertexElementType.Color, VertexElementSemantic.Color)
        .AddElement(VertexElementType.Float2, VertexElementSemantic.TexCoord);

        _material = Tig.MdfFactory.LoadMaterial("art/interface/intgame_select/Spell_Effect-Pointer.mdf");
    }
    protected QuadParticleRenderer(RenderingDevice device)
    {
        _device = device;

        // Set up an index bufer for the max. quad drawing
        var indices = new List <ushort>(0x8000 / 4 * 6);

        for (ushort i = 0; i < 0x8000; i += 4)
        {
            indices.Add((ushort)(i + 0));
            indices.Add((ushort)(i + 1));
            indices.Add((ushort)(i + 2));
            indices.Add((ushort)(i + 2));
            indices.Add((ushort)(i + 3));
            indices.Add((ushort)(i + 0));
        }

        _indexBuffer = device.CreateIndexBuffer(indices.ToArray());
    }
Example #6
0
    public FogOfWarRenderer(MapFoggingSystem fogSystem, RenderingDevice device)
    {
        _device    = device;
        _fogSystem = fogSystem;

        _vertexShader  = device.GetShaders().LoadVertexShader("fogofwar_vs");
        _bufferBinding = new BufferBinding(device, _vertexShader).Ref();

        UpdateBufferSize(true);

        Span <ushort> indices = stackalloc ushort[]
        {
            0, 2, 1, 2, 0, 3
        };

        _indexBuffer  = device.CreateIndexBuffer(indices, debugName: "FogOfWar");
        _vertexBuffer = device.CreateEmptyVertexBuffer(FogOfWarVertex.Size * 4, debugName: "FogOfWar");

        _bufferBinding.Resource
        .AddBuffer <FogOfWarVertex>(_vertexBuffer, 0)
        .AddElement(VertexElementType.Float3, VertexElementSemantic.Position)
        .AddElement(VertexElementType.Float2, VertexElementSemantic.TexCoord);
    }
Example #7
0
    private AasRenderSubmeshData GetSubmeshData(AasRenderData renderData,
                                                int submeshId,
                                                ISubmesh submesh)
    {
        if (renderData.submeshes[submeshId] == null)
        {
            renderData.submeshes[submeshId] = new AasRenderSubmeshData(mDevice);
        }

        var submeshData = renderData.submeshes[submeshId];

        if (!submeshData.created)
        {
            submeshData.posBuffer     = mDevice.CreateVertexBuffer(submesh.Positions, false, "AasSubmeshPositions");
            submeshData.normalsBuffer = mDevice.CreateVertexBuffer <Vector4>(submesh.Normals, false, "AasSubmeshNormals");
            submeshData.uvBuffer      = mDevice.CreateVertexBuffer(submesh.UV, debugName: "AasSubmeshUV");
            submeshData.idxBuffer     = mDevice.CreateIndexBuffer(submesh.Indices);

            var binding = submeshData.binding.Resource;
            binding.AddBuffer <Vector4>(submeshData.posBuffer, 0)
            .AddElement(VertexElementType.Float4, VertexElementSemantic.Position);
            binding.AddBuffer <Vector4>(submeshData.normalsBuffer, 0)
            .AddElement(VertexElementType.Float4, VertexElementSemantic.Normal);
            binding.AddBuffer <Vector2>(submeshData.uvBuffer, 0)
            .AddElement(VertexElementType.Float2, VertexElementSemantic.TexCoord);

            submeshData.created = true;
        }
        else
        {
            submeshData.posBuffer.Resource.Update(submesh.Positions);
            submeshData.normalsBuffer.Resource.Update <Vector4>(submesh.Normals);
        }

        return(submeshData);
    }
Example #8
0
    public ShapeRenderer2d(RenderingDevice device)
    {
        _device   = device;
        _textures = device.GetTextures();

        untexturedMaterial = CreateMaterial(device, "diffuse_only_ps");
        texturedMaterial   = CreateMaterial(device, "textured_simple_ps");
        texturedWithoutBlendingMaterial = CreateMaterial(device, "textured_simple_ps", false, false);
        texturedWithMaskMaterial        = CreateMaterial(device, "textured_two_ps");
        lineMaterial      = CreateMaterial(device, "diffuse_only_ps", true);
        outlineMaterial   = CreateOutlineMaterial(device);
        pieFillMaterial   = CreatePieFillMaterial(device);
        bufferBinding     = new BufferBinding(device, texturedMaterial.VertexShader).Ref();
        mdfBufferBinding  = _device.CreateMdfBufferBinding();
        lineBufferBinding = new BufferBinding(device, lineMaterial.VertexShader).Ref();


        SamplerSpec samplerWrapSpec = new SamplerSpec();

        samplerWrapSpec.addressU  = TextureAddress.Wrap;
        samplerWrapSpec.addressV  = TextureAddress.Wrap;
        samplerWrapSpec.minFilter = TextureFilterType.Linear;
        samplerWrapSpec.magFilter = TextureFilterType.Linear;
        samplerWrapSpec.mipFilter = TextureFilterType.Linear;
        samplerWrapState          = _device.CreateSamplerState(samplerWrapSpec);

        SamplerSpec samplerClampPointSpec = new SamplerSpec();

        samplerClampPointSpec.addressU  = TextureAddress.Clamp;
        samplerClampPointSpec.addressV  = TextureAddress.Clamp;
        samplerClampPointSpec.minFilter = TextureFilterType.NearestNeighbor;
        samplerClampPointSpec.magFilter = TextureFilterType.NearestNeighbor;
        samplerClampPointSpec.mipFilter = TextureFilterType.NearestNeighbor;
        samplerClampPointState          = _device.CreateSamplerState(samplerClampPointSpec);

        SamplerSpec samplerClampSpec = new SamplerSpec();

        samplerClampSpec.addressU  = TextureAddress.Clamp;
        samplerClampSpec.addressV  = TextureAddress.Clamp;
        samplerClampSpec.minFilter = TextureFilterType.Linear;
        samplerClampSpec.magFilter = TextureFilterType.Linear;
        samplerClampSpec.mipFilter = TextureFilterType.Linear;
        samplerClampState          = _device.CreateSamplerState(samplerClampSpec);

        DepthStencilSpec noDepthSpec = new DepthStencilSpec();

        noDepthSpec.depthEnable = false;
        noDepthState            = _device.CreateDepthStencilState(noDepthSpec);

        vertexBuffer = _device.CreateEmptyVertexBuffer(Vertex2d.Size * 8, debugName: "ShapeRenderer2d");

        var indexData = new ushort[]
        {
            0, 1, 2,
            2, 3, 0
        };

        indexBuffer = _device.CreateIndexBuffer(indexData);

        bufferBinding.Resource.AddBuffer <Vertex2d>(vertexBuffer, 0)
        .AddElement(VertexElementType.Float4, VertexElementSemantic.Position)
        .AddElement(VertexElementType.Float4, VertexElementSemantic.Normal)
        .AddElement(VertexElementType.Color, VertexElementSemantic.Color)
        .AddElement(VertexElementType.Float2, VertexElementSemantic.TexCoord);

        mdfBufferBinding.AddBuffer <Vertex2d>(vertexBuffer, 0)
        .AddElement(VertexElementType.Float4, VertexElementSemantic.Position)
        .AddElement(VertexElementType.Float4, VertexElementSemantic.Normal)
        .AddElement(VertexElementType.Color, VertexElementSemantic.Color)
        .AddElement(VertexElementType.Float2, VertexElementSemantic.TexCoord);
    }