OpenTkEngine.Core.Graphics.BindSquare C# (CSharp) Method

BindSquare() private static method

private static BindSquare ( ) : void
return void
        private static void BindSquare()
        {
            if (_vao == 0)
            {
                _vao = GL.GenVertexArray();
                _vbos = new int[3];
                GL.GenBuffers(3, _vbos);

                float[] verts = new float[] {
                    0, 0, 0,
                    1, 0, 0,
                    1, 1, 0,
                    0, 1, 0
                };

                int[] indices = new int[] {
                    0, 1, 2, 3
                };

                GL.BindVertexArray(_vao);
                _currentVao = _vao;

                GL.BindBuffer(BufferTarget.ArrayBuffer, _vbos[0]);
                GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(verts.Length * sizeof(float)), verts, BufferUsageHint.StaticDraw);

                int size;
                GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
                if (verts.Length * sizeof(float) != size)
                {
                    throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
                }

                int vPositionLocation = _currentShader.GetAttribLocation("vPosition");
                GL.EnableVertexAttribArray(vPositionLocation);
                GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 3 * sizeof(float), 0);

                BindTextureCoords();

                GL.BindBuffer(BufferTarget.ElementArrayBuffer, _vbos[2]);
                GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(int)), indices, BufferUsageHint.StaticDraw);

                GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
                if (indices.Length * sizeof(int) != size)
                {
                    throw new ApplicationException("Index data not loaded onto graphics card correctly");
                }

                int vTexCoordsLocation = _currentShader.GetAttribLocation("vTexCoords");
                GL.EnableVertexAttribArray(vTexCoordsLocation);
                GL.VertexAttribPointer(vTexCoordsLocation, 2, VertexAttribPointerType.Float, false, 2 * sizeof(float), 0);

            }
            else
            {
                GL.BindVertexArray(_vao);
                _currentVao = _vao;
            }
        }