fix bug
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include <basalt/export_macro.hpp>
|
||||
#include <basalt/kernel.hpp>
|
||||
#include <basalt/engine.hpp>
|
||||
#include <windows.h>
|
||||
#include <d3d11.h>
|
||||
#include <d3dcompiler.h>
|
||||
@@ -28,10 +28,9 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
|
||||
}
|
||||
|
||||
// Create a render window for DirectX
|
||||
static HWND CreateRenderWindow(std::uint32_t width, std::uint32_t height, const std::wstring_view& title) {
|
||||
static HWND CreateRenderWindow(std::uint32_t width, std::uint32_t height) {
|
||||
static bool g_CLSREG = false;
|
||||
constexpr wchar_t class_name[] = L"DirectXRenderWindowClass";
|
||||
std::wstring c_title(title);
|
||||
|
||||
if (!g_CLSREG) {
|
||||
WNDCLASSEXW wc = {0};
|
||||
@@ -55,7 +54,7 @@ static HWND CreateRenderWindow(std::uint32_t width, std::uint32_t height, const
|
||||
|
||||
HWND hwnd = CreateWindowExW(0,
|
||||
class_name,
|
||||
c_title.c_str(),
|
||||
L"DirectXRenderWindow",
|
||||
WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME ^ WS_MAXIMIZEBOX,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
@@ -161,8 +160,9 @@ const char* g_PS = R"(
|
||||
}
|
||||
)";
|
||||
|
||||
using ::Basalt::Shared::Kernel::EngineConfig;
|
||||
using ::Basalt::Shared::Kernel::IEngine;
|
||||
namespace engine = ::basalt::shared::engine;
|
||||
using engine::EngineConfig;
|
||||
using engine::IEngine;
|
||||
|
||||
class DirectX11Engine : public IEngine {
|
||||
public:
|
||||
@@ -197,7 +197,7 @@ public:
|
||||
if (this->config.headless) {
|
||||
window = NULL;
|
||||
} else {
|
||||
window = CreateRenderWindow(this->config.width, this->config.height, this->config.title);
|
||||
window = CreateRenderWindow(this->config.width, this->config.height);
|
||||
ShowWindow(window, SW_SHOW);
|
||||
UpdateWindow(window);
|
||||
}
|
||||
@@ -314,6 +314,17 @@ public:
|
||||
// return;
|
||||
//}
|
||||
|
||||
// 设置管线
|
||||
context->OMSetRenderTargets(1, rtv.GetAddressOf(), dsv.Get());
|
||||
context->OMSetDepthStencilState(depth_state.Get(), 1);
|
||||
context->RSSetState(rasterizer_state.Get());
|
||||
context->VSSetShader(vs.Get(), nullptr, 0);
|
||||
context->PSSetShader(ps.Get(), nullptr, 0);
|
||||
context->IASetInputLayout(input_layout.Get());
|
||||
UINT stride = sizeof(Vertex), offset = 0;
|
||||
context->IASetVertexBuffers(0, 1, vertex_buffer.GetAddressOf(), &stride, &offset);
|
||||
context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
|
||||
// 缩放深度数据数组到指定大小
|
||||
depth_data.resize(this->config.width * this->config.height * sizeof(float));
|
||||
|
||||
@@ -331,17 +342,6 @@ public:
|
||||
context->ClearRenderTargetView(rtv.Get(), clear_color);
|
||||
context->ClearDepthStencilView(dsv.Get(), D3D11_CLEAR_DEPTH, 1.0f, 0);
|
||||
|
||||
// 设置管线
|
||||
context->OMSetRenderTargets(1, rtv.GetAddressOf(), dsv.Get());
|
||||
context->OMSetDepthStencilState(depth_state.Get(), 1);
|
||||
context->RSSetState(rasterizer_state.Get());
|
||||
context->VSSetShader(vs.Get(), nullptr, 0);
|
||||
context->PSSetShader(ps.Get(), nullptr, 0);
|
||||
context->IASetInputLayout(input_layout.Get());
|
||||
UINT stride = sizeof(Vertex), offset = 0;
|
||||
context->IASetVertexBuffers(0, 1, vertex_buffer.GetAddressOf(), &stride, &offset);
|
||||
context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
|
||||
// 绘制立方体
|
||||
context->Draw(sizeof(CubeVertices) / sizeof(Vertex), 0); // 自动计算顶点数
|
||||
|
||||
|
||||
Reference in New Issue
Block a user