コード例 #1
0
        public void initialize(uint maxNumVertices, uint[] texChannels, ushort[] indices, uint maxNumRenderCalls)
        {
            {
                uint positionsDataSize = (uint)(maxNumVertices * Marshal.SizeOf(typeof(Neutrino._math.vec3)));
                positionsId_ = Gl.GenBuffer();
                positions_   = new Neutrino._math.vec3[maxNumVertices];

                Gl.BindBuffer(BufferTarget.ArrayBuffer, positionsId_);
                Gl.BufferData(BufferTarget.ArrayBuffer, (IntPtr)positionsDataSize, IntPtr.Zero, BufferUsageHint.DynamicDraw);
            }

            {
                uint colorsDataSize = (uint)(maxNumVertices * Marshal.SizeOf(typeof(uint)));
                colorsId_ = Gl.GenBuffer();
                colors_   = new uint[maxNumVertices];

                Gl.BindBuffer(BufferTarget.ArrayBuffer, colorsId_);
                Gl.BufferData(BufferTarget.ArrayBuffer, (IntPtr)colorsDataSize, IntPtr.Zero, BufferUsageHint.DynamicDraw);
            }

            texChannels_ = new TexChannel[texChannels.Length];

            for (uint texIndex = 0; texIndex < texChannels.Length; ++texIndex)
            {
                TexChannel texChannel  = new TexChannel();
                uint       texDataSize = (uint)(maxNumVertices * texChannels[texIndex] * Marshal.SizeOf(typeof(float)));
                texChannel.dimensions_ = texChannels[texIndex];
                texChannel.id_         = Gl.GenBuffer();
                texChannel.data_       = new float[maxNumVertices * texChannels[texIndex]];

                Gl.BindBuffer(BufferTarget.ArrayBuffer, texChannel.id_);
                Gl.BufferData(BufferTarget.ArrayBuffer, (IntPtr)texDataSize, IntPtr.Zero, BufferUsageHint.DynamicDraw);

                texChannels_[texIndex] = texChannel;
            }

            {
                uint indicesDataSize = (uint)(indices.Length * Marshal.SizeOf(typeof(ushort)));
                indicesId_   = Gl.GenBuffer();
                indicesData_ = Marshal.AllocHGlobal((int)indicesDataSize);

                {
                    IntPtr ptr = indicesData_;
                    for (uint i = 0; i < indices.Length; ptr = IntPtr.Add(ptr, Marshal.SizeOf(typeof(ushort))), ++i)
                    {
                        Marshal.WriteInt16(ptr, (short)indices[i]);
                    }
                }

                Gl.BindBuffer(BufferTarget.ElementArrayBuffer, indicesId_);
                Gl.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)indicesDataSize, indicesData_, BufferUsageHint.StaticDraw);
            }

            numVertices_ = 0;

            renderCalls_    = new Neutrino.RenderCall[maxNumRenderCalls];
            numRenderCalls_ = 0;
        }
コード例 #2
0
        public void updateGlBuffers()
        {
            {
                GCHandle handle  = GCHandle.Alloc(positions_, GCHandleType.Pinned);
                IntPtr   pointer = handle.AddrOfPinnedObject();

                Gl.BindBuffer(BufferTarget.ArrayBuffer, positionsId_);
                Gl.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)0, (IntPtr)(numVertices_ * Marshal.SizeOf(typeof(Neutrino._math.vec3))), pointer);

                handle.Free();
            }

            {
                GCHandle handle  = GCHandle.Alloc(colors_, GCHandleType.Pinned);
                IntPtr   pointer = handle.AddrOfPinnedObject();

                Gl.BindBuffer(BufferTarget.ArrayBuffer, colorsId_);
                Gl.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)0, (IntPtr)(numVertices_ * Marshal.SizeOf(typeof(uint))), pointer);

                handle.Free();
            }

            for (uint texIndex = 0; texIndex < texChannels_.Length; ++texIndex)
            {
                TexChannel texChannel = texChannels_[texIndex];

                GCHandle handle  = GCHandle.Alloc(texChannel.data_, GCHandleType.Pinned);
                IntPtr   pointer = handle.AddrOfPinnedObject();

                Gl.BindBuffer(BufferTarget.ArrayBuffer, texChannel.id_);
                Gl.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)0,
                                 (IntPtr)(numVertices_ * texChannel.dimensions_ * Marshal.SizeOf(typeof(float))), pointer);

                handle.Free();
            }
        }