Microsoft.Xna.Framework.Graphics.GraphicsExtensions.OpenGLNumberOfElements C# (CSharp) Method

OpenGLNumberOfElements() public static method

public static OpenGLNumberOfElements ( this elementFormat ) : int
elementFormat this
return int
        public static int OpenGLNumberOfElements(this VertexElementFormat elementFormat)
        {
            switch (elementFormat)
            {
                case VertexElementFormat.Single:
                    return 1;

                case VertexElementFormat.Vector2:
                    return 2;

                case VertexElementFormat.Vector3:
                    return 3;

                case VertexElementFormat.Vector4:
                    return 4;

                case VertexElementFormat.Color:
                    return 4;

                case VertexElementFormat.Byte4:
                    return 4;

                case VertexElementFormat.Short2:
                    return 2;

                case VertexElementFormat.Short4:
                    return 2;

                case VertexElementFormat.NormalizedShort2:
                    return 2;

                case VertexElementFormat.NormalizedShort4:
                    return 4;

                case VertexElementFormat.HalfVector2:
                    return 2;

                case VertexElementFormat.HalfVector4:
                    return 4;
            }

            throw new ArgumentException();
        }

Usage Example

Example #1
0
        internal void Apply(Shader shader, IntPtr offset)
        {
            int hashCode = shader.GetHashCode();

            VertexDeclaration.VertexDeclarationAttributeInfo declarationAttributeInfo;
            if (!this.shaderAttributeInfo.TryGetValue(hashCode, out declarationAttributeInfo))
            {
                declarationAttributeInfo = new VertexDeclaration.VertexDeclarationAttributeInfo(this.GraphicsDevice.MaxVertexAttributes);
                foreach (VertexElement element in this._elements)
                {
                    int attribLocation = shader.GetAttribLocation(element.VertexElementUsage, element.UsageIndex);
                    if (attribLocation >= 0)
                    {
                        declarationAttributeInfo.Elements.Add(new VertexDeclaration.VertexDeclarationAttributeInfo.Element()
                        {
                            Offset                  = element.Offset,
                            AttributeLocation       = attribLocation,
                            NumberOfElements        = GraphicsExtensions.OpenGLNumberOfElements(element.VertexElementFormat),
                            VertexAttribPointerType = GraphicsExtensions.OpenGLVertexAttribPointerType(element.VertexElementFormat),
                            Normalized              = GraphicsExtensions.OpenGLVertexAttribNormalized(element)
                        });
                        declarationAttributeInfo.EnabledAttributes[attribLocation] = true;
                    }
                }
                this.shaderAttributeInfo.Add(hashCode, declarationAttributeInfo);
            }
            foreach (VertexDeclaration.VertexDeclarationAttributeInfo.Element element in declarationAttributeInfo.Elements)
            {
                GL.VertexAttribPointer(element.AttributeLocation, element.NumberOfElements, element.VertexAttribPointerType, element.Normalized, this.VertexStride, (IntPtr)(offset.ToInt64() + (long)element.Offset));
            }
            this.GraphicsDevice.SetVertexAttributeArray(declarationAttributeInfo.EnabledAttributes);
        }