Exemple #1
0
        void CreateDeviceObjects()
        {
            // set up a commandlist
            commandList = context.CommandList;

            // compile de shader
            imShader = new EffectInstance(effectSystem.LoadEffect("ImGuiShader").WaitForResult());
            imShader.UpdateEffect(device);

            var layout = new VertexDeclaration(
                VertexElement.Position <Vector2>(),
                VertexElement.TextureCoordinate <Vector2>(),
                VertexElement.Color(PixelFormat.R8G8B8A8_UNorm)
                );

            imVertLayout = layout;

            // de pipeline desc
            var pipeline = new PipelineStateDescription()
            {
                BlendState = BlendStates.NonPremultiplied,

                RasterizerState = new RasterizerStateDescription()
                {
                    CullMode  = CullMode.None,
                    DepthBias = 0,
                    FillMode  = FillMode.Solid,
                    MultisampleAntiAliasLine = false,
                    ScissorTestEnable        = true,
                    SlopeScaleDepthBias      = 0,
                },

                PrimitiveType     = PrimitiveType.TriangleList,
                InputElements     = imVertLayout.CreateInputElements(),
                DepthStencilState = DepthStencilStates.Default,

                EffectBytecode = imShader.Effect.Bytecode,
                RootSignature  = imShader.RootSignature,

                Output = new RenderOutputDescription(PixelFormat.R8G8B8A8_UNorm)
            };

            // finally set up the pipeline
            var pipelineState = PipelineState.New(device, ref pipeline);

            imPipeline = pipelineState;

            var is32Bits           = false;
            var indexBuffer        = Xenko.Graphics.Buffer.Index.New(device, INITIAL_INDEX_BUFFER_SIZE * sizeof(ushort), GraphicsResourceUsage.Dynamic);
            var indexBufferBinding = new IndexBufferBinding(indexBuffer, is32Bits, 0);

            indexBinding = indexBufferBinding;

            var vertexBuffer        = Xenko.Graphics.Buffer.Vertex.New(device, INITIAL_VERTEX_BUFFER_SIZE * imVertLayout.CalculateSize(), GraphicsResourceUsage.Dynamic);
            var vertexBufferBinding = new VertexBufferBinding(vertexBuffer, layout, 0);

            vertexBinding = vertexBufferBinding;
        }
Exemple #2
0
        static VertexDeclaration GetVertexDeclaration(SimpleMesh mesh)
        {
            var elements = new List <VertexElement>();

            elements.Add(VertexElement.Position <Vector3>());
            if (mesh.HasVertexNormals)
            {
                elements.Add(VertexElement.Normal <Vector3>());
            }
            if (mesh.HasVertexUVs)
            {
                elements.Add(VertexElement.TextureCoordinate <Vector2>());
            }
            if (mesh.HasVertexColors)
            {
                elements.Add(VertexElement.Color <Color>());
            }
            return(new VertexDeclaration(elements.ToArray()));
        }
Exemple #3
0
        private static VertexElement[] CreateElement(VertexShaderFlags flag)
        {
            switch (flag)
            {
            case VertexShaderFlags.Position:
                return(new[] { VertexElement.Position(Format.R32G32B32_Float) });

            case VertexShaderFlags.Normal:
                return(new[] { VertexElement.Normal(Format.R32G32B32_Float) });

            case VertexShaderFlags.TextureUV:
                return(new[] { VertexElement.TextureCoordinate(Format.R32G32_Float) });

            case VertexShaderFlags.TextureUVW:
                return(new[] { VertexElement.TextureCoordinate(Format.R32G32B32_Float) });

            case VertexShaderFlags.Color:
                return(new[] { VertexElement.Color(Format.R32G32B32A32_Float) });

            case VertexShaderFlags.Tangent:
                return(new[] { VertexElement.Tangent(Format.R32G32B32A32_Float) });

            case VertexShaderFlags.Barycentric:
                return(new[] { new VertexElement("BARYCENTRIC", Format.R32G32B32_Float) });

            case VertexShaderFlags.InstanceWorld:
                return(new[]
                {
                    new VertexElement("INSTANCEWORLD", 0, Format.R32G32B32A32_Float),
                    new VertexElement("INSTANCEWORLD", 1, Format.R32G32B32A32_Float),
                    new VertexElement("INSTANCEWORLD", 2, Format.R32G32B32A32_Float),
                    new VertexElement("INSTANCEWORLD", 3, Format.R32G32B32A32_Float),
                });

            default:
                throw new ArgumentOutOfRangeException(string.Format("[{0}]: VertexShaderFlag not valid", flag));
            }
        }
Exemple #4
0
 public static (VertexElement, int) ConvertVertexElement(KeyValuePair <string, SharpGLTF.Schema2.Accessor> accessor, int offset)
 {
     return((accessor.Key, accessor.Value.Format.ByteSize) switch
     {
         ("POSITION", 12) => (VertexElement.Position <Vector3>(0, offset), Vector3.SizeInBytes),
         ("NORMAL", 12) => (VertexElement.Normal <Vector3>(0, offset), Vector3.SizeInBytes),
         ("TANGENT", 12) => (VertexElement.Tangent <Vector3>(0, offset), Vector3.SizeInBytes),
         ("COLOR", 16) => (VertexElement.Color <Vector4>(0, offset), Vector4.SizeInBytes),
         ("TEXCOORD_0", 8) => (VertexElement.TextureCoordinate <Vector2>(0, offset), Vector2.SizeInBytes),
         ("TEXCOORD_1", 8) => (VertexElement.TextureCoordinate <Vector2>(1, offset), Vector2.SizeInBytes),
         ("TEXCOORD_2", 8) => (VertexElement.TextureCoordinate <Vector2>(2, offset), Vector2.SizeInBytes),
         ("TEXCOORD_3", 8) => (VertexElement.TextureCoordinate <Vector2>(3, offset), Vector2.SizeInBytes),
         ("TEXCOORD_4", 8) => (VertexElement.TextureCoordinate <Vector2>(4, offset), Vector2.SizeInBytes),
         ("TEXCOORD_5", 8) => (VertexElement.TextureCoordinate <Vector2>(5, offset), Vector2.SizeInBytes),
         ("TEXCOORD_6", 8) => (VertexElement.TextureCoordinate <Vector2>(6, offset), Vector2.SizeInBytes),
         ("TEXCOORD_7", 8) => (VertexElement.TextureCoordinate <Vector2>(7, offset), Vector2.SizeInBytes),
         ("TEXCOORD_8", 8) => (VertexElement.TextureCoordinate <Vector2>(8, offset), Vector2.SizeInBytes),
         ("TEXCOORD_9", 8) => (VertexElement.TextureCoordinate <Vector2>(9, offset), Vector2.SizeInBytes),
         ("JOINTS_0", 8) => (new VertexElement(VertexElementUsage.BlendIndices, 0, PixelFormat.R16G16B16A16_UInt, offset), 8),
         ("JOINTS_0", 4) => (new VertexElement(VertexElementUsage.BlendIndices, 0, PixelFormat.R8G8B8A8_UInt, offset), 4),
         ("WEIGHTS_0", 16) => (new VertexElement(VertexElementUsage.BlendWeight, 0, PixelFormat.R32G32B32A32_Float, offset), Vector4.SizeInBytes),
         _ => throw new NotImplementedException(),
     });