feat: add camera viewport rect render areas

This commit is contained in:
2026-04-01 13:01:11 +08:00
parent 0fe02fd1b4
commit f80fb9860e
9 changed files with 219 additions and 12 deletions

View File

@@ -25,6 +25,16 @@ void CameraComponent::SetFarClipPlane(float value) {
m_farClipPlane = std::max(m_nearClipPlane + 0.001f, value);
}
void CameraComponent::SetViewportRect(const Math::Rect& value) {
const float x = std::clamp(value.x, 0.0f, 1.0f);
const float y = std::clamp(value.y, 0.0f, 1.0f);
const float width = std::clamp(value.width, 0.0f, 1.0f);
const float height = std::clamp(value.height, 0.0f, 1.0f);
const float right = std::min(1.0f, x + width);
const float bottom = std::min(1.0f, y + height);
m_viewportRect = Math::Rect(x, y, right - x, bottom - y);
}
void CameraComponent::Serialize(std::ostream& os) const {
os << "projection=" << static_cast<int>(m_projectionType) << ";";
os << "fov=" << m_fieldOfView << ";";
@@ -35,6 +45,7 @@ void CameraComponent::Serialize(std::ostream& os) const {
os << "primary=" << (m_primary ? 1 : 0) << ";";
os << "clearMode=" << static_cast<int>(m_clearMode) << ";";
os << "cullingMask=" << m_cullingMask << ";";
os << "viewportRect=" << m_viewportRect.x << "," << m_viewportRect.y << "," << m_viewportRect.width << "," << m_viewportRect.height << ";";
os << "clearColor=" << m_clearColor.r << "," << m_clearColor.g << "," << m_clearColor.b << "," << m_clearColor.a << ";";
}
@@ -71,6 +82,12 @@ void CameraComponent::Deserialize(std::istream& is) {
m_clearMode = static_cast<CameraClearMode>(std::stoi(value));
} else if (key == "cullingMask") {
m_cullingMask = static_cast<uint32_t>(std::stoul(value));
} else if (key == "viewportRect") {
std::replace(value.begin(), value.end(), ',', ' ');
std::istringstream ss(value);
Math::Rect viewportRect;
ss >> viewportRect.x >> viewportRect.y >> viewportRect.width >> viewportRect.height;
SetViewportRect(viewportRect);
} else if (key == "clearColor") {
std::replace(value.begin(), value.end(), ',', ' ');
std::istringstream ss(value);