Beispiel #1
0
        /// <summary>
        /// Sets the "native", "type" and "offset" attributes for all the vertex elements
        /// (texture, color, normal and position).
        /// Computes the stride.
        /// </summary>
        private void update()
        {
            stride = 0;

            // Weight
            IVertexInfoReader weightReader = getWeightReader(false);

            weightNative       = weightReader.Native;
            weightType         = weightReader.type();
            weightOffset       = 0;
            weightNumberValues = weightReader.numberValues();
            int weightSize = weightReader.size();

            stride += weightSize;

            // Texture
            IVertexInfoReader textureReader = getTextureReader(false);

            textureNative       = textureReader.Native;
            textureType         = textureReader.type();
            textureOffset       = (textureNative ? vertexInfo.textureOffset : stride);
            textureNumberValues = textureReader.numberValues();
            int textureSize = textureReader.size();

            stride += textureSize;

            // Color
            IVertexInfoReader colorReader = getColorReader(false);

            colorNative       = colorReader.Native;
            colorType         = colorReader.type();
            colorOffset       = (colorNative ? vertexInfo.colorOffset : stride);
            colorNumberValues = colorReader.numberValues();
            int colorSize = colorReader.size();

            stride += colorSize;

            // Normal
            IVertexInfoReader normalReader = getNormalReader(false);

            normalNative       = normalReader.Native;
            normalType         = normalReader.type();
            normalOffset       = (normalNative ? vertexInfo.normalOffset : stride);
            normalNumberValues = normalReader.numberValues();
            int normalSize = normalReader.size();

            stride += normalSize;

            // Position
            IVertexInfoReader positionReader = getPositionReader(false);

            positionNative       = positionReader.Native;
            positionType         = positionReader.type();
            positionOffset       = (positionNative ? vertexInfo.positionOffset : stride);
            positionNumberValues = positionReader.numberValues();
            int positionSize = positionReader.size();

            stride += positionSize;
        }
Beispiel #2
0
        /// <summary>
        /// Reads a sequence of VertexInfo structures.
        /// </summary>
        /// <param name="vertexInfo">		The VertexInfo prepared by the command list </param>
        /// <param name="address">			The start address of the structures </param>
        /// <param name="numberOfVertex">	The number of VertexInfo to read
        /// @return					A Buffer containing all the non-native VertexInfo
        ///							elements. The native elements are not included.
        ///							Returns "null" if all the elements are native. </param>
        public Buffer read(VertexInfo vertexInfo, int address, int firstVertex, int numberOfVertex, bool canAllNativeVertexInfo)
        {
            videoEngine                 = VideoEngine.Instance;
            this.vertexInfo             = vertexInfo;
            this.canAllNativeVertexInfo = canAllNativeVertexInfo;

            update();

            // Don't need to read the vertex data if all elements are native
            if (AllNative)
            {
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("Not reading Vertex, all native at 0x{0:X8}", address));
                }
                return(null);
            }

            // Display debug information on non-native elements
            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("Reading {0:D} Vertex at 0x{1:X8}", numberOfVertex, address + firstVertex * vertexInfo.vertexSize));
                if (!textureNative)
                {
                    Console.WriteLine("Texture non-native " + vertexInfo.ToString());
                }
                if (!colorNative)
                {
                    Console.WriteLine("Color non-native " + vertexInfo.ToString());
                }
                if (!normalNative)
                {
                    Console.WriteLine("Normal non-native " + vertexInfo.ToString());
                }
                if (!positionNative)
                {
                    Console.WriteLine("Position non-native " + vertexInfo.ToString());
                }
            }

            Address = address + firstVertex * vertexInfo.vertexSize;
            createVertexDataBuffer(numberOfVertex);

            // Prepare all the element readers
            IVertexInfoReader weightReader   = getWeightReader(weightNative);
            IVertexInfoReader textureReader  = getTextureReader(textureNative);
            IVertexInfoReader colorReader    = getColorReader(colorNative);
            IVertexInfoReader normalReader   = getNormalReader(normalNative);
            IVertexInfoReader positionReader = getPositionReader(positionNative);
            IVertexInfoReader padReader      = getPaddingReader(vertexInfo.alignmentSize);

            // Read all the VertexInfo in sequence
            for (int i = 0; i < numberOfVertex; i++)
            {
                weightReader.read();
                textureReader.read();
                colorReader.read();
                normalReader.read();
                positionReader.read();
                padReader.read();
            }

            return(vertexDataBuffer.Buffer);
        }