Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rtoumazet committed Oct 10, 2024
1 parent 7905c0f commit 457eaf3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions saturnin/src/video/opengl/opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ void Opengl::displayFramebuffer(core::EmulatorContext& state) {
addVdp1PartsToList();
std::ranges::stable_sort(parts_list, [](const RenderPart& a, const RenderPart& b) { return a.priority < b.priority; });
if constexpr (render_type == RenderType::RenderType_drawElements) {
if (parts_list_.empty()) {
if (parts_list_global_[mixed_parts_key].empty()) {
std::unique_lock lk(getMutex(MutexType::parts_list));
parts_list_ = std::move(parts_list);
data_condition_.wait(lk, [this]() { return parts_list_.empty(); });
parts_list_global_[mixed_parts_key] = std::move(parts_list);
data_condition_.wait(lk, [this]() { return parts_list_global_[mixed_parts_key].empty(); });
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion saturnin/src/video/opengl/opengl.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ using FboKeyToFbo = std::map<FboKey, u8>; // Link between a priority to displ
using FboTexturePool = std::array<u32, max_fbo_texture>; // Pool of textures ids to be used for rendering by priority.
using FboTexturePoolStatus = std::array<FboTextureStatus, max_fbo_texture>; // State of the textures in the pool.

constexpr auto mixed_parts_key = FboKey{-1, VdpLayer::undefined};

struct string_hash {
using is_transparent = void;
[[nodiscard]] size_t operator()(const char* txt) const { return std::hash<std::string_view>{}(txt); }
Expand Down Expand Up @@ -731,7 +733,6 @@ class Opengl {
ScreenResolutions screen_resolutions_; // Host and Saturn screen resolution

// Following parts data will have to be moved to the platform agnostic renderer
PartsList parts_list_; // Used when use_fbo is false, parts are
MapOfPartsList parts_list_global_; // Used when use_fbo is true,
PartsList parts_list_debug_; // List of parts used to generate textures for debugging.
Vdp1Part part_to_highlight_; // Part that will be highlighted during debug.
Expand Down
5 changes: 3 additions & 2 deletions saturnin/src/video/opengl/opengl_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void Opengl::render() {

const auto getParts = [this, &parts_list]() {
std::lock_guard lock(getMutex(MutexType::parts_list));
if (!parts_list_.empty()) { parts_list = std::move(parts_list_); }
if (!parts_list_global_[mixed_parts_key].empty()) { parts_list = std::move(parts_list_global_[mixed_parts_key]); }
};
getParts();

Expand Down Expand Up @@ -443,7 +443,8 @@ auto Opengl::isThereSomethingToRender() const -> bool {
if constexpr (uses_fbo) {
return !parts_list_global_.empty();
} else {
return !parts_list_.empty();
if (parts_list_global_.contains(mixed_parts_key)) { return !parts_list_global_.at(mixed_parts_key).empty(); }
return false;
}
}
if constexpr (render_type == RenderType::RenderType_drawTest) { return true; }
Expand Down

0 comments on commit 457eaf3

Please sign in to comment.