使用WIN32创建编译目标

This commit is contained in:
daiqingshuang
2025-06-12 15:49:46 +08:00
parent 467db07d73
commit 0d4c681699
4 changed files with 403 additions and 399 deletions

View File

@@ -31,6 +31,6 @@ add_subdirectory(third_party/SDL_ttf)
SET(SRC_FILES)
retrieve_files(${CMAKE_CURRENT_SOURCE_DIR}/src SRC_FILES)
add_executable(learn ${SRC_FILES})
add_executable(learn WIN32 ${SRC_FILES})
target_include_directories(learn PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(learn SDL3-static SDL3_ttf-static d3d12)

View File

@@ -32,7 +32,7 @@ void EnableD3D12DebugLayer() {
}
int main(int argc, char* argv[]) {
EnableD3D12DebugLayer();
// EnableD3D12DebugLayer();
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = SDL_CreateWindow("Hello World", 640, 480, 0);
if (window == nullptr) {
@@ -47,7 +47,7 @@ int main(int argc, char* argv[]) {
return 1;
}
SDL3GPU::test_shader_handle_t shader_handle;
test_shader_handle_t shader_handle;
auto result = shader_handle.init(gpu_device);
if (!result) {
SDL_Log("Failed to initialize shader handle: %s", result.error().c_str());
@@ -65,6 +65,9 @@ int main(int argc, char* argv[]) {
SDL_DestroyWindow(window);
return 1;
}
TTF_Font* emoji_font = TTF_OpenFont("C:\\Windows\\Fonts\\wingding.ttf", 24);
TTF_AddFallbackFont(font, emoji_font);
// 设置字体hinting为轻量级
TTF_SetFontHinting(font, TTF_HINTING_LIGHT_SUBPIXEL);
// 设置字体为 SDF 模式
@@ -99,15 +102,15 @@ int main(int argc, char* argv[]) {
const auto render_state = shader_handle.get_render_state(renderer);
SDL_FRect shader_rect = { 0, text_height, text_width, text_height };
test_shader::ParamBuffer param_buffer{};
test_shader_bindings::ParamBuffer param_buffer{};
param_buffer.pos[0] = shader_rect.x;
param_buffer.pos[1] = shader_rect.y;
param_buffer.size[0] = shader_rect.w;
param_buffer.size[1] = shader_rect.h;
param_buffer.raduis[0] = 5;
param_buffer.raduis[1] = 10;
param_buffer.raduis[2] = 0;
param_buffer.raduis[3] = 15;
param_buffer.radius[0] = 5;
param_buffer.radius[1] = 10;
param_buffer.radius[2] = 0;
param_buffer.radius[3] = 15;
shader_handle.set_render_state_uniforms(renderer, param_buffer);
// 生成随机数
@@ -153,3 +156,7 @@ int main(int argc, char* argv[]) {
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
return main(0, nullptr);
}

View File

@@ -7,10 +7,16 @@
#include <cstdint>
#include "shader_handle.h"
namespace SDL3GPU {
class test_shader_bindings {
class test_shader_bindings {
public:
// Uniform buffer structures
struct ParamBuffer {
float pos[2]; // offset: 0, size: 8
float size[2]; // offset: 8, size: 8
float radius[4]; // offset: 16, size: 16
};
// Binding: 0, Size: 32 bytes (aligned: 32)
static constexpr std::array<uint8_t, 4616> pixel_main_blob = {
0x44, 0x58, 0x42, 0x43, 0x8e, 0xb2, 0xde, 0xf0, 0x60, 0x58, 0x8d, 0x29, 0xe2, 0xcd, 0xdf, 0xa6,
0x42, 0x0e, 0xe2, 0xc9, 0x01, 0x00, 0x00, 0x00, 0x08, 0x12, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
@@ -388,9 +394,9 @@ namespace SDL3GPU {
auto it = shader_infos_.find(in_shader_name);
return it != shader_infos_.end() ? &it->second : nullptr;
}
};
};
class test_shader_handle_t : public pixel_shader_handle_t {
class test_shader_handle_t : public pixel_shader_handle_t {
protected:
virtual SDL_GPUShader* create_fragment_shader(SDL_GPUDevice* in_gpu_device) override {
SDL_GPUShaderCreateInfo info{};
@@ -406,5 +412,4 @@ namespace SDL3GPU {
return SDL_CreateGPUShader(in_gpu_device, &info);
}
};
} // namespace SDL3GPU
};

View File

@@ -24,14 +24,6 @@ namespace test_shader {
// Total size: 80 bytes
static_assert(sizeof(vertex_t) == 80, "Vertex struct size mismatch");
// Uniform buffer structures
typedef struct ParamBuffer {
float pos[2];
float size[2];
float raduis[4]; // offset: 64, size: 16
} ParamBuffer;
// Binding: 0, Size: 80 bytes (aligned: 80)
// Vertex attribute descriptions
static constexpr uint32_t VERTEX_ATTRIBUTE_COUNT = 6;