Ejemplo n.º 1
0
 // Really the same as CreateVertexBuffer - but we need a separate return type so we make a new method.
 public DynamicDataBuffer CreateDynamicVertexBuffer(int length, VertexFormat vertexFormat)
 {
     IntPtr pOut = IntPtr.Zero;
     int res = Interop.Calli(comPointer, length, (int)Usage.Dynamic, (int)vertexFormat, (int)Pool.Default, (IntPtr)(void*)&pOut, IntPtr.Zero,(*(IntPtr**)comPointer)[26]);
     if( res < 0 ) { throw new SharpDXException( res ); }
     return new DynamicDataBuffer( pOut );
 }
		public Microsoft.Xna.Framework.Graphics.VertexElement[] ConvertFrom(VertexFormat format)
		{
			var xnaElements = new Microsoft.Xna.Framework.Graphics.VertexElement[format.Elements.Length];
			usageCounts = new Dictionary<VertexElementUsage, int>();
			for (int i = 0; i < xnaElements.Length; i++)
				xnaElements[i] = ConvertToXnaElement(format.Elements[i]);
			return xnaElements;
		}
Ejemplo n.º 3
0
 public void FormatToString()
 {
     var elements = new[] {
         new VertexElement(VertexElementType.Position3D),
         new VertexElement(VertexElementType.TextureUV) };
     var format = new VertexFormat(elements);
     Assert.AreEqual("VertexFormat: Position3D*3, TextureUV*2, Stride=20", format.ToString());
 }
Ejemplo n.º 4
0
 public ShaderCreationData(string vertexCode, string fragmentCode, string dx11Code,
     string dx9Code, VertexFormat format)
 {
     VertexCode = vertexCode;
     FragmentCode = fragmentCode;
     DX11Code = dx11Code;
     DX9Code = dx9Code;
     Format = format;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VertexElement"/> structure.
        /// </summary>
        /// <param name="position">The element's position within the vertex data, in bytes.</param>
        /// <param name="format">The element's vertex format.</param>
        /// <param name="usage">The element's usage hint.</param>
        /// <param name="index">The element's usage index.</param>
        public VertexElement(Int32 position, VertexFormat format, VertexUsage usage, Int32 index)
        {
            Contract.EnsureRange(index >= 0 && index < UsageIndexCount, "index");

            this.position = position;
            this.format = format;
            this.usage = usage;
            this.index = index;
        }
		public ShaderWithFormatCreationData(ShaderFlags flags, string glVertexCode,
			string glFragmentCode, string dx11Code, string dx9Code, VertexFormat format)
			: base(flags)
		{
			VertexCode = glVertexCode;
			FragmentCode = glFragmentCode;
			DX11Code = dx11Code;
			DX9Code = dx9Code;
			Format = format;
		}
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SharpDX.Direct3D9.VertexBuffer" /> class.
 /// </summary>
 /// <param name="device">The device that will be used to create the buffer.</param>
 /// <param name="sizeInBytes">Size of the buffer, in bytes.</param>
 /// <param name="usage">The requested usage of the buffer.</param>
 /// <param name="format">The vertex format of the vertices in the buffer. If set to <see cref="SharpDX.Direct3D9.VertexFormat" />.None, the buffer will be a non-FVF buffer.</param>
 /// <param name="pool">The memory class into which the resource will be placed.</param>
 /// <param name="sharedHandle">The variable that will receive the shared handle for this resource.</param>
 /// <remarks>This method is only available in Direct3D9 Ex.</remarks>
 /// <msdn-id>bb174364</msdn-id>	
 /// <unmanaged>HRESULT IDirect3DDevice9::CreateVertexBuffer([In] unsigned int Length,[In] D3DUSAGE Usage,[In] D3DFVF FVF,[In] D3DPOOL Pool,[Out, Fast] IDirect3DVertexBuffer9** ppVertexBuffer,[In] void** pSharedHandle)</unmanaged>	
 /// <unmanaged-short>IDirect3DDevice9::CreateVertexBuffer</unmanaged-short>	
 public VertexBuffer(Device device, int sizeInBytes, Usage usage, VertexFormat format, Pool pool, ref IntPtr sharedHandle)
     : base(IntPtr.Zero)
 {
     unsafe
     {
         sharedHandle = IntPtr.Zero;
         fixed (void* pSharedHandle = &sharedHandle)
             device.CreateVertexBuffer(sizeInBytes, usage, format, pool, this, new IntPtr(pSharedHandle));
     }
 }
Ejemplo n.º 8
0
        public VertexFloatBuffer(VertexFormat format, int limit = 1024,
                                 BeginMode drawMode             = BeginMode.Triangles)
        {
            Format = format;
            SetStride();
            UsageHint = BufferUsageHint.StreamDraw;
            DrawMode  = drawMode;

            vertex_data = new float[limit * AttributeCount];
            index_data  = new uint[limit];
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SharpDX.Direct3D9.VertexBuffer" /> class.
        /// </summary>
        /// <param name="device">The device that will be used to create the buffer.</param>
        /// <param name="sizeInBytes">Size of the buffer, in bytes.</param>
        /// <param name="usage">The requested usage of the buffer.</param>
        /// <param name="format">The vertex format of the vertices in the buffer. If set to <see cref="SharpDX.Direct3D9.VertexFormat" />.None, the buffer will be a non-FVF buffer.</param>
        /// <param name="pool">The memory class into which the resource will be placed.</param>
        /// <param name="sharedHandle">The variable that will receive the shared handle for this resource.</param>
        /// <remarks>This method is only available in Direct3D9 Ex.</remarks>
        /// <msdn-id>bb174364</msdn-id>
        /// <unmanaged>HRESULT IDirect3DDevice9::CreateVertexBuffer([In] unsigned int Length,[In] D3DUSAGE Usage,[In] D3DFVF FVF,[In] D3DPOOL Pool,[Out, Fast] IDirect3DVertexBuffer9** ppVertexBuffer,[In] void** pSharedHandle)</unmanaged>
        /// <unmanaged-short>IDirect3DDevice9::CreateVertexBuffer</unmanaged-short>
        public VertexBuffer(Device device, int sizeInBytes, Usage usage, VertexFormat format, Pool pool, ref IntPtr sharedHandle)
            : base(IntPtr.Zero)
        {
            unsafe
            {
                sharedHandle = IntPtr.Zero;

                fixed(void *pSharedHandle = &sharedHandle)
                device.CreateVertexBuffer(sizeInBytes, usage, format, pool, this, new IntPtr(pSharedHandle));
            }
        }
Ejemplo n.º 10
0
        protected override void UploadInstances <T>(ReadOnlySequence <T> instances, VertexFormat format)
        {
            if (format != lastInstanceFormat)
            {
                lastInstanceFormat = format;
                bindedArrays.Clear();
            }

            // upload buffer data
            UploadBuffer(ref instanceBuffer, GLEnum.ARRAY_BUFFER, instances, ref instanceBufferSize);
        }
Ejemplo n.º 11
0
        public void VertexFormatGetVertexElement()
        {
            var elements = new[] {
                new VertexElement(VertexElementType.Position3D),
                new VertexElement(VertexElementType.TextureUV)
            };
            var format = new VertexFormat(elements);

            Assert.IsNull(format.GetElementFromType(VertexElementType.Color));
            Assert.IsNotNull(format.GetElementFromType(VertexElementType.TextureUV));
        }
Ejemplo n.º 12
0
        public override object Read(ContentReader reader)
        {
            VertexFormat format      = reader.ReadObjectRaw <VertexFormat>();
            uint         vertexCount = reader.ReadUInt32();

            byte[] data = reader.ReadBytes(format.Stride * (int)vertexCount);

            VertexBuffer buffer = VertexBuffer.Create(format, data);

            return(buffer);
        }
Ejemplo n.º 13
0
 public void HasProperties()
 {
     var elements = new[] {
         new VertexElement(VertexElementType.Position3D),
         new VertexElement(VertexElementType.TextureUV) };
     var format = new VertexFormat(elements);
     Assert.IsTrue(format.HasUV);
     Assert.IsTrue(format.Is3D);
     Assert.IsFalse(format.HasColor);
     Assert.IsFalse(format.HasNormal);
 }
Ejemplo n.º 14
0
        public override void SetBatchFormat(VertexFormat format)
        {
            if (format == batchFormat)
            {
                return;
            }
            batchFormat = format;

            Device.SetVertexFormat(device, formatMapping[(int)format]);
            batchStride = strideSizes[(int)format];
        }
Ejemplo n.º 15
0
        public Microsoft.Xna.Framework.Graphics.VertexElement[] ConvertFrom(VertexFormat format)
        {
            var xnaElements = new Microsoft.Xna.Framework.Graphics.VertexElement[format.Elements.Length];

            usageCounts = new Dictionary <VertexElementUsage, int>();
            for (int i = 0; i < xnaElements.Length; i++)
            {
                xnaElements[i] = ConvertToXnaElement(format.Elements[i]);
            }
            return(xnaElements);
        }
Ejemplo n.º 16
0
        public override int CreateDynamicVb(VertexFormat format, int maxVertices)
        {
            if (glLists)
            {
                return(dynamicListId);
            }
            int id          = GenAndBind(BufferTarget.ArrayBuffer);
            int sizeInBytes = maxVertices * strideSizes[(int)format];

            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(sizeInBytes), IntPtr.Zero, BufferUsage.DynamicDraw);
            return(id);
        }
Ejemplo n.º 17
0
        private int InitializeVertexBuffer <TVertex>(ICollection <TVertex> vertices) where TVertex : struct
        {
            var vertexType = typeof(TVertex);

            _stride      = Marshal.SizeOf(vertexType);
            _vertexCount = vertices.Count;
            var size = _stride * _vertexCount;

            _vertexFormat = (VertexFormat)vertexType.GetField("Format").GetValue(null);
            _vertices     = new VertexBuffer(_device, size, Usage.WriteOnly, _vertexFormat, Pool.Default);
            return(size);
        }
 void IDisposable.Dispose()
 {
     effectInstance?.Dispose(); effectInstance = null;
     if (linesBuffer != indexLinesBuffer && linesBuffer != indexPointsBuffer)
     {
         linesBuffer?.Dispose();
     }
     linesBuffer = null; linesCount = 0;
     triangleBuffer?.Dispose(); triangleBuffer = null; triangleCount = 0;
     vertexFormat?.Dispose();   vertexFormat   = null;
     vertexBuffer?.Dispose();   vertexBuffer   = null; vertexCount = 0;
 }
Ejemplo n.º 19
0
        public override int CreateVb(IntPtr vertices, VertexFormat format, int count)
        {
            if (glLists)
            {
                // We need to setup client state properly when building the list
                VertexFormat curFormat = batchFormat;
                SetBatchFormat(format);
                int list = GL.GenLists(1);
                GL.NewList(list, 0x1300);
                count &= ~0x01;                 // Need to get rid of the 1 extra element, see comment in chunk mesh builder for why

                const int maxIndices = 65536 / 4 * 6;
                ushort *  indicesPtr = stackalloc ushort[maxIndices];
                MakeIndices(indicesPtr, maxIndices);

                int stride = 0;
                if (format == VertexFormat.P3fT2fC4b)
                {
                    stride = VertexP3fT2fC4b.Size;
                }
                else if (format == VertexFormat.P3fT2fC4bN1v)
                {
                    stride = VertexP3fT2fC4bN1v.Size;
                }
                else
                {
                    stride = VertexP3fC4b.Size;
                }
                GL.VertexPointer(3, PointerType.Float, stride, vertices);
                GL.ColorPointer(4, PointerType.UnsignedByte, stride, (IntPtr)((byte *)vertices + 12));
                if (format == VertexFormat.P3fT2fC4b)
                {
                    GL.TexCoordPointer(2, PointerType.Float, stride, (IntPtr)((byte *)vertices + 16));
                }
                else if (format == VertexFormat.P3fT2fC4bN1v)
                {
                    GL.TexCoordPointer(2, PointerType.Float, stride, (IntPtr)((byte *)vertices + 16));
                    GL.NormalPointer(NormalPointerType.Float, stride, (IntPtr)((byte *)vertices + 24));
                }

                GL.DrawElements(BeginMode.Triangles, (count >> 2) * 6, DrawElementsType.UnsignedShort, (IntPtr)indicesPtr);
                GL.EndList();
                SetBatchFormat(curFormat);
                return(list);
            }

            int id          = GenAndBind(BufferTarget.ArrayBuffer);
            int sizeInBytes = count * strideSizes[(int)format];

            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(sizeInBytes), vertices, BufferUsage.StaticDraw);
            return(id);
        }
Ejemplo n.º 20
0
            /// <summary>
            /// Called by Game1. Initializes textures, buffers, etc.
            /// </summary>
            public void loadContent(GraphicsDevice device, ContentManager cm)
            {
                _vd = new VertexDeclaration(4 * sizeof(float), VertexFormat.VertexElements);

                _vb = new VertexBuffer(device, _vd, 6, BufferUsage.WriteOnly);
                VertexFormat[] data = new VertexFormat[6];
                data[0].position.X = -1.0f;
                data[0].position.Y = 1.0f;
                data[0].texCoord.X = 0.0f;
                data[0].texCoord.Y = 0.0f;

                data[1].position.X = 1.0f;
                data[1].position.Y = 1.0f;
                data[1].texCoord.X = 1.0f;
                data[1].texCoord.Y = 0.0f;

                data[2].position.X = 1.0f;
                data[2].position.Y = -1.0f;
                data[2].texCoord.X = 1.0f;
                data[2].texCoord.Y = 1.0f;

                data[3].position.X = -1.0f;
                data[3].position.Y = 1.0f;
                data[3].texCoord.X = 0.0f;
                data[3].texCoord.Y = 0.0f;

                data[4].position.X = 1.0f;
                data[4].position.Y = -1.0f;
                data[4].texCoord.X = 1.0f;
                data[4].texCoord.Y = 1.0f;

                data[5].position.X = -1.0f;
                data[5].position.Y = -1.0f;
                data[5].texCoord.X = 0.0f;
                data[5].texCoord.Y = 1.0f;

                _vb.SetData<VertexFormat>(data, 0, 6);

                _colorTexture = new Texture2D(device, horRes, vertRes,
                                             false, SurfaceFormat.Color);

                _depthTexture = new Texture2D(device, horRes, vertRes,
                                             false, SurfaceFormat.Single);

                cm.RootDirectory = "Content";
                _effect = cm.Load<Effect>("simple");
                _effect.Parameters["pixelWidth"].SetValue((float)pixelWidth);
                _effect.Parameters["pixelHeight"].SetValue((float)pixelHeight);
                _effect.Parameters["fillColor"].SetValue(fillColor.ToVector4());
                _effect.Parameters["horRes"].SetValue(horRes);
                _effect.Parameters["vertRes"].SetValue(vertRes);
            }
Ejemplo n.º 21
0
        public void BuildMeshFromGeometry(
            BufferUsageHint bufferUsageHint,
            NormalStyle normalStyle
            )
        {
            var attributePosition     = new Attribute(VertexUsage.Position, VertexAttribPointerType.Float, 0, 3);
            var attributeNormal       = new Attribute(VertexUsage.Normal, VertexAttribPointerType.Float, 0, 3);       /*  content normals     */
            var attributeNormalFlat   = new Attribute(VertexUsage.Normal, VertexAttribPointerType.Float, 1, 3);       /*  flat normals        */
            var attributeNormalSmooth = new Attribute(VertexUsage.Normal, VertexAttribPointerType.Float, 2, 3);       /*  smooth normals      */
            var attributeColor        = new Attribute(VertexUsage.Color, VertexAttribPointerType.Float, 0, 4);
            var attributeIdVec3       = new Attribute(VertexUsage.Id, VertexAttribPointerType.Float, 0, 3);
            var attributeIdUInt       = (RenderStack.Graphics.Configuration.useIntegerPolygonIDs)
                                        ? new Attribute(VertexUsage.Id, VertexAttribPointerType.UnsignedInt, 0, 1)
                                        : null;

            VertexFormat vertexFormat = new VertexFormat();

            vertexFormat.Add(attributePosition);
            vertexFormat.Add(attributeNormal);
            vertexFormat.Add(attributeNormalFlat);
            vertexFormat.Add(attributeNormalSmooth);

            Dictionary <Corner, Vector2> cornerTexcoords = null;
            Dictionary <Point, Vector2>  pointTexcoords  = null;

            if (Geometry.CornerAttributes.Contains <Vector2>("corner_texcoords"))
            {
                cornerTexcoords = Geometry.CornerAttributes.Find <Vector2>("corner_texcoords");
            }
            if (Geometry.PointAttributes.Contains <Vector2>("point_texcoords"))
            {
                pointTexcoords = Geometry.PointAttributes.Find <Vector2>("point_texcoords");
            }

            if (cornerTexcoords != null || pointTexcoords != null)
            {
                var attributeTexcoord = new Attribute(VertexUsage.TexCoord, VertexAttribPointerType.Float, 0, 2);
                vertexFormat.Add(attributeTexcoord);
            }
            // \todo When do we want color attribute and when we don't?
            //if(cornerColors != null || pointColors != null)
            //{
            vertexFormat.Add(attributeColor);
            //}
            vertexFormat.Add(attributeIdVec3);
            if (RenderStack.Graphics.Configuration.useIntegerPolygonIDs)
            {
                vertexFormat.Add(attributeIdUInt);
            }

            BuildMeshFromGeometry(bufferUsageHint, normalStyle, vertexFormat);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Enables the flag on the vertex format.
        /// </summary>
        /// <param name="flag">The vertex format flag.</param>
        /// <param name="enabled">if set to <c>true</c> the flag is set.</param>
        private void SetFlag(VertexFormat flag, bool enabled)
        {
            bool currentValue = CheckFlag(flag);

            if (enabled && !currentValue)
            {
                format = format | flag;
            }
            else if (!enabled && currentValue)
            {
                format = format ^ flag;
            }
        }
Ejemplo n.º 23
0
        public void SetVertices(int stream, Array vertices, VertexFormat format, Vector4 trans, Vector4 scale, int offset, int stride, int to, int from, int count)
        {
            if (count < 0)
            {
                count = int.MaxValue;
            }
            int errorCode = PsmVertexBuffer.SetVertices2(this.handle, stream, vertices, format, ref trans, ref scale, offset, stride, to, from, count);

            if (errorCode != 0)
            {
                Error.ThrowNativeException(errorCode);
            }
        }
Ejemplo n.º 24
0
 public VertexAttributeDescription(
     string semanticName,
     int semanticIndex,
     VertexFormat format,
     int offset,
     int bufferIndex)
 {
     SemanticName  = semanticName;
     SemanticIndex = semanticIndex;
     Format        = format;
     Offset        = offset;
     BufferIndex   = bufferIndex;
 }
Ejemplo n.º 25
0
        public override int CreateDynamicVb(VertexFormat format, int maxVertices)
        {
            int    size   = maxVertices * strideSizes[(int)format];
            IntPtr buffer = IntPtr.Zero;
            int    res    = Device.CreateVertexBuffer(device, size, Usage.Dynamic | Usage.WriteOnly,
                                                      formatMapping[(int)format], Pool.Default, &buffer);

            if (res < 0)
            {
                throw new SharpDXException(res);
            }
            return(GetOrExpand(ref vBuffers, buffer, iBufferSize));
        }
Ejemplo n.º 26
0
        public static int GetStride(VertexFormat vertexFormat)
        {
            switch (vertexFormat)
            {
            case VertexFormat.Vector2: return(8);

            case VertexFormat.Vector3: return(12);

            case VertexFormat.Vector4: return(16);

            default: return(0);
            }
        }
Ejemplo n.º 27
0
        public static Format GetFormat(VertexFormat vertexFormat)
        {
            switch (vertexFormat)
            {
            case VertexFormat.Vector2: return(Format.R32G32_Float);

            case VertexFormat.Vector3: return(Format.R32G32B32_Float);

            case VertexFormat.Vector4: return(Format.R32G32B32A32_Float);

            default: return(Format.Unknown);
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Converts a declarator from a flexible vertex format (FVF) code.
        /// </summary>
        /// <param name="fvf">Combination of <see cref="VertexFormat"/> that describes the FVF from which to generate the returned declarator array..</param>
        /// <returns>
        /// A declarator from a flexible vertex format (FVF) code.
        /// </returns>
        /// <unmanaged>HRESULT D3DXDeclaratorFromFVF([In] D3DFVF FVF,[In, Buffer] D3DVERTEXELEMENT9* pDeclarator)</unmanaged>
        public static VertexElement[] DeclaratorFromFVF(VertexFormat fvf)
        {
            var vertices = new VertexElement[(int)VertexFormatDeclaratorCount.Max];

            var result = D3DX9.DeclaratorFromFVF(fvf, vertices);
            if (result.Failure)
                return null;

            var copy = new VertexElement[D3DX9.GetDeclLength(vertices) + 1];
            Array.Copy(vertices, copy, copy.Length);
            copy[copy.Length - 1] = VertexElement.VertexDeclarationEnd;
            return copy;
        }
Ejemplo n.º 29
0
        private void PlatformSetAttributeDescriptor(
            int index,
            string semanticName,
            int semanticIndex,
            VertexFormat format,
            int bufferIndex,
            int offset)
        {
            var attributeDescriptor = DeviceVertexDescriptor.Attributes[index];

            attributeDescriptor.Format      = format.ToMTLVertexFormat();
            attributeDescriptor.BufferIndex = (nuint)bufferIndex;
            attributeDescriptor.Offset      = (nuint)offset;
        }
Ejemplo n.º 30
0
        public static int GetSizeInBytes(VertexFormat format)
        {
            switch (format)
            {
            case VertexFormat.UChar2:
            case VertexFormat.Char2:
            case VertexFormat.UChar2Norm:
            case VertexFormat.Char2Norm:
            case VertexFormat.Half:
                return(2);

            case VertexFormat.Float:
            case VertexFormat.UInt:
            case VertexFormat.Int:
            case VertexFormat.UChar4:
            case VertexFormat.Char4:
            case VertexFormat.UChar4Norm:
            case VertexFormat.Char4Norm:
            case VertexFormat.UShort2:
            case VertexFormat.Short2:
            case VertexFormat.UShort2Norm:
            case VertexFormat.Short2Norm:
            case VertexFormat.Half2:
            case VertexFormat.UInt1010102Norm:
                return(4);

            case VertexFormat.Float2:
            case VertexFormat.UInt2:
            case VertexFormat.Int2:
            case VertexFormat.UShort4:
            case VertexFormat.Short4:
            case VertexFormat.UShort4Norm:
            case VertexFormat.Short4Norm:
            case VertexFormat.Half4:
                return(8);

            case VertexFormat.Float3:
            case VertexFormat.UInt3:
            case VertexFormat.Int3:
                return(12);

            case VertexFormat.Float4:
            case VertexFormat.UInt4:
            case VertexFormat.Int4:
                return(16);

            default:
                throw new GraphicsException($"Invalid {format} value");
            }
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Returns a new instance of the <see cref="Mesh"/>, where all <see cref="SubSet"/>s
        /// have the specified <see cref="VertexFormat"/>.
        /// </summary>
        /// <param name="format">Format to convert into.</param>
        /// <returns>Cloned instance of the mesh.</returns>
        public Mesh Clone(VertexFormat format)
        {
            Mesh ret = new Mesh();

            for (int i = 0; i < SubSets.Count; i++)
            {
                ret.SubSets.Add(SubSets[i].Clone(format));
            }
            for (int i = 0; i < Textures.Count; i++)
            {
                ret.Textures.Add(Textures[i]);
            }
            return(ret);
        }
Ejemplo n.º 32
0
        public int UploadModel(Model <BitmapTag> model, out DrawCommand[] meshCommands)
        {
            int vao, vbo, ibo;

            GL.GenVertexArrays(1, out vao);
            GL.BindVertexArray(vao);

            var vertCount = model.Meshes.Sum(m => m.Verticies.Length);
            var indxCount = model.Meshes.Sum(m => m.Indicies.Length);

            meshCommands = new DrawCommand[model.Meshes.Length];
            var vertices = new VertexFormat[vertCount];
            var indices  = new int[indxCount];

            var currentVert = 0;
            var currentIndx = 0;

            for (var i = 0; i < model.Meshes.Length; i++)
            {
                var mesh = model.Meshes[i];

                var command = new DrawCommand(mesh)
                {
                    VaoHandle       = vao,
                    IndexBase       = currentIndx,
                    VertexBase      = currentVert,
                    ColorChangeData = model.ColorChangeData
                };

                Array.Copy(mesh.Verticies, 0, vertices, currentVert, mesh.Verticies.Length);
                currentVert += mesh.Verticies.Length;

                Array.Copy(mesh.Indicies, 0, indices, currentIndx, mesh.Indicies.Length);
                currentIndx += mesh.Indicies.Length;

                meshCommands[i] = command;
            }

            GL.GenBuffers(1, out vbo);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * VertexFormat.Size), vertices, BufferUsageHint.StaticDraw);

            GL.GenBuffers(1, out ibo);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(int)), indices, BufferUsageHint.StaticDraw);

            SetupVertexFormatAttributes();

            return(vao);
        }
Ejemplo n.º 33
0
        public void HasProperties()
        {
            var elements = new[] {
                new VertexElement(VertexElementType.Position3D),
                new VertexElement(VertexElementType.TextureUV)
            };
            var format = new VertexFormat(elements);

            Assert.IsTrue(format.HasUV);
            Assert.IsTrue(format.Is3D);
            Assert.IsFalse(format.HasColor);
            Assert.IsFalse(format.HasNormal);
            Assert.IsFalse(format.HasLightmap);
        }
Ejemplo n.º 34
0
        public void VertexFormatPosition3DTextureUVColor()
        {
            var elements = new[] {
                new VertexElement(VertexElementType.Position3D),
                new VertexElement(VertexElementType.TextureUV),
                new VertexElement(VertexElementType.Color)
            };
            var format = new VertexFormat(elements);

            Assert.AreEqual(24, format.Stride);
            Assert.AreEqual(0, elements[0].Offset);
            Assert.AreEqual(12, elements[1].Offset);
            Assert.AreEqual(20, elements[2].Offset);
        }
        public Rmv2Geometry(RmvSubModel modelPart, IGeometryGraphicsContext context) : base(VertexPositionNormalTextureCustom.VertexDeclaration, context)
        {
            Pivot = new Vector3(modelPart.Header.Transform.Pivot.X, modelPart.Header.Transform.Pivot.Y, modelPart.Header.Transform.Pivot.Z);

            _vertexArray  = new VertexPositionNormalTextureCustom[modelPart.Mesh.VertexList.Length];
            _indexList    = (ushort[])modelPart.Mesh.IndexList.Clone();
            _vertedFormat = modelPart.Header.VertextType;

            for (int i = 0; i < modelPart.Mesh.VertexList.Length; i++)
            {
                var vertex = modelPart.Mesh.VertexList[i];
                _vertexArray[i].Position = new Vector4(vertex.Postition.X, vertex.Postition.Y, vertex.Postition.Z, 1);

                _vertexArray[i].Normal            = new Vector3(vertex.Normal.X, vertex.Normal.Y, vertex.Normal.Z);
                _vertexArray[i].BiNormal          = new Vector3(vertex.BiNormal.X, vertex.BiNormal.Y, vertex.BiNormal.Z);
                _vertexArray[i].Tangent           = new Vector3(vertex.Tangent.X, vertex.Tangent.Y, vertex.Tangent.Z);
                _vertexArray[i].TextureCoordinate = new Vector2(vertex.Uv.X, vertex.Uv.Y);

                _vertexArray[i].BlendIndices = Vector4.Zero;
                _vertexArray[i].BlendWeights = Vector4.Zero;

                if (_vertedFormat == VertexFormat.Cinematic)
                {
                    _vertexArray[i].BlendIndices.X = vertex.BoneIndex[0];
                    _vertexArray[i].BlendIndices.Y = vertex.BoneIndex[1];
                    _vertexArray[i].BlendIndices.Z = vertex.BoneIndex[2];
                    _vertexArray[i].BlendIndices.W = vertex.BoneIndex[3];

                    _vertexArray[i].BlendWeights.X = vertex.BoneWeight[0];
                    _vertexArray[i].BlendWeights.Y = vertex.BoneWeight[1];
                    _vertexArray[i].BlendWeights.Z = vertex.BoneWeight[2];
                    _vertexArray[i].BlendWeights.W = vertex.BoneWeight[3];

                    WeightCount = 4;
                }
                else if (_vertedFormat == VertexFormat.Weighted)
                {
                    _vertexArray[i].BlendIndices.X = vertex.BoneIndex[0];
                    _vertexArray[i].BlendWeights.X = vertex.BoneWeight[0];

                    _vertexArray[i].BlendIndices.Y = vertex.BoneIndex[1];
                    _vertexArray[i].BlendWeights.Y = vertex.BoneWeight[1];
                    WeightCount = 2;
                }
            }

            RebuildVertexBuffer();
            RebuildIndexBuffer();
        }
Ejemplo n.º 36
0
 public static byte ToFormat(this VertexFormat _this, Version version)
 {
     if (version.IsGreaterEqual(2019))
     {
         return((byte)_this.ToVertexFormatV2019());
     }
     else if (version.IsGreaterEqual(2017))
     {
         return((byte)_this.ToVertexFormatV2017());
     }
     else
     {
         return((byte)_this.ToVertexChannelFormat());
     }
 }
Ejemplo n.º 37
0
 public static byte ToFormat(this VertexFormat _this, Version version)
 {
     if (VertexFormat2019Relevant(version))
     {
         return((byte)_this.ToVertexFormat2019());
     }
     else if (VertexFormat2017Relevant(version))
     {
         return((byte)_this.ToVertexFormat2017());
     }
     else
     {
         return((byte)_this.ToVertexChannelFormat());
     }
 }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            VertexFormat vf = value as VertexFormat;

            if (vf == null)
            {
                throw new ArgumentException("value must be of type VertexFormat");
            }

            if (vf.ArrayType == VertexArrayType.Color0 || vf.ArrayType == VertexArrayType.Color1)
            {
                return(vf.ColorDataType.ToString());
            }

            return(vf.DataType.ToString());
        }
Ejemplo n.º 39
0
        /// <summary>
        /// Deserializes the object and populates it from the input.
        /// </summary>
        /// <param name="input">Savable input</param>
        public void Read(ISavableReader input)
        {
            _vertexStride = input.ReadInt();
            int count = input.ReadInt();

            _elements = new VertexElement[count];
            for (int i = 0; i < count; i++)
            {
                VertexSemantic semantic      = input.ReadEnum <VertexSemantic>();
                int            semanticIndex = input.ReadInt();
                VertexFormat   format        = input.ReadEnum <VertexFormat>();
                int            offset        = input.ReadInt();
                _elements[i] = new VertexElement(semantic, semanticIndex, format, offset);
            }
            GetHashCode();
        }
Ejemplo n.º 40
0
            public List <VertexFormat> GetAllVertexFormats()
            {
                var          allFormats = new List <VertexFormat>();
                VertexFormat vFormat;
                uint         dataOffset = _vertexFormatsOffset;

                do
                {
                    vFormat = new VertexFormat();
                    vFormat.Load(_dataCopy, dataOffset);
                    allFormats.Add(vFormat);

                    dataOffset += VertexFormat.Size;
                } while (vFormat.ArrayType != ArrayTypes.NullAttr);

                return(allFormats);
            }
Ejemplo n.º 41
0
 public void AreEqual()
 {
     var elements = new[] {
         new VertexElement(VertexElementType.Position3D),
         new VertexElement(VertexElementType.TextureUV) };
     var format = new VertexFormat(elements);
     Assert.IsTrue(VertexFormat.Position3DUV.Equals(format));
     Assert.IsTrue(VertexFormat.Position3DUV.Equals((object)format));
     Assert.AreEqual(VertexFormat.Position3DUV, format);
     Assert.IsTrue(VertexFormat.Position3DUV == format);
     Assert.IsTrue(VertexFormat.Position2DUV.Equals(VertexFormat.Position2DUV));
     Assert.IsFalse(VertexFormat.Position2DUV == VertexFormat.Position2DColor);
     Assert.AreEqual(VertexFormat.Position2DUV, VertexFormat.Position2DUV);
     Assert.AreNotEqual(VertexFormat.Position2DUV, VertexFormat.Position2DColor);
     VertexFormat unassignedFormat = null;
     Assert.IsTrue(unassignedFormat == null);
 }
        public void CanDrawSquare()
        {
            VertexBuffer vbuf = new VertexBuffer(Test_VertexBuffer.CUBE_VERTICES.Length);
            vbuf.CopyData(Test_VertexBuffer.CUBE_VERTICES);

            IndexBuffer ibuf = new IndexBuffer(Test_IndexBuffer.CUBE_INDICES.Length);
            ibuf.CopyData(Test_IndexBuffer.CUBE_INDICES);

            VertexFormat vfmt = new VertexFormat(Test_VertexFormat.CUBE_ATTRIBUTES);

            GraphicsSystem.BeginFrame();
            GraphicsSystem.Clear(Color.Black);
            GraphicsSystem.Draw(vbuf, vfmt, ibuf);
            GraphicsSystem.EndFrame();
            GraphicsSystem.Swap();

            Bitmap image = _wnd.GrabScreen();
            Assert.IsTrue(0 == image.GetPixel(30,30).R, "Square is larger than expected");
            Assert.IsTrue(0 < image.GetPixel(48,48).R, "Square was not rendered");
        }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="mesh"></param>
		/// <param name="numVertices"></param>
		public void beginOverwrite( VertexFormat vertFormat, int numVertices, int numTriangles )
		{
			isLocked = true;

			// Vertex format
			this.VertFormat = vertFormat | VertexFormat.Position;

			// Number
			this.firstVertexIndex = 0;
			this.numVertices = numVertices;
			this.numIndices	= numTriangles * 3;
			
			// Data
			this.vertices.positions = new Vector3[this.numVertices];

			if (vertexHasComponent(VertexFormat.Normal))
				this.vertices.normals = new Vector3[this.numVertices];

			if (vertexHasComponent(VertexFormat.BoneWeight))
				this.vertices.boneWeights = new BoneWeight[this.numVertices];

			if (vertexHasComponent(VertexFormat.Color))
				this.vertices.colors = new Color[this.numVertices];

			if (vertexHasComponent(VertexFormat.UV))
				this.vertices.uv = new Vector2[this.numVertices];

			if (vertexHasComponent(VertexFormat.UV1))
				this.vertices.uv1 = new Vector2[this.numVertices];

			if (vertexHasComponent(VertexFormat.UV2))
				this.vertices.uv2 = new Vector2[this.numVertices];

			if (vertexHasComponent(VertexFormat.Tangent))
				this.vertices.tangents = new Vector4[this.numVertices];
			
			this.indices = new int[this.numIndices];

			// reset to begin of buffer
			reset( 0, 0 );
		}
Ejemplo n.º 44
0
 public void SetVertexFormat(VertexFormat vertexFormat)
 {
     int res = Interop.Calli(comPointer, (int)vertexFormat,(*(IntPtr**)comPointer)[89]);
     if( res < 0 ) { throw new SharpDXException( res ); }
 }
Ejemplo n.º 45
0
        /// <summary>
        /// Gets the OpenGL vertex format that corresponds to the specified Ultraviolet vertex format.
        /// </summary>
        /// <param name="format">The vertex format to convert.</param>
        /// <param name="size">The number of components in the element.</param>
        /// <param name="stride">The vertex stride in bytes.</param>
        /// <param name="normalize">A value indicating whether to normalize the attribute's values.</param>
        /// <param name="integer">A value indicating whether to upload the attribute as an integer type.</param>
        /// <returns>The converted vertex format.</returns>
        private static UInt32 GetVertexFormatGL(VertexFormat format, out Int32 size, out Int32 stride, out Boolean normalize, out Boolean integer)
        {
            switch (format)
            {
                case VertexFormat.Single:
                    size = 1;
                    stride = size * sizeof(float);
                    normalize = false;
                    integer = false;
                    return gl.GL_FLOAT;

                case VertexFormat.Vector2:
                    size = 2;
                    stride = size * sizeof(float);
                    normalize = false;
                    integer = false;
                    return gl.GL_FLOAT;

                case VertexFormat.Vector3:
                    size = 3;
                    stride = size * sizeof(float);
                    normalize = false;
                    integer = false;
                    return gl.GL_FLOAT;

                case VertexFormat.Vector4:
                    size = 4;
                    stride = size * sizeof(float);
                    normalize = false;
                    integer = false;
                    return gl.GL_FLOAT;

                case VertexFormat.Color:
                    size = 4;
                    stride = size * sizeof(byte);
                    normalize = true;
                    integer = false;
                    return gl.GL_UNSIGNED_BYTE;

                case VertexFormat.NormalizedShort2:
                    size = 2;
                    stride = size * sizeof(short);
                    normalize = true;
                    integer = true;
                    return gl.GL_SHORT;

                case VertexFormat.NormalizedShort4:
                    size = 4;
                    stride = size * sizeof(short);
                    normalize = true;
                    integer = true;
                    return gl.GL_SHORT;

                case VertexFormat.Short2:
                    size = 2;
                    stride = size * sizeof(short);
                    normalize = false;
                    integer = true;
                    return gl.GL_SHORT;

                case VertexFormat.Short4:
                    size = 4;
                    stride = size * sizeof(short);
                    normalize = false;
                    integer = true;
                    return gl.GL_SHORT;

                default:
                    throw new NotSupportedException(OpenGLStrings.UnsupportedVertexFormat);
            }
        }
 public void SetFVF(VertexFormat fvf)
 {
     device.VertexFormat = fvf;
 }
Ejemplo n.º 47
0
 public DataBuffer CreateVertexBuffer(int length, Usage usage, VertexFormat vertexFormat, Pool pool)
 {
     IntPtr pOut = IntPtr.Zero;
     int res = Interop.Calli(comPointer, length, (int)usage, (int)vertexFormat, (int)pool, (IntPtr)(void*)&pOut, IntPtr.Zero,(*(IntPtr**)comPointer)[26]);
     if( res < 0 ) { throw new SharpDXException( res ); }
     return new DataBuffer( pOut );
 }
Ejemplo n.º 48
0
 public void VertexFormatPosition3DTextureUVColor()
 {
     var elements = new[] {
         new VertexElement(VertexElementType.Position3D),
         new VertexElement(VertexElementType.TextureUV),
         new VertexElement(VertexElementType.Color)};
     var format = new VertexFormat(elements);
     Assert.AreEqual(24, format.Stride);
     Assert.AreEqual(0, elements[0].Offset);
     Assert.AreEqual(12, elements[1].Offset);
     Assert.AreEqual(20, elements[2].Offset);
 }
Ejemplo n.º 49
0
		public GeometryCreationData(VertexFormat format, int numberOfVertices, int numberOfIndices)
		{
			Format = format;
			NumberOfVertices = numberOfVertices;
			NumberOfIndices = numberOfIndices;
		}
Ejemplo n.º 50
0
 /// <summary>
 /// Gets an array of <see cref="Vector3"/> from a <see cref="DataStream"/>.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="vertexCount">The vertex count.</param>
 /// <param name="format">The format.</param>
 /// <returns>An array of <see cref="Vector3"/> </returns>
 public static Vector3[] GetVectors(DataStream stream, int vertexCount, VertexFormat format)
 {
     int stride = GetFVFVertexSize(format);
     return GetVectors(stream, vertexCount, stride);
 }
Ejemplo n.º 51
0
 public void VertexFormatGetVertexElement()
 {
     var elements = new[] {
         new VertexElement(VertexElementType.Position3D),
         new VertexElement(VertexElementType.TextureUV) };
     var format = new VertexFormat(elements);
     Assert.IsNull(format.GetElementFromType(VertexElementType.Color));
     Assert.IsNotNull(format.GetElementFromType(VertexElementType.TextureUV));
 }
Ejemplo n.º 52
0
		//ncrunch: no coverage start
		public void LoadFromFile(Stream fileData)
		{
			var reader = new BinaryReader(fileData);
			string shortName = reader.ReadString();
			var dataVersion = reader.ReadBytes(4);
			var boolean = reader.ReadBoolean();
			if (boolean)
				reader.ReadString();
			boolean = reader.ReadBoolean();
			var type = reader.ReadString();
			if (type == null)
				throw new NullReferenceException();

			boolean = reader.ReadBoolean();
			var count = reader.ReadByte();
			var typeOfByte = reader.ReadByte();
			if (typeOfByte == 255)
				throw new NullReferenceException();
			type = reader.ReadString();
			var list = new VertexElement[count];
			for (int i = 0; i < count; i++)
			{
				var vertexElementType = reader.ReadInt32();
				var size = reader.ReadInt32();
				var vertexCount = reader.ReadInt32();
				var vertexElementOffset = reader.ReadInt32();
				list[i] = new VertexElement((VertexElementType)vertexElementType, size, vertexCount);
			}
			Format = new VertexFormat(list);
			var formatStride = reader.ReadInt32();

			int verticesLength = reader.ReadInt32(); //Int32 numberofvertices
			boolean = reader.ReadBoolean();
			if (boolean)
			{
				verticesLength = ReadNumberMostlyBelow255(reader);
				vertices = reader.ReadBytes(verticesLength);
			}

			reader.ReadBoolean(); //Indices
			var indicesLength = ReadNumberMostlyBelow255(reader);
			typeOfByte = reader.ReadByte();
			reader.ReadString();
			indices = new short[indicesLength];
			for (int i = 0; i < indicesLength; i++)
				indices[i] = reader.ReadInt16();
			SetNativeData(vertices, indices);
		}
Ejemplo n.º 53
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SharpDX.Direct3D9.VertexBuffer" /> class.
 /// </summary>
 /// <param name="device">The device that will be used to create the buffer.</param>
 /// <param name="sizeInBytes">Size of the buffer, in bytes.</param>
 /// <param name="usage">The requested usage of the buffer.</param>
 /// <param name="format">The vertex format of the vertices in the buffer. If set to <see cref="SharpDX.Direct3D9.VertexFormat" />.None, the buffer will be a non-FVF buffer.</param>
 /// <param name="pool">The memory class into which the resource will be placed.</param>
 /// <msdn-id>bb174364</msdn-id>	
 /// <unmanaged>HRESULT IDirect3DDevice9::CreateVertexBuffer([In] unsigned int Length,[In] D3DUSAGE Usage,[In] D3DFVF FVF,[In] D3DPOOL Pool,[Out, Fast] IDirect3DVertexBuffer9** ppVertexBuffer,[In] void** pSharedHandle)</unmanaged>	
 /// <unmanaged-short>IDirect3DDevice9::CreateVertexBuffer</unmanaged-short>	
 public VertexBuffer(Device device, int sizeInBytes, Usage usage, VertexFormat format, Pool pool)
     : base(IntPtr.Zero)
 {
     device.CreateVertexBuffer(sizeInBytes, usage, format, pool, this, IntPtr.Zero);
 }
Ejemplo n.º 54
0
 private static extern ulong NativeCreateVertexBuffer(VertexFormat vf, void* buffer, uint vertexCount);
Ejemplo n.º 55
0
        protected void PrepareVerticesSmooth(ref VertexFormat.VertexC1P3T4A1[] vertices, IDrawDevice device, float curAnimFrameFade, ColorRgba mainClr, Rect uvRect, Rect uvRectNext)
        {
            Vector3 posTemp = this.gameobj.Transform.Pos;
            float scaleTemp = 1.0f;
            device.PreprocessCoords(ref posTemp, ref scaleTemp);

            Vector2 xDot, yDot;
            MathF.GetTransformDotVec(this.GameObj.Transform.Angle, scaleTemp, out xDot, out yDot);

            Rect rectTemp = this.rect.Transform(this.gameobj.Transform.Scale, this.gameobj.Transform.Scale);
            Vector2 edge1 = rectTemp.TopLeft;
            Vector2 edge2 = rectTemp.BottomLeft;
            Vector2 edge3 = rectTemp.BottomRight;
            Vector2 edge4 = rectTemp.TopRight;

            MathF.TransformDotVec(ref edge1, ref xDot, ref yDot);
            MathF.TransformDotVec(ref edge2, ref xDot, ref yDot);
            MathF.TransformDotVec(ref edge3, ref xDot, ref yDot);
            MathF.TransformDotVec(ref edge4, ref xDot, ref yDot);

            if (vertices == null || vertices.Length != 4) vertices = new VertexFormat.VertexC1P3T4A1[4];

            vertices[0].Pos.X = posTemp.X + edge1.X;
            vertices[0].Pos.Y = posTemp.Y + edge1.Y;
            vertices[0].Pos.Z = posTemp.Z + this.VertexZOffset;
            vertices[0].TexCoord.X = uvRect.X;
            vertices[0].TexCoord.Y = uvRect.Y;
            vertices[0].TexCoord.Z = uvRectNext.X;
            vertices[0].TexCoord.W = uvRectNext.Y;
            vertices[0].Color = mainClr;
            vertices[0].Attrib = curAnimFrameFade;

            vertices[1].Pos.X = posTemp.X + edge2.X;
            vertices[1].Pos.Y = posTemp.Y + edge2.Y;
            vertices[1].Pos.Z = posTemp.Z + this.VertexZOffset;
            vertices[1].TexCoord.X = uvRect.X;
            vertices[1].TexCoord.Y = uvRect.MaximumY;
            vertices[1].TexCoord.Z = uvRectNext.X;
            vertices[1].TexCoord.W = uvRectNext.MaximumY;
            vertices[1].Color = mainClr;
            vertices[1].Attrib = curAnimFrameFade;

            vertices[2].Pos.X = posTemp.X + edge3.X;
            vertices[2].Pos.Y = posTemp.Y + edge3.Y;
            vertices[2].Pos.Z = posTemp.Z + this.VertexZOffset;
            vertices[2].TexCoord.X = uvRect.MaximumX;
            vertices[2].TexCoord.Y = uvRect.MaximumY;
            vertices[2].TexCoord.Z = uvRectNext.MaximumX;
            vertices[2].TexCoord.W = uvRectNext.MaximumY;
            vertices[2].Color = mainClr;
            vertices[2].Attrib = curAnimFrameFade;

            vertices[3].Pos.X = posTemp.X + edge4.X;
            vertices[3].Pos.Y = posTemp.Y + edge4.Y;
            vertices[3].Pos.Z = posTemp.Z + this.VertexZOffset;
            vertices[3].TexCoord.X = uvRect.MaximumX;
            vertices[3].TexCoord.Y = uvRect.Y;
            vertices[3].TexCoord.Z = uvRectNext.MaximumX;
            vertices[3].TexCoord.W = uvRectNext.Y;
            vertices[3].Color = mainClr;
            vertices[3].Attrib = curAnimFrameFade;

            if (this.pixelGrid)
            {
                vertices[0].Pos.X = MathF.Round(vertices[0].Pos.X);
                vertices[1].Pos.X = MathF.Round(vertices[1].Pos.X);
                vertices[2].Pos.X = MathF.Round(vertices[2].Pos.X);
                vertices[3].Pos.X = MathF.Round(vertices[3].Pos.X);

                if (MathF.RoundToInt(device.TargetSize.X) != (MathF.RoundToInt(device.TargetSize.X) / 2) * 2)
                {
                    vertices[0].Pos.X += 0.5f;
                    vertices[1].Pos.X += 0.5f;
                    vertices[2].Pos.X += 0.5f;
                    vertices[3].Pos.X += 0.5f;
                }

                vertices[0].Pos.Y = MathF.Round(vertices[0].Pos.Y);
                vertices[1].Pos.Y = MathF.Round(vertices[1].Pos.Y);
                vertices[2].Pos.Y = MathF.Round(vertices[2].Pos.Y);
                vertices[3].Pos.Y = MathF.Round(vertices[3].Pos.Y);

                if (MathF.RoundToInt(device.TargetSize.Y) != (MathF.RoundToInt(device.TargetSize.Y) / 2) * 2)
                {
                    vertices[0].Pos.Y += 0.5f;
                    vertices[1].Pos.Y += 0.5f;
                    vertices[2].Pos.Y += 0.5f;
                    vertices[3].Pos.Y += 0.5f;
                }
            }
        }
Ejemplo n.º 56
0
 /// <summary>
 /// Checks the flag against the vertex format.
 /// </summary>
 /// <param name="flag">The vertex format flag.</param>
 /// <returns>A value indicating if the flag is set.</returns>
 private bool CheckFlag(VertexFormat flag)
 {
     return (format & flag) == flag;
 }
Ejemplo n.º 57
0
        /// <summary>
        /// Loads the file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        public override void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR"));

            string identifier = reader.ReadNullTerminatedString();

            int version;

            if (string.Compare(identifier, FILE_IDENTIFIER_7, false) == 0) {
                version = 7;
            } else if (string.Compare(identifier, FILE_IDENTIFIER_8, false) == 0) {
                version = 8;
            } else {
                throw new FileIdentifierMismatchException(FilePath, string.Format("{0} / {1}", FILE_IDENTIFIER_7, FILE_IDENTIFIER_8), identifier);
            }

            format = (VertexFormat)reader.ReadInt32();
            BoundingBox = new Bounds(reader.ReadVector3(), reader.ReadVector3());

            short boneCount = reader.ReadInt16();

            for (int i = 0; i < boneCount; i++) {
                BoneTable.Add(reader.ReadInt16());
            }

            short vertexCount = reader.ReadInt16();

            for (int i = 0; i < vertexCount; i++) {
                ModelVertex vertex = new ModelVertex();
                vertex.Position = reader.ReadVector3();

                Vertices.Add(vertex);
            }

            if (NormalsEnabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.Normal = reader.ReadVector3();
                }
            }

            if (ColoursEnabled) {
                for (int i = 0; i < vertexCount; i++) {
                    float a = reader.ReadSingle();
                    ModelVertex vertex = Vertices[i];
                    vertex.Colour = new Color(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), a);
                }
            }

            if (BonesEnabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.BoneWeights = reader.ReadVector4();
                    vertex.BoneIndices = reader.ReadShortVector4();
                }
            }

            if (TangentsEnabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.Tangent = reader.ReadVector3();
                }
            }

            if (TextureCoordinates1Enabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.TextureCoordinates[0] = reader.ReadVector2();
                }
            }

            if (TextureCoordinates2Enabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.TextureCoordinates[1] = reader.ReadVector2();
                }
            }

            if (TextureCoordinates3Enabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.TextureCoordinates[2] = reader.ReadVector2();
                }
            }

            if (TextureCoordinates4Enabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.TextureCoordinates[3] = reader.ReadVector2();
                }
            }

            short indexCount = reader.ReadInt16();

            for (int i = 0; i < indexCount; i++) {
                Indices.Add(reader.ReadShortVector3());
            }

            short materialCount = reader.ReadInt16();

            for (int i = 0; i < materialCount; i++) {
                Materials.Add(reader.ReadInt16());
            }

            short stripCount = reader.ReadInt16();

            for (int i = 0; i < stripCount; i++) {
                Strips.Add(reader.ReadInt16());
            }

            if (version >= 8) {
                Pool = (PoolType)reader.ReadInt16();
            }
        }
Ejemplo n.º 58
0
        /// <summary>
        /// Resets properties to their default values.
        /// </summary>
        public override void Reset()
        {
            base.Reset();

            Pool = PoolType.Static;
            format = VertexFormat.Position | VertexFormat.TextureCoordinate1;

            Clear();
        }
Ejemplo n.º 59
0
        /// <summary>
        /// Enables the flag on the vertex format.
        /// </summary>
        /// <param name="flag">The vertex format flag.</param>
        /// <param name="enabled">if set to <c>true</c> the flag is set.</param>
        private void SetFlag(VertexFormat flag, bool enabled)
        {
            bool currentValue = CheckFlag(flag);

            if (enabled && !currentValue) {
                format = format | flag;
            } else if (!enabled && currentValue) {
                format = format ^ flag;
            }
        }
Ejemplo n.º 60
0
 /// <summary>
 /// Returns the size of a vertex for a flexible vertex format (FVF).
 /// </summary>
 /// <param name="fvf">The vertex format.</param>
 /// <returns>The FVF vertex size, in bytes.</returns>
 /// <unmanaged>unsigned int D3DXGetFVFVertexSize([In] D3DFVF FVF)</unmanaged>
 public static int GetFVFVertexSize(VertexFormat fvf)
 {
     return D3DX9.GetFVFVertexSize(fvf);
 }