Exemplo n.º 1
0
    public static void Main()
    {
        using (var na = new NativePackedArray <byte>(512)) {
            var pFunction = ReturnWriteStringIntoBuffer();
            var d         = Marshal.GetDelegateForFunctionPointer <TWriteStringIntoBuffer>(pFunction);

            int numBytes;
            fixed(byte *pBuffer = na.Array)
            {
                numBytes = d(pBuffer, na.Length);
            }

            var s = Encoding.ASCII.GetString(na, 0, numBytes);
            Console.WriteLine("'{0}'", s);
        }

        {
            var pFunction = ReturnReturnStructArgument();
            var d         = Marshal.GetDelegateForFunctionPointer <TReturnStructArgument>(pFunction);

            var a = new TestStruct {
                I = 3, F = 5.5f
            };
            var b = d(a);

            Console.WriteLine("i={0} f={1:F4}", b.I, b.F);
        }
    }
Exemplo n.º 2
0
    public static void Main () {
        using (var na = new NativePackedArray<byte>("common.dll", 512)) {
            int numBytes;
            fixed (byte* pBuffer = na.Array)
                numBytes = WriteStringIntoBuffer(pBuffer, na.Length);

            var s = Encoding.ASCII.GetString(na, 0, numBytes);
            Console.WriteLine("'{0}'", s);
        }
    }
Exemplo n.º 3
0
    public static void Main()
    {
        using (var na = new NativePackedArray <byte>("common.dll", 512)) {
            int numBytes;

            fixed(byte *pBuffer = na.Array)
            numBytes = WriteStringIntoBuffer(pBuffer, na.Length);

            var s = Encoding.ASCII.GetString(na, 0, numBytes);
            Console.WriteLine("'{0}'", s);
        }
    }
Exemplo n.º 4
0
        private void _glUniform4fv(
            OpenGLDevice openGLDevice, int _location, Array _buffer
            )
        {
            var lengthBytes = Buffer.ByteLength(_buffer);

            // FIXME: Blech, copy into the emscripten heap
            using (var packed = new NativePackedArray <float>("sdl2.dll", lengthBytes / 4))
                fixed(float *pPacked = packed.Array)
                {
                    Buffer.BlockCopy(_buffer, 0, packed.Array, 0, lengthBytes);
                    openGLDevice.glUniform4fv(_location, packed.Length / 4, pPacked);
                }
        }
Exemplo n.º 5
0
    public static void Main () {
        using (var na = new NativePackedArray<byte>(512)) {
            var d = ReturnWriteStringIntoBuffer();

            int numBytes;
            fixed (byte* pBuffer = na.Array) {
                numBytes = d(pBuffer, na.Length);
            }

            var s = Encoding.ASCII.GetString(na, 0, numBytes);
            Console.WriteLine("'{0}'", s);
        }

        {
            var d = ReturnReturnStructArgument();

            var a = new TestStruct { I = 3, F = 5.5f };
            var b = d(a);

            Console.WriteLine("i={0} f={1:F4}", b.I, b.F);
        }
    }