From f1e774dc58da7d791b0428595dfea14fa351e34c Mon Sep 17 00:00:00 2001 From: Andrew Wason Date: Wed, 24 Jul 2024 17:20:03 -0400 Subject: [PATCH] Conditionally enable MSAA, disabled for now. --- src/MediaFX/CMakeLists.txt | 14 ++++++++++---- src/MediaFX/render_control.cpp | 29 +++++++++++++++++++++++++---- src/MediaFX/render_control.h | 3 +++ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/MediaFX/CMakeLists.txt b/src/MediaFX/CMakeLists.txt index c117eee..621a3ae 100644 --- a/src/MediaFX/CMakeLists.txt +++ b/src/MediaFX/CMakeLists.txt @@ -7,8 +7,6 @@ pkg_search_module(libavcodec REQUIRED IMPORTED_TARGET libavcodec>=58.134.100) pkg_search_module(libavfilter REQUIRED IMPORTED_TARGET libavfilter>=7.110.100) pkg_search_module(libavutil REQUIRED IMPORTED_TARGET libavutil>=56.70.100) -option(EVENT_LOGGER "Enable event logger" OFF) - find_package(Git QUIET) if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") @@ -44,6 +42,12 @@ target_include_directories(mediafx PRIVATE ${LIBAVFORMAT_INCLUDE_DIRS} ${LIBAVCO target_include_directories(mediafx PUBLIC ${LIBAVUTIL_INCLUDE_DIRS}) target_compile_options(mediafx PRIVATE ${LIBAVFORMAT_CFLAGS} ${LIBAVCODEC_CFLAGS} ${LIBAVFILTER_CFLAGS} ${LIBAVUTIL_CFLAGS}) +option(WITH_MSAA "Enable MSAA antialiasing." OFF) + +if(WITH_MSAA) + target_compile_definitions(mediafx PRIVATE MSAA) +endif() + qt_add_executable(mediafxtool main.cpp ) @@ -51,9 +55,11 @@ qt_add_executable(mediafxtool # For generated version.h target_include_directories(mediafxtool PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") -if(EVENT_LOGGER) +option(WITH_EVENT_LOGGER "Enable event logger" OFF) + +if(WITH_EVENT_LOGGER) target_sources(mediafxtool PRIVATE event_logger.h) - add_compile_definitions(EVENTLOGGER) + target_compile_definitions(mediafxtool PRIVATE EVENTLOGGER) endif() set_property(TARGET mediafxtool PROPERTY OUTPUT_NAME mediafx) diff --git a/src/MediaFX/render_control.cpp b/src/MediaFX/render_control.cpp index 8fa46d0..67b9707 100644 --- a/src/MediaFX/render_control.cpp +++ b/src/MediaFX/render_control.cpp @@ -14,6 +14,12 @@ bool RenderControl::reconfigure() { +#ifdef MSAA + int sampleCount = 4; +#else + int sampleCount = 1; +#endif + if (!window()) return false; QSize size = window()->size(); @@ -22,6 +28,9 @@ bool RenderControl::reconfigure() texture.reset(); stencilBuffer.reset(); +#ifdef MSAA + colorBuffer.reset(); +#endif textureRenderTarget.reset(); renderPassDescriptor.reset(); @@ -37,18 +46,30 @@ bool RenderControl::reconfigure() return false; } +#ifdef MSAA + colorBuffer.reset(rhi->newRenderBuffer(QRhiRenderBuffer::Color, size, sampleCount)); + if (!colorBuffer->create()) { + qCritical() << "Failed to create color buffer"; + return false; + } +#endif + // depth-stencil is mandatory with RHI, although strictly speaking the // scenegraph could operate without one, but it has no means to figure out // the lack of a ds buffer, so just be nice and provide one. - stencilBuffer.reset(rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, size, 1)); + stencilBuffer.reset(rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, size, sampleCount)); if (!stencilBuffer->create()) { qCritical() << "Failed to create render buffer"; return false; } - QRhiTextureRenderTargetDescription renderTargetDescription((QRhiColorAttachment(texture.get()))); - renderTargetDescription.setDepthStencilBuffer(stencilBuffer.get()); - textureRenderTarget.reset(rhi->newTextureRenderTarget(renderTargetDescription)); +#ifdef MSAA + QRhiColorAttachment colorAtt(colorBuffer.get()); + colorAtt.setResolveTexture(texture.get()); +#else + QRhiColorAttachment colorAtt(texture.get()); +#endif + textureRenderTarget.reset(rhi->newTextureRenderTarget({ colorAtt, stencilBuffer.get() })); renderPassDescriptor.reset(textureRenderTarget->newCompatibleRenderPassDescriptor()); textureRenderTarget->setRenderPassDescriptor(renderPassDescriptor.get()); if (!textureRenderTarget->create()) { diff --git a/src/MediaFX/render_control.h b/src/MediaFX/render_control.h index b76ceb1..fd4fcad 100644 --- a/src/MediaFX/render_control.h +++ b/src/MediaFX/render_control.h @@ -27,6 +27,9 @@ class RenderControl : public QQuickRenderControl { std::unique_ptr texture; std::unique_ptr stencilBuffer; +#ifdef MSAA + std::unique_ptr colorBuffer; +#endif std::unique_ptr textureRenderTarget; std::unique_ptr renderPassDescriptor; };