重构:将 NanoVDB 加载改为固定初始化步骤
修改内容: 1. 移除 RunNanoVDBTest 测试函数 2. NanoVDB 加载现在作为程序初始化的标准步骤 3. 简化代码流程,直接调用 LoadNanoVDB 4. 保留调试输出便于排查问题
This commit is contained in:
48
main.cpp
48
main.cpp
@@ -15,33 +15,6 @@
|
||||
|
||||
LPCWSTR gWindowClassName = L"BattleFire";
|
||||
|
||||
void RunNanoVDBTest() {
|
||||
ID3D12GraphicsCommandList* commandList = GetCommandList();
|
||||
ID3D12CommandAllocator* commandAllocator = GetCommandAllocator();
|
||||
const char* vdbFiles[] = {
|
||||
"Res/NanoVDB/bunny.nvdb"
|
||||
};
|
||||
|
||||
NanoVDBData vdbData = {};
|
||||
|
||||
for (int i = 0; i < sizeof(vdbFiles) / sizeof(vdbFiles[0]); i++) {
|
||||
const char* currentVdbFile = vdbFiles[i];
|
||||
printf("[NanoVDB Test] Loading: %s\n", currentVdbFile);
|
||||
|
||||
bool loadSuccess = LoadNanoVDB(currentVdbFile, vdbData, commandList, commandAllocator);
|
||||
if (loadSuccess) {
|
||||
printf(" SUCCESS - %llu bytes, %llu elements\n",
|
||||
(unsigned long long)vdbData.byteSize,
|
||||
(unsigned long long)vdbData.elementCount);
|
||||
} else {
|
||||
printf(" FAILED\n");
|
||||
}
|
||||
}
|
||||
printf("[NanoVDB Test] Done.\n");
|
||||
|
||||
FreeNanoVDB(vdbData);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WindowProc(HWND inHWND, UINT inMSG, WPARAM inWParam, LPARAM inLParam) {
|
||||
switch (inMSG) {
|
||||
case WM_CLOSE:
|
||||
@@ -105,15 +78,13 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
|
||||
ID3D12GraphicsCommandList* commandList = GetCommandList();
|
||||
ID3D12CommandAllocator* commandAllocator = GetCommandAllocator();
|
||||
|
||||
bool runTest = true; // set to true to run NanoVDB test
|
||||
if (runTest) {
|
||||
RunNanoVDBTest();
|
||||
}
|
||||
printf("After NanoVDB test\n");
|
||||
NanoVDBData nanoVDBData = {};
|
||||
LoadNanoVDB("Res/NanoVDB/bunny.nvdb", nanoVDBData, commandList, commandAllocator);
|
||||
printf("NanoVDB loaded: %llu bytes\n", (unsigned long long)nanoVDBData.byteSize);
|
||||
|
||||
StaticMeshComponent staticMeshComponent;
|
||||
staticMeshComponent.InitFromFile(commandList, "Res/Model/Sphere.lhsm");
|
||||
printf("Mesh loaded, vertex count: %d\n", staticMeshComponent.mVertexCount);
|
||||
printf("Mesh loaded\n");
|
||||
|
||||
ID3D12RootSignature* rootSignature = InitRootSignature();
|
||||
printf("Root signature created\n");
|
||||
@@ -122,12 +93,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
|
||||
CreateShaderFromFile(L"Res/Shader/gs.hlsl", "MainGS", "gs_5_1", &gs);
|
||||
CreateShaderFromFile(L"Res/Shader/gs.hlsl", "MainPS", "ps_5_1", &ps);
|
||||
ID3D12PipelineState*pso=CreatePSO(rootSignature, vs, ps, gs);
|
||||
printf("PSO created: %p\n", pso);
|
||||
|
||||
ID3D12Device* device = GetD3DDevice();
|
||||
if (device->GetDeviceRemovedReason() != S_OK) {
|
||||
printf("DEVICE REMOVED! Reason: 0x%08X\n", device->GetDeviceRemovedReason());
|
||||
}
|
||||
printf("PSO created\n");
|
||||
|
||||
ID3D12Resource* cb = CreateConstantBufferObject(65536);//1024x64(4x4)
|
||||
DirectX::XMMATRIX projectionMatrix=DirectX::XMMatrixPerspectiveFovLH(
|
||||
@@ -165,12 +131,10 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
|
||||
UpdateConstantBuffer(sb, materialDatas, sizeof(MaterialData) * 3000);
|
||||
|
||||
int imageWidth, imageHeight,imageChannel;
|
||||
//stbi_set_flip_vertically_on_load(true);
|
||||
stbi_uc* pixels = stbi_load("Res/Image/earth_d.jpg", &imageWidth, &imageHeight, &imageChannel, 4);
|
||||
printf("Texture loaded: %dx%d, pixels=%p\n", imageWidth, imageHeight, pixels);
|
||||
printf("Texture loaded: %dx%d\n", imageWidth, imageHeight);
|
||||
ID3D12Resource* texture = CreateTexture2D(commandList, pixels,
|
||||
imageWidth * imageHeight * imageChannel, imageWidth, imageHeight,DXGI_FORMAT_R8G8B8A8_UNORM);
|
||||
printf("Texture created: %p\n", texture);
|
||||
delete[]pixels;
|
||||
ID3D12Device* d3dDevice = GetD3DDevice();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user