1
0
This commit is contained in:
2026-01-08 20:25:33 +08:00
parent 886e0caab2
commit 55ed60c643
7 changed files with 50 additions and 55 deletions

View File

@@ -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); // 自动计算顶点数

View File

@@ -11,7 +11,7 @@ namespace basalt::presenter::cmd_client {
DATA_READY = 0x01, ///< Presenter -> Trainer
DATA_RECEIVED = 0x02, ///< Trainer -> Presenter
ACTIVELY_STOP = 0x21, ///< Presenter-->Trainer
STOP_REQUEST = 0X71, ///< Presenter<--Trainer
STOP_REQUEST = 0x71, ///< Presenter<--Trainer
STOP_RESPONSE = 0x72, ///< Presenter-->Trainer
};

View File

@@ -77,7 +77,7 @@ namespace basalt::presenter::dll_loader {
}
}
void *DllLoader::GetFunctionPointer(const char *name) {
void *DllLoader::get_function_pointer(const char *name) {
if (!m_Handle) throw std::runtime_error("Can not fetch function pointer on not loaded dynamic library.");
#if defined(BASALT_OS_WINDOWS)
return (void *) GetProcAddress(m_Handle, name);

View File

@@ -28,21 +28,21 @@ namespace basalt::presenter::dll_loader {
~DllLoader();
private:
void* GetFunctionPointer(const char* name);
void* get_function_pointer(const char* name);
public:
template<typename T>
T* CreateInstance() {
T* create_instance() {
using Fct = T* (*) ();
constexpr char EXPOSE_FUNC_NAME[] = "BSCreateInstance";
auto fct = (Fct) GetFunctionPointer(EXPOSE_FUNC_NAME);
auto fct = (Fct) get_function_pointer(EXPOSE_FUNC_NAME);
return fct();
}
template<typename T>
void DestroyInstance(T* instance) {
void destroy_instance(T* instance) {
using Fct = void (*)(T*);
constexpr char EXPOSE_FUNC_NAME[] = "BSDestroyInstance";
auto fct = (Fct) GetFunctionPointer(EXPOSE_FUNC_NAME);
auto fct = (Fct) get_function_pointer(EXPOSE_FUNC_NAME);
fct(instance);
}

View File

@@ -1,6 +1,15 @@
#include "dll_loader.hpp"
#include "cmd_client.hpp"
#include <basalt/char_types.hpp>
#include <basalt/engine.hpp>
#include <basalt/deliver.hpp>
namespace engine = ::basalt::shared::engine;
using engine::EngineConfig;
using engine::IEngine;
namespace deliver = ::basalt::shared::deliver;
using deliver::DeliverConfig;
using deliver::IDeliver;
namespace dll_loader = ::basalt::presenter::dll_loader;
using dll_loader::DllKind;
@@ -15,18 +24,18 @@ int main(int argc, char* argv[]) {
auto client = CmdClient();
auto payload = client.wait_handshake();
//auto* engine = engine_dll.CreateInstance<Kernel::IEngine>();
//auto* deliver = deliver_dll.CreateInstance<Kernel::IDeliver>();
auto* engine = engine_dll.create_instance<IEngine>();
//auto* deliver = deliver_dll.create_instance<IDeliver>();
//Kernel::EngineConfig engine_config{.headless = false, .title = BSTEXT("Fuck You"), .width = payload.width, .height = payload.height};
//engine->startup(std::move(engine_config));
EngineConfig engine_config{.headless = false, .width = payload.width, .height = payload.height};
engine->startup(std::move(engine_config));
while (true) {
auto req_stop = false; //engine->tick();
auto req_stop = engine->tick();
auto can_stop = client.tick(req_stop);
if (can_stop) break;
}
//engine->shutdown();
//engine_dll.DestroyInstance(engine);
engine->shutdown();
engine_dll.destroy_instance(engine);
}