Microsoft.Xna.Framework.Graphics.Shader.GetAttribLocation C# (CSharp) Метод

GetAttribLocation() приватный Метод

private GetAttribLocation ( VertexElementUsage usage, int index ) : int
usage VertexElementUsage
index int
Результат int
        internal int GetAttribLocation(VertexElementUsage usage, int index)
        {
            for (int i = 0; i < _attributes.Length; ++i)
            {
                if ((_attributes[i].usage == usage) && (_attributes[i].index == index))
                    return _attributes[i].location;
            }
            return -1;
        }

Usage Example

Пример #1
0
        internal void Apply(Shader shader, IntPtr offset, int divisor = 0)
        {
            List <Element> attrInfo;
            int            shaderHash = shader.GetHashCode();

            if (!shaderAttributeInfo.TryGetValue(shaderHash, out attrInfo))
            {
                // Get the vertex attribute info and cache it
                attrInfo = new List <Element>(16);                // 16, per XNA4 HiDef spec

                foreach (VertexElement ve in elements)
                {
                    int attributeLocation = shader.GetAttribLocation(ve.VertexElementUsage, ve.UsageIndex);

                    // XNA appears to ignore usages it can't find a match for, so we will do the same
                    if (attributeLocation >= 0)
                    {
                        attrInfo.Add(new Element()
                        {
                            Offset                  = ve.Offset,
                            AttributeLocation       = attributeLocation,
                            NumberOfElements        = GetNumberOfElements(ve.VertexElementFormat),
                            VertexAttribPointerType = ve.VertexElementFormat,
                            Normalized              = GetVertexAttribNormalized(ve),
                        });
                    }
                }

                shaderAttributeInfo.Add(shaderHash, attrInfo);
            }

            // Apply the vertex attribute info
            foreach (Element element in attrInfo)
            {
                GraphicsDevice.GLDevice.AttributeEnabled[element.AttributeLocation]   = true;
                GraphicsDevice.GLDevice.Attributes[element.AttributeLocation].Divisor = divisor;
                GraphicsDevice.GLDevice.VertexAttribPointer(
                    element.AttributeLocation,
                    element.NumberOfElements,
                    element.VertexAttribPointerType,
                    element.Normalized,
                    VertexStride,
#if JSIL
                    (IntPtr)(offset.ToInt32() + element.Offset)
#else
                    (IntPtr)(offset.ToInt64() + element.Offset)
#endif
                    );
            }
        }
All Usage Examples Of Microsoft.Xna.Framework.Graphics.Shader::GetAttribLocation