Esempio n. 1
0
        /// <summary>
        /// 获取一个可渲染此VBO的渲染器。
        /// </summary>
        /// <returns></returns>
        public BufferRenderer GetRenderer()
        {
            if (renderer == null)
            {
                renderer = CreateRenderer();
            }

            return(renderer);
        }
        private unsafe void InitVertexBuffers()
        {
            {
                VR02PositionBuffer positionBuffer = new VR02PositionBuffer(strin_Position);
                positionBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                vec3* array = (vec3*)positionBuffer.FirstElement();
                int index = 0;
                for (int i = 0; i < xFrameCount; i++)
                {
                    for (int j = 0; j < yFrameCount; j++)
                    {
                        for (int k = 0; k < zFrameCount; k++)
                        {
                            array[index++] = new vec3(
                                (float)i / (float)xFrameCount - 0.5f,
                                (float)j / (float)yFrameCount - 0.5f,
                                ((float)k / (float)zFrameCount - 0.5f) * 109.0f / 256.0f
                                );
                        }
                    }
                }
                this.positionBufferRenderer = positionBuffer.GetRenderer();
                positionBuffer.Dispose();
            }

            {
                VR02UVBuffer uvBuffer = new VR02UVBuffer(strin_uv);
                uvBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                vec3* array = (vec3*)uvBuffer.FirstElement();
                int index = 0;
                for (int i = 0; i < xFrameCount; i++)
                {
                    for (int j = 0; j < yFrameCount; j++)
                    {
                        for (int k = 0; k < zFrameCount; k++)
                        {
                            array[index++] = new vec3(
                                (float)i / (float)xFrameCount,
                                (float)j / (float)yFrameCount,
                                (float)k / (float)zFrameCount
                                );
                        }
                    }
                }
                this.uvBufferRenderer = uvBuffer.GetRenderer();
                uvBuffer.Dispose();
            }
            {
                var indexBuffer = new ZeroIndexBuffer(DrawMode.Points, 0, xFrameCount * yFrameCount * zFrameCount);
                indexBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);// this actually does nothing.
                this.indexBufferRenderer = indexBuffer.GetRenderer();
                indexBuffer.Dispose();
            }
            this.vao = new VertexArrayObject(this.positionBufferRenderer, this.uvBufferRenderer, this.indexBufferRenderer);
        }
Esempio n. 3
0
        protected void InitializeVAO()
        {
            //IModel model = IceCreamModel.GetModel(1, 10, 10);
            IModel model = this.model;

            this.positionBufferRenderer = model.GetPositionBufferRenderer(strin_Position);
            //this.colorBufferRenderer = model.GetColorBufferRenderer(strin_Color);
            this.normalBufferRenderer = model.GetNormalBufferRenderer(strin_Normal);
            this.indexBufferRenderer = model.GetIndexes();
            IndexBufferRenderer renderer = this.indexBufferRenderer as IndexBufferRenderer;
            if (renderer != null)
            {
                this.indexCount = renderer.ElementCount;
            }
        }
Esempio n. 4
0
        protected void InitializeVAO()
        {
            IModel model = this.objModelAdapter;

            this.positionBufferRenderer = model.GetPositionBufferRenderer(strin_Position);
            //this.colorBufferRenderer = model.GetColorBufferRenderer(strin_Color);
            this.normalBufferRenderer = model.GetNormalBufferRenderer(strin_Normal);
            this.indexBufferRenderer = model.GetIndexes();

            IndexBufferRenderer renderer = this.indexBufferRenderer as IndexBufferRenderer;
            if (renderer != null)
            {
                this.indexCount = renderer.ElementCount;
            }
        }
Esempio n. 5
0
        private unsafe void InitVertexBuffers()
        {
            {
                VR01PositionBuffer positionBuffer = new VR01PositionBuffer(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();
            }

            {
                VR01UVBuffer uvBuffer = new VR01UVBuffer(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 ZeroIndexBuffer(DrawMode.Quads, 0, zFrameCount * 4);
                indexBuffer.Alloc(zFrameCount);// this actually does nothing.
                this.indexBufferRenderer = indexBuffer.GetRenderer();
                indexBuffer.Dispose();
            }
            this.vao = new VertexArrayObject(this.positionBufferRenderer, this.uvBufferRenderer, this.indexBufferRenderer);
        }
Esempio n. 6
0
        protected void InitializeVAO()
        {
            IModel model = this.model;

            this.positionBufferRenderer = model.GetPositionBufferRenderer(strin_Position);
            this.colorBufferRenderer = model.GetColorBufferRenderer(strin_Color);
            this.normalBufferRenderer = model.GetNormalBufferRenderer(strin_Normal);
            this.indexBufferRenderer = model.GetIndexes();

            {
                IndexBufferRenderer renderer = this.indexBufferRenderer as IndexBufferRenderer;
                if (renderer != null)
                {
                    this.elementCount = renderer.ElementCount;
                }
            }
            {
                ZeroIndexBufferRenderer renderer = this.indexBufferRenderer as ZeroIndexBufferRenderer;
                if (renderer != null)
                {
                    this.elementCount = renderer.VertexCount;
                }
            }
        }
        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. 8
0
        protected unsafe void InitializeVAO()
        {

            vec3[] colors = new vec3[] { new vec3(1, 0, 0), new vec3(0, 1, 0), new vec3(0, 0, 1) };
            // 计算三个坐标轴
            for (int axisIndex = 0; axisIndex < 3; axisIndex++)
            {
                var axisVertexCount = faceCount * 2;

                //  Create a vertex buffer for the vertex data.
                using (var positionBuffer = new AxisPositionBuffer(strin_Position, BufferUsage.StaticDraw))
                {
                    positionBuffer.Alloc(axisVertexCount);
                    vec3* positionArray = (vec3*)positionBuffer.FirstElement();
                    for (int i = 0; i < axisVertexCount; i++)
                    {
                        int face = i / 2;
                        float[] components = new float[]{
                            i % 2 == 1 ? 0 : this.axisLength,
                            (float)(this.radius * Math.Cos(face * (Math.PI * 2) / faceCount)),
                            (float)(this.radius * Math.Sin(face * (Math.PI * 2) / faceCount))};
                        positionArray[i] = new vec3(
                            components[(0 + axisIndex) % 3], components[(2 + axisIndex) % 3], components[(4 + axisIndex) % 3]);
                    }
                    this.positionBufferRenderers[axisIndex] = positionBuffer.GetRenderer();
                }

                //  Now do the same for the color data.
                using (var colorBuffer = new AxisColorBuffer(strin_Color, BufferUsage.StaticDraw))
                {
                    colorBuffer.Alloc(axisVertexCount);
                    vec3* colorArray = (vec3*)colorBuffer.FirstElement();
                    for (int i = 0; i < axisVertexCount; i++)
                    {
                        colorArray[i] = colors[axisIndex];
                    }
                    this.colorBufferRenderers[axisIndex] = colorBuffer.GetRenderer();
                }

                // Now for the index data.
                using (var indexBuffer = new AxisIndexBuffer())
                {
                    int indexLength = axisVertexCount + 2;
                    indexBuffer.Alloc(indexLength);
                    byte* cylinderIndex = (byte*)indexBuffer.FirstElement();
                    for (int i = 0; i < indexLength - 2; i++)
                    {
                        cylinderIndex[i] = (byte)i;
                    }
                    cylinderIndex[indexLength - 2] = 0;
                    cylinderIndex[indexLength - 1] = 1;
                    this.indexBufferRenderers[axisIndex] = indexBuffer.GetRenderer();
                }

            }
            // 计算XZ平面
            {
                int planVertexCount = 4;

                //  Create a vertex buffer for the vertex data.
                using (var positionBuffer = new AxisPositionBuffer(strin_Position, BufferUsage.StaticDraw))
                {
                    positionBuffer.Alloc(planVertexCount);
                    vec3* plan = (vec3*)positionBuffer.FirstElement();
                    {
                        float length = this.axisLength;
                        plan[0] = new vec3(-length, 0, -length);
                        plan[1] = new vec3(-length, 0, length);
                        plan[2] = new vec3(length, 0, length);
                        plan[3] = new vec3(length, 0, -length);
                    }
                    this.planPositionBufferRenderer = positionBuffer.GetRenderer();
                }

                //  Now do the same for the colour data.
                using (var colorBuffer = new AxisColorBuffer(strin_Color, BufferUsage.StaticDraw))
                {
                    colorBuffer.Alloc(planVertexCount);
                    vec3* colorArray = (vec3*)colorBuffer.FirstElement();
                    {
                        for (int i = 0; i < planVertexCount; i++)
                        {
                            colorArray[i] = this.planColor;
                        }
                    }
                    this.planColorBufferRenderer = colorBuffer.GetRenderer();
                }

                using (var indexBuffer = new ZeroIndexBuffer(DrawMode.LineLoop, 0, planVertexCount))
                {
                    indexBuffer.Alloc(planVertexCount);//这句话实际上什么都没有做。
                    this.planIndexBufferRenderer = indexBuffer.GetRenderer();
                }
            }
        }
        private unsafe void InitVertexBuffers()
        {
            // http://images.cnblogs.com/cnblogs_com/bitzhuwei/482613/o_Cube-small.jpg
            {
                VR03PositionBuffer positionBuffer = new VR03PositionBuffer(strin_Position);
                positionBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                HexahedronPosition* array = (HexahedronPosition*)positionBuffer.FirstElement();
                int index = 0;
                for (int i = 0; i < xFrameCount; i++)
                {
                    for (int j = 0; j < yFrameCount; j++)
                    {
                        for (int k = 0; k < zFrameCount; k++)
                        {
                            var x = ((float)i / (float)xFrameCount - 0.5f) * factor;
                            var y = ((float)j / (float)yFrameCount - 0.5f) * factor;
                            var z = (((float)k / (float)zFrameCount - 0.5f) * 109.0f / 256.0f) * factor;
                            var hexahedron = new HexahedronPosition();
                            hexahedron.v0 = new vec3(x + hexahedronHalfLength, y + hexahedronHalfLength, z + hexahedronHalfLength);
                            hexahedron.v1 = new vec3(x - hexahedronHalfLength, y + hexahedronHalfLength, z + hexahedronHalfLength);
                            hexahedron.v2 = new vec3(x + hexahedronHalfLength, y - hexahedronHalfLength, z + hexahedronHalfLength);
                            hexahedron.v3 = new vec3(x - hexahedronHalfLength, y - hexahedronHalfLength, z + hexahedronHalfLength);
                            hexahedron.v4 = new vec3(x + hexahedronHalfLength, y + hexahedronHalfLength, z - hexahedronHalfLength);
                            hexahedron.v5 = new vec3(x - hexahedronHalfLength, y + hexahedronHalfLength, z - hexahedronHalfLength);
                            hexahedron.v6 = new vec3(x + hexahedronHalfLength, y - hexahedronHalfLength, z - hexahedronHalfLength);
                            hexahedron.v7 = new vec3(x - hexahedronHalfLength, y - hexahedronHalfLength, z - hexahedronHalfLength);
                            array[index++] = hexahedron;
                        }
                    }
                }
                this.positionBufferRenderer = positionBuffer.GetRenderer();
                positionBuffer.Dispose();
            }

            {
                VR03UVBuffer uvBuffer = new VR03UVBuffer(strin_uv);
                uvBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                HexahedronUV* array = (HexahedronUV*)uvBuffer.FirstElement();
                int index = 0;
                for (int i = 0; i < xFrameCount; i++)
                {
                    for (int j = 0; j < yFrameCount; j++)
                    {
                        for (int k = 0; k < zFrameCount; k++)
                        {
                            var x = (float)i / (float)xFrameCount;
                            var y = (float)j / (float)yFrameCount;
                            var z = (float)k / (float)zFrameCount;
                            var color = new vec3(x, y, z);
                            var uv = new HexahedronUV();
                            uv.v0 = color;
                            uv.v1 = color;
                            uv.v2 = color;
                            uv.v3 = color;
                            uv.v4 = color;
                            uv.v5 = color;
                            uv.v6 = color;
                            uv.v7 = color;
                            array[index++] = uv;
                        }
                    }
                }
                this.uvBufferRenderer = uvBuffer.GetRenderer();
                uvBuffer.Dispose();
            }
            {
                var indexBuffer = new VR03IndexBuffer();
                indexBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                HexahedronIndex* array = (HexahedronIndex*)indexBuffer.FirstElement();
                int index = 0;
                for (int i = 0; i < xFrameCount; i++)
                {
                    for (int j = 0; j < yFrameCount; j++)
                    {
                        for (int k = 0; k < zFrameCount; k++)
                        {
                            uint centerIndex = (uint)((i * yFrameCount * zFrameCount + j * zFrameCount + k) * 8);
                            array[index++] = new HexahedronIndex(centerIndex);
                        }
                    }
                }
                this.indexBufferRenderer = indexBuffer.GetRenderer();
                indexBuffer.Dispose();
            }

            this.vao = new VertexArrayObject(this.positionBufferRenderer, this.uvBufferRenderer, this.indexBufferRenderer);
        }