1 /* 2 * Modern effects for a modern Streamer 3 * Copyright (C) 2020 Michael Fabian Dirks 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 18 */ 19 20 #pragma once 21 #include "common.hpp" 22 #include <vector> 23 #include "plugin.hpp" 24 25 namespace gs { 26 class context { 27 public: context()28 inline context() 29 { 30 obs_enter_graphics(); 31 if (gs_get_context() == nullptr) 32 throw std::runtime_error("Failed to enter graphics context."); 33 } ~context()34 ~context() 35 { 36 obs_leave_graphics(); 37 } 38 }; 39 40 #ifdef ENABLE_PROFILING 41 static constexpr float_t debug_color_white[4] = {1.f, 1.f, 1.f, 1.f}; 42 static constexpr float_t debug_color_gray[4] = {.5f, .5f, .5f, 1.f}; 43 static constexpr float_t debug_color_black[4] = {0.f, 0.f, 0.f, 1.f}; 44 static constexpr float_t debug_color_red[4] = {1.f, 0.f, 0.f, 1.f}; 45 static constexpr float_t debug_color_flush_orange[4] = {1.f, .5f, 0.f, 1.f}; 46 static constexpr float_t debug_color_yellow[4] = {1.f, 1.f, 0.f, 1.f}; 47 static constexpr float_t debug_color_chartreuse[4] = {.5f, 1.f, 0.f, 1.f}; 48 static constexpr float_t debug_color_green[4] = {0.f, 1.f, 0.f, 1.f}; 49 static constexpr float_t debug_color_spring_green[4] = {0.f, 1.f, .5f, 1.f}; 50 static constexpr float_t debug_color_teal[4] = {0.f, 1.f, 1.f, 1.f}; 51 static constexpr float_t debug_color_azure_radiance[4] = {0.f, .5f, 1.f, 1.f}; 52 static constexpr float_t debug_color_blue[4] = {0.f, 0.f, 1.f, 1.f}; 53 static constexpr float_t debug_color_electric_violet[4] = {.5f, 0.f, 1.f, 1.f}; 54 static constexpr float_t debug_color_magenta[4] = {1.f, 0.f, 1.f, 1.f}; 55 static constexpr float_t debug_color_rose[4] = {1.f, 0.f, .5f, 1.f}; 56 57 static const float_t* debug_color_source = debug_color_white; 58 static const float_t* debug_color_capture = debug_color_flush_orange; 59 static const float_t* debug_color_cache = debug_color_capture; 60 static const float_t* debug_color_convert = debug_color_electric_violet; 61 static const float_t* debug_color_cache_render = debug_color_convert; 62 static const float_t* debug_color_copy = debug_color_azure_radiance; 63 static const float_t* debug_color_allocate = debug_color_red; 64 static const float_t* debug_color_render = debug_color_teal; 65 66 class debug_marker { 67 std::string _name; 68 69 public: debug_marker(const float_t color[4],const char * format,...)70 inline debug_marker(const float_t color[4], const char* format, ...) 71 { 72 std::size_t size; 73 std::vector<char> buffer(64); 74 75 va_list vargs; 76 va_start(vargs, format); 77 size = static_cast<size_t>(vsnprintf(buffer.data(), buffer.size(), format, vargs)); 78 va_end(vargs); 79 80 _name = std::string(buffer.data(), buffer.data() + size); 81 gs_debug_marker_begin(color, _name.c_str()); 82 } 83 ~debug_marker()84 inline ~debug_marker() 85 { 86 gs_debug_marker_end(); 87 } 88 }; 89 #endif 90 } // namespace gs 91