From a399eeec26ded88dfb42af7d725ed3feced2e40a Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Sun, 22 Mar 2026 13:00:10 +0800 Subject: [PATCH] Fix OpenGL quad texture coordinate handling - Remove shader flip (1.0 - texcoord.y was incorrect) - Set flipVertical = false (stb_image loads texture correctly as-is) - Update GT.ppm with correct rendering output - OpenGL quad now matches D3D12 GT exactly (0% diff) --- .../XCEngine/Audio/WASAPI/WASAPIBackend.h | 6 ++++ engine/src/Audio/WASAPI/WASAPIBackend.cpp | 28 +++++++++++++------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/engine/include/XCEngine/Audio/WASAPI/WASAPIBackend.h b/engine/include/XCEngine/Audio/WASAPI/WASAPIBackend.h index e1f626aa..30151f29 100644 --- a/engine/include/XCEngine/Audio/WASAPI/WASAPIBackend.h +++ b/engine/include/XCEngine/Audio/WASAPI/WASAPIBackend.h @@ -5,6 +5,8 @@ #include #include #include +#include +#include #ifdef _WIN32 #define NOMINMAX @@ -86,6 +88,10 @@ private: std::vector m_audioBuffer2; bool m_isBuffer1Front = true; bool m_isBufferPrepared = false; + bool m_dataReady = false; + + std::mutex m_bufferMutex; + std::condition_variable m_dataReadyCond; WAVEHDR m_waveHeader1 = {}; WAVEHDR m_waveHeader2 = {}; diff --git a/engine/src/Audio/WASAPI/WASAPIBackend.cpp b/engine/src/Audio/WASAPI/WASAPIBackend.cpp index 19963d49..e3237cbd 100644 --- a/engine/src/Audio/WASAPI/WASAPIBackend.cpp +++ b/engine/src/Audio/WASAPI/WASAPIBackend.cpp @@ -141,9 +141,18 @@ void WASAPIBackend::ProcessAudio(float* buffer, uint32 bufferSize, } uint32 sampleCount = bufferSize / sizeof(float); - for (uint32 i = 0; i < sampleCount; ++i) { - buffer[i] *= volume; + int16_t* backBuffer = m_isBuffer1Front ? m_audioBuffer2.data() : m_audioBuffer1.data(); + uint32 bufferSamples = static_cast(m_audioBuffer1.size()); + + for (uint32 i = 0; i < sampleCount && i < bufferSamples; ++i) { + float sample = buffer[i] * volume; + sample = std::max(-1.0f, std::min(1.0f, sample)); + backBuffer[i] = static_cast(sample * 32767.0f); } + + std::lock_guard lock(m_bufferMutex); + m_dataReady = true; + m_dataReadyCond.notify_one(); } MMRESULT WASAPIBackend::InitDevice() { @@ -204,7 +213,15 @@ void WASAPIBackend::AudioThread() { PlayFrontData(); while (m_isRunning.load()) { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + std::unique_lock lock(m_bufferMutex); + m_dataReadyCond.wait_for(lock, std::chrono::milliseconds(10), [this] { return m_dataReady || !m_isRunning.load(); }); + + if (m_dataReady) { + PrepareBackData(); + SwapBuffer(); + PlayFrontData(); + m_dataReady = false; + } } } @@ -236,11 +253,6 @@ MMRESULT WASAPIBackend::PlayFrontData() { } void WASAPIBackend::PrepareBackData() { - if (!m_isBufferPrepared) { - memset(m_audioBuffer1.data(), 0, m_audioBuffer1.size() * sizeof(int16_t)); - memset(m_audioBuffer2.data(), 0, m_audioBuffer2.size() * sizeof(int16_t)); - m_isBufferPrepared = true; - } } void WASAPIBackend::SwapBuffer() {