Ejemplo n.º 1
0
        private static void initBuffers()
        {
            triangleVertexPositionBuffer        = new PositionBuffer();
            triangleVertexPositionBuffer.Buffer = gl.CreateBuffer();
            gl.BindBuffer(gl.ArrayBuffer, triangleVertexPositionBuffer.Buffer);
            var vertices = new [] {
                0.0, 1.0, 0.0,
                -1.0, -1.0, 0.0,
                1.0, -1.0, 0.0
            };

            gl.BufferData(gl.ArrayBuffer, Float32Array.Create(vertices), gl.StaticDraw);
            triangleVertexPositionBuffer.ItemSize = 3;
            triangleVertexPositionBuffer.NumItems = 3;

            squareVertexPositionBuffer        = new PositionBuffer();
            squareVertexPositionBuffer.Buffer = gl.CreateBuffer();
            gl.BindBuffer(gl.ArrayBuffer, squareVertexPositionBuffer.Buffer);
            vertices = new [] {
                1.0, 1.0, 0.0,
                -1.0, 1.0, 0.0,
                1.0, -1.0, 0.0,
                -1.0, -1.0, 0.0
            };
            gl.BufferData(gl.ArrayBuffer, Float32Array.Create(vertices), gl.StaticDraw);
            squareVertexPositionBuffer.ItemSize = 3;
            squareVertexPositionBuffer.NumItems = 4;
        }
Ejemplo n.º 2
0
        protected override void OnAfterRender()
        {
            WebGLContext context = this.canvasReference.CreateWebGL(new WebGLContextAttributes
            {
                PowerPreference = WebGLContextAttributes.POWER_PREFERENCE_HIGH_PERFORMANCE
            });

            context.ClearColor(0, 0, 0, 1);
            context.Clear(BufferBits.COLOR_BUFFER_BIT);

            var program = this.InitProgram(context, VS_SOURCE, FS_SOURCE);

            var vertexBuffer = context.CreateBuffer();

            context.BindBuffer(BufferType.ARRAY_BUFFER, vertexBuffer);

            var vertices = new[]
            {
                -0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f,
                0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f,
                0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f
            };

            context.BufferData(BufferType.ARRAY_BUFFER, vertices, BufferUsageHint.STATIC_DRAW);

            context.VertexAttribPointer(0, 3, DataType.FLOAT, false, 6 * sizeof(float), 0);
            context.VertexAttribPointer(1, 3, DataType.FLOAT, false, 6 * sizeof(float), 3 * sizeof(float));
            context.EnableVertexAttribArray(0);
            context.EnableVertexAttribArray(1);

            context.UseProgram(program);

            context.DrawArrays(Primitive.TRIANGLES, 0, 3);
        }
Ejemplo n.º 3
0
        public RenderBatch(WebGLContext context, int elementCount)
        {
            this.context    = context;
            this.descriptor = new TDescriptor();
            itemPool        = new DefaultVertexFormat[elementCount * descriptor.ElementVertexCount];

            modelBuffer = context.CreateBuffer(BufferType.ARRAY_BUFFER, BufferUsage.STREAM_DRAW);
            modelBuffer.Bind();
            modelBuffer.SetDataSize(itemPool.Length * descriptor.ByteSize);

            System.Console.WriteLine("Buffer size: " + itemPool.Length * descriptor.ByteSize);

            indicesBuffer = context.CreateBuffer(BufferType.ELEMENT_ARRAY_BUFFER, BufferUsage.STATIC_DRAW);

            indicesBuffer.Bind();
            indicesBuffer.SetData(descriptor.CreateIndices(elementCount));

            textures = new Texture2D[10];
        }