protected override void Arrange(byte[] newOrder)
        {
            byte[] bytes =
                CLAPI.ReadBuffer <byte>(Root.Instance, Root.ActiveBuffer.Buffer, (int)Root.ActiveBuffer.Size);
            for (int i = 0; i < bytes.Length; i++)
            {
                if (i % Root.ActiveChannels.Length == 0)
                {
                    byte[] channelValues = new byte[Root.ActiveChannels.Length];
                    for (int j = 0; j < channelValues.Length; j++)
                    {
                        channelValues[j] = bytes[i + j];
                    }

                    channelValues = SwapChannel(channelValues, newOrder);

                    for (int j = 0; j < channelValues.Length; j++)
                    {
                        bytes[i + j] = channelValues[j];
                    }
                }
            }

            byte[] test = bytes.Reverse().Take(50).Reverse().ToArray();

            CLAPI.WriteToBuffer(Root.Instance, Root.ActiveBuffer.Buffer, bytes);
        }
Beispiel #2
0
        public void SetData(byte[] data)
        {
            MemoryBuffer buf = Buffer;

            if (data.Length != buf.Size)
            {
                throw new InvalidOperationException("The passed data has not the same size as the buffer has.");
            }

            if ((buf.Flags & MemoryFlag.ReadOnly) != 0)
            {
                throw new InvalidOperationException("Can not write to a ReadOnly Buffer");
            }

            CLAPI.WriteToBuffer(Root.Instance, buf, data);
        }
Beispiel #3
0
        public void OpenCL_WriteBuffer_Test()
        {
            float[] b = new float[255];
            for (int i = 0; i < b.Length; i++)
            {
                b[i] = i;
            }

            MemoryBuffer buffer = CLAPI.CreateEmpty <float>(CLAPI.MainThread, b.Length,
                                                            MemoryFlag.ReadWrite, "TestBuffer");


            CLAPI.WriteToBuffer(CLAPI.MainThread, buffer, b);

            float[] c = CLAPI.ReadBuffer <float>(CLAPI.MainThread, buffer, b.Length);


            Assert.True(CheckValues(c, b));
        }
Beispiel #4
0
        public void WriteBuffer()
        {
            CLAPI.Reinitialize();
            DebugHelper.ThrowOnAllExceptions = true;
            float[] b = new float[255];
            for (int i = 0; i < b.Length; i++)
            {
                b[i] = i;
            }

            MemoryBuffer buffer = CLAPI.CreateEmpty <float>(b.Length, MemoryFlag.CopyHostPointer | MemoryFlag.ReadWrite);


            CLAPI.WriteToBuffer(buffer, b);

            float[] c = CLAPI.ReadBuffer <float>(buffer, b.Length);


            Assert.True(CheckValues(c, b));
        }
        /// <summary>
        /// The implementation of the command setactive
        /// </summary>
        private void cmd_setactive()
        {
            if (_currentArgStack.Count < 1)
            {
                Logger.Crash(new FLInvalidFunctionUseException("setactive", "Specify the buffer you want to activate"),
                             true);
                return;
            }

            byte[] temp = new byte[_channelCount];
            while (_currentArgStack.Count != 1)
            {
                object val = _currentArgStack.Pop();
                if (!(val is decimal))
                {
                    Logger.Crash(new FLInvalidFunctionUseException("setactive", "Invalid channel Arguments"), true);
                    val = 0;
                }

                byte channel = (byte)Convert.ChangeType(val, typeof(byte));
                if (channel >= _channelCount)
                {
                    Logger.Log("Script is enabling channels beyond channel count. Ignoring...", DebugChannel.Warning | DebugChannel.OpenFL, 10);
                }
                else
                {
                    temp[channel] = 1;
                }
            }

            if (_currentArgStack.Peek() == null ||
                !(_currentArgStack.Peek() is CLBufferInfo) && !(_currentArgStack.Peek() is decimal))
            {
                Logger.Crash(new FLInvalidFunctionUseException("setactive", "Specify the buffer you want to activate"),
                             true);
                return;
            }

            if (_currentArgStack.Peek() is decimal)
            {
                byte channel = (byte)Convert.ChangeType(_currentArgStack.Pop(), typeof(byte));
                temp[channel] = 1;
            }
            else
            {
                _currentBuffer = (CLBufferInfo)_currentArgStack.Pop();
            }

            bool needCopy = false;

            for (int i = 0; i < _channelCount; i++)
            {
                if (_activeChannels[i] != temp[i])
                {
                    needCopy = true;
                    break;
                }
            }

            if (needCopy)
            {
                Logger.Log("Updating Channel Buffer", DebugChannel.Log | DebugChannel.OpenFL, 6);
                _activeChannels = temp;
                CLAPI.WriteToBuffer(_activeChannelBuffer, _activeChannels);
            }
            else
            {
                Logger.Log("Skipping Updating Channel Buffer", DebugChannel.Log | DebugChannel.OpenFL, 6);
            }
        }
Beispiel #6
0
        /// <summary>
        /// The implementation of the command setactive
        /// </summary>
        private void CmdSetActive()
        {
            if (currentArgStack.Count < 1)
            {
                throw new FLInvalidFunctionUseException("setactive", "Specify the buffer you want to activate");
            }

            byte[] temp = new byte[channelCount];
            while (currentArgStack.Count != 1)
            {
                object val = currentArgStack.Pop();
                if (!(val is decimal))
                {
                    throw new FLInvalidFunctionUseException("setactive", "Invalid channel Arguments");
                }

                byte channel = (byte)Convert.ChangeType(val, typeof(byte));
                if (channel >= channelCount)
                {
                    Logger.Log(DebugChannel.Error, Verbosity.Level1,
                               "Script is enabling channels beyond channel count. Ignoring...",
                               DebugChannel.Warning | DebugChannel.OpenFL, 10);
                }
                else
                {
                    temp[channel] = 1;
                }
            }

            if (currentArgStack.Peek() == null ||
                !(currentArgStack.Peek() is CLBufferInfo) && !(currentArgStack.Peek() is decimal))
            {
                throw new FLInvalidFunctionUseException("setactive", "Specify the buffer you want to activate");
            }

            if (currentArgStack.Peek() is decimal)
            {
                byte channel = (byte)Convert.ChangeType(currentArgStack.Pop(), typeof(byte));
                temp[channel] = 1;
            }
            else
            {
                currentBuffer = (CLBufferInfo)currentArgStack.Pop();
            }

            bool needCopy = false;

            for (int i = 0; i < channelCount; i++)
            {
                if (activeChannels[i] != temp[i])
                {
                    needCopy = true;
                    break;
                }
            }

            if (needCopy)
            {
                Logger.Log(DebugChannel.Error, Verbosity.Level1, "Updating Channel Buffer",
                           DebugChannel.Log | DebugChannel.OpenFL, 6);
                activeChannels = temp;
                CLAPI.WriteToBuffer(instance, activeChannelBuffer, activeChannels);
            }
            else
            {
                Logger.Log(DebugChannel.Error, Verbosity.Level1, "Skipping Updating Channel Buffer",
                           DebugChannel.Log | DebugChannel.OpenFL, 6);
            }
        }