Ejemplo n.º 1
0
        public static uint Encode(PerVertexDefinition def)
        {
            uint finalResult = ((uint)def.Position);

            finalResult |= ((uint)def.Normal) << 3;
            finalResult |= ((uint)def.Tangent) << 5;
            finalResult |= ((uint)def.TexCoords0) << 7;
            finalResult |= ((uint)def.TexCoords1) << 12;
            finalResult |= ((uint)def.Color0) << 16;
            finalResult |= ((uint)def.Color1) << 19;
            finalResult |= ((uint)def.Joints0) << 22;
            finalResult |= ((uint)def.Joints1) << 24;
            finalResult |= ((uint)def.Weights0) << 26;
            finalResult |= ((uint)def.Weights1) << 28;
            finalResult |= ((uint)def.IndexType) << 30;
            return(finalResult);
        }
Ejemplo n.º 2
0
        private MgPipelineVertexInputStateCreateInfo GenerateVertexInputState(PerVertexDefinition definition)
        {
            PerVertexStrideInfo[] strides = new PerVertexStrideInfo[]
            {
                GetPositionStride(definition.Position),    // 0
                GetNormalStride(definition.Normal),        // 1
                GetTangentStride(definition.Tangent),      // 2
                GetTexCoordsStride(definition.TexCoords0), // 3
                GetTexCoordsStride(definition.TexCoords1), // 4
                GetColorStride(definition.Color0),         // 5
                GetJointsStride(definition.Joints0),       // 6
                GetWeightsStride(definition.Weights0),     // 7
                GetColorStride(definition.Color1),         // 8
                GetJointsStride(definition.Joints1),       // 9
                GetWeightsStride(definition.Weights1),     // 10
            };

            var attributes      = new List <MgVertexInputAttributeDescription>();
            var perVertexStride = 0U;
            var location        = 0U;

            foreach (var stride in strides)
            {
                if (stride.Range > 0)
                {
                    var attribute = new MgVertexInputAttributeDescription
                    {
                        Binding  = 0U,
                        Format   = stride.Format,
                        Location = location,
                        Offset   = perVertexStride,
                    };

                    location += 1;

                    attributes.Add(attribute);
                }
                perVertexStride += stride.Range;
            }

            var perInstanceStride = (uint)Marshal.SizeOf(typeof(PerInstance));

            IncludePerInstanceAttributes(attributes);

            return(new MgPipelineVertexInputStateCreateInfo
            {
                VertexBindingDescriptions = new[]
                {
                    new MgVertexInputBindingDescription
                    {
                        Binding = 0U,
                        InputRate = MgVertexInputRate.VERTEX,
                        Stride = perVertexStride,
                    },
                    new MgVertexInputBindingDescription
                    {
                        Binding = 1U,
                        InputRate = MgVertexInputRate.INSTANCE,
                        Stride = perInstanceStride,
                    },
                },
                VertexAttributeDescriptions = attributes.ToArray(),
            });
        }
Ejemplo n.º 3
0
 public PerVertexInputPipelineState(PerVertexDefinition definition)
 {
     VertexMask       = PerVertexDefinitionEncoder.Encode(definition);
     VertexInputState = GenerateVertexInputState(definition);
 }