From 90cdc30ef114d5869082abb0d25a94ef1d24a830 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Fri, 18 Oct 2019 22:59:30 +0200 Subject: [PATCH] gs-helper: Add class for managed debug markers --- source/obs/gs/gs-helper.cpp | 24 ++++++++++++++++++++++++ source/obs/gs/gs-helper.hpp | 9 +++++++++ 2 files changed, 33 insertions(+) diff --git a/source/obs/gs/gs-helper.cpp b/source/obs/gs/gs-helper.cpp index 587d0859..d074d554 100644 --- a/source/obs/gs/gs-helper.cpp +++ b/source/obs/gs/gs-helper.cpp @@ -28,3 +28,27 @@ gs::context::~context() { obs_leave_graphics(); } + +gs::debug_marker::debug_marker(const float color[4], std::string name) : _name(name) +{ + gs_debug_marker_begin(color, _name.c_str()); +} + +gs::debug_marker::debug_marker(const float color[4], std::string format, ...) +{ + size_t size; + std::vector buffer(64); + + va_list vargs; + va_start(vargs, format); + size = vsnprintf(buffer.data(), buffer.size(), format.c_str(), vargs); + va_end(vargs); + + _name = std::string(buffer.data(), buffer.data() + size); + gs_debug_marker_begin(color, _name.c_str()); +} + +gs::debug_marker::~debug_marker() +{ + gs_debug_marker_end(); +} diff --git a/source/obs/gs/gs-helper.hpp b/source/obs/gs/gs-helper.hpp index 6ed6e54e..d0fdfdb1 100644 --- a/source/obs/gs/gs-helper.hpp +++ b/source/obs/gs/gs-helper.hpp @@ -37,4 +37,13 @@ namespace gs { context(); ~context(); }; + + class debug_marker { + std::string _name; + + public: + debug_marker(const float color[4], std::string name); + debug_marker(const float color[4], std::string format, ...); + ~debug_marker(); + }; } // namespace gs