Beispiel #1
0
        private void BufferAttributeData(ICollection <GlobalGeometrySectionStructBlock> sectionData)
        {
            var firstPass = true;
            var index     = 0;

            MoonGL.VertexAttribArray(7, 7, 4, VertexAttribType.Float, false, 0, 1);
            MoonGL.VertexAttribArray(8, 7, 4, VertexAttribType.Float, false, 16, 1);
            MoonGL.VertexAttribArray(9, 7, 4, VertexAttribType.Float, false, 32, 1);
            MoonGL.VertexAttribArray(10, 7, 4, VertexAttribType.Float, false, 48, 1);

            foreach (var supportedFormat in SupportedVertexAttributes)
            {
                var bufferSize =
                    sectionData.SelectMany(e => e.VertexBuffers)
                    .Where(e => e.VertexBuffer.Type == supportedFormat)
                    .Sum(e => e.VertexBuffer.Data.Length);

                int attributeSize = supportedFormat.GetSize( );

                GL.BindBuffer(BufferTarget.ArrayBuffer, _attributeBuffers[supportedFormat]);
                GL.BufferData(BufferTarget.ArrayBuffer, ( IntPtr )bufferSize, ( IntPtr )null,
                              BufferUsageHint.StaticDraw);

                var offset       = 0;
                var vertexOffset = 0;
                foreach (var renderModelSectionDataBlock in sectionData)
                {
                    var vertexBuffer =
                        renderModelSectionDataBlock.VertexBuffers.Select(u => u.VertexBuffer)
                        .Single(e => e.Type == supportedFormat);

                    GL.BufferSubData(BufferTarget.ArrayBuffer, ( IntPtr )offset,
                                     ( IntPtr )vertexBuffer.Data.Length,
                                     vertexBuffer.Data);

                    if (firstPass)
                    {
                        foreach (var part in renderModelSectionDataBlock.Parts)
                        {
                            SetVertexOffset(part, vertexOffset);
                        }
                    }
                    vertexOffset += vertexBuffer.VertexElementCount;
                    offset       += vertexBuffer.Data.Length;
                }
                firstPass = false;
                GL.BindVertexBuffer(index, _attributeBuffers[supportedFormat], ( IntPtr )0, attributeSize);
                ConfigureVertexAttributeArray(supportedFormat, index);
                index++;
            }
        }
Beispiel #2
0
        /// <summary>
        ///     Calls glVertexAttribPointer to setup attributes for shaders and enables the vertex attribute array
        /// </summary>
        /// <param name="type">Type of attribute data</param>
        /// <param name="bindingIndex"></param>
        private static void ConfigureVertexAttributeArray(VertexAttributeType type, int bindingIndex)
        {
            switch (type)
            {
            case VertexAttributeType.UnpackedWorldCoordinateData:
                MoonGL.VertexAttribArray(0, bindingIndex, 3, VertexAttribType.Float);
                MoonGL.VertexAttribArray(1, bindingIndex, 4, VertexAttribType.Byte, false, 12);
                MoonGL.VertexAttribArray(2, bindingIndex, 4, VertexAttribType.Float, false, 16);
                break;

            case VertexAttributeType.UnpackedTextureCoordinateData:
                MoonGL.VertexAttribArray(3, bindingIndex, 2, VertexAttribType.Float);
                break;

            case VertexAttributeType.UnpackedLightingData:
                MoonGL.VertexAttribArray(4, bindingIndex, 3, VertexAttribType.Float);
                MoonGL.VertexAttribArray(5, bindingIndex, 3, VertexAttribType.Float, false, 12);
                MoonGL.VertexAttribArray(6, bindingIndex, 3, VertexAttribType.Float, false, 24);
                break;

            case VertexAttributeType.CoordinateFloat:
                MoonGL.VertexAttribArray(0, bindingIndex, 3, VertexAttribType.Float);
                break;

            case VertexAttributeType.TextureCoordinateFloat:
                MoonGL.VertexAttribArray(3, bindingIndex, 2, VertexAttribType.Float);
                break;

            case VertexAttributeType.LightmapUVCoordinateOneXbox:
                MoonGL.VertexAttribArray(11, bindingIndex, 2, VertexAttribType.Short, true);
                break;

            case VertexAttributeType.LightmapUVCoordinateTwoXbox:
                MoonGL.VertexAttribArray(12, bindingIndex, 2, VertexAttribType.Short, true);
                break;

            default:
                return;
            }
        }