Example #1
0
        internal BatchBuffer(Renderer.RenderSystem renderSystem, Renderer.VertexFormat vertexFormat = null, int initialTriangleCount = 128)
        {
            if (renderSystem == null)
                throw new ArgumentNullException("renderSystem");
            if (initialTriangleCount <= 0)
                throw new ArgumentException("invalid initialTriangleCount");

            RenderSystem = renderSystem;

            var dataCount = initialTriangleCount * (3 + 3 + 3 + 2); // vec3 pos, vec3 normal, vec3 tangent, vec2 texcoord
            VertexData = new float[dataCount];
            IndexData = new int[initialTriangleCount];

            if (vertexFormat != null)
            {
                VertexFormat = vertexFormat;
            }
            else
            {
                VertexFormat = new Renderer.VertexFormat(new Renderer.VertexFormatElement[]
                {
                    new Renderer.VertexFormatElement(Renderer.VertexFormatSemantic.Position, Renderer.VertexPointerType.Float, 3, 0),
                    new Renderer.VertexFormatElement(Renderer.VertexFormatSemantic.TexCoord, Renderer.VertexPointerType.Float, 2, sizeof(float) * 3),
                });
            }

            VertexBufferHandle = RenderSystem.CreateBuffer(Renderer.BufferTarget.ArrayBuffer, VertexFormat);
            IndexBufferHandle = RenderSystem.CreateBuffer(Renderer.BufferTarget.ElementArrayBuffer);

            RenderSystem.SetBufferData(VertexBufferHandle, new byte[0], true, true);
            RenderSystem.SetBufferData(IndexBufferHandle, new byte[0], true, true);

            MeshHandle = RenderSystem.CreateMesh(0, VertexBufferHandle, IndexBufferHandle, true);
        }