public bool ReadValueByName <T>(string name, out T value) where T : unmanaged
            {
                var v = default(T);

                if (IsValid && IsAttached)
                {
                    lock (lck)
                    {
                        if (IsValid && IsAttached)
                        {
                            if (ModelConstBuffer.TryGetVariableByName(name, out var variable))
                            {
                                return(storage.Read(storageId, variable.StartOffset, out value));
                            }
                            else
                            {
#if DEBUG
                                throw new ArgumentException($"Variable not found in constant buffer {bufferDesc.Name}. Variable = {name}");
#else
                                Technique.EffectsManager.Logger.Log(Logger.LogLevel.Warning, $"Variable not found in constant buffer {bufferDesc.Name}. Variable = {name}");
                                value = v;
                                return(false);
#endif
                            }
                        }
                    }
                }
                value = v;
                return(false);
            }
Ejemplo n.º 2
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);
            }