2026-03-27 15:05:15 +08:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
2026-04-02 22:33:04 +08:00
|
|
|
#include "../RenderingIntegrationMain.h"
|
|
|
|
|
|
2026-03-27 15:05:15 +08:00
|
|
|
#include <XCEngine/Components/CameraComponent.h>
|
|
|
|
|
#include <XCEngine/Components/GameObject.h>
|
|
|
|
|
#include <XCEngine/Components/MeshFilterComponent.h>
|
|
|
|
|
#include <XCEngine/Components/MeshRendererComponent.h>
|
|
|
|
|
#include <XCEngine/Core/Asset/IResource.h>
|
|
|
|
|
#include <XCEngine/Core/Math/Color.h>
|
|
|
|
|
#include <XCEngine/Core/Math/Quaternion.h>
|
|
|
|
|
#include <XCEngine/Core/Math/Vector2.h>
|
|
|
|
|
#include <XCEngine/Core/Math/Vector3.h>
|
|
|
|
|
#include <XCEngine/Debug/ConsoleLogSink.h>
|
|
|
|
|
#include <XCEngine/Debug/Logger.h>
|
|
|
|
|
#include <XCEngine/Rendering/RenderContext.h>
|
|
|
|
|
#include <XCEngine/Rendering/RenderSurface.h>
|
|
|
|
|
#include <XCEngine/Rendering/SceneRenderer.h>
|
|
|
|
|
#include <XCEngine/Resources/Material/Material.h>
|
|
|
|
|
#include <XCEngine/Resources/Mesh/Mesh.h>
|
|
|
|
|
#include <XCEngine/Resources/Texture/Texture.h>
|
|
|
|
|
#include <XCEngine/RHI/RHITexture.h>
|
|
|
|
|
#include <XCEngine/Scene/Scene.h>
|
|
|
|
|
|
|
|
|
|
#include "../../../RHI/integration/fixtures/RHIIntegrationFixture.h"
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
using namespace XCEngine::Components;
|
|
|
|
|
using namespace XCEngine::Debug;
|
|
|
|
|
using namespace XCEngine::Math;
|
|
|
|
|
using namespace XCEngine::Rendering;
|
|
|
|
|
using namespace XCEngine::Resources;
|
|
|
|
|
using namespace XCEngine::RHI;
|
|
|
|
|
using namespace XCEngine::RHI::Integration;
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
constexpr const char* kD3D12Screenshot = "material_state_scene_d3d12.ppm";
|
|
|
|
|
constexpr const char* kOpenGLScreenshot = "material_state_scene_opengl.ppm";
|
2026-04-02 04:00:58 +08:00
|
|
|
constexpr const char* kVulkanScreenshot = "material_state_scene_vulkan.ppm";
|
2026-03-27 15:05:15 +08:00
|
|
|
constexpr uint32_t kFrameWidth = 1280;
|
|
|
|
|
constexpr uint32_t kFrameHeight = 720;
|
|
|
|
|
constexpr float kPi = 3.1415926535f;
|
|
|
|
|
|
|
|
|
|
Mesh* CreateQuadMesh() {
|
|
|
|
|
auto* mesh = new Mesh();
|
|
|
|
|
IResource::ConstructParams params = {};
|
|
|
|
|
params.name = "MaterialStateQuad";
|
|
|
|
|
params.path = "Tests/Rendering/MaterialStateQuad.mesh";
|
|
|
|
|
params.guid = ResourceGUID::Generate(params.path);
|
|
|
|
|
mesh->Initialize(params);
|
|
|
|
|
|
|
|
|
|
StaticMeshVertex vertices[4] = {};
|
|
|
|
|
vertices[0].position = Vector3(-1.0f, -1.0f, 0.0f);
|
|
|
|
|
vertices[0].uv0 = Vector2(0.0f, 1.0f);
|
|
|
|
|
vertices[1].position = Vector3(-1.0f, 1.0f, 0.0f);
|
|
|
|
|
vertices[1].uv0 = Vector2(0.0f, 0.0f);
|
|
|
|
|
vertices[2].position = Vector3(1.0f, -1.0f, 0.0f);
|
|
|
|
|
vertices[2].uv0 = Vector2(1.0f, 1.0f);
|
|
|
|
|
vertices[3].position = Vector3(1.0f, 1.0f, 0.0f);
|
|
|
|
|
vertices[3].uv0 = Vector2(1.0f, 0.0f);
|
|
|
|
|
|
|
|
|
|
const uint32_t indices[6] = { 0, 1, 2, 2, 1, 3 };
|
|
|
|
|
mesh->SetVertexData(
|
|
|
|
|
vertices,
|
|
|
|
|
sizeof(vertices),
|
|
|
|
|
4,
|
|
|
|
|
sizeof(StaticMeshVertex),
|
|
|
|
|
VertexAttribute::Position | VertexAttribute::UV0);
|
|
|
|
|
mesh->SetIndexData(indices, sizeof(indices), 6, true);
|
|
|
|
|
|
|
|
|
|
MeshSection section = {};
|
|
|
|
|
section.baseVertex = 0;
|
|
|
|
|
section.vertexCount = 4;
|
|
|
|
|
section.startIndex = 0;
|
|
|
|
|
section.indexCount = 6;
|
|
|
|
|
section.materialID = 0;
|
|
|
|
|
mesh->AddSection(section);
|
|
|
|
|
return mesh;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Texture* CreateSolidTexture(const char* name, const char* path, const unsigned char rgba[4]) {
|
|
|
|
|
auto* texture = new Texture();
|
|
|
|
|
IResource::ConstructParams params = {};
|
|
|
|
|
params.name = name;
|
|
|
|
|
params.path = path;
|
|
|
|
|
params.guid = ResourceGUID::Generate(params.path);
|
|
|
|
|
texture->Initialize(params);
|
|
|
|
|
texture->Create(
|
|
|
|
|
1,
|
|
|
|
|
1,
|
|
|
|
|
1,
|
|
|
|
|
1,
|
|
|
|
|
XCEngine::Resources::TextureType::Texture2D,
|
|
|
|
|
XCEngine::Resources::TextureFormat::RGBA8_UNORM,
|
|
|
|
|
rgba,
|
|
|
|
|
4);
|
|
|
|
|
return texture;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Material* CreateMaterial(
|
|
|
|
|
const char* name,
|
|
|
|
|
const char* path,
|
|
|
|
|
Texture* texture,
|
|
|
|
|
MaterialRenderQueue renderQueue,
|
|
|
|
|
const MaterialRenderState& renderState) {
|
|
|
|
|
auto* material = new Material();
|
|
|
|
|
IResource::ConstructParams params = {};
|
|
|
|
|
params.name = name;
|
|
|
|
|
params.path = path;
|
|
|
|
|
params.guid = ResourceGUID::Generate(params.path);
|
|
|
|
|
material->Initialize(params);
|
|
|
|
|
material->SetTexture("_BaseColorTexture", ResourceHandle<Texture>(texture));
|
|
|
|
|
material->SetRenderQueue(renderQueue);
|
|
|
|
|
material->SetRenderState(renderState);
|
|
|
|
|
return material;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GameObject* CreateQuadObject(
|
|
|
|
|
Scene& scene,
|
|
|
|
|
const char* name,
|
|
|
|
|
Mesh* mesh,
|
|
|
|
|
Material* material,
|
|
|
|
|
const Vector3& position,
|
|
|
|
|
const Vector3& scale,
|
|
|
|
|
const Quaternion& rotation = Quaternion::Identity()) {
|
|
|
|
|
GameObject* gameObject = scene.CreateGameObject(name);
|
|
|
|
|
gameObject->GetTransform()->SetLocalPosition(position);
|
|
|
|
|
gameObject->GetTransform()->SetLocalScale(scale);
|
|
|
|
|
gameObject->GetTransform()->SetLocalRotation(rotation);
|
|
|
|
|
|
|
|
|
|
auto* meshFilter = gameObject->AddComponent<MeshFilterComponent>();
|
|
|
|
|
auto* meshRenderer = gameObject->AddComponent<MeshRendererComponent>();
|
|
|
|
|
meshFilter->SetMesh(ResourceHandle<Mesh>(mesh));
|
|
|
|
|
meshRenderer->SetMaterial(0, ResourceHandle<Material>(material));
|
|
|
|
|
return gameObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* GetScreenshotFilename(RHIType backendType) {
|
2026-04-02 04:00:58 +08:00
|
|
|
switch (backendType) {
|
|
|
|
|
case RHIType::D3D12:
|
|
|
|
|
return kD3D12Screenshot;
|
|
|
|
|
case RHIType::Vulkan:
|
|
|
|
|
return kVulkanScreenshot;
|
|
|
|
|
case RHIType::OpenGL:
|
|
|
|
|
default:
|
|
|
|
|
return kOpenGLScreenshot;
|
|
|
|
|
}
|
2026-03-27 15:05:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GetComparisonThreshold(RHIType backendType) {
|
|
|
|
|
(void)backendType;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MaterialStateSceneTest : public RHIIntegrationFixture {
|
|
|
|
|
protected:
|
|
|
|
|
void SetUp() override;
|
|
|
|
|
void TearDown() override;
|
|
|
|
|
void RenderFrame() override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void BuildScene();
|
|
|
|
|
RHIResourceView* GetCurrentBackBufferView();
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<Scene> mScene;
|
|
|
|
|
std::unique_ptr<SceneRenderer> mSceneRenderer;
|
|
|
|
|
std::vector<RHIResourceView*> mBackBufferViews;
|
|
|
|
|
std::vector<Texture*> mTextures;
|
|
|
|
|
std::vector<Material*> mMaterials;
|
|
|
|
|
RHITexture* mDepthTexture = nullptr;
|
|
|
|
|
RHIResourceView* mDepthView = nullptr;
|
|
|
|
|
Mesh* mMesh = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void MaterialStateSceneTest::SetUp() {
|
|
|
|
|
RHIIntegrationFixture::SetUp();
|
|
|
|
|
|
|
|
|
|
mSceneRenderer = std::make_unique<SceneRenderer>();
|
|
|
|
|
mScene = std::make_unique<Scene>("MaterialStateScene");
|
|
|
|
|
mMesh = CreateQuadMesh();
|
|
|
|
|
|
|
|
|
|
BuildScene();
|
|
|
|
|
|
|
|
|
|
TextureDesc depthDesc = {};
|
|
|
|
|
depthDesc.width = kFrameWidth;
|
|
|
|
|
depthDesc.height = kFrameHeight;
|
|
|
|
|
depthDesc.depth = 1;
|
|
|
|
|
depthDesc.mipLevels = 1;
|
|
|
|
|
depthDesc.arraySize = 1;
|
|
|
|
|
depthDesc.format = static_cast<uint32_t>(Format::D24_UNorm_S8_UInt);
|
|
|
|
|
depthDesc.textureType = static_cast<uint32_t>(XCEngine::RHI::TextureType::Texture2D);
|
|
|
|
|
depthDesc.sampleCount = 1;
|
|
|
|
|
depthDesc.sampleQuality = 0;
|
|
|
|
|
depthDesc.flags = 0;
|
|
|
|
|
mDepthTexture = GetDevice()->CreateTexture(depthDesc);
|
|
|
|
|
ASSERT_NE(mDepthTexture, nullptr);
|
|
|
|
|
|
|
|
|
|
ResourceViewDesc depthViewDesc = {};
|
|
|
|
|
depthViewDesc.format = static_cast<uint32_t>(Format::D24_UNorm_S8_UInt);
|
|
|
|
|
depthViewDesc.dimension = ResourceViewDimension::Texture2D;
|
|
|
|
|
depthViewDesc.mipLevel = 0;
|
|
|
|
|
mDepthView = GetDevice()->CreateDepthStencilView(mDepthTexture, depthViewDesc);
|
|
|
|
|
ASSERT_NE(mDepthView, nullptr);
|
|
|
|
|
|
|
|
|
|
mBackBufferViews.resize(2, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaterialStateSceneTest::TearDown() {
|
|
|
|
|
mSceneRenderer.reset();
|
|
|
|
|
|
|
|
|
|
if (mDepthView != nullptr) {
|
|
|
|
|
mDepthView->Shutdown();
|
|
|
|
|
delete mDepthView;
|
|
|
|
|
mDepthView = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mDepthTexture != nullptr) {
|
|
|
|
|
mDepthTexture->Shutdown();
|
|
|
|
|
delete mDepthTexture;
|
|
|
|
|
mDepthTexture = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (RHIResourceView*& backBufferView : mBackBufferViews) {
|
|
|
|
|
if (backBufferView != nullptr) {
|
|
|
|
|
backBufferView->Shutdown();
|
|
|
|
|
delete backBufferView;
|
|
|
|
|
backBufferView = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mBackBufferViews.clear();
|
|
|
|
|
|
|
|
|
|
mScene.reset();
|
|
|
|
|
|
|
|
|
|
for (Material* material : mMaterials) {
|
|
|
|
|
delete material;
|
|
|
|
|
}
|
|
|
|
|
mMaterials.clear();
|
|
|
|
|
|
|
|
|
|
for (Texture* texture : mTextures) {
|
|
|
|
|
delete texture;
|
|
|
|
|
}
|
|
|
|
|
mTextures.clear();
|
|
|
|
|
|
|
|
|
|
delete mMesh;
|
|
|
|
|
mMesh = nullptr;
|
|
|
|
|
|
|
|
|
|
RHIIntegrationFixture::TearDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaterialStateSceneTest::BuildScene() {
|
|
|
|
|
ASSERT_NE(mScene, nullptr);
|
|
|
|
|
ASSERT_NE(mMesh, nullptr);
|
|
|
|
|
|
|
|
|
|
GameObject* cameraObject = mScene->CreateGameObject("MainCamera");
|
|
|
|
|
auto* camera = cameraObject->AddComponent<CameraComponent>();
|
|
|
|
|
camera->SetPrimary(true);
|
|
|
|
|
camera->SetProjectionType(CameraProjectionType::Orthographic);
|
|
|
|
|
camera->SetOrthographicSize(2.05f);
|
|
|
|
|
camera->SetNearClipPlane(0.1f);
|
|
|
|
|
camera->SetFarClipPlane(10.0f);
|
|
|
|
|
camera->SetClearColor(XCEngine::Math::Color(0.04f, 0.05f, 0.08f, 1.0f));
|
|
|
|
|
|
|
|
|
|
const unsigned char backgroundPixel[4] = { 58, 88, 164, 255 };
|
|
|
|
|
const unsigned char centerPixel[4] = { 242, 236, 220, 255 };
|
|
|
|
|
const unsigned char backCullVisiblePixel[4] = { 84, 220, 128, 255 };
|
|
|
|
|
const unsigned char backCullHiddenPixel[4] = { 232, 86, 86, 255 };
|
|
|
|
|
const unsigned char frontCullHiddenPixel[4] = { 244, 180, 72, 255 };
|
|
|
|
|
const unsigned char frontCullVisiblePixel[4] = { 78, 188, 238, 255 };
|
|
|
|
|
const unsigned char farTransparentPixel[4] = { 238, 104, 170, 160 };
|
|
|
|
|
const unsigned char nearTransparentPixel[4] = { 96, 236, 142, 160 };
|
|
|
|
|
|
|
|
|
|
Texture* backgroundTexture = CreateSolidTexture(
|
|
|
|
|
"BackgroundTexture",
|
|
|
|
|
"Tests/Rendering/MaterialState/background.texture",
|
|
|
|
|
backgroundPixel);
|
|
|
|
|
Texture* centerTexture = CreateSolidTexture(
|
|
|
|
|
"CenterTexture",
|
|
|
|
|
"Tests/Rendering/MaterialState/center.texture",
|
|
|
|
|
centerPixel);
|
|
|
|
|
Texture* backCullVisibleTexture = CreateSolidTexture(
|
|
|
|
|
"BackCullVisibleTexture",
|
|
|
|
|
"Tests/Rendering/MaterialState/back_visible.texture",
|
|
|
|
|
backCullVisiblePixel);
|
|
|
|
|
Texture* backCullHiddenTexture = CreateSolidTexture(
|
|
|
|
|
"BackCullHiddenTexture",
|
|
|
|
|
"Tests/Rendering/MaterialState/back_hidden.texture",
|
|
|
|
|
backCullHiddenPixel);
|
|
|
|
|
Texture* frontCullHiddenTexture = CreateSolidTexture(
|
|
|
|
|
"FrontCullHiddenTexture",
|
|
|
|
|
"Tests/Rendering/MaterialState/front_hidden.texture",
|
|
|
|
|
frontCullHiddenPixel);
|
|
|
|
|
Texture* frontCullVisibleTexture = CreateSolidTexture(
|
|
|
|
|
"FrontCullVisibleTexture",
|
|
|
|
|
"Tests/Rendering/MaterialState/front_visible.texture",
|
|
|
|
|
frontCullVisiblePixel);
|
|
|
|
|
Texture* farTransparentTexture = CreateSolidTexture(
|
|
|
|
|
"FarTransparentTexture",
|
|
|
|
|
"Tests/Rendering/MaterialState/far_transparent.texture",
|
|
|
|
|
farTransparentPixel);
|
|
|
|
|
Texture* nearTransparentTexture = CreateSolidTexture(
|
|
|
|
|
"NearTransparentTexture",
|
|
|
|
|
"Tests/Rendering/MaterialState/near_transparent.texture",
|
|
|
|
|
nearTransparentPixel);
|
|
|
|
|
mTextures = {
|
|
|
|
|
backgroundTexture,
|
|
|
|
|
centerTexture,
|
|
|
|
|
backCullVisibleTexture,
|
|
|
|
|
backCullHiddenTexture,
|
|
|
|
|
frontCullHiddenTexture,
|
|
|
|
|
frontCullVisibleTexture,
|
|
|
|
|
farTransparentTexture,
|
|
|
|
|
nearTransparentTexture
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MaterialRenderState opaqueState = {};
|
|
|
|
|
opaqueState.depthTestEnable = true;
|
|
|
|
|
opaqueState.depthWriteEnable = true;
|
|
|
|
|
opaqueState.depthFunc = MaterialComparisonFunc::LessEqual;
|
|
|
|
|
opaqueState.cullMode = MaterialCullMode::None;
|
|
|
|
|
|
|
|
|
|
MaterialRenderState backCullState = opaqueState;
|
|
|
|
|
backCullState.cullMode = MaterialCullMode::Back;
|
|
|
|
|
|
|
|
|
|
MaterialRenderState frontCullState = opaqueState;
|
|
|
|
|
frontCullState.cullMode = MaterialCullMode::Front;
|
|
|
|
|
|
|
|
|
|
MaterialRenderState transparentState = {};
|
|
|
|
|
transparentState.blendEnable = true;
|
|
|
|
|
transparentState.srcBlend = MaterialBlendFactor::SrcAlpha;
|
|
|
|
|
transparentState.dstBlend = MaterialBlendFactor::InvSrcAlpha;
|
|
|
|
|
transparentState.srcBlendAlpha = MaterialBlendFactor::One;
|
|
|
|
|
transparentState.dstBlendAlpha = MaterialBlendFactor::Zero;
|
|
|
|
|
transparentState.depthTestEnable = true;
|
|
|
|
|
transparentState.depthWriteEnable = false;
|
|
|
|
|
transparentState.depthFunc = MaterialComparisonFunc::LessEqual;
|
|
|
|
|
transparentState.cullMode = MaterialCullMode::None;
|
|
|
|
|
|
|
|
|
|
Material* backgroundMaterial = CreateMaterial(
|
|
|
|
|
"BackgroundMaterial",
|
|
|
|
|
"Tests/Rendering/MaterialState/background.mat",
|
|
|
|
|
backgroundTexture,
|
|
|
|
|
MaterialRenderQueue::Geometry,
|
|
|
|
|
opaqueState);
|
|
|
|
|
Material* centerMaterial = CreateMaterial(
|
|
|
|
|
"CenterMaterial",
|
|
|
|
|
"Tests/Rendering/MaterialState/center.mat",
|
|
|
|
|
centerTexture,
|
|
|
|
|
MaterialRenderQueue::Geometry,
|
|
|
|
|
opaqueState);
|
|
|
|
|
Material* backCullVisibleMaterial = CreateMaterial(
|
|
|
|
|
"BackCullVisibleMaterial",
|
|
|
|
|
"Tests/Rendering/MaterialState/back_visible.mat",
|
|
|
|
|
backCullVisibleTexture,
|
|
|
|
|
MaterialRenderQueue::Geometry,
|
|
|
|
|
backCullState);
|
|
|
|
|
Material* backCullHiddenMaterial = CreateMaterial(
|
|
|
|
|
"BackCullHiddenMaterial",
|
|
|
|
|
"Tests/Rendering/MaterialState/back_hidden.mat",
|
|
|
|
|
backCullHiddenTexture,
|
|
|
|
|
MaterialRenderQueue::Geometry,
|
|
|
|
|
backCullState);
|
|
|
|
|
Material* frontCullHiddenMaterial = CreateMaterial(
|
|
|
|
|
"FrontCullHiddenMaterial",
|
|
|
|
|
"Tests/Rendering/MaterialState/front_hidden.mat",
|
|
|
|
|
frontCullHiddenTexture,
|
|
|
|
|
MaterialRenderQueue::Geometry,
|
|
|
|
|
frontCullState);
|
|
|
|
|
Material* frontCullVisibleMaterial = CreateMaterial(
|
|
|
|
|
"FrontCullVisibleMaterial",
|
|
|
|
|
"Tests/Rendering/MaterialState/front_visible.mat",
|
|
|
|
|
frontCullVisibleTexture,
|
|
|
|
|
MaterialRenderQueue::Geometry,
|
|
|
|
|
frontCullState);
|
|
|
|
|
Material* farTransparentMaterial = CreateMaterial(
|
|
|
|
|
"FarTransparentMaterial",
|
|
|
|
|
"Tests/Rendering/MaterialState/far_transparent.mat",
|
|
|
|
|
farTransparentTexture,
|
|
|
|
|
MaterialRenderQueue::Transparent,
|
|
|
|
|
transparentState);
|
|
|
|
|
Material* nearTransparentMaterial = CreateMaterial(
|
|
|
|
|
"NearTransparentMaterial",
|
|
|
|
|
"Tests/Rendering/MaterialState/near_transparent.mat",
|
|
|
|
|
nearTransparentTexture,
|
|
|
|
|
MaterialRenderQueue::Transparent,
|
|
|
|
|
transparentState);
|
|
|
|
|
mMaterials = {
|
|
|
|
|
backgroundMaterial,
|
|
|
|
|
centerMaterial,
|
|
|
|
|
backCullVisibleMaterial,
|
|
|
|
|
backCullHiddenMaterial,
|
|
|
|
|
frontCullHiddenMaterial,
|
|
|
|
|
frontCullVisibleMaterial,
|
|
|
|
|
farTransparentMaterial,
|
|
|
|
|
nearTransparentMaterial
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CreateQuadObject(
|
|
|
|
|
*mScene,
|
|
|
|
|
"Background",
|
|
|
|
|
mMesh,
|
|
|
|
|
backgroundMaterial,
|
|
|
|
|
Vector3(0.0f, 0.0f, 4.0f),
|
|
|
|
|
Vector3(2.95f, 1.88f, 1.0f));
|
|
|
|
|
|
|
|
|
|
CreateQuadObject(
|
|
|
|
|
*mScene,
|
|
|
|
|
"CenterPanel",
|
|
|
|
|
mMesh,
|
|
|
|
|
centerMaterial,
|
|
|
|
|
Vector3(0.0f, 0.0f, 3.0f),
|
|
|
|
|
Vector3(0.34f, 1.22f, 1.0f));
|
|
|
|
|
|
|
|
|
|
CreateQuadObject(
|
|
|
|
|
*mScene,
|
|
|
|
|
"BackCullVisible",
|
|
|
|
|
mMesh,
|
|
|
|
|
backCullVisibleMaterial,
|
|
|
|
|
Vector3(-1.9f, 1.08f, 2.9f),
|
|
|
|
|
Vector3(0.60f, 0.60f, 1.0f));
|
|
|
|
|
|
|
|
|
|
CreateQuadObject(
|
|
|
|
|
*mScene,
|
|
|
|
|
"BackCullHidden",
|
|
|
|
|
mMesh,
|
|
|
|
|
backCullHiddenMaterial,
|
|
|
|
|
Vector3(1.9f, 1.08f, 2.9f),
|
|
|
|
|
Vector3(0.60f, 0.60f, 1.0f),
|
|
|
|
|
Quaternion::FromAxisAngle(Vector3::Up(), kPi));
|
|
|
|
|
|
|
|
|
|
CreateQuadObject(
|
|
|
|
|
*mScene,
|
|
|
|
|
"FrontCullHidden",
|
|
|
|
|
mMesh,
|
|
|
|
|
frontCullHiddenMaterial,
|
|
|
|
|
Vector3(-1.9f, -1.08f, 2.9f),
|
|
|
|
|
Vector3(0.60f, 0.60f, 1.0f));
|
|
|
|
|
|
|
|
|
|
CreateQuadObject(
|
|
|
|
|
*mScene,
|
|
|
|
|
"FrontCullVisible",
|
|
|
|
|
mMesh,
|
|
|
|
|
frontCullVisibleMaterial,
|
|
|
|
|
Vector3(1.9f, -1.08f, 2.9f),
|
|
|
|
|
Vector3(0.60f, 0.60f, 1.0f),
|
|
|
|
|
Quaternion::FromAxisAngle(Vector3::Up(), kPi));
|
|
|
|
|
|
|
|
|
|
CreateQuadObject(
|
|
|
|
|
*mScene,
|
|
|
|
|
"FarTransparent",
|
|
|
|
|
mMesh,
|
|
|
|
|
farTransparentMaterial,
|
|
|
|
|
Vector3(-0.16f, 0.0f, 3.36f),
|
|
|
|
|
Vector3(0.94f, 1.02f, 1.0f),
|
|
|
|
|
Quaternion::FromAxisAngle(Vector3::Up(), 0.54f));
|
|
|
|
|
|
|
|
|
|
CreateQuadObject(
|
|
|
|
|
*mScene,
|
|
|
|
|
"NearTransparent",
|
|
|
|
|
mMesh,
|
|
|
|
|
nearTransparentMaterial,
|
|
|
|
|
Vector3(0.16f, 0.0f, 2.64f),
|
|
|
|
|
Vector3(0.94f, 1.02f, 1.0f),
|
|
|
|
|
Quaternion::FromAxisAngle(Vector3::Up(), -0.54f));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RHIResourceView* MaterialStateSceneTest::GetCurrentBackBufferView() {
|
|
|
|
|
const int backBufferIndex = GetCurrentBackBufferIndex();
|
|
|
|
|
if (backBufferIndex < 0) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (static_cast<size_t>(backBufferIndex) >= mBackBufferViews.size()) {
|
|
|
|
|
mBackBufferViews.resize(static_cast<size_t>(backBufferIndex) + 1, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mBackBufferViews[backBufferIndex] == nullptr) {
|
|
|
|
|
ResourceViewDesc viewDesc = {};
|
|
|
|
|
viewDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
|
|
|
viewDesc.dimension = ResourceViewDimension::Texture2D;
|
|
|
|
|
viewDesc.mipLevel = 0;
|
|
|
|
|
mBackBufferViews[backBufferIndex] = GetDevice()->CreateRenderTargetView(GetCurrentBackBuffer(), viewDesc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return mBackBufferViews[backBufferIndex];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaterialStateSceneTest::RenderFrame() {
|
|
|
|
|
ASSERT_NE(mScene, nullptr);
|
|
|
|
|
ASSERT_NE(mSceneRenderer, nullptr);
|
|
|
|
|
|
|
|
|
|
RHICommandList* commandList = GetCommandList();
|
|
|
|
|
ASSERT_NE(commandList, nullptr);
|
|
|
|
|
|
|
|
|
|
commandList->Reset();
|
|
|
|
|
|
|
|
|
|
RenderSurface surface(kFrameWidth, kFrameHeight);
|
|
|
|
|
surface.SetColorAttachment(GetCurrentBackBufferView());
|
|
|
|
|
surface.SetDepthAttachment(mDepthView);
|
|
|
|
|
|
|
|
|
|
RenderContext renderContext = {};
|
|
|
|
|
renderContext.device = GetDevice();
|
|
|
|
|
renderContext.commandList = commandList;
|
|
|
|
|
renderContext.commandQueue = GetCommandQueue();
|
|
|
|
|
renderContext.backendType = GetBackendType();
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(mSceneRenderer->Render(*mScene, nullptr, renderContext, surface));
|
|
|
|
|
|
|
|
|
|
commandList->Close();
|
|
|
|
|
void* commandLists[] = { commandList };
|
|
|
|
|
GetCommandQueue()->ExecuteCommandLists(1, commandLists);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_P(MaterialStateSceneTest, RenderMaterialStateScene) {
|
|
|
|
|
RHICommandQueue* commandQueue = GetCommandQueue();
|
|
|
|
|
RHISwapChain* swapChain = GetSwapChain();
|
|
|
|
|
const int targetFrameCount = 30;
|
|
|
|
|
const char* screenshotFilename = GetScreenshotFilename(GetBackendType());
|
|
|
|
|
const int comparisonThreshold = GetComparisonThreshold(GetBackendType());
|
|
|
|
|
|
|
|
|
|
for (int frameCount = 0; frameCount <= targetFrameCount; ++frameCount) {
|
|
|
|
|
if (frameCount > 0) {
|
|
|
|
|
commandQueue->WaitForPreviousFrame();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BeginRender();
|
|
|
|
|
RenderFrame();
|
|
|
|
|
|
|
|
|
|
if (frameCount >= targetFrameCount) {
|
|
|
|
|
commandQueue->WaitForIdle();
|
|
|
|
|
ASSERT_TRUE(TakeScreenshot(screenshotFilename));
|
|
|
|
|
ASSERT_TRUE(CompareWithGoldenTemplate(screenshotFilename, "GT.ppm", static_cast<float>(comparisonThreshold)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
swapChain->Present(0, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_SUITE_P(D3D12, MaterialStateSceneTest, ::testing::Values(RHIType::D3D12));
|
|
|
|
|
INSTANTIATE_TEST_SUITE_P(OpenGL, MaterialStateSceneTest, ::testing::Values(RHIType::OpenGL));
|
2026-04-02 04:00:58 +08:00
|
|
|
#if defined(XCENGINE_SUPPORT_VULKAN)
|
|
|
|
|
INSTANTIATE_TEST_SUITE_P(Vulkan, MaterialStateSceneTest, ::testing::Values(RHIType::Vulkan));
|
|
|
|
|
#endif
|
2026-03-27 15:05:15 +08:00
|
|
|
|
|
|
|
|
GTEST_API_ int main(int argc, char** argv) {
|
2026-04-02 22:33:04 +08:00
|
|
|
return RunRenderingIntegrationTestMain(argc, argv);
|
2026-03-27 15:05:15 +08:00
|
|
|
}
|