예제 #1
0
            /// <summary>
            /// Updates the material structure. And upload data to constant buffer
            /// </summary>
            /// <typeparam name="T"></typeparam>
            /// <param name="context">The context.</param>
            /// <param name="model">The model.</param>
            public bool UpdateMaterialStruct <T>(DeviceContextProxy context, ref T model) where T : unmanaged
            {
                if (!initialized)
                {
                    return(false);
                }
                if (NeedUpdate)
                {
                    lock (updateLock)
                    {
                        if (NeedUpdate)
                        {
                            UpdateInternalVariables(context);
                            NeedUpdate = false;
                        }
                    }
                }
                var structSize = UnsafeHelper.SizeOf <T>();
                var box        = materialCB.Map(context);

                UnsafeHelper.Write(box.DataPointer, ref model);
                var succ = storage.Read(storageId, structSize,
                                        box.DataPointer + structSize,
                                        storage.StructSize - structSize);

                materialCB.Unmap(context);
                return(succ);
            }
예제 #2
0
            /// <summary>
            /// Updates the non material structure.
            /// </summary>
            /// <typeparam name="T"></typeparam>
            /// <param name="context">The context.</param>
            /// <param name="model">The model.</param>
            /// <returns></returns>
            public bool UpdateNonMaterialStruct <T>(DeviceContextProxy context, ref T model) where T : unmanaged
            {
                if (!initialized)
                {
                    return(false);
                }
                if (UnsafeHelper.SizeOf <T>() != nonMaterialCB.StructureSize)
                {
                    Debug.Assert(false);
                    return(false);
                }
                var box = nonMaterialCB.Map(context);

                UnsafeHelper.Write(box.DataPointer, ref model);
                nonMaterialCB.Unmap(context);
                return(true);
            }