Esempio n. 1
0
        public override unsafe bool ScheduleVertexColorJob(VertexInputData colorInput, NativeSlice <JobHandle> handles)
        {
            Profiler.BeginSample("ScheduleVertexColorJob");
            Profiler.BeginSample("AllocateNativeArray");
            vData = new NativeArray <Color>(colorInput.count, VertexBufferConfigBase.defaultAllocator);
            var vDataPtr = (byte *)NativeArrayUnsafeUtility.GetUnsafeReadOnlyPtr(vData);

            Profiler.EndSample();

            fixed(void *input = &(colorInput.buffer[colorInput.startOffset]))
            {
                var h = GetColors32Job(
                    input,
                    colorInput.type,
                    colorInput.attributeType,
                    colorInput.byteStride,
                    vData
                    );

                if (h.HasValue)
                {
                    handles[0] = h.Value;
                }
                else
                {
                    Profiler.EndSample();
                    return(false);
                }
            }

            Profiler.EndSample();
            return(true);
        }
Esempio n. 2
0
 public abstract unsafe JobHandle?ScheduleVertexJobs(
     VertexInputData posInput,
     VertexInputData?nrmInput     = null,
     VertexInputData?tanInput     = null,
     VertexInputData[] uvInputs   = null,
     VertexInputData?colorInput   = null,
     VertexInputData?weightsInput = null,
     VertexInputData?jointsInput  = null
     );
Esempio n. 3
0
        public override unsafe JobHandle?ScheduleVertexJobs(
            VertexInputData posInput,
            VertexInputData?nrmInput     = null,
            VertexInputData?tanInput     = null,
            VertexInputData[] uvInputs   = null,
            VertexInputData?colorInput   = null,
            VertexInputData?weightsInput = null,
            VertexInputData?jointsInput  = null
            )
        {
            Profiler.BeginSample("ScheduleVertexJobs");
            Profiler.BeginSample("AllocateNativeArray");
            vData = new NativeArray <VType>(posInput.count, defaultAllocator);
            var vDataPtr = (byte *)NativeArrayUnsafeUtility.GetUnsafeReadOnlyPtr(vData);

            Profiler.EndSample();

            int jobCount         = 1;
            int outputByteStride = 12; // sizeof Vector3

            hasNormals = nrmInput.HasValue || calculateNormals;
            if (hasNormals)
            {
                if (nrmInput.HasValue)
                {
                    jobCount++;
                }
                outputByteStride += 12;
            }

            hasTangents = tanInput.HasValue || calculateTangents;
            if (hasTangents)
            {
                if (tanInput.HasValue)
                {
                    jobCount++;
                }
                outputByteStride += 16;
            }

            if (uvInputs != null && uvInputs.Length > 0)
            {
                jobCount += uvInputs.Length;
                switch (uvInputs.Length)
                {
                case 1:
                    texCoords = new VertexBufferTexCoords <VTexCoord1>();
                    break;

                default:
                    texCoords = new VertexBufferTexCoords <VTexCoord2>();
                    break;
                }
            }

            hasColors = colorInput.HasValue;
            if (hasColors)
            {
                jobCount++;
                colors = new VertexBufferColors();
            }

            hasBones = weightsInput.HasValue && jointsInput.HasValue;
            if (hasBones)
            {
                jobCount += 2;
                bones     = new VertexBufferBones();
            }

            NativeArray <JobHandle> handles = new NativeArray <JobHandle>(jobCount, Allocator.Temp);
            int handleIndex = 0;

            fixed(void *input = &(posInput.buffer[posInput.startOffset]))
            {
                var h = GetVector3sJob(
                    input,
                    posInput.count,
                    posInput.type,
                    posInput.byteStride,
                    (Vector3 *)vDataPtr,
                    outputByteStride,
                    posInput.normalize
                    );

                if (h.HasValue)
                {
                    handles[handleIndex] = h.Value;
                    handleIndex++;
                }
                else
                {
                    Profiler.EndSample();
                    return(null);
                }
            }

            if (nrmInput.HasValue)
            {
                fixed(void *input = &(nrmInput.Value.buffer[nrmInput.Value.startOffset]))
                {
                    var h = GetVector3sJob(
                        input,
                        nrmInput.Value.count,
                        nrmInput.Value.type,
                        nrmInput.Value.byteStride,
                        (Vector3 *)(vDataPtr + 12),
                        outputByteStride,
                        nrmInput.Value.normalize
                        );

                    if (h.HasValue)
                    {
                        handles[handleIndex] = h.Value;
                        handleIndex++;
                    }
                    else
                    {
                        Profiler.EndSample();
                        return(null);
                    }
                }
            }

            if (tanInput.HasValue)
            {
                fixed(void *input = &(tanInput.Value.buffer[tanInput.Value.startOffset]))
                {
                    var h = GetTangentsJob(
                        input,
                        tanInput.Value.count,
                        tanInput.Value.type,
                        tanInput.Value.byteStride,
                        (Vector4 *)(vDataPtr + 24),
                        outputByteStride,
                        tanInput.Value.normalize
                        );

                    if (h.HasValue)
                    {
                        handles[handleIndex] = h.Value;
                        handleIndex++;
                    }
                    else
                    {
                        Profiler.EndSample();
                        return(null);
                    }
                }
            }

            if (texCoords != null)
            {
                texCoords.ScheduleVertexUVJobs(uvInputs, new NativeSlice <JobHandle>(handles, handleIndex, uvInputs.Length));
                handleIndex++;
            }

            if (hasColors)
            {
                colors.ScheduleVertexColorJob(colorInput.Value, new NativeSlice <JobHandle>(handles, handleIndex, 1));
                handleIndex++;
            }

            if (hasBones)
            {
                bones.ScheduleVertexBonesJob(weightsInput.Value, jointsInput.Value, new NativeSlice <JobHandle>(handles, handleIndex, 2));
                handleIndex += 2;
            }

            var handle = (jobCount > 1) ? JobHandle.CombineDependencies(handles) : handles[0];

            handles.Dispose();
            Profiler.EndSample();
            return(handle);
        }
Esempio n. 4
0
        public override unsafe bool ScheduleVertexBonesJob(
            VertexInputData weightsInput,
            VertexInputData jointsInput,
            NativeSlice <JobHandle> handles
            )
        {
            Profiler.BeginSample("ScheduleVertexBonesJob");
            Profiler.BeginSample("AllocateNativeArray");
            vData = new NativeArray <VBones>(weightsInput.count, VertexBufferConfigBase.defaultAllocator);
            var vDataPtr = (byte *)NativeArrayUnsafeUtility.GetUnsafeReadOnlyPtr(vData);

            Profiler.EndSample();

            fixed(void *input = &(weightsInput.buffer[weightsInput.startOffset]))
            {
                var h = GetWeightsJob(
                    input,
                    weightsInput.count,
                    weightsInput.type,
                    weightsInput.byteStride,
                    (Vector4 *)vDataPtr,
                    32,
                    weightsInput.normalize
                    );

                if (h.HasValue)
                {
                    handles[0] = h.Value;
                }
                else
                {
                    Profiler.EndSample();
                    return(false);
                }
            }

            fixed(void *input = &(jointsInput.buffer[jointsInput.startOffset]))
            {
                var h = GetJointsJob(
                    input,
                    jointsInput.count,
                    jointsInput.type,
                    jointsInput.byteStride,
                    (uint *)(vDataPtr + 16),
                    32,
                    logger
                    );

                if (h.HasValue)
                {
                    handles[1] = h.Value;
                }
                else
                {
                    Profiler.EndSample();
                    return(false);
                }
            }

            Profiler.EndSample();
            return(true);
        }
Esempio n. 5
0
 public abstract unsafe bool ScheduleVertexBonesJob(
     VertexInputData weightsInput,
     VertexInputData jointsInput,
     NativeSlice <JobHandle> handles
     );
Esempio n. 6
0
 public abstract unsafe bool ScheduleVertexColorJob(VertexInputData colorInput, NativeSlice <JobHandle> handles);