예제 #1
0
        public int ReadRange <T>(T[] buffer, int offset, int numElems)
            where T : struct
        {
            if (!mCanRead)
            {
                throw new NotSupportedException("Optix Error: BufferStream: Cannot read from non Output Optix buffers");
            }

            var elemSize    = Marshal.SizeOf <T>();
            var sizeInBytes = numElems * elemSize;

            //perform some validation steps
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset");
            }

            if (sizeInBytes < 0 || (offset + sizeInBytes > buffer.Length * elemSize))//
            {
                throw new ArgumentOutOfRangeException("numElems");
            }

            var validSize = Math.Min(mSize - mPosition, sizeInBytes);

            var l          = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            var bufferSpan = new Span <T>(buffer, offset, numElems);

            MemoryHelper.CopyFromUnmanaged(new IntPtr(this.Buffer.ToInt64() + mPosition), ref bufferSpan, (uint)numElems);
            l.Free();

            mPosition += validSize;

            return((int)validSize);
        }
예제 #2
0
        public void WriteRange <T>(T[] buffer, int offset, int numElems)
            where T : struct
        {
            if (!mCanWrite)
            {
                throw new NotSupportedException("Optix Error: BufferStream: Cannot write to non Input Optix buffers");
            }
            var elemSize    = Marshal.SizeOf <T>();
            var sizeInBytes = numElems * elemSize;

            //perform some validation steps
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset");
            }

            if (sizeInBytes < 0 || (offset + numElems > buffer.Length))
            {
                throw new ArgumentOutOfRangeException("numElems", buffer.Length, $"Buffer length < {offset + sizeInBytes}");
            }
            if (mPosition + sizeInBytes > mSize)
            {
                throw new EndOfStreamException();
            }

            var buffSpan = new Span <T>(buffer, offset, numElems);

            MemoryHelper.CopyFromUnmanaged(new IntPtr(this.Buffer.ToInt64() + mPosition), ref buffSpan, (uint)sizeInBytes);


            mPosition += sizeInBytes;
        }
예제 #3
0
        public void GetBaryCentricOutput(Vector2[] output)
        {
            if (output.Length != mCurrentNumRays)
            {
                throw new ArgumentOutOfRangeException("output", "Output array must equal number of rays set on the Traversal object");
            }

            IntPtr outputData = IntPtr.Zero;

            CheckError(TraversalApi.rtuTraversalMapOutput(mTraversal, RTUoutput.RTU_OUTPUT_BARYCENTRIC, ref outputData));

            if (outputData == IntPtr.Zero)
            {
                throw new OptixException("Traversal Error: NormalOutput buffer cannot be mapped");
            }
            var lc = GCHandle.Alloc(output, GCHandleType.Pinned);

            var span = new Span <Vector2>(output);

            MemoryHelper.CopyFromUnmanaged(outputData, ref span, (uint)mCurrentNumRays);

            CheckError(TraversalApi.rtuTraversalUnmapOutput(mTraversal, RTUoutput.RTU_OUTPUT_BARYCENTRIC));
            lc.Free();
        }