示例#1
0
void ezRendererTestBasics::RenderObjects(ezBitflags<ezShaderBindFlags> ShaderBindFlags)
{
  ezCamera cam;
  cam.SetCameraMode(ezCameraMode::PerspectiveFixedFovX, 90, 0.5f, 1000.0f);
  cam.LookAt(ezVec3(0, 0, 0), ezVec3(0, 0, -1), ezVec3(0, 1, 0));
  ezMat4 mProj;
  cam.GetProjectionMatrix((float)GetResolution().width / (float)GetResolution().height, mProj);
  ezMat4 mView = cam.GetViewMatrix();

  ezMat4 mTransform, mOther, mRot;

  mRot.SetRotationMatrixX(ezAngle::Degree(-90));

  mOther.SetScalingMatrix(ezVec3(1.0f, 1.0f, 1.0f));
  mTransform.SetTranslationMatrix(ezVec3(-0.3f, -0.3f, 0.0f));
  RenderObject(m_hLongBox, mProj * mView * mTransform * mOther, ezColor(1, 0, 1, 0.25f), ShaderBindFlags);

  mOther.SetRotationMatrixX(ezAngle::Degree(80.0f));
  mTransform.SetTranslationMatrix(ezVec3(0.75f, 0, -1.8f));
  RenderObject(m_hTorus, mProj * mView * mTransform * mOther * mRot, ezColor(1, 0, 0, 0.5f), ShaderBindFlags);

  mOther.SetIdentity();
  mTransform.SetTranslationMatrix(ezVec3(0, 0.1f, -2.0f));
  RenderObject(m_hSphere, mProj * mView * mTransform * mOther, ezColor(0, 1, 0, 0.75f), ShaderBindFlags);

  mOther.SetScalingMatrix(ezVec3(1.5f, 1.0f, 1.0f));
  mTransform.SetTranslationMatrix(ezVec3(-0.6f, -0.2f, -2.2f));
  RenderObject(m_hSphere2, mProj * mView * mTransform * mOther * mRot, ezColor(0, 0, 1, 1), ShaderBindFlags);
}
示例#2
0
ezTestAppRun ezRendererTestBasics::SubtestClearScreen()
{
  BeginFrame();

  switch (m_iFrame)
  {
    case 0:
      ClearScreen(ezColor(1, 0, 0));
      break;
    case 1:
      ClearScreen(ezColor(0, 1, 0));
      break;
    case 2:
      ClearScreen(ezColor(0, 0, 1));
      break;
    case 3:
      ClearScreen(ezColor(0.5f, 0.5f, 0.5f, 0.5f));
      break;
  }

  EZ_TEST_IMAGE(m_iFrame, 1);

  EndFrame();

  return m_iFrame < 3 ? ezTestAppRun::Continue : ezTestAppRun::Quit;
}
示例#3
0
void ezConsole::LogHandler(const ezLoggingEventData& data)
{
  bool bShow = false;
  ezColor color = ezColor::White;

  switch (data.m_EventType)
  {
  case ezLogMsgType::BeginGroup:
  case ezLogMsgType::EndGroup:
  case ezLogMsgType::None:
  case ezLogMsgType::ENUM_COUNT:
  case ezLogMsgType::All:
    return;

  case ezLogMsgType::ErrorMsg:
    color = ezColor(1.0f, 0.1f, 0.1f);
    bShow = true;
    break;
  case ezLogMsgType::SeriousWarningMsg:
    color = ezColor(1.0f, 0.4f, 0.1f);
    bShow = true;
    break;
  case ezLogMsgType::WarningMsg:
    color = ezColor(1.0f, 0.6f, 0.1f);
    break;
  case ezLogMsgType::SuccessMsg:
    color = ezColor(0.1f, 1.0f, 0.1f);
    break;
  case ezLogMsgType::InfoMsg:
    break;
  case ezLogMsgType::DevMsg:
    color = ezColor(200.0f / 255.0f, 200.0f / 255.0f, 200.0f / 255.0f);
    break;
  case ezLogMsgType::DebugMsg:
    color = ezColor(180.0f / 255.0f, 0.1f, 1.0f);
    break;
  }

  ezStringBuilder sFormat;
  sFormat.Format("%*s%s", data.m_uiIndentation, "", data.m_szText);

  AddConsoleString(sFormat.GetData(), color, bShow);
}
示例#4
0
  virtual ezTestAppRun RunSubTest(ezInt32 iIdentifier, ezUInt32 uiInvocationCount) override
  {
    ezImageFormat::Enum format = static_cast<ezImageFormat::Enum>(iIdentifier);

    bool isDecodable = ezImageConversion::IsConvertible(format, defaultFormat);

    if (!isDecodable)
    {
      EZ_TEST_BOOL_MSG(false, "Format %s can be encoded from %s but not decoded - add a decoder for this format please",
                       ezImageFormat::GetName(format), ezImageFormat::GetName(defaultFormat));

      return ezTestAppRun::Quit;
    }

    {
      ezHybridArray<ezImageConversion::ConversionPathNode, 16> decodingPath;
      ezUInt32 decodingPathScratchBuffers;
      ezImageConversion::BuildPath(format, defaultFormat, false, decodingPath, decodingPathScratchBuffers);

      // the [test] tag tells the test framework to output the log message in the GUI
      ezLog::Info("[test]Default decoding Path:");
      for (ezUInt32 i = 0; i < decodingPath.GetCount(); ++i)
      {
        ezLog::Info("[test]  {} -> {}", ezImageFormat::GetName(decodingPath[i].m_sourceFormat),
                       ezImageFormat::GetName(decodingPath[i].m_targetFormat));
      }
    }

    {
      ezHybridArray<ezImageConversion::ConversionPathNode, 16> encodingPath;
      ezUInt32 encodingPathScratchBuffers;
      ezImageConversion::BuildPath(defaultFormat, format, false, encodingPath, encodingPathScratchBuffers);

      // the [test] tag tells the test framework to output the log message in the GUI
      ezLog::Info("[test]Default encoding Path:");
      for (ezUInt32 i = 0; i < encodingPath.GetCount(); ++i)
      {
        ezLog::Info("[test]  {} -> {}", ezImageFormat::GetName(encodingPath[i].m_sourceFormat),
                       ezImageFormat::GetName(encodingPath[i].m_targetFormat));
      }
    }

    // Test LDR: Load, encode to target format, then do image comparison (which internally decodes to BGR8_UNORM again).
    // This visualizes quantization for low bit formats, block compression artifacts, or whether formats have fewer than 3 channels.
    {
      EZ_TEST_BOOL(m_image.LoadFrom("ImageConversions/reference.png").Succeeded());

      EZ_TEST_BOOL(m_image.Convert(format).Succeeded());

      EZ_TEST_IMAGE(iIdentifier * 2, ezImageFormat::IsCompressed(format) ? 10 : 0);
    }

    // Test HDR: Load, decode to FLOAT32, stretch to [-range, range] and encode;
    // then decode to FLOAT32 again, bring back into LDR range and do image comparison.
    // If the format doesn't support negative values, the left half of the image will be black.
    // If the format doesn't support values with absolute value > 1, the image will appear clipped to fullbright.
    // Also, fill the first few rows in the top left with Infinity, -Infinity, and NaN, which should
    // show up as White, White, and Black, resp., in the comparison.
    {
      const float range = 8;

      EZ_TEST_BOOL(m_image.LoadFrom("ImageConversions/reference.png").Succeeded());

      EZ_TEST_BOOL(m_image.Convert(ezImageFormat::R32G32B32A32_FLOAT).Succeeded());

      float posInf = +ezMath::BasicType<float>::GetInfinity();
      float negInf = -ezMath::BasicType<float>::GetInfinity();
      float NaN = ezMath::BasicType<float>::GetNaN();

      for (ezUInt32 y = 0; y < m_image.GetHeight(); ++y)
      {
        ezColor* pPixelPointer = m_image.GetPixelPointer<ezColor>(0, 0, 0, 0, y);

        for (ezUInt32 x = 0; x < m_image.GetWidth(); ++x)
        {
          // Fill with Inf or Nan resp. scale the image into positive and negative HDR range
          if (x < 30 && y < 10)
          {
            *pPixelPointer = ezColor(posInf, posInf, posInf, posInf);
          }
          else if (x < 30 && y < 20)
          {
            *pPixelPointer = ezColor(negInf, negInf, negInf, negInf);
          }
          else if (x < 30 && y < 30)
          {
            *pPixelPointer = ezColor(NaN, NaN, NaN, NaN);
          }
          else
          {
            float scale = (x / float(m_image.GetWidth()) - 0.5f) * 2.0f * range;

            if (ezMath::Abs(scale) > 0.5)
            {
              *pPixelPointer *= scale;
            }
          }

          pPixelPointer++;
        }
      }

      EZ_TEST_BOOL(m_image.Convert(format).Succeeded());

      EZ_TEST_BOOL(m_image.Convert(ezImageFormat::R32G32B32A32_FLOAT).Succeeded());

      for (ezUInt32 y = 0; y < m_image.GetHeight(); ++y)
      {
        ezColor* pPixelPointer = m_image.GetPixelPointer<ezColor>(0, 0, 0, 0, y);

        for (ezUInt32 x = 0; x < m_image.GetWidth(); ++x)
        {
          // Scale the image back into LDR range if possible
          if (x < 30 && y < 10)
          {
            // Leave pos inf as is - this should be clipped to 1 in the LDR conversion for img cmp
          }
          else if (x < 30 && y < 20)
          {
            // Flip neg inf to pos inf
            *pPixelPointer *= -1.0f;
          }
          else if (x < 30 && y < 30)
          {
            // Leave nan as is - this should be clipped to 0 in the LDR conversion for img cmp
          }
          else
          {
            float scale = (x / float(m_image.GetWidth()) - 0.5f) * 2.0f * range;
            if (ezMath::Abs(scale) > 0.5)
            {
              *pPixelPointer /= scale;
            }
          }

          pPixelPointer++;
        }
      }

      EZ_TEST_IMAGE(iIdentifier * 2 + 1, ezImageFormat::IsCompressed(format) ? 10 : 0);
    }

    return ezTestAppRun::Quit;
  }
void OnScreenLogWriter::LogMessageHandler(const ezLoggingEventData& eventData)
{
  // ignore registered input sloat
  if(ezStringUtils::FindSubString(eventData.m_szText, "Registered Input Slot") != NULL)
    return;

  // ignore groups
  if(eventData.m_EventType == ezLogMsgType::BeginGroup)
  {
    m_sCurrentGroup = eventData.m_szText;
    return;
  }
  if(eventData.m_EventType == ezLogMsgType::EndGroup)
  {
    m_sCurrentGroup = "";
    return;
  }

  // split up every line
  const char* text = eventData.m_szText;
  do {
    ezStringBuilder logtext;
    if(m_sCurrentGroup != "")
    {
      logtext.Append("[");
      logtext.Append(m_sCurrentGroup.GetData());
      logtext.Append("] ");
    }

    const char* nextLine = ezStringIterator(text).FindSubString("\n");
    if(nextLine != NULL)
    {
      ezUInt32 count = static_cast<ezUInt32>(nextLine-text);
      ezHybridArray<char, 128> linecpy;
      linecpy.SetCount(count);
      char* data = static_cast<ezArrayPtr<char>>(linecpy).GetPtr();
      ezStringUtils::Copy(data, count, text);
      logtext.Append(data);
      text = nextLine+1;
    }
    else
    {
      logtext.Append(text);
      text = NULL;
    }

    LogEntry newEntry;
    newEntry.text = logtext.GetData();
    switch(eventData.m_EventType)
    {
    case ezLogMsgType::InfoMsg:
      newEntry.color = ezColor(0.4f, 0.4f, 0.4f);
      break;
    case ezLogMsgType::SeriousWarningMsg:
    case ezLogMsgType::WarningMsg:
      newEntry.color = ezColor(1.0f, 0.7f, 0.1f);
      break;
    case ezLogMsgType::ErrorMsg:
      newEntry.color = ezColor::GetRed();
      break;
    case ezLogMsgType::SuccessMsg:
      newEntry.color = ezColor::GetGreen();
      break;
    default:
      newEntry.color = ezColor::GetWhite();
      break;
    }
    if(!m_MessageBuffer.CanAppend())
    {
      m_fOldestItemFade = 1.0f;
      m_MessageBuffer.PopFront();
    }
    m_MessageBuffer.PushBack(newEntry);
  } while(text != NULL);
}