Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VertexAttribute"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="size">The size.</param>
 /// <param name="type">The type.</param>
 /// <param name="normalised">if set to <c>true</c> [normalised].</param>
 public VertexAttribute(string name, int size, VertexAttributeType type, bool normalised = false)
 {
     this.Name       = name;
     this.Size       = size;
     this.Type       = type;
     this.Normalised = normalised;
 }
Beispiel #2
0
        public static byte[] UnpackNormals(byte[] data, VertexAttributeType attributeType, ref int stride)
        {
            switch (attributeType)
            {
            case VertexAttributeType.TangentSpaceUnitVectorsCompressed:
                var packedElementSize = attributeType.GetSize();
                stride = Vector3.SizeInBytes * 3;
                var count        = (data.Length / packedElementSize);
                var bufferLength = count * stride;
                var buffer       = new byte[bufferLength];
                using (var binaryReader = new BinaryReader(new MemoryStream(data)))
                    using (var binaryWriter = new BinaryWriter(new MemoryStream(buffer)))
                    {
                        while (binaryReader.BaseStream.Position < data.Length)
                        {
                            var normal    = VertexFunctions.UnpackVectorInt(binaryReader.ReadInt32());
                            var tangent   = VertexFunctions.UnpackVectorInt(binaryReader.ReadInt32());
                            var bitangent = VertexFunctions.UnpackVectorInt(binaryReader.ReadInt32());
                            binaryWriter.Write(normal);
                            binaryWriter.Write(tangent);
                            binaryWriter.Write(bitangent);
                        }
                    }
                return(buffer);

            default:
                return(data);
            }
        }
Beispiel #3
0
        public static byte GetSize(this VertexAttributeType attribute_type)
        {
            var value = (short)attribute_type;
            var size  = (byte)(value & 0x00FF);

            return(size);
        }
 public VertexAttributeDescriptor(VertexAttributeType type, int size, VertexAttributeDataType dataType, int stride, int offset)
 {
     Type     = type;
     Size     = size;
     DataType = dataType;
     Stride   = stride;
     Offset   = offset;
 }
Beispiel #5
0
 public VertexAttribute(VertexAttributeType type, int size, int stride, int offset, bool normalized = false)
 {
     Type       = type;
     Size       = size;
     Normalized = normalized;
     Stride     = stride;
     Offset     = offset;
 }
        public VertexAttribute(VertexAttributeName name, int size, VertexAttributeType type, bool normalized, uint offset = 0)
        {
            Name = name;
            Size = size;
            Type = type;

            Normalized = normalized;

            Index = GetAttributeIndex(name) + offset;
        }
Beispiel #7
0
        public VertexAttribute(string name, VertexAttributeType type)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                Log.WriteLine("VertexAttribute name must not be null or empty.", LogType.Error);
                return;
            }


            Name = name;
            Type = type;
        }
Beispiel #8
0
        private static VertexAttributeType[] GetSectionVertexAttributeTypes(GlobalGeometrySectionStructBlock section)
        {
            var sectionVertexBufferTypes =
                new VertexAttributeType[section.VertexBuffers.Length];

            for (var i = 0; i < section.VertexBuffers.Length; ++i)
            {
                sectionVertexBufferTypes[i] = section.VertexBuffers[i].VertexBuffer.Type;
            }

            return(sectionVertexBufferTypes);
        }
Beispiel #9
0
 public void VertexAttribPointer(int index, int size, VertexAttributeType type, bool normalize, int stride, IntPtr pointer)
 {
     if (index < 0)
     {
         throw new Exception("Invalid Index");
     }
     if (size < 1 || size > 4)
     {
         throw new Exception("Size must be a value between 1 and 4");
     }
     if (stride < 0)
     {
         throw new Exception("Invalid stride value");
     }
     _glVertexAttribPointer(index, size, (int)(type), normalize ? 1 : 0, stride, pointer);
 }
Beispiel #10
0
        /// <summary>
        ///     Calls glVertexAttribPointer to setup attributes for shaders and enables the vertex attribute array
        /// </summary>
        /// <param name="type">Type of attribute data</param>
        /// <param name="bindingIndex"></param>
        private static void ConfigureVertexAttributeArray(VertexAttributeType type, int bindingIndex)
        {
            switch (type)
            {
            case VertexAttributeType.UnpackedWorldCoordinateData:
                MoonGL.VertexAttribArray(0, bindingIndex, 3, VertexAttribType.Float);
                MoonGL.VertexAttribArray(1, bindingIndex, 4, VertexAttribType.Byte, false, 12);
                MoonGL.VertexAttribArray(2, bindingIndex, 4, VertexAttribType.Float, false, 16);
                break;

            case VertexAttributeType.UnpackedTextureCoordinateData:
                MoonGL.VertexAttribArray(3, bindingIndex, 2, VertexAttribType.Float);
                break;

            case VertexAttributeType.UnpackedLightingData:
                MoonGL.VertexAttribArray(4, bindingIndex, 3, VertexAttribType.Float);
                MoonGL.VertexAttribArray(5, bindingIndex, 3, VertexAttribType.Float, false, 12);
                MoonGL.VertexAttribArray(6, bindingIndex, 3, VertexAttribType.Float, false, 24);
                break;

            case VertexAttributeType.CoordinateFloat:
                MoonGL.VertexAttribArray(0, bindingIndex, 3, VertexAttribType.Float);
                break;

            case VertexAttributeType.TextureCoordinateFloat:
                MoonGL.VertexAttribArray(3, bindingIndex, 2, VertexAttribType.Float);
                break;

            case VertexAttributeType.LightmapUVCoordinateOneXbox:
                MoonGL.VertexAttribArray(11, bindingIndex, 2, VertexAttribType.Short, true);
                break;

            case VertexAttributeType.LightmapUVCoordinateTwoXbox:
                MoonGL.VertexAttribArray(12, bindingIndex, 2, VertexAttribType.Short, true);
                break;

            default:
                return;
            }
        }
        internal static int GetSizeInBytes(VertexAttributeType attrType, int count)
        {
            switch (attrType)
            {
            case VertexAttributeType.Byte:
            case VertexAttributeType.UnsignedByte:
                return(1 * count);

            case VertexAttributeType.Short:
            case VertexAttributeType.UnsignedShort:
            case VertexAttributeType.HalfFloat:
                return(2 * count);

            case VertexAttributeType.Int:
            case VertexAttributeType.UnsignedInt:
            case VertexAttributeType.Float:
            case VertexAttributeType.Fixed:
                return(4 * count);
            }

            throw new InvalidOperationException($"Unknown vertex attribute type: {attrType}");
        }
Beispiel #12
0
 /// <summary>
 /// Starts a stream of vertex attribute additions to the layout.
 /// </summary>
 /// <param name="attribute">The kind of attribute to add.</param>
 /// <param name="count">The number of elements in the attribute (1, 2, 3, or 4).</param>
 /// <param name="type">The type of data described by the attribute.</param>
 /// <param name="normalized">if set to <c>true</c>, values will be normalized from a 0-255 range to 0.0 - 0.1 in the shader.</param>
 /// <param name="asInt">if set to <c>true</c>, the attribute is packaged as an integer in the shader.</param>
 /// <returns>
 /// This instance, for use in a fluent API.
 /// </returns>
 public VertexLayout Add(VertexAttributeUsage attribute, int count, VertexAttributeType type, bool normalized = false, bool asInt = false)
 {
     NativeMethods.bgfx_vertex_layout_add(ref data, attribute, (byte)count, type, normalized, asInt);
     return(this);
 }
 internal ShaderVertexAttribute(string name, int attributeIndex, VertexAttributeType type)
     : base(name, type)
 {
     AttributeIndex = attributeIndex;
     ByteOffset     = -1;
 }
Beispiel #14
0
        private static byte[] UnpackCoordinates(byte[] data, VertexAttributeType attributeType,
                                                GlobalGeometryCompressionInfoBlock compressionInfo, ref int stride)
        {
            switch (attributeType)
            {
            case VertexAttributeType.CoordinateCompressed:
            case VertexAttributeType.CoordinateWithTripleNode:
            case VertexAttributeType.CoordinateWithDoubleNode:
            case VertexAttributeType.CoordinateWithSingleNode:
                var packedElementSize = attributeType.GetSize();
                stride = (3 * sizeof(float)) + (4 * sizeof(float)) + 4;
                var count        = (data.Length / packedElementSize);
                var bufferLength = count * stride;
                var buffer       = new byte[bufferLength];
                using (var binaryReader = new BinaryReader(new MemoryStream(data)))
                    using (var binaryWriter = new BinaryWriter(new MemoryStream(buffer)))
                    {
                        while (binaryReader.BaseStream.Position < data.Length)
                        {
                            var x = VertexFunctions.Unpack(binaryReader.ReadInt16(),
                                                           compressionInfo.PositionBoundsX.Min,
                                                           compressionInfo.PositionBoundsX.Max);
                            var y = VertexFunctions.Unpack(binaryReader.ReadInt16(),
                                                           compressionInfo.PositionBoundsY.Min,
                                                           compressionInfo.PositionBoundsY.Max);
                            var z = VertexFunctions.Unpack(binaryReader.ReadInt16(),
                                                           compressionInfo.PositionBoundsZ.Min,
                                                           compressionInfo.PositionBoundsZ.Max);
                            binaryWriter.Write(x);
                            binaryWriter.Write(y);
                            binaryWriter.Write(z);
                            switch (attributeType)
                            {
                            case VertexAttributeType.CoordinateCompressed:
                                WriteVertexNodeInformation(binaryWriter,
                                                           0,
                                                           0,
                                                           0,
                                                           1.0f,
                                                           0,
                                                           0);
                                break;

                            case VertexAttributeType.CoordinateWithSingleNode:
                                WriteVertexNodeInformation(binaryWriter,
                                                           binaryReader.ReadByte(),
                                                           binaryReader.ReadByte(),
                                                           0,
                                                           1.0f,
                                                           0,
                                                           0);
                                break;

                            case VertexAttributeType.CoordinateWithDoubleNode:
                                binaryReader.ReadBytes(2);
                                WriteVertexNodeInformation(binaryWriter,
                                                           binaryReader.ReadByte(),
                                                           binaryReader.ReadByte(),
                                                           0,
                                                           binaryReader.ReadByte() / 255.0f,
                                                           binaryReader.ReadByte() / 255.0f,
                                                           0);
                                break;

                            case VertexAttributeType.CoordinateWithTripleNode:
                                WriteVertexNodeInformation(binaryWriter,
                                                           binaryReader.ReadByte(),
                                                           binaryReader.ReadByte(),
                                                           binaryReader.ReadByte(),
                                                           binaryReader.ReadByte() / 255.0f,
                                                           binaryReader.ReadByte() / 255.0f,
                                                           binaryReader.ReadByte() / 255.0f);
                                break;
                            }
                        }
                    }
                return(buffer);

            default:
                return(data);
            }
        }
 /// <summary>
 /// Adds a vertex attributes to the list of vertex attributes. The vertex
 /// attributes are used to describe the layout of the verrex data. The
 /// order in which the attributes are added is the same order in which the
 /// data has to be aligned for the vertex. This has be done before adding
 /// actual vertex data to the GeometryBuffer.
 /// </summary>
 /// <param name="attribute">
 /// The attribute that should be added to the list of vertex attributes
 /// describing the vertices of this GeometryBuffer.
 /// </param>
 public void AddVertexAttribute(VertexAttributeType attribute)
 {
     d_vertexAttributes.Add(attribute);
 }
Beispiel #16
0
 public VertexAttributeAttribute(VertexAttributeType type, VkFormat format)
 {
     Format = format;
     Type   = type;
 }
Beispiel #17
0
 protected VertexAttribute(string name, VertexAttributeType type)
 {
     _name = name;
     _type = type;
 }
Beispiel #18
0
 public static extern void bgfx_vertex_decl_add(ref VertexLayout.Data decl, VertexAttributeUsage attribute, byte count, VertexAttributeType type, [MarshalAs(UnmanagedType.U1)] bool normalized, [MarshalAs(UnmanagedType.U1)] bool asInt);
Beispiel #19
0
 /// <summary>
 /// Starts a stream of vertex attribute additions to the layout.
 /// </summary>
 /// <param name="attribute">The kind of attribute to add.</param>
 /// <param name="count">The number of elements in the attribute (1, 2, 3, or 4).</param>
 /// <param name="type">The type of data described by the attribute.</param>
 /// <param name="normalized">if set to <c>true</c>, values will be normalized from a 0-255 range to 0.0 - 0.1 in the shader.</param>
 /// <param name="asInt">if set to <c>true</c>, the attribute is packaged as an integer in the shader.</param>
 /// <returns>
 /// This instance, for use in a fluent API.
 /// </returns>
 public VertexLayout Add(VertexAttributeUsage attribute, int count, VertexAttributeType type, bool normalized = false, bool asInt = false)
 {
     NativeMethods.bgfx_vertex_decl_add(ref data, attribute, (byte)count, type, normalized, asInt);
     return this;
 }
Beispiel #20
0
 public static extern void bgfx_vertex_decl_add(ref VertexLayout.Data decl, VertexAttributeUsage attribute, byte count, VertexAttributeType type, [MarshalAs(UnmanagedType.U1)] bool normalized, [MarshalAs(UnmanagedType.U1)] bool asInt);
 protected VertexAttribute(string name, VertexAttributeType type)
 {
     _name = name;
     _type = type;
 }