예제 #1
0
 public void ReplaceLines(int[] ids, IList <Vector2>[] vertexs)
 {
     for (int i = 0; i < ids.Length; i++)
     {
         Lines[ids[i]] = new VertexStream(vertexs[i], LineColors[ids[i]]);
     }
 }
예제 #2
0
        public void DeserializeExtraData(BinaryReader reader)
        {
            VertexElementCount = reader.ReadUInt32();
            uint vertexStreamCount = reader.ReadUInt32();

            IsStreaming = reader.ReadBooleanStrict();

            Streams = new VertexStream[vertexStreamCount];

            for (int i = 0; i < Streams.Length; i++)
            {
                var stream = new VertexStream();
                Streams[i] = stream;

                stream.Flags = reader.ReadUInt32();
                uint vertexByteStride = reader.ReadUInt32();
                stream.UnknownData = new byte[reader.ReadUInt32()][];

                for (uint j = 0; j < stream.UnknownData.Length; j++)
                {
                    // 4 bytes read separately
                    stream.UnknownData[j] = reader.ReadBytesStrict(4);
                }

                stream.GUID   = GGUUID.FromData(reader);
                stream.Buffer = HwBuffer.FromVertexData(reader, IsStreaming, vertexByteStride, VertexElementCount);
            }
        }
예제 #3
0
            public void                     Load(System.IO.BinaryReader _Reader)
            {
                // Retrieve the material parameters
                int MaterialID = _Reader.ReadInt32();

                m_Parameters = m_Parent.m_Owner.FindMaterialParameters(MaterialID);

                // Read faces & vertices count
                int FacesCount = _Reader.ReadInt32();

                m_VerticesCount = _Reader.ReadInt32();

                // Read faces
                m_Faces = new Face[FacesCount];
                for (int FaceIndex = 0; FaceIndex < FacesCount; FaceIndex++)
                {
                    m_Faces[FaceIndex].Load(_Reader);
                }

                // Read vertex streams
                ClearVertexStreams();
                int StreamsCount = _Reader.ReadInt32();

                for (int StreamIndex = 0; StreamIndex < StreamsCount; StreamIndex++)
                {
                    VertexStream Stream = new VertexStream(_Reader);
                    m_Streams.Add(Stream);
                }
            }
예제 #4
0
            public VertexStream     AddVertexStream(VertexStream.USAGE _Usage, VertexStream.FIELD_TYPE _FieldType, int _StreamIndex, object _Content)
            {
                VertexStream Result = new VertexStream(_Usage, _FieldType, _StreamIndex, _Content);

                m_Streams.Add(Result);

                return(Result);
            }
        public void Item()
        {
            VertexStream vs   = vsc[10];
            VertexStream temp = vsc[30]; //here we made it increase size
            VertexStream vs2  = vsc[10]; //check if we get back the same obj

            Assert.AreEqual(vs, vs2, "#1");
        }
예제 #6
0
        private VertexStream Read_VertexStream(BinaryReader reader)
        {
            var result = new VertexStream();

            result.Version = ReadVersion(reader, 1, 0x1411E4EF0);

            result.Type = Read_GeometryType(reader);
            result.Data = Read_Array(reader);

            return(result);
        }
예제 #7
0
            public static VertexStream LoadFromStream(Stream stream, Int32 vertexCount, Int32 bytesPerVertex)
            {
                VertexStream vertexStream = new VertexStream();

                vertexStream.BytesPerVertex = bytesPerVertex;

                BinaryReader binaryReader = new BinaryReader(stream);

                vertexStream.Data = binaryReader.ReadBytes(vertexCount * bytesPerVertex);

                return(vertexStream);
            }
예제 #8
0
    /// <summary>
    /// Gets the VertexStream component from the specified GameObject.
    /// </summary>
    /// <param name="gameObject">The GameObject.</param>
    /// <returns></returns>
    public static VertexStream GetComponent(GameObject gameObject)
    {
        VertexStream vertexStream = gameObject.GetComponent <VertexStream> ();

        if (vertexStream == null)
        {
            vertexStream           = gameObject.AddComponent <VertexStream> ();
            vertexStream.hideFlags = HideFlags.HideInInspector;
            vertexStream.CreateNewMesh();
        }

        return(vertexStream);
    }
예제 #9
0
파일: Mesh.cs 프로젝트: dak0ta101/ps2ls
        public static Mesh LoadFromStream(Model model, Stream stream)
        {
            BinaryReader binaryReader      = new BinaryReader(stream);
            uint         bytesPerVertex    = 0;
            uint         vertexStreamCount = 0;

            Mesh mesh = new Mesh(model);

            mesh.MaterialIndex = binaryReader.ReadUInt32();
            mesh.Unknown1      = binaryReader.ReadUInt32();
            mesh.Unknown2      = binaryReader.ReadUInt32();
            mesh.Unknown3      = binaryReader.ReadUInt32();
            vertexStreamCount  = binaryReader.ReadUInt32();
            mesh.IndexSize     = binaryReader.ReadUInt32();
            mesh.IndexCount    = binaryReader.ReadUInt32();
            mesh.VertexCount   = binaryReader.ReadUInt32();

            mesh.VertexStreams = new VertexStream[(int)vertexStreamCount];

            // read vertex streams
            for (int j = 0; j < vertexStreamCount; ++j)
            {
                bytesPerVertex = binaryReader.ReadUInt32();

                byte[]       buffer       = binaryReader.ReadBytes((int)mesh.VertexCount * (int)bytesPerVertex);
                VertexStream vertexStream = new VertexStream((int)bytesPerVertex, buffer);

                if (vertexStream != null)
                {
                    mesh.VertexStreams[j] = vertexStream;
                }
            }

            // read indices
            mesh.IndexData = binaryReader.ReadBytes((int)mesh.IndexCount * (int)mesh.IndexSize);

            uint materialDefinitionHash = model.Materials[(int)mesh.MaterialIndex].MaterialDefinitionHash;

            MaterialDefinition materialDefinition = null;

            MaterialDefinitionLibrary.Instance.MaterialDefinitions.TryGetValue(materialDefinitionHash, out materialDefinition);

            string effectName = materialDefinition.DrawStyles[0].Effect;

            return(mesh);
        }
        public static HwVertexArray FromData(BinaryReader reader, GameType gameType)
        {
            var x = new HwVertexArray();

            x.VertexCount = reader.ReadUInt32();
            uint streamCount = reader.ReadUInt32();

            x.IsStreaming = reader.ReadBooleanStrict();

            x.Streams = new List <VertexStream>((int)streamCount);

            for (uint i = 0; i < streamCount; i++)
            {
                uint flags            = reader.ReadUInt32();
                uint byteStride       = reader.ReadUInt32();
                uint elementDescCount = reader.ReadUInt32();

                var stream = new VertexStream();
                stream.Flags       = flags;
                stream.ElementInfo = new List <VertexElementDesc>((int)elementDescCount);

                for (uint j = 0; j < elementDescCount; j++)
                {
                    stream.ElementInfo.Add(new VertexElementDesc()
                    {
                        ByteOffset     = reader.ReadByte(),
                        StorageType    = (BaseVertexElementStorageType)reader.ReadByte(),
                        ComponentCount = reader.ReadByte(),
                        ElementType    = (BaseVertexElement)reader.ReadByte(),
                    });
                }

                stream.GUID   = new BaseGGUUID().FromData(reader);
                stream.Buffer = HwBuffer.FromVertexData(reader, gameType, x.IsStreaming, byteStride, x.VertexCount);

                x.Streams.Add(stream);
            }

            return(x);
        }
예제 #11
0
        public static HwVertexArray FromData(BinaryReader reader, GameType gameType)
        {
            var array = new HwVertexArray();

            array.VertexCount = reader.ReadUInt32();
            uint streamCount = reader.ReadUInt32();

            array.StreamingMode = (BaseRenderDataStreamingMode)reader.ReadByte();

            array.Streams = new List <VertexStream>((int)streamCount);

            for (uint i = 0; i < streamCount; i++)
            {
                uint flags            = reader.ReadUInt32();
                uint byteStride       = reader.ReadUInt32();
                uint elementDescCount = reader.ReadUInt32();

                var stream = new VertexStream();
                stream.Flags       = flags;
                stream.ElementInfo = new List <VertexElementDesc>((int)elementDescCount);

                for (uint j = 0; j < elementDescCount; j++)
                {
                    stream.ElementInfo.Add(new VertexElementDesc()
                    {
                        ByteOffset     = reader.ReadByte(),
                        StorageType    = (BaseVertexElementStorageType)reader.ReadByte(),
                        ComponentCount = reader.ReadByte(),
                        ElementType    = (BaseVertexElement)reader.ReadByte(),
                    });
                }

                stream.ResourceDataHash = BaseGGUUID.FromData(reader);
                stream.Buffer           = HwBuffer.FromVertexData(reader, gameType, array.StreamingMode, byteStride, array.VertexCount);

                array.Streams.Add(stream);
            }

            return(array);
        }
예제 #12
0
        public static Mesh LoadFromStream(Stream stream, ICollection <Dma.Material> materials)
        {
            BinaryReader binaryReader = new BinaryReader(stream);

            Mesh mesh = new Mesh();

            UInt32 bytesPerVertex    = 0;
            UInt32 vertexStreamCount = 0;

            mesh.MaterialIndex = binaryReader.ReadUInt32();
            mesh.Unknown1      = binaryReader.ReadUInt32();
            mesh.Unknown2      = binaryReader.ReadUInt32();
            mesh.Unknown3      = binaryReader.ReadUInt32();
            vertexStreamCount  = binaryReader.ReadUInt32();
            mesh.IndexSize     = binaryReader.ReadUInt32();
            mesh.IndexCount    = binaryReader.ReadUInt32();
            mesh.VertexCount   = binaryReader.ReadUInt32();

            mesh.VertexStreams = new VertexStream[(Int32)vertexStreamCount];

            // read vertex streams
            for (Int32 j = 0; j < vertexStreamCount; ++j)
            {
                bytesPerVertex = binaryReader.ReadUInt32();

                VertexStream vertexStream = VertexStream.LoadFromStream(binaryReader.BaseStream, (Int32)mesh.VertexCount, (Int32)bytesPerVertex);

                if (vertexStream != null)
                {
                    mesh.VertexStreams[j] = vertexStream;
                }
            }

            // read indices
            mesh.IndexData = binaryReader.ReadBytes((Int32)mesh.IndexCount * (Int32)mesh.IndexSize);

            return(mesh);
        }
예제 #13
0
        private void InitGraphics()
        {
            var io = ImGui.GetIO();

            io.DisplaySize = new System.Numerics.Vector2(Engine.Canvas.Width, Engine.Canvas.Height);

            m_imgui_program     = Engine.Content.Get <ShaderProgram>("imgui_shader");
            m_imgui_tex_program = Engine.Content.Get <ShaderProgram>("imgui_shader_image");

            m_vertex_layout = new VertexLayout();
            m_vertex_layout.Begin();
            m_vertex_layout.Add(Attrib.Position, AttribType.Float, 2, false, false);
            m_vertex_layout.Add(Attrib.TexCoord0, AttribType.Float, 2, false, false);
            m_vertex_layout.Add(Attrib.Color0, AttribType.Uint8, 4, true, false);
            m_vertex_layout.End();

            m_fonts.Add("default", io.Fonts.AddFontDefault());

            unsafe
            {
                io.Fonts.GetTexDataAsRGBA32(out IntPtr data, out var width, out var height, out var bytes_per_pixel);

                m_font_atlas = Texture2D.Create(data, width, height, bytes_per_pixel);

                m_textures.Add((IntPtr)m_font_atlas.GetHashCode(), m_font_atlas);
            }

            m_font_atlas_tex_id = (IntPtr)m_font_atlas.GetHashCode();

            io.Fonts.SetTexID(m_font_atlas_tex_id);

            m_canvas_view = Engine.Canvas.CreateView(Color.Transparent);

            m_vertex_stream = new VertexStream(VertexStreamMode.Stream);

            m_vertex_stream.SetVertexLayout(m_vertex_layout);
        }
        public static Mesh LoadFromStream(Stream stream, ICollection <Material> materials)
        {
            BinaryReader binaryReader = new BinaryReader(stream);

            Mesh mesh = new Mesh();

            mesh.MaterialIndex = binaryReader.ReadUInt32();
            mesh.Unknown1      = binaryReader.ReadUInt32();
            mesh.Unknown2      = binaryReader.ReadUInt32();
            mesh.Unknown3      = binaryReader.ReadUInt32();
            uint vertexStreamCount = binaryReader.ReadUInt32();

            mesh.IndexSize   = binaryReader.ReadUInt32();
            mesh.IndexCount  = binaryReader.ReadUInt32();
            mesh.VertexCount = binaryReader.ReadUInt32();

            mesh.VertexStreams = new VertexStream[(int)vertexStreamCount];

            // read vertex streams
            for (int j = 0; j < vertexStreamCount; ++j)
            {
                uint bytesPerVertex = binaryReader.ReadUInt32();

                VertexStream vertexStream = new VertexStream();

                vertexStream.BytesPerVertex = (int)bytesPerVertex;
                vertexStream.Data           = binaryReader.ReadBytes((int)(mesh.VertexCount * bytesPerVertex));

                mesh.VertexStreams[j] = vertexStream;
            }

            // read indices
            mesh.IndexData = binaryReader.ReadBytes((int)mesh.IndexCount * (int)mesh.IndexSize);

            return(mesh);
        }
예제 #15
0
파일: Mesh.cs 프로젝트: SlyvanGames/ps2ls
        public static Mesh LoadFromStream(Model model, Stream stream)
        {
            BinaryReader binaryReader = new BinaryReader(stream);
            uint bytesPerVertex = 0;
            uint vertexStreamCount = 0;

            Mesh mesh = new Mesh(model);
            mesh.MaterialIndex = binaryReader.ReadUInt32();
            mesh.Unknown1 = binaryReader.ReadUInt32();
            mesh.Unknown2 = binaryReader.ReadUInt32();
            mesh.Unknown3 = binaryReader.ReadUInt32();
            vertexStreamCount = binaryReader.ReadUInt32();
            mesh.IndexSize = binaryReader.ReadUInt32();
            mesh.IndexCount = binaryReader.ReadUInt32();
            mesh.VertexCount = binaryReader.ReadUInt32();

            mesh.VertexStreams = new VertexStream[(int)vertexStreamCount];

            // read vertex streams
            for (int j = 0; j < vertexStreamCount; ++j)
            {
                bytesPerVertex = binaryReader.ReadUInt32();

                byte[] buffer = binaryReader.ReadBytes((int)mesh.VertexCount * (int)bytesPerVertex);
                VertexStream vertexStream = new VertexStream((int)bytesPerVertex, buffer);

                if (vertexStream != null)
                {
                    mesh.VertexStreams[j] = vertexStream;
                }
            }

            // read indices
            mesh.IndexData = binaryReader.ReadBytes((int)mesh.IndexCount * (int)mesh.IndexSize);

            uint materialDefinitionHash = model.Materials[(int)mesh.MaterialIndex].MaterialDefinitionHash;

            MaterialDefinition materialDefinition = null;

            MaterialDefinitionLibrary.Instance.MaterialDefinitions.TryGetValue(materialDefinitionHash, out materialDefinition);

            string effectName = materialDefinition.DrawStyles[0].Effect;

            return mesh;
        }
예제 #16
0
        private void ReadChunks(long totalSize)
        {
            var runTo = Reader.BaseStream.Position + totalSize;

            for (var i = 0; i < 0xFFFF && Reader.BaseStream.Position < runTo; i++)
            {
                var chunkId   = Reader.ReadUInt32();
                var chunkSize = Reader.ReadUInt32();

                BinaryUtil.ApplyPadding(Reader, ref chunkSize);

                Console.WriteLine($"\tID: 0x{chunkId:X8} size: {chunkSize}");
                var chunkRunTo = Reader.BaseStream.Position + chunkSize;

                switch (chunkId)
                {
                case 0x00134011:
                {
                    _header = BinaryUtil.ReadStruct <ObjectHeader>(Reader);

                    //Console.WriteLine($"object 0x{_header.ObjectHash:X8} @ ({_header.Matrix.Data[12]}, {_header.Matrix.Data[13]}, {_header.Matrix.Data[14]})");
                    _name = BinaryUtil.ReadNullTerminatedString(Reader);
                    //Console.WriteLine(_name);

                    break;
                }

                case 0x80134100:     // mesh header
                {
                    ReadChunks(chunkSize);
                    break;
                }

                case 0x00134900:
                {
                    var msd = BinaryUtil.ReadStruct <MeshDescriptor>(Reader);

                    //Console.WriteLine(@"MESH INFO:");
                    //Console.WriteLine($"\tFlags -> 0x{msd.Flags:X8}");
                    //Console.WriteLine($"\tMSN -> {msd.MaterialShaderNum}");
                    //Console.WriteLine($"\tNVS -> {msd.NumVertexStreams}");
                    //Console.WriteLine($"\tNT -> {msd.NumTriangles}");
                    //Console.WriteLine($"\tNTI -> {msd.NumTriIndex}");

                    _meshDescriptor = msd;

                    break;
                }

                case 0x00134012:
                {
                    for (var j = 0; j < chunkSize / 8; j++)
                    {
                        var texHash = Reader.ReadUInt32();

                        //Console.WriteLine($"TEXTURE ID: 0x{texHash:X8}");

                        Reader.BaseStream.Position += 4;
                    }

                    break;
                }

                case 0x00134C02:
                {
                    //Console.WriteLine($"MAT NAME: {BinaryUtil.ReadNullTerminatedString(Reader)}");
                    break;
                }

                case 0x00134B02:
                {
                    Debug.Assert(chunkSize % _meshDescriptor.MaterialShaderNum == 0);

                    for (var j = 0; j < _meshDescriptor.MaterialShaderNum; ++j)
                    {
                        //Console.WriteLine($"MATERIAL INFO #{j + 1}");
                        var material = BinaryUtil.ReadStruct <Material>(Reader, 116);
                        //Console.WriteLine($"\tFlags -> 0x{material.Flags:X8}");
                        //Console.WriteLine($"\tHash  -> 0x{material.ID:X8}");
                    }

                    break;
                }

                case 0x00134b01:
                {
                    if (_meshDescriptor.NumVertexStreams != 1)
                    {
                        break;
                    }

                    var vs = new VertexStream();

                    while (Reader.BaseStream.Position < chunkRunTo)
                    {
                        vs.Data.Add(Reader.ReadSingle());
                        vs.Position += 4;
                    }

                    vs.Interval = chunkSize / _maxVertex / 4;

                    _vertexStreams.Add(vs);

                    break;
                }

                case 0x00134b03:     // faces
                {
                    for (var j = 0; j < _header.NumTris; j++)
                    {
                        var f1 = (ushort)(Reader.ReadUInt16() + 1);
                        var f2 = (ushort)(Reader.ReadUInt16() + 1);
                        var f3 = (ushort)(Reader.ReadUInt16() + 1);

                        if (f1 > _maxVertex)
                        {
                            _maxVertex = f1;
                        }

                        if (f2 > _maxVertex)
                        {
                            _maxVertex = f2;
                        }

                        if (f3 > _maxVertex)
                        {
                            _maxVertex = f3;
                        }

                        _faces.Add(new[] { f1, f2, f3 });
                    }

                    break;
                }
                }

                Reader.BaseStream.Seek(chunkRunTo, SeekOrigin.Begin);
            }
        }
예제 #17
0
        /// <summary>
        /// Draw the vertices group as primitives, using an optional index buffer (indices) and a <see cref="StreamFrequency"/> object to specify Hardware Instancing information (Shader Model 3 and Windows Only)
        /// </summary>
        /// <param name="state"></param>
        /// <param name="indices">(optional) indices to use during drawing</param>
        /// <param name="primitiveType">Primitive type to draw, eg PrimitiveType.TriangleList</param>
        /// <param name="frequency">(optional) <see cref="StreamFrequency"/> setting the shader model 3 instance frequency data (used for hardware instancing)</param>
        /// <param name="primitveCount">The number of primitives to draw</param>
        /// <param name="startIndex">The start index in the index buffer (defaults to the first index - 0)</param>
        /// <param name="vertexOffset">Starting offset into the vertex buffer (defaults to the first vertex - 0)</param>
        /// <remarks></remarks>
        public void Draw(DrawState state, IIndices indices, PrimitiveType primitiveType, StreamFrequency frequency, int primitveCount, int startIndex, int vertexOffset)
        {
            if (frequency != null && !state.SupportsHardwareInstancing)
            {
                throw new InvalidOperationException("Only windows devices supporting Shader Model 3.0 or better to can use hardware instancing. Check DrawState.SupportsHardwareInstancing");
            }

#if XBOX360
            if (frequency != null)
            {
#if DEBUG
                if (frequency.layout != StreamFrequency.DataLayout.Stream0Geometry_Stream1InstanceData)
                {
                    throw new InvalidOperationException("Only StreamFrequency DataLayout of Stream0Geometry_Stream1InstanceData is emulated on the xbox360");
                }

                if (primitveCount != int.MaxValue ||
                    startIndex != 0 || vertexOffset != 0)
                {
                    throw new ArgumentException("Only default values for primitiveCount, startIndex and vertexOffset may be used when emulating instancing on the xbox");
                }
                if (primitiveType == PrimitiveType.TriangleFan ||
                    primitiveType == PrimitiveType.TriangleStrip ||
                    primitiveType == PrimitiveType.LineStrip)
                {
                    throw new ArgumentException("Only Primitive List Types (eg TriangleList) are supported as a primitiveType when emulating instancing on the xbox");
                }
#endif
                if (indices != null)
                {
                    ((IDeviceIndexBuffer)indices).AllocateForInstancing(state);
                }
            }
#endif

            GraphicsDevice device = state.graphics;

            IDeviceIndexBuffer devib = indices as IDeviceIndexBuffer;
            IndexBuffer        ib    = null;
            if (devib != null)
            {
                ib = devib.GetIndexBuffer(state);
            }

            if (decl == null)
            {
                decl = ((IDeviceVertexBuffer)this).GetVertexDeclaration(state.Application);
            }

            state.VertexDeclaration = decl;

#if DEBUG
            state.ValidateVertexDeclarationForShader(decl, null);
#endif

            int vertices = 0;
            for (int i = 0; i < buffers.Length; i++)
            {
                IDeviceVertexBuffer dev = buffers[i] as IDeviceVertexBuffer;
                if (dev != null)
                {
                    state.SetStream(i, dev.GetVertexBuffer(state), offsets[i], buffers[i].Stride);
                }
                else
                {
                    state.SetStream(i, null, 0, 0);
                }

                if (i == 0)
                {
                    vertices = buffers[i].Count;
                }
                else
                if (frequency == null)
                {
                    vertices = Math.Min(buffers[i].Count, vertices);
                }
            }


            state.IndexBuffer = ib;

            if (ib != null)
            {
                vertices = indices.Count;
            }

            int primitives = 0;
            switch (primitiveType)
            {
            case PrimitiveType.LineList:
                primitives = vertices / 2;
                break;

            case PrimitiveType.LineStrip:
                primitives = vertices - 1;
                break;

            case PrimitiveType.PointList:
                primitives = vertices;
                break;

            case PrimitiveType.TriangleList:
                primitives = vertices / 3;
                break;

            case PrimitiveType.TriangleFan:
            case PrimitiveType.TriangleStrip:
                primitives = vertices - 2;
                break;
            }


            int vertexCount = 0;
            if (indices != null)
            {
                vertexCount = indices.MaxIndex + 1;
            }
            else
            {
                switch (primitiveType)
                {
                case PrimitiveType.LineStrip:
                    vertexCount = primitives * 2;
                    break;

                case PrimitiveType.PointList:
                case PrimitiveType.LineList:
                case PrimitiveType.TriangleList:
                    vertexCount = vertices;
                    break;

                case PrimitiveType.TriangleFan:
                case PrimitiveType.TriangleStrip:
                    vertexCount = primitives * 3;
                    break;
                }
            }

            state.ApplyRenderStateChanges(vertexCount);

#if DEBUG
            int instances = 1;
#endif

#if !XBOX360
            if (frequency != null && frequency.frequency.Length >= this.buffers.Length)
            {
#if DEBUG
                if (frequency.indexFrequency.Length > 0)
                {
                    System.Threading.Interlocked.Increment(ref state.Application.currentFrame.InstancesDrawBatchCount);
                    state.Application.currentFrame.InstancesDrawn += frequency.indexFrequency[0];
                    instances = frequency.indexFrequency[0];
                }
#endif

                for (int i = 0; i < this.buffers.Length; i++)
                {
                    VertexStream vs = device.Vertices[i];
                    if (frequency.frequency[i] != 0)
                    {
                        vs.SetFrequency(frequency.frequency[i]);
                    }
                    if (frequency.indexFrequency[i] != 0)
                    {
                        vs.SetFrequencyOfIndexData(frequency.indexFrequency[i]);
                    }
                    if (frequency.dataFrequency[i] != 0)
                    {
                        vs.SetFrequencyOfInstanceData(frequency.dataFrequency[i]);
                    }
                }
            }
#endif

            if (primitveCount != int.MaxValue)
            {
                if (primitveCount > primitives ||
                    primitveCount <= 0)
                {
                    throw new ArgumentException("primitiveCount");
                }
            }
            else
            {
                primitveCount = primitives;
            }

#if DEBUG
            state.CalcBoundTextures();
#endif

            //it is possible to have the debug runtime throw an exception here when using instancing,
            //as it thinks stream1 doesn't have enough data.
            //This is most common with sprite groups (however sprite groups will use shader-instancing with small groups)
            //eg, drawing a single instance requires only 64bytes in stream1, yet the triangle count could be very large
            //this makes the debug runtime think that stream1 doesn't have enough data
            if (ib != null)
            {
#if DEBUG
                System.Threading.Interlocked.Increment(ref state.Application.currentFrame.DrawIndexedPrimitiveCallCount);
#endif
#if XBOX360
                if (frequency != null)
                {
                    int repeats = frequency.RepeatCount;
#if DEBUG
                    System.Threading.Interlocked.Increment(ref state.Application.currentFrame.InstancesDrawBatchCount);
                    state.Application.currentFrame.InstancesDrawn += frequency.indexFrequency[0];
                    instances = repeats;
#endif
                    int          maxInstances = ((IDeviceIndexBuffer)indices).MaxInstances;
                    int          offset       = 0;
                    VertexBuffer vb           = ((IDeviceVertexBuffer)buffers[1]).GetVertexBuffer(state);

                    while (repeats - offset > 0)
                    {
                        if (offset != 0)
                        {
                            //read the next set of instances
                            state.SetStream(1, vb, offsets[1] + 64 * offset, buffers[1].Stride);
                        }

                        int count = Math.Min(repeats - offset, maxInstances);
                        device.DrawIndexedPrimitives(primitiveType, vertexOffset, indices.MinIndex, ((indices.MaxIndex) + 1) - indices.MinIndex - vertexOffset, startIndex, primitveCount * count);

                        offset += count;
                    }
                }
                else
#endif
                device.DrawIndexedPrimitives(primitiveType, vertexOffset, indices.MinIndex, (indices.MaxIndex - indices.MinIndex) + 1 - vertexOffset, startIndex, primitveCount);
            }
            else
            {
#if DEBUG
                System.Threading.Interlocked.Increment(ref state.Application.currentFrame.DrawPrimitivesCallCount);
#endif
#if XBOX360
                if (frequency != null)
                {
                    int          repeats      = frequency.RepeatCount;
                    int          maxInstances = ((IDeviceIndexBuffer)indices).MaxInstances;
                    int          offset       = 0;
                    VertexBuffer vb           = ((IDeviceVertexBuffer)buffers[1]).GetVertexBuffer(state);

                    while (repeats - offset > 0)
                    {
                        if (offset != 0)
                        {
                            //read the next set of instances
                            state.SetStream(1, vb, offsets[1] + 64 * offset, buffers[1].Stride);
                        }

                        int count = Math.Min(repeats - offset, maxInstances);
                        device.DrawPrimitives(primitiveType, vertexOffset, primitveCount * count);

                        offset += count;
                    }
                }
                else
#endif
                device.DrawPrimitives(primitiveType, vertexOffset, primitveCount);
            }


#if DEBUG
            switch (primitiveType)
            {
            case PrimitiveType.LineList:
            case PrimitiveType.LineStrip:
                state.Application.currentFrame.LinesDrawn += primitives * instances;
                break;

            case PrimitiveType.PointList:
                state.Application.currentFrame.PointsDrawn += primitives * instances;
                break;

            case PrimitiveType.TriangleList:
            case PrimitiveType.TriangleFan:
            case PrimitiveType.TriangleStrip:
                state.Application.currentFrame.TrianglesDrawn += primitives * instances;
                break;
            }
#endif

#if !XBOX360
            if (frequency != null && frequency.frequency.Length >= this.buffers.Length)
            {
                device.Vertices[0].SetFrequency(1);
            }
#endif

            for (int i = 0; i < buffers.Length; i++)
            {
                if (i > 0)
                {
                    state.SetStream(i, null, 0, 0);
                }
            }
        }
예제 #18
0
파일: Mesh.cs 프로젝트: Patapom/GodComplex
            public void Load( System.IO.BinaryReader _Reader )
            {
                // Retrieve the material parameters
                int	MaterialID = _Reader.ReadInt32();
                m_Parameters = m_Parent.m_Owner.FindMaterialParameters( MaterialID );

                // Read faces & vertices count
                int	FacesCount = _Reader.ReadInt32();
                m_VerticesCount = _Reader.ReadInt32();

                // Read faces
                m_Faces = new Face[FacesCount];
                for ( int FaceIndex=0; FaceIndex < FacesCount; FaceIndex++ )
                    m_Faces[FaceIndex].Load( _Reader );

                // Read vertex streams
                ClearVertexStreams();
                int	StreamsCount = _Reader.ReadInt32();
                for ( int StreamIndex=0; StreamIndex < StreamsCount; StreamIndex++ )
                {
                    VertexStream	Stream = new VertexStream( _Reader );
                    m_Streams.Add( Stream );
                }
            }
예제 #19
0
파일: Mesh.cs 프로젝트: Patapom/GodComplex
            public VertexStream[] FindStreamsByUsage( VertexStream.USAGE _Usage )
            {
                List<VertexStream>	Result = new List<VertexStream>();
                foreach ( VertexStream VS in m_Streams )
                    if ( VS.Usage == _Usage )
                        Result.Add( VS );

                return Result.ToArray();
            }
예제 #20
0
파일: Mesh.cs 프로젝트: Patapom/GodComplex
            public VertexStream AddVertexStream( VertexStream.USAGE _Usage, VertexStream.FIELD_TYPE _FieldType, int _StreamIndex, object _Content )
            {
                VertexStream	Result = new VertexStream( _Usage, _FieldType, _StreamIndex, _Content );
                m_Streams.Add( Result );

                return Result;
            }
예제 #21
0
파일: Mesh.cs 프로젝트: psemu/ps2ls
            public static VertexStream LoadFromStream(Stream stream, Int32 vertexCount, Int32 bytesPerVertex)
            {
                VertexStream vertexStream = new VertexStream();

                vertexStream.BytesPerVertex = bytesPerVertex;

                BinaryReader binaryReader = new BinaryReader(stream);

                vertexStream.Data = binaryReader.ReadBytes(vertexCount * bytesPerVertex);

                return vertexStream;
            }