public void CompileAndBind(DeviceContext context) { foreach (var v in m_Values) { var property = m_Definition.GetPropertyForName(v.Key); m_Writer.Seek(property.byteOffset, SeekOrigin.Begin); CustomConstantBufferDefinition.ConstantType type = property.type; Object value = v.Value; BufferWriteType(type, value); } var paramProperties = m_Definition.GetParamProperties(); foreach (var paramPropertyP in paramProperties) { m_Writer.Seek(paramPropertyP.byteOffset, SeekOrigin.Begin); CustomConstantBufferDefinition.ConstantType type = paramPropertyP.type; Object value = paramPropertyP.paramValue; BufferWriteType(type, value); } var scriptedProperties = m_Definition.GetScriptedProperties(); if (scriptedProperties.Count > 0) { using (Lua luaContext = new Lua()) { foreach (var globalBuffer in s_AllGlobalInstances) { foreach (var val in globalBuffer.m_Values) { string name = val.Key; object value = val.Value; FillScriptLuaContext(luaContext, name, value); } var bufferParamProperties = globalBuffer.m_Definition.GetParamProperties(); foreach (var param in bufferParamProperties) { string name = param.name; object value = param.paramValue; FillScriptLuaContext(luaContext, name, value); } } if (!s_AllGlobalInstances.Contains(this)) { foreach (var val in m_Values) { string name = val.Key; object value = val.Value; FillScriptLuaContext(luaContext, name, value); } var bufferParamProperties = m_Definition.GetParamProperties(); foreach (var param in bufferParamProperties) { string name = param.name; object value = param.paramValue; FillScriptLuaContext(luaContext, name, value); } } // Execute! luaContext.DoString(m_Definition.m_Script); foreach (var scriptedProperty in scriptedProperties) { m_Writer.Seek(scriptedProperty.byteOffset, SeekOrigin.Begin); CustomConstantBufferDefinition.ConstantType type = scriptedProperty.type; float value = (float)(double)luaContext[scriptedProperty.name]; BufferWriteType(type, value); } } } m_Writer.Flush(); ContextHelper.SetConstantBuffer(context, null, m_Definition.m_Register); DataBox box = context.MapSubresource(m_ConstantBuffer, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None); box.Data.Write(m_DataBuffer, 0, m_Size); context.UnmapSubresource(m_ConstantBuffer, 0); ContextHelper.SetConstantBuffer(context, m_ConstantBuffer, m_Definition.m_Register); }