Exemple #1
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);
    }