Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rtoumazet committed Oct 18, 2024
1 parent ebc4b27 commit 28aaf4d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
13 changes: 4 additions & 9 deletions saturnin/src/video/opengl/opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ auto Opengl::getRenderedBufferTextureId(const GuiTextureType type) -> u32 {
switch (type) {
using enum GuiTextureType;
case render_buffer: {
layer = getFboTextureLayer(currentRenderedBuffer());
layer = getFboTextureLayer(render()->currentRenderedBuffer());
break;
}
case vdp1_debug_buffer: {
Expand Down Expand Up @@ -474,7 +474,7 @@ void Opengl::initializeFbo() {
fbo_texture_type_to_layer_[i] = priority;
}

currentRenderedBuffer(front_buffer);
render()->currentRenderedBuffer(front_buffer);

// Generating FBOs used by the renderer.
using enum FboType;
Expand All @@ -501,7 +501,7 @@ auto Opengl::generateFbo(const FboType fbo_type) -> u32 {

// Attaching the color texture currently used as framebuffer to the FBO.
attachTextureLayerToFbo(fbo_texture_array_id_,
getFboTextureLayer(currentRenderedBuffer()),
getFboTextureLayer(render()->currentRenderedBuffer()),
GLenum::GL_FRAMEBUFFER,
GLenum::GL_COLOR_ATTACHMENT0);
break;
Expand All @@ -510,7 +510,7 @@ auto Opengl::generateFbo(const FboType fbo_type) -> u32 {
glBindFramebuffer(GLenum::GL_FRAMEBUFFER, fbo);

attachTextureLayerToFbo(fbo_texture_array_id_,
getFboTextureLayer(currentRenderedBuffer()),
getFboTextureLayer(render()->currentRenderedBuffer()),
GLenum::GL_FRAMEBUFFER,
GLenum::GL_COLOR_ATTACHMENT0);

Expand Down Expand Up @@ -585,11 +585,6 @@ inline auto Opengl::getFboTextureLayer(const FboTextureType type) const -> u8 {
std::distance(fbo_texture_type_to_layer_.begin(), std::ranges::find(fbo_texture_type_to_layer_, type)));
}

void Opengl::switchRenderedBuffer() {
current_rendered_buffer_
= (current_rendered_buffer_ == FboTextureType::back_buffer) ? FboTextureType::front_buffer : FboTextureType::back_buffer;
}

void Opengl::attachTextureLayerToFbo(const u32 texture_id,
const u8 layer,
const gl::GLenum framebuffer_target,
Expand Down
19 changes: 10 additions & 9 deletions saturnin/src/video/opengl/opengl.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ class Opengl {
~Opengl();

// Accessors / Mutators
[[nodiscard]] auto currentRenderedBuffer() const { return current_rendered_buffer_; };
void currentRenderedBuffer(const FboTextureType type) { current_rendered_buffer_ = type; };
[[nodiscard]] auto vdp1DebugOverlayTextureId() const { return getFboTextureLayer(FboTextureType::vdp1_debug_overlay); };
[[nodiscard]] auto vdp2DebugLayerTextureId() const -> u32 {
return gui_texture_type_to_id_.at(GuiTextureType::vdp2_debug_buffer);
Expand Down Expand Up @@ -360,9 +358,6 @@ class Opengl {
// Gets the FBO texture layer currently used by the FboTextureType.
auto getFboTextureLayer(const FboTextureType type) const -> u8;

// Switch between back and front rendering buffers.
void switchRenderedBuffer();

// Attachs a texture array layer to the curently bound FBO.
void attachTextureLayerToFbo(const u32 texture_id,
const u8 layer,
Expand Down Expand Up @@ -434,7 +429,6 @@ class Opengl {
u32 fbo_texture_array_id_; // Identifier for the FBO texture array.
FboTextureTypeToLayer fbo_texture_type_to_layer_; // Links the used FBO texture layer to a texture type. Index of the array
// is the layer, content is the type.
FboTextureType current_rendered_buffer_; // The current rendered buffer (front or back)
GuiTextureTypeToId gui_texture_type_to_id_; // Links the texture to be used in the GUI to a type.

FboKeyToFbo fbo_key_to_fbo_pool_index_; // Link between a FBO key and its relative FBO index in the pool.
Expand Down Expand Up @@ -506,14 +500,21 @@ class OpenglRender {
// Checks if there's something to render.
auto isThereSomethingToRender() const -> bool;

// Accessors to the Vdp1Part to highlight on the debug layer.
void partToHighlight(const Vdp1Part& part) { part_to_highlight_ = part; };
auto partToHighlight() const -> Vdp1Part { return part_to_highlight_; };
// Switch between back and front rendering buffers.
void switchRenderedBuffer();

// Accessors / mutators
void partToHighlight(const Vdp1Part& part) { part_to_highlight_ = part; };
auto partToHighlight() const -> Vdp1Part { return part_to_highlight_; };
[[nodiscard]] auto currentRenderedBuffer() const { return current_rendered_buffer_; };
void currentRenderedBuffer(const FboTextureType type) { current_rendered_buffer_ = type; };

private:
Opengl* opengl_;

Vdp1Part part_to_highlight_; // Part that will be highlighted during debug.

FboTextureType current_rendered_buffer_; // The current rendered buffer (front or back)
};

// Queries if the current video card is capable of rendering modern opengl (ie version 3.3+).
Expand Down
9 changes: 7 additions & 2 deletions saturnin/src/video/opengl/opengl_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ using namespace gl21ext;
using core::tr;

void OpenglRender::preRender() {
opengl_->switchRenderedBuffer();
switchRenderedBuffer();

glBindFramebuffer(GLenum::GL_FRAMEBUFFER, opengl_->fbo_type_to_id_[FboType::general]);

opengl_->attachTextureLayerToFbo(opengl_->fbo_texture_array_id_,
opengl_->getFboTextureLayer(opengl_->currentRenderedBuffer()),
opengl_->getFboTextureLayer(currentRenderedBuffer()),
GLenum::GL_FRAMEBUFFER,
GLenum::GL_COLOR_ATTACHMENT0);

Expand Down Expand Up @@ -556,4 +556,9 @@ auto OpenglRender::isThereSomethingToRender() const -> bool {
if constexpr (render_type == RenderType::RenderType_drawTest) { return true; }
}

void OpenglRender::switchRenderedBuffer() {
current_rendered_buffer_
= (current_rendered_buffer_ == FboTextureType::back_buffer) ? FboTextureType::front_buffer : FboTextureType::back_buffer;
}

} // namespace saturnin::video
1 change: 0 additions & 1 deletion saturnin/src/video/opengl/opengl_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ void errorCallback(int error, const char* description) { fprintf(stderr, "Error

void Opengl::onWindowResize(const u16 new_width, const u16 new_height) { hostScreenResolution({new_width, new_height}); }

// static
auto initializeVao() -> std::tuple<u32, u32> {
auto vao = u32{};
glGenVertexArrays(1, &vao);
Expand Down

0 comments on commit 28aaf4d

Please sign in to comment.