示例#1
0
        public static WebGLBuffer CreateArrayBuffer(this WebGLRenderingContextBase gl, Array items)
        {
            var arrayBuffer = gl.CreateBuffer();

            gl.BindBuffer(WebGLRenderingContextBase.ARRAY_BUFFER, arrayBuffer);
            gl.BufferData(WebGLRenderingContextBase.ARRAY_BUFFER, items, WebGLRenderingContextBase.STATIC_DRAW);
            gl.BindBuffer(WebGLRenderingContextBase.ARRAY_BUFFER, null);

            return(arrayBuffer);
        }
示例#2
0
        public static WebGLBuffer CreateElementArrayBuffer(this WebGLRenderingContextBase gl, Array items)
        {
            var elementArrayBuffer = gl.CreateBuffer();

            gl.BindBuffer(WebGLRenderingContextBase.ELEMENT_ARRAY_BUFFER, elementArrayBuffer);
            gl.BufferData(WebGLRenderingContextBase.ELEMENT_ARRAY_BUFFER, items, WebGLRenderingContextBase.STATIC_DRAW);
            gl.BindBuffer(WebGLRenderingContextBase.ELEMENT_ARRAY_BUFFER, null);

            return(elementArrayBuffer);
        }
示例#3
0
        public static WebGLBuffer CreateArrayBufferWithUsage(this WebGLRenderingContextBase gl, Array items, uint usage)
        {
            var arrayBuffer = gl.CreateBuffer();

            gl.BindBuffer(WebGLRenderingContextBase.ARRAY_BUFFER, arrayBuffer);
            gl.BufferData(WebGLRenderingContextBase.ARRAY_BUFFER, items, usage);

            return(arrayBuffer);
        }
示例#4
0
        void IGraphicsBackend.EndRendering()
        {
            GL.BindBuffer(WebGLRenderingContextBase.ARRAY_BUFFER, null);

            this.currentDevice = null;
            this.renderOptions = null;
            this.renderStats   = null;

            DebugCheckOpenGLErrors();
        }
示例#5
0
        public void Run()
        {
            var vertices = new float[]
            {
                -1, -1, -1,
                1, -1, -1,
                1, 1, -1,

                -1, 1, -1,
                -1, -1, 1,
                1, -1, 1,

                1, 1, 1,
                -1, 1, 1,
                -1, -1, -1,

                -1, 1, -1,
                -1, 1, 1,
                -1, -1, 1,

                1, -1, -1,
                1, 1, -1,
                1, 1, 1,

                1, -1, 1,
                -1, -1, -1,
                -1, -1, 1,

                1, -1, 1,
                1, -1, -1,
                -1, 1, -1,

                -1, 1, 1,
                1, 1, 1,
                1, 1, -1
            };

            vertexBuffer = gl.CreateArrayBuffer(vertices);

            indices = new ushort[]
            {
                0, 1, 2,
                0, 2, 3,

                4, 5, 6,
                4, 6, 7,

                8, 9, 10,
                8, 10, 11,

                12, 13, 14,
                12, 14, 15,

                16, 17, 18,
                16, 18, 19,

                20, 21, 22,
                20, 22, 23
            };
            indexBuffer = gl.CreateElementArrayBuffer(indices);

            var colors = new float[]
            {
                1, 0, 0,
                1, 0, 0,
                1, 0, 0,
                1, 0, 0,

                0, 1, 0,
                0, 1, 0,
                0, 1, 0,
                0, 1, 0,

                0, 0, 1,
                0, 0, 1,
                0, 0, 1,
                0, 0, 1,

                1, 1, 0,
                1, 1, 0,
                1, 1, 0,
                1, 1, 0,

                0, 1, 1,
                0, 1, 1,
                0, 1, 1,
                0, 1, 1,

                1, 1, 1,
                1, 1, 1,
                1, 1, 1,
                1, 1, 1
            };

            colorBuffer = gl.CreateArrayBuffer(colors);

            var shaderProgram = InitShaders();

            pMatrixUniform = gl.GetUniformLocation(shaderProgram, "pMatrix");
            vMatrixUniform = gl.GetUniformLocation(shaderProgram, "vMatrix");
            wMatrixUniform = gl.GetUniformLocation(shaderProgram, "wMatrix");

            gl.BindBuffer(WebGLRenderingContextBase.ARRAY_BUFFER, vertexBuffer);
            var positionAttribute = (uint)gl.GetAttribLocation(shaderProgram, "position");

            gl.VertexAttribPointer(positionAttribute, 3, WebGLRenderingContextBase.FLOAT, false, 0, 0);
            gl.EnableVertexAttribArray(positionAttribute);

            gl.BindBuffer(WebGLRenderingContextBase.ARRAY_BUFFER, colorBuffer);
            var colorAttribute = (uint)gl.GetAttribLocation(shaderProgram, "color");

            gl.VertexAttribPointer(colorAttribute, 3, WebGLRenderingContextBase.FLOAT, false, 0, 0);
            gl.EnableVertexAttribArray(colorAttribute);

            gl.BindBuffer(WebGLRenderingContextBase.ELEMENT_ARRAY_BUFFER, indexBuffer);
            worldMatrix = Matrix.Identity;
        }