Beispiel #1
0
ezAngle ezCamera::GetFovX(float fAspectRatioWidthDivHeight) const
{
  if (m_Mode == PerspectiveFixedFovX)
    return ezAngle::Degree(m_fFovOrDim);

  if (m_Mode == PerspectiveFixedFovY)
    return ezAngle::Degree(m_fFovOrDim) * fAspectRatioWidthDivHeight;

  EZ_REPORT_FAILURE("You cannot get the camera FOV when it is not a perspective camera.");
  return ezAngle();
}
Beispiel #2
0
void ezExpressionVM::Execute(const ezExpressionByteCode& byteCode, ezArrayPtr<const ezExpression::Stream> inputs,
                             ezArrayPtr<ezExpression::Stream> outputs, ezUInt32 uiNumInstances)
{
  // Input mapping
  {
    auto inputNames = byteCode.GetInputs();

    m_InputMapping.Clear();
    m_InputMapping.Reserve(inputNames.GetCount());

    for (auto& inputName : inputNames)
    {
      bool bInputFound = false;

      for (ezUInt32 i = 0; i < inputs.GetCount(); ++i)
      {
        if (inputs[i].m_sName == inputName)
        {
          inputs[i].ValidateDataSize(uiNumInstances, "Input");

          m_InputMapping.PushBack(i);
          bInputFound = true;
          break;
        }
      }

      EZ_ASSERT_DEV(bInputFound, "Bytecode expects an input '{0}'", inputName);
    }
  }

  // Output mapping
  {
    auto outputNames = byteCode.GetOutputs();

    m_OutputMapping.Clear();
    m_OutputMapping.Reserve(outputNames.GetCount());

    for (auto& outputName : outputNames)
    {
      bool bOutputFound = false;

      for (ezUInt32 i = 0; i < outputs.GetCount(); ++i)
      {
        if (outputs[i].m_sName == outputName)
        {
          outputs[i].ValidateDataSize(uiNumInstances, "Output");

          m_OutputMapping.PushBack(i);
          bOutputFound = true;
          break;
        }
      }

      EZ_ASSERT_DEV(bOutputFound, "Bytecode expects an output '{0}'", outputName);
    }
  }

  ezSimdVec4f* pRegisters = m_Registers.GetData();
  const ezUInt32 uiNumRegisters = (uiNumInstances + 3) / 4;
  const ezUInt32 uiLastInstanceIndex = uiNumInstances - 1;

  const ezUInt32 uiTotalNumRegisters = byteCode.GetNumTempRegisters() * uiNumRegisters;
  if (uiTotalNumRegisters > m_Registers.GetCount())
  {
    EZ_REPORT_FAILURE("Not enough registers to execute bytecode. Needs {0} but only has {1}.", uiTotalNumRegisters, m_Registers.GetCount());
    return;
  }

  // Execute bytecode
  const ezExpressionByteCode::StorageType* pByteCode = byteCode.GetByteCode();
  const ezExpressionByteCode::StorageType* pByteCodeEnd = byteCode.GetByteCodeEnd();

  while (pByteCode < pByteCodeEnd)
  {
    ezExpressionByteCode::OpCode::Enum opCode = ezExpressionByteCode::GetOpCode(pByteCode);

    switch (opCode)
    {
        // unary
      case ezExpressionByteCode::OpCode::Abs_R:
        VMOperation1(pByteCode, pRegisters, uiNumRegisters, [](const ezSimdVec4f& x) { return x.Abs(); });
        break;

      case ezExpressionByteCode::OpCode::Sqrt_R:
        VMOperation1(pByteCode, pRegisters, uiNumRegisters, [](const ezSimdVec4f& x) { return x.GetSqrt(); });
        break;

      case ezExpressionByteCode::OpCode::Mov_R:
        VMOperation1(pByteCode, pRegisters, uiNumRegisters, [](const ezSimdVec4f& x) { return x; });
        break;

      case ezExpressionByteCode::OpCode::Mov_C:
        VMOperation1_C(pByteCode, pRegisters, uiNumRegisters, [](const ezSimdVec4f& x) { return x; });
        break;

      case ezExpressionByteCode::OpCode::Mov_I:
        VMLoadInput(pByteCode, pRegisters, uiNumRegisters, inputs, m_InputMapping);
        break;

      case ezExpressionByteCode::OpCode::Mov_O:
        VMStoreOutput(pByteCode, pRegisters, uiNumRegisters, outputs, m_OutputMapping);
        break;

        // binary
      case ezExpressionByteCode::OpCode::Add_RR:
        VMOperation2(pByteCode, pRegisters, uiNumRegisters, [](const ezSimdVec4f& a, const ezSimdVec4f& b) { return a + b; });
        break;

      case ezExpressionByteCode::OpCode::Add_CR:
        VMOperation2_C(pByteCode, pRegisters, uiNumRegisters, [](const ezSimdVec4f& a, const ezSimdVec4f& b) { return a + b; });
        break;

      case ezExpressionByteCode::OpCode::Sub_RR:
        VMOperation2(pByteCode, pRegisters, uiNumRegisters, [](const ezSimdVec4f& a, const ezSimdVec4f& b) { return a - b; });
        break;

      case ezExpressionByteCode::OpCode::Sub_CR:
        VMOperation2_C(pByteCode, pRegisters, uiNumRegisters, [](const ezSimdVec4f& a, const ezSimdVec4f& b) { return a - b; });
        break;

      case ezExpressionByteCode::OpCode::Mul_RR:
        VMOperation2(pByteCode, pRegisters, uiNumRegisters, [](const ezSimdVec4f& a, const ezSimdVec4f& b) { return a.CompMul(b); });
        break;

      case ezExpressionByteCode::OpCode::Mul_CR:
        VMOperation2_C(pByteCode, pRegisters, uiNumRegisters, [](const ezSimdVec4f& a, const ezSimdVec4f& b) { return a.CompMul(b); });
        break;

      case ezExpressionByteCode::OpCode::Div_RR:
        VMOperation2(pByteCode, pRegisters, uiNumRegisters, [](const ezSimdVec4f& a, const ezSimdVec4f& b) { return a.CompDiv(b); });
        break;

      case ezExpressionByteCode::OpCode::Div_CR:
        VMOperation2_C(pByteCode, pRegisters, uiNumRegisters, [](const ezSimdVec4f& a, const ezSimdVec4f& b) { return a.CompDiv(b); });
        break;

      case ezExpressionByteCode::OpCode::Min_RR:
        VMOperation2(pByteCode, pRegisters, uiNumRegisters, [](const ezSimdVec4f& a, const ezSimdVec4f& b) { return a.CompMin(b); });
        break;

      case ezExpressionByteCode::OpCode::Min_CR:
        VMOperation2_C(pByteCode, pRegisters, uiNumRegisters, [](const ezSimdVec4f& a, const ezSimdVec4f& b) { return a.CompMin(b); });
        break;

      case ezExpressionByteCode::OpCode::Max_RR:
        VMOperation2(pByteCode, pRegisters, uiNumRegisters, [](const ezSimdVec4f& a, const ezSimdVec4f& b) { return a.CompMax(b); });
        break;

      case ezExpressionByteCode::OpCode::Max_CR:
        VMOperation2_C(pByteCode, pRegisters, uiNumRegisters, [](const ezSimdVec4f& a, const ezSimdVec4f& b) { return a.CompMax(b); });
        break;

        // call
      case ezExpressionByteCode::OpCode::Call:
        VMCall(pByteCode, pRegisters, uiNumRegisters);
        break;

      default:
        EZ_ASSERT_NOT_IMPLEMENTED;
        return;
    }
  }
}
Beispiel #3
0
void ezJSONWriter::WriteVariant(const ezVariant& value)
{
  switch (value.GetType())
  {
  case ezVariant::Type::Invalid:
    //EZ_REPORT_FAILURE("Variant of Type 'Invalid' cannot be written as JSON.");
    WriteNULL();
    return;
  case ezVariant::Type::Bool:
    WriteBool(value.Get<bool>());
    return;
  case ezVariant::Type::Int8:
    WriteInt32(value.Get<ezInt8>());
    return;
  case ezVariant::Type::UInt8:
    WriteUInt32(value.Get<ezUInt8>());
    return;
  case ezVariant::Type::Int16:
    WriteInt32(value.Get<ezInt16>());
    return;
  case ezVariant::Type::UInt16:
    WriteUInt32(value.Get<ezUInt16>());
    return;
  case ezVariant::Type::Int32:
    WriteInt32(value.Get<ezInt32>());
    return;
  case ezVariant::Type::UInt32:
    WriteUInt32(value.Get<ezUInt32>());
    return;
  case ezVariant::Type::Int64:
    WriteInt64(value.Get<ezInt64>());
    return;
  case ezVariant::Type::UInt64:
    WriteUInt64(value.Get<ezUInt64>());
    return;
  case ezVariant::Type::Float:
    WriteFloat(value.Get<float>());
    return;
  case ezVariant::Type::Double:
    WriteDouble(value.Get<double>());
    return;
  case ezVariant::Type::Color:
    WriteColor(value.Get<ezColor>());
    return;
  case ezVariant::Type::Vector2:
    WriteVec2(value.Get<ezVec2>());
    return;
  case ezVariant::Type::Vector3:
    WriteVec3(value.Get<ezVec3>());
    return;
  case ezVariant::Type::Vector4:
    WriteVec4(value.Get<ezVec4>());
    return;
  case ezVariant::Type::Quaternion:
    WriteQuat(value.Get<ezQuat>());
    return;
  case ezVariant::Type::Matrix3:
    WriteMat3(value.Get<ezMat3>());
    return;
  case ezVariant::Type::Matrix4:
    WriteMat4(value.Get<ezMat4>());
    return;
  case ezVariant::Type::String:
    WriteString(value.Get<ezString>().GetData());
    return;
  case ezVariant::Type::Time:
    WriteTime(value.Get<ezTime>());
    return;
  case ezVariant::Type::Uuid:
    WriteUuid(value.Get<ezUuid>());
    return;

  default:
    break;
  }

  EZ_REPORT_FAILURE("The Variant Type %i is not supported by ezJSONWriter::WriteVariant.", value.GetType());
}
Beispiel #4
0
void ezJSONWriter::WriteMat4(const ezMat4& value)
{
  EZ_REPORT_FAILURE("The complex data type ezMat4 is not supported by this JSON writer.");
}
Beispiel #5
0
void ezJSONWriter::WriteColor(const ezColor& value)
{
  EZ_REPORT_FAILURE("The complex data type ezColor is not supported by this JSON writer.");
}
Beispiel #6
0
static ezQtPropertyWidget* StandardTypeCreator(const ezRTTI* pRtti)
{
  EZ_ASSERT_DEV(pRtti->GetTypeFlags().IsSet(ezTypeFlags::StandardType),
                "This function is only valid for StandardType properties, regardless of category");

  if (pRtti == ezGetStaticRTTI<ezVariant>())
  {
    return new ezQtVariantPropertyWidget();
  }

  switch (pRtti->GetVariantType())
  {
    case ezVariant::Type::Bool:
      return new ezQtPropertyEditorCheckboxWidget();

    case ezVariant::Type::Time:
      return new ezQtPropertyEditorTimeWidget();

    case ezVariant::Type::Float:
    case ezVariant::Type::Double:
      return new ezQtPropertyEditorDoubleSpinboxWidget(1);

    case ezVariant::Type::Vector2:
      return new ezQtPropertyEditorDoubleSpinboxWidget(2);

    case ezVariant::Type::Vector3:
      return new ezQtPropertyEditorDoubleSpinboxWidget(3);

    case ezVariant::Type::Vector4:
      return new ezQtPropertyEditorDoubleSpinboxWidget(4);

    case ezVariant::Type::Quaternion:
      return new ezQtPropertyEditorQuaternionWidget();

    case ezVariant::Type::Int8:
      return new ezQtPropertyEditorIntSpinboxWidget(-127, 127);

    case ezVariant::Type::UInt8:
      return new ezQtPropertyEditorIntSpinboxWidget(0, 255);

    case ezVariant::Type::Int16:
      return new ezQtPropertyEditorIntSpinboxWidget(-32767, 32767);

    case ezVariant::Type::UInt16:
      return new ezQtPropertyEditorIntSpinboxWidget(0, 65535);

    case ezVariant::Type::Int32:
    case ezVariant::Type::Int64:
      return new ezQtPropertyEditorIntSpinboxWidget(-2147483645, 2147483645);

    case ezVariant::Type::UInt32:
    case ezVariant::Type::UInt64:
      return new ezQtPropertyEditorIntSpinboxWidget(0, 2147483645);

    case ezVariant::Type::String:
      return new ezQtPropertyEditorLineEditWidget();

    case ezVariant::Type::Color:
    case ezVariant::Type::ColorGamma:
      return new ezQtPropertyEditorColorWidget();

    case ezVariant::Type::Angle:
      return new ezQtPropertyEditorAngleWidget();


    default:
      EZ_REPORT_FAILURE("No default property widget available for type: {0}", pRtti->GetTypeName());
      return nullptr;
  }
}
Beispiel #7
0
const char* GetProfileName(const char* szPlatform, ezGALShaderStage::Enum Stage)
{
  if (ezStringUtils::IsEqual(szPlatform, "DX11_SM40_93"))
  {
    switch (Stage)
    {
      case ezGALShaderStage::VertexShader:
        return "vs_4_0_level_9_3";
      case ezGALShaderStage::PixelShader:
        return "ps_4_0_level_9_3";
      default:
        break;
    }
  }

  if (ezStringUtils::IsEqual(szPlatform, "DX11_SM40"))
  {
    switch (Stage)
    {
      case ezGALShaderStage::VertexShader:
        return "vs_4_0";
      case ezGALShaderStage::GeometryShader:
        return "gs_4_0";
      case ezGALShaderStage::PixelShader:
        return "ps_4_0";
      case ezGALShaderStage::ComputeShader:
        return "cs_4_0";
      default:
        break;
    }
  }

  if (ezStringUtils::IsEqual(szPlatform, "DX11_SM41"))
  {
    switch (Stage)
    {
      case ezGALShaderStage::GeometryShader:
        return "gs_4_0";
      case ezGALShaderStage::VertexShader:
        return "vs_4_1";
      case ezGALShaderStage::PixelShader:
        return "ps_4_1";
      case ezGALShaderStage::ComputeShader:
        return "cs_4_1";
      default:
        break;
    }
  }

  if (ezStringUtils::IsEqual(szPlatform, "DX11_SM50"))
  {
    switch (Stage)
    {
      case ezGALShaderStage::VertexShader:
        return "vs_5_0";
      case ezGALShaderStage::HullShader:
        return "hs_5_0";
      case ezGALShaderStage::DomainShader:
        return "ds_5_0";
      case ezGALShaderStage::GeometryShader:
        return "gs_5_0";
      case ezGALShaderStage::PixelShader:
        return "ps_5_0";
      case ezGALShaderStage::ComputeShader:
        return "cs_5_0";
      default:
        break;
    }
  }

  EZ_REPORT_FAILURE("Unknown Platform '{0}' or Stage {1}", szPlatform, Stage);
  return "";
}
Beispiel #8
0
void ezRTTI::SanityCheckType(ezRTTI* pType)
{
  EZ_ASSERT_DEV(pType->GetTypeFlags().IsSet(ezTypeFlags::StandardType) + pType->GetTypeFlags().IsSet(ezTypeFlags::IsEnum) +
                        pType->GetTypeFlags().IsSet(ezTypeFlags::Bitflags) + pType->GetTypeFlags().IsSet(ezTypeFlags::Class) ==
                    1,
                "Types are mutually exclusive!");

  for (auto pProp : pType->m_Properties)
  {
    const ezRTTI* pSpecificType = pProp->GetSpecificType();

    EZ_ASSERT_DEBUG(IsValidIdentifierName(pProp->GetPropertyName()), "Property name is invalid: '{0}'", pProp->GetPropertyName());

    // if (!IsValidIdentifierName(pProp->GetPropertyName()))
    //{
    //  ezStringBuilder s;
    //  s.Format("RTTI: {0}\n", pProp->GetPropertyName());

    //  OutputDebugStringA(s.GetData());
    //}

    if (pProp->GetCategory() != ezPropertyCategory::Function)
    {
      EZ_ASSERT_DEV(pProp->GetFlags().IsSet(ezPropertyFlags::StandardType) + pProp->GetFlags().IsSet(ezPropertyFlags::IsEnum) +
                            pProp->GetFlags().IsSet(ezPropertyFlags::Bitflags) + pProp->GetFlags().IsSet(ezPropertyFlags::Class) <=
                        1,
                    "Types are mutually exclusive!");
    }

    switch (pProp->GetCategory())
    {
      case ezPropertyCategory::Constant:
      {
        EZ_ASSERT_DEV(pSpecificType->GetTypeFlags().IsSet(ezTypeFlags::StandardType), "Only standard type constants are supported!");
      }
      break;
      case ezPropertyCategory::Member:
      {
        EZ_ASSERT_DEV(pProp->GetFlags().IsSet(ezPropertyFlags::StandardType) ==
                          pSpecificType->GetTypeFlags().IsSet(ezTypeFlags::StandardType),
                      "Property-Type missmatch!");
        EZ_ASSERT_DEV(pProp->GetFlags().IsSet(ezPropertyFlags::IsEnum) == pSpecificType->GetTypeFlags().IsSet(ezTypeFlags::IsEnum),
                      "Property-Type missmatch! Use EZ_BEGIN_STATIC_REFLECTED_ENUM for type and EZ_ENUM_MEMBER_PROPERTY / "
                      "EZ_ENUM_ACCESSOR_PROPERTY for property.");
        EZ_ASSERT_DEV(pProp->GetFlags().IsSet(ezPropertyFlags::Bitflags) == pSpecificType->GetTypeFlags().IsSet(ezTypeFlags::Bitflags),
                      "Property-Type missmatch! Use EZ_BEGIN_STATIC_REFLECTED_ENUM for type and EZ_BITFLAGS_MEMBER_PROPERTY / "
                      "EZ_BITFLAGS_ACCESSOR_PROPERTY for property.");
        EZ_ASSERT_DEV(pProp->GetFlags().IsSet(ezPropertyFlags::Class) == pSpecificType->GetTypeFlags().IsSet(ezTypeFlags::Class),
                      "If ezPropertyFlags::Class is set, the property type must be ezTypeFlags::Class and vise versa.");
      }
      break;
      case ezPropertyCategory::Array:
      case ezPropertyCategory::Set:
      case ezPropertyCategory::Map:
      {
        EZ_ASSERT_DEV(pProp->GetFlags().IsSet(ezPropertyFlags::StandardType) ==
                          pSpecificType->GetTypeFlags().IsSet(ezTypeFlags::StandardType),
                      "Property-Type missmatch!");
        EZ_ASSERT_DEV(pProp->GetFlags().IsSet(ezPropertyFlags::Class) == pSpecificType->GetTypeFlags().IsSet(ezTypeFlags::Class),
                      "If ezPropertyFlags::Class is set, the property type must be ezTypeFlags::Class and vise versa.");
      }
      break;
      case ezPropertyCategory::Function:
        EZ_REPORT_FAILURE("Functions need to be put into the EZ_BEGIN_FUNCTIONS / EZ_END_FUNCTIONS; block.");
        break;
    }
  }
}