private unsafe void InitVertexBuffers()
        {
            {
                VR04PositionBuffer positionBuffer = new VR04PositionBuffer(strin_Position);
                positionBuffer.Alloc(zFrameCount);
                QuadPosition *array = (QuadPosition *)positionBuffer.FirstElement();
                for (int i = 0; i < zFrameCount; i++)
                {
                    array[i] = new QuadPosition(
                        new vec3(-xLength, -yLength, (float)i / (float)zFrameCount - 0.5f),
                        new vec3(xLength, -yLength, (float)i / (float)zFrameCount - 0.5f),
                        new vec3(xLength, yLength, (float)i / (float)zFrameCount - 0.5f),
                        new vec3(-xLength, yLength, (float)i / (float)zFrameCount - 0.5f)
                        );
                }
                this.positionBufferRenderer = positionBuffer.GetRenderer();
                positionBuffer.Dispose();
            }

            {
                VR04UVBuffer uvBuffer = new VR04UVBuffer(strin_uv);
                uvBuffer.Alloc(zFrameCount);
                QuadUV *array = (QuadUV *)uvBuffer.FirstElement();
                for (int i = 0; i < zFrameCount; i++)
                {
                    array[i] = new QuadUV(
                        new vec3(0, 0, (float)i / (float)zFrameCount),
                        new vec3(1, 0, (float)i / (float)zFrameCount),
                        new vec3(1, 1, (float)i / (float)zFrameCount),
                        new vec3(0, 1, (float)i / (float)zFrameCount)
                        );
                }
                this.uvBufferRenderer = uvBuffer.GetRenderer();
                uvBuffer.Dispose();
            }
            {
                var indexBuffer = new VR04IndexBuffer();
                indexBuffer.Alloc(zFrameCount);
                QuadIndex *array = (QuadIndex *)indexBuffer.FirstElement();
                for (uint i = 0; i < zFrameCount; i++)
                {
                    if (this.reverSide)
                    {
                        array[i] = new QuadIndex((zFrameCount - i - 1) * 4 + 0,
                                                 (zFrameCount - i - 1) * 4 + 1,
                                                 (zFrameCount - i - 1) * 4 + 2,
                                                 (zFrameCount - i - 1) * 4 + 3
                                                 );
                    }
                    else
                    {
                        array[i] = new QuadIndex(i * 4 + 0, i * 4 + 1, i * 4 + 2, i * 4 + 3);
                    }
                }
                this.indexBufferRenderer = indexBuffer.GetRenderer();
                indexBuffer.Dispose();
            }

            //if (!this.reverSide)
            //{
            //    var indexBuffer = new ZeroIndexBuffer(DrawMode.Quads, zFrameCount * 4);
            //    indexBuffer.Alloc(zFrameCount);// this actually does nothing.
            //    this.indexBufferRenderer = indexBuffer.GetRenderer();
            //    indexBuffer.Dispose();
            //}
            //else
            //{
            //    var indexBuffer = new VR04IndexBuffer();
            //    indexBuffer.Alloc(zFrameCount);
            //    QuadIndex* array = (QuadIndex*)indexBuffer.FirstElement();
            //    for (uint i = 0; i < zFrameCount; i++)
            //    {
            //        //array[i] = new QuadIndex(i * 4 + 0, i * 4 + 1, i * 4 + 2, i * 4 + 3);
            //        array[i] = new QuadIndex((zFrameCount - i - 1) * 4 + 0,
            //            (zFrameCount - i - 1) * 4 + 1,
            //            (zFrameCount - i - 1) * 4 + 2,
            //            (zFrameCount - i - 1) * 4 + 3
            //            );
            //    }
            //    this.indexBufferRenderer = indexBuffer.GetRenderer();
            //    indexBuffer.Dispose();
            //}
            this.vao = new VertexArrayObject(this.positionBufferRenderer, this.uvBufferRenderer, this.indexBufferRenderer);
        }
Esempio n. 2
0
        private unsafe void InitVertexBuffers()
        {
            {
                VR04PositionBuffer positionBuffer = new VR04PositionBuffer(strin_Position);
                positionBuffer.Alloc(zFrameCount);
                QuadPosition* array = (QuadPosition*)positionBuffer.FirstElement();
                for (int i = 0; i < zFrameCount; i++)
                {
                    array[i] = new QuadPosition(
                        new vec3(-xLength, -yLength, (float)i / (float)zFrameCount - 0.5f),
                        new vec3(xLength, -yLength, (float)i / (float)zFrameCount - 0.5f),
                        new vec3(xLength, yLength, (float)i / (float)zFrameCount - 0.5f),
                        new vec3(-xLength, yLength, (float)i / (float)zFrameCount - 0.5f)
                        );
                }
                this.positionBufferRenderer = positionBuffer.GetRenderer();
                positionBuffer.Dispose();
            }

            {
                VR04UVBuffer uvBuffer = new VR04UVBuffer(strin_uv);
                uvBuffer.Alloc(zFrameCount);
                QuadUV* array = (QuadUV*)uvBuffer.FirstElement();
                for (int i = 0; i < zFrameCount; i++)
                {
                    array[i] = new QuadUV(
                        new vec3(0, 0, (float)i / (float)zFrameCount),
                        new vec3(1, 0, (float)i / (float)zFrameCount),
                        new vec3(1, 1, (float)i / (float)zFrameCount),
                        new vec3(0, 1, (float)i / (float)zFrameCount)
                        );
                }
                this.uvBufferRenderer = uvBuffer.GetRenderer();
                uvBuffer.Dispose();
            }
            {
                var indexBuffer = new VR04IndexBuffer();
                indexBuffer.Alloc(zFrameCount);
                QuadIndex* array = (QuadIndex*)indexBuffer.FirstElement();
                for (uint i = 0; i < zFrameCount; i++)
                {
                    if (this.reverSide)
                        array[i] = new QuadIndex((zFrameCount - i - 1) * 4 + 0,
                            (zFrameCount - i - 1) * 4 + 1,
                            (zFrameCount - i - 1) * 4 + 2,
                            (zFrameCount - i - 1) * 4 + 3
                            );
                    else
                    {
                        array[i] = new QuadIndex(i * 4 + 0, i * 4 + 1, i * 4 + 2, i * 4 + 3);
                    }
                }
                this.indexBufferRenderer = indexBuffer.GetRenderer();
                indexBuffer.Dispose();
            }

            //if (!this.reverSide)
            //{
            //    var indexBuffer = new ZeroIndexBuffer(DrawMode.Quads, zFrameCount * 4);
            //    indexBuffer.Alloc(zFrameCount);// this actually does nothing.
            //    this.indexBufferRenderer = indexBuffer.GetRenderer();
            //    indexBuffer.Dispose();
            //}
            //else
            //{
            //    var indexBuffer = new VR04IndexBuffer();
            //    indexBuffer.Alloc(zFrameCount);
            //    QuadIndex* array = (QuadIndex*)indexBuffer.FirstElement();
            //    for (uint i = 0; i < zFrameCount; i++)
            //    {
            //        //array[i] = new QuadIndex(i * 4 + 0, i * 4 + 1, i * 4 + 2, i * 4 + 3);
            //        array[i] = new QuadIndex((zFrameCount - i - 1) * 4 + 0,
            //            (zFrameCount - i - 1) * 4 + 1,
            //            (zFrameCount - i - 1) * 4 + 2,
            //            (zFrameCount - i - 1) * 4 + 3
            //            );
            //    }
            //    this.indexBufferRenderer = indexBuffer.GetRenderer();
            //    indexBuffer.Dispose();
            //}
            this.vao = new VertexArrayObject(this.positionBufferRenderer, this.uvBufferRenderer, this.indexBufferRenderer);
        }