64 lines
1.7 KiB
C++
64 lines
1.7 KiB
C++
|
#include "RHI/RHICommondList.h"
|
||
|
|
||
|
#include "RHI/RHICommond.h"
|
||
|
#include "RHI/RHI.h"
|
||
|
#include "Core/Thread/ThreadChecker.h"
|
||
|
|
||
|
RHICommonList::RHICommonList() noexcept {
|
||
|
INFOLOG("actor self:{}", spdlog::fmt_lib::ptr(this));
|
||
|
}
|
||
|
|
||
|
RHICommonList::~RHICommonList() {
|
||
|
INFOLOG("dctor self:{}", spdlog::fmt_lib::ptr(this));
|
||
|
}
|
||
|
|
||
|
RHICommonList::Ptr RHICommonList::Create() {
|
||
|
RHICommonList::Ptr Self(new RHICommonList());
|
||
|
return Self;
|
||
|
}
|
||
|
|
||
|
bool RHICommonList::Start() {
|
||
|
isRunning_ = true;
|
||
|
thread_ = std::make_unique<std::thread>([this]() {
|
||
|
SetThreadName("renderThread");
|
||
|
|
||
|
DriverSettings& driverSetting = RHI::Get()->GetDriverSettings();
|
||
|
if (nullptr == driverSetting.renderMakeCurrentContext) {
|
||
|
return;
|
||
|
}
|
||
|
driverSetting.renderMakeCurrentContext();
|
||
|
RHI::Get()->InitRenderEnv();
|
||
|
while (isRunning_) {
|
||
|
{
|
||
|
std::unique_lock<std::mutex> lock(queueMutex_);
|
||
|
queueCondVar_.wait(lock, [this]() { return !queue_.empty() || !isRunning_; });
|
||
|
|
||
|
while (!queue_.empty() && isRunning_) {
|
||
|
SharedPtr<RHICommond> commond = queue_.front();
|
||
|
queue_.pop();
|
||
|
commond->Execute();
|
||
|
}
|
||
|
}
|
||
|
driverSetting.renderSwapBuffers();
|
||
|
}
|
||
|
});
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void RHICommonList::Stop() {
|
||
|
isRunning_ = false;
|
||
|
|
||
|
if (thread_ && thread_->joinable()) {
|
||
|
thread_->join();
|
||
|
thread_.reset();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void RHICommonList::Push(RHICommond* commond) {
|
||
|
{
|
||
|
std::lock_guard<std::mutex> lock(queueMutex_);
|
||
|
queue_.emplace(commond);
|
||
|
}
|
||
|
queueCondVar_.notify_one();
|
||
|
}
|