Skip to content

Commit

Permalink
Conditionally enable MSAA, disabled for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
rectalogic committed Jul 24, 2024
1 parent 9e37b38 commit f1e774d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/MediaFX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -44,16 +42,24 @@ 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
)

# 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)
Expand Down
29 changes: 25 additions & 4 deletions src/MediaFX/render_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -22,6 +28,9 @@ bool RenderControl::reconfigure()

texture.reset();
stencilBuffer.reset();
#ifdef MSAA
colorBuffer.reset();
#endif
textureRenderTarget.reset();
renderPassDescriptor.reset();

Expand All @@ -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()) {
Expand Down
3 changes: 3 additions & 0 deletions src/MediaFX/render_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class RenderControl : public QQuickRenderControl {

std::unique_ptr<QRhiTexture> texture;
std::unique_ptr<QRhiRenderBuffer> stencilBuffer;
#ifdef MSAA
std::unique_ptr<QRhiRenderBuffer> colorBuffer;
#endif
std::unique_ptr<QRhiTextureRenderTarget> textureRenderTarget;
std::unique_ptr<QRhiRenderPassDescriptor> renderPassDescriptor;
};

0 comments on commit f1e774d

Please sign in to comment.