diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ac203ce..151be8c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,9 +128,21 @@ if(MSVC) endif() elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) # Update if necessary - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic") + # GCC: -fpermissive is required as GCC does not allow the same template to be in different namespaces. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -Wpedantic -fpermissive") endif() +# C++ Standard and Extensions +IF (CMAKE_VERSION VERSION_LESS "3.8") + SET(CMAKE_CXX_STANDARD 14) +ELSEIF (CMAKE_VERSION VERSION_LESS "3.11") + SET(CMAKE_CXX_STANDARD 17) +ELSE() # CMake 3.11 or higher: + SET(CMAKE_CXX_STANDARD 20) +ENDIF() +## Disable nonstandard extensions +SET(CMAKE_CXX_EXTENSIONS OFF) + ################################################################################ # Options ################################################################################ @@ -239,57 +251,57 @@ SET(PROJECT_PRIVATE ${PROJECT_DATA_SHADERS_FILTER} "${PROJECT_BINARY_DIR}/source/module.cpp" "${PROJECT_BINARY_DIR}/source/version.hpp" - "${PROJECT_SOURCE_DIR}/source/plugin.h" + "${PROJECT_SOURCE_DIR}/source/plugin.hpp" "${PROJECT_SOURCE_DIR}/source/plugin.cpp" - "${PROJECT_SOURCE_DIR}/source/filter-displacement.h" + "${PROJECT_SOURCE_DIR}/source/filter-displacement.hpp" "${PROJECT_SOURCE_DIR}/source/filter-displacement.cpp" - "${PROJECT_SOURCE_DIR}/source/filter-blur.h" + "${PROJECT_SOURCE_DIR}/source/filter-blur.hpp" "${PROJECT_SOURCE_DIR}/source/filter-blur.cpp" "${PROJECT_SOURCE_DIR}/source/filter-shadow-sdf.hpp" "${PROJECT_SOURCE_DIR}/source/filter-shadow-sdf.cpp" - "${PROJECT_SOURCE_DIR}/source/filter-shape.h" + "${PROJECT_SOURCE_DIR}/source/filter-shape.hpp" "${PROJECT_SOURCE_DIR}/source/filter-shape.cpp" - "${PROJECT_SOURCE_DIR}/source/filter-transform.h" + "${PROJECT_SOURCE_DIR}/source/filter-transform.hpp" "${PROJECT_SOURCE_DIR}/source/filter-transform.cpp" - "${PROJECT_SOURCE_DIR}/source/filter-custom-shader.h" + "${PROJECT_SOURCE_DIR}/source/filter-custom-shader.hpp" "${PROJECT_SOURCE_DIR}/source/filter-custom-shader.cpp" - "${PROJECT_SOURCE_DIR}/source/source-mirror.h" + "${PROJECT_SOURCE_DIR}/source/source-mirror.hpp" "${PROJECT_SOURCE_DIR}/source/source-mirror.cpp" - "${PROJECT_SOURCE_DIR}/source/gfx-effect-source.h" + "${PROJECT_SOURCE_DIR}/source/gfx-effect-source.hpp" "${PROJECT_SOURCE_DIR}/source/gfx-effect-source.cpp" - "${PROJECT_SOURCE_DIR}/source/gfx-source-texture.h" + "${PROJECT_SOURCE_DIR}/source/gfx-source-texture.hpp" "${PROJECT_SOURCE_DIR}/source/gfx-source-texture.cpp" - "${PROJECT_SOURCE_DIR}/source/gs-helper.h" + "${PROJECT_SOURCE_DIR}/source/gs-helper.hpp" "${PROJECT_SOURCE_DIR}/source/gs-helper.cpp" - "${PROJECT_SOURCE_DIR}/source/gs-effect.h" + "${PROJECT_SOURCE_DIR}/source/gs-effect.hpp" "${PROJECT_SOURCE_DIR}/source/gs-effect.cpp" - "${PROJECT_SOURCE_DIR}/source/gs-indexbuffer.h" + "${PROJECT_SOURCE_DIR}/source/gs-indexbuffer.hpp" "${PROJECT_SOURCE_DIR}/source/gs-indexbuffer.cpp" - "${PROJECT_SOURCE_DIR}/source/gs-limits.h" - "${PROJECT_SOURCE_DIR}/source/gs-mipmapper.h" + "${PROJECT_SOURCE_DIR}/source/gs-limits.hpp" + "${PROJECT_SOURCE_DIR}/source/gs-mipmapper.hpp" "${PROJECT_SOURCE_DIR}/source/gs-mipmapper.cpp" - "${PROJECT_SOURCE_DIR}/source/gs-rendertarget.h" + "${PROJECT_SOURCE_DIR}/source/gs-rendertarget.hpp" "${PROJECT_SOURCE_DIR}/source/gs-rendertarget.cpp" - "${PROJECT_SOURCE_DIR}/source/gs-sampler.h" + "${PROJECT_SOURCE_DIR}/source/gs-sampler.hpp" "${PROJECT_SOURCE_DIR}/source/gs-sampler.cpp" - "${PROJECT_SOURCE_DIR}/source/gs-texture.h" + "${PROJECT_SOURCE_DIR}/source/gs-texture.hpp" "${PROJECT_SOURCE_DIR}/source/gs-texture.cpp" - "${PROJECT_SOURCE_DIR}/source/gs-vertex.h" + "${PROJECT_SOURCE_DIR}/source/gs-vertex.hpp" "${PROJECT_SOURCE_DIR}/source/gs-vertex.cpp" - "${PROJECT_SOURCE_DIR}/source/gs-vertexbuffer.h" + "${PROJECT_SOURCE_DIR}/source/gs-vertexbuffer.hpp" "${PROJECT_SOURCE_DIR}/source/gs-vertexbuffer.cpp" - "${PROJECT_SOURCE_DIR}/source/obs-audio-capture.h" + "${PROJECT_SOURCE_DIR}/source/obs-audio-capture.hpp" "${PROJECT_SOURCE_DIR}/source/obs-audio-capture.cpp" "${PROJECT_SOURCE_DIR}/source/obs-tools.hpp" "${PROJECT_SOURCE_DIR}/source/obs-tools.cpp" - "${PROJECT_SOURCE_DIR}/source/strings.h" - "${PROJECT_SOURCE_DIR}/source/utility.h" + "${PROJECT_SOURCE_DIR}/source/strings.hpp" + "${PROJECT_SOURCE_DIR}/source/utility.hpp" "${PROJECT_SOURCE_DIR}/source/utility.cpp" "${PROJECT_SOURCE_DIR}/source/util-event.hpp" "${PROJECT_SOURCE_DIR}/source/util-event.cpp" - "${PROJECT_SOURCE_DIR}/source/util-math.h" + "${PROJECT_SOURCE_DIR}/source/util-math.hpp" "${PROJECT_SOURCE_DIR}/source/util-math.cpp" - "${PROJECT_SOURCE_DIR}/source/util-memory.h" + "${PROJECT_SOURCE_DIR}/source/util-memory.hpp" "${PROJECT_SOURCE_DIR}/source/util-memory.cpp" "${PROJECT_SOURCE_DIR}/source/obs-source.hpp" "${PROJECT_SOURCE_DIR}/source/obs-source.cpp" diff --git a/source/filter-blur.cpp b/source/filter-blur.cpp index 07422b63..e462b19b 100644 --- a/source/filter-blur.cpp +++ b/source/filter-blur.cpp @@ -17,22 +17,26 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "filter-blur.h" +#include "filter-blur.hpp" #include -#include +#include #include -#include "strings.h" -#include "util-math.h" +#include "strings.hpp" +#include "util-math.hpp" +#include -extern "C" { +// OBS +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4201) -#include "callback/signal.h" -#include "graphics/graphics.h" -#include "graphics/matrix4.h" -#include "util/platform.h" +#endif +#include +#include +#include +#include +#ifdef _MSC_VER #pragma warning(pop) -} +#endif // Translation Strings #define SOURCE_NAME "Filter.Blur" @@ -569,7 +573,7 @@ void filter::blur::blur_instance::video_render(gs_effect_t* effect) if (obs_source_process_filter_begin(this->m_source, GS_RGBA, OBS_NO_DIRECT_RENDERING)) { obs_source_process_filter_end(this->m_source, defaultEffect, baseW, baseH); } else { - throw std::exception("Failed to render source"); + throw std::runtime_error("Failed to render source"); } } catch (std::exception ex) { if (this->can_log()) { diff --git a/source/filter-blur.h b/source/filter-blur.hpp similarity index 95% rename from source/filter-blur.h rename to source/filter-blur.hpp index a8da7ce2..f39364a3 100644 --- a/source/filter-blur.h +++ b/source/filter-blur.hpp @@ -26,19 +26,22 @@ #include #include #include -#include "gfx-source-texture.h" -#include "gs-effect.h" -#include "gs-helper.h" -#include "gs-texture.h" -#include "gs-rendertarget.h" -#include "plugin.h" +#include "gfx-source-texture.hpp" +#include "gs-effect.hpp" +#include "gs-helper.hpp" +#include "gs-texture.hpp" +#include "gs-rendertarget.hpp" +#include "plugin.hpp" -extern "C" { +// OBS +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4201) -#include "callback/signal.h" +#endif +#include +#ifdef _MSC_VER #pragma warning(pop) -} +#endif namespace filter { namespace blur { diff --git a/source/filter-custom-shader.cpp b/source/filter-custom-shader.cpp index 9b984760..13790780 100644 --- a/source/filter-custom-shader.cpp +++ b/source/filter-custom-shader.cpp @@ -17,20 +17,23 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "filter-custom-shader.h" +#include "filter-custom-shader.hpp" #include #include #include -#include "strings.h" +#include "strings.hpp" -extern "C" { +// OBS +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4201) -#include "graphics/graphics.h" -#include "graphics/matrix4.h" -#include "util/platform.h" +#endif +#include +#include +#include +#ifdef _MSC_VER #pragma warning(pop) -} +#endif #define S "Filter.CustomShader" diff --git a/source/filter-custom-shader.h b/source/filter-custom-shader.hpp similarity index 94% rename from source/filter-custom-shader.h rename to source/filter-custom-shader.hpp index 7b045cd0..0e3c17fc 100644 --- a/source/filter-custom-shader.h +++ b/source/filter-custom-shader.hpp @@ -18,13 +18,13 @@ */ #pragma once -#include +#include #include #include -#include "gfx-effect-source.h" -#include "gs-effect.h" -#include "gs-rendertarget.h" -#include "plugin.h" +#include "gfx-effect-source.hpp" +#include "gs-effect.hpp" +#include "gs-rendertarget.hpp" +#include "plugin.hpp" namespace filter { class CustomShader { diff --git a/source/filter-displacement.cpp b/source/filter-displacement.cpp index 6d86b1c3..f5ca8974 100644 --- a/source/filter-displacement.cpp +++ b/source/filter-displacement.cpp @@ -17,8 +17,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "filter-displacement.h" -#include "strings.h" +#include "filter-displacement.hpp" +#include +#include "strings.hpp" // Initializer & Finalizer static filter::Displacement* filterDisplacementInstance; diff --git a/source/filter-displacement.h b/source/filter-displacement.hpp similarity index 97% rename from source/filter-displacement.h rename to source/filter-displacement.hpp index 50e0a09b..ecf176cd 100644 --- a/source/filter-displacement.h +++ b/source/filter-displacement.hpp @@ -18,17 +18,19 @@ */ #pragma once -#include "plugin.h" +#include "plugin.hpp" +#include -extern "C" { +// OBS +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4201) +#endif #include #include +#ifdef _MSC_VER #pragma warning(pop) -} - -#include +#endif #define S_FILTER_DISPLACEMENT "Filter.Displacement" #define S_FILTER_DISPLACEMENT_FILE "Filter.Displacement.File" diff --git a/source/filter-shadow-sdf.cpp b/source/filter-shadow-sdf.cpp index 609da31a..34ba90e8 100644 --- a/source/filter-shadow-sdf.cpp +++ b/source/filter-shadow-sdf.cpp @@ -18,7 +18,7 @@ */ #include "filter-shadow-sdf.hpp" -#include "strings.h" +#include "strings.hpp" // Translation Strings #define SOURCE_NAME "Filter.ShadowSDF" @@ -221,25 +221,25 @@ void filter::shadow_sdf::shadow_sdf_instance::video_render(gs_effect_t*) if (obs_source_process_filter_begin(this->m_self, GS_RGBA, OBS_ALLOW_DIRECT_RENDERING)) { obs_source_process_filter_end(this->m_self, default_effect, baseW, baseH); } else { - throw std::exception("failed to process source"); + throw std::runtime_error("failed to process source"); } } m_input->get_texture(this->m_source_texture); if (!this->m_source_texture) { - throw std::exception("failed to draw source"); + throw std::runtime_error("failed to draw source"); } // Generate SDF Buffers { this->m_sdf_read->get_texture(this->m_sdf_texture); if (!this->m_sdf_texture) { - throw std::exception("SDF Backbuffer empty"); + throw std::runtime_error("SDF Backbuffer empty"); } std::shared_ptr sdf_effect = filter::shadow_sdf::shadow_sdf_factory::get()->get_sdf_generator_effect(); if (!sdf_effect) { - throw std::exception("SDF Effect no loaded"); + throw std::runtime_error("SDF Effect no loaded"); } { @@ -266,7 +266,7 @@ void filter::shadow_sdf::shadow_sdf_instance::video_render(gs_effect_t*) this->m_sdf_write.swap(this->m_sdf_read); this->m_sdf_read->get_texture(this->m_sdf_texture); if (!this->m_sdf_texture) { - throw std::exception("SDF Backbuffer empty"); + throw std::runtime_error("SDF Backbuffer empty"); } } } @@ -275,7 +275,7 @@ void filter::shadow_sdf::shadow_sdf_instance::video_render(gs_effect_t*) std::shared_ptr shadow_effect = filter::shadow_sdf::shadow_sdf_factory::get()->get_sdf_shadow_effect(); if (!shadow_effect) { - throw std::exception("Shadow Effect no loaded"); + throw std::runtime_error("Shadow Effect no loaded"); } gs_set_cull_mode(GS_NEITHER); diff --git a/source/filter-shadow-sdf.hpp b/source/filter-shadow-sdf.hpp index 01076879..b94b36c2 100644 --- a/source/filter-shadow-sdf.hpp +++ b/source/filter-shadow-sdf.hpp @@ -22,16 +22,22 @@ #pragma once #include -#include "gs-effect.h" -#include "gs-rendertarget.h" -#include "gs-sampler.h" -#include "gs-texture.h" -#include "gs-vertexbuffer.h" -#include "plugin.h" +#include "gs-effect.hpp" +#include "gs-rendertarget.hpp" +#include "gs-sampler.hpp" +#include "gs-texture.hpp" +#include "gs-vertexbuffer.hpp" +#include "plugin.hpp" -extern "C" { +// OBS +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4201) +#endif #include -} +#ifdef _MSC_VER +#pragma warning(pop) +#endif namespace filter { namespace shadow_sdf { diff --git a/source/filter-shape.cpp b/source/filter-shape.cpp index bedf5b3f..7fbd4941 100644 --- a/source/filter-shape.cpp +++ b/source/filter-shape.cpp @@ -17,21 +17,24 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "filter-shape.h" +#include "filter-shape.hpp" #include #include #include #include -#include "strings.h" +#include "strings.hpp" -extern "C" { +// OBS +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4201) -#include "graphics/graphics.h" -#include "graphics/matrix4.h" -#include "util/platform.h" +#endif +#include +#include +#include +#ifdef _MSC_VER #pragma warning(pop) -} +#endif // Initializer & Finalizer static filter::Shape* filterShapeInstance; diff --git a/source/filter-shape.h b/source/filter-shape.hpp similarity index 98% rename from source/filter-shape.h rename to source/filter-shape.hpp index bc7c14b5..797a11b9 100644 --- a/source/filter-shape.h +++ b/source/filter-shape.hpp @@ -18,8 +18,8 @@ */ #pragma once -#include "gs-vertexbuffer.h" -#include "plugin.h" +#include "gs-vertexbuffer.hpp" +#include "plugin.hpp" #define P_SHAPE "Shape" #define P_SHAPE_LOOP "Shape.Loop" diff --git a/source/filter-transform.cpp b/source/filter-transform.cpp index 7fda061e..e5e4322b 100644 --- a/source/filter-transform.cpp +++ b/source/filter-transform.cpp @@ -17,18 +17,21 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "filter-transform.h" -#include "strings.h" -#include "util-math.h" +#include "filter-transform.hpp" +#include "strings.hpp" +#include "util-math.hpp" -extern "C" { +// OBS +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4201) -#include "graphics/graphics.h" -#include "graphics/matrix4.h" -#include "util/platform.h" +#endif +#include +#include +#include +#ifdef _MSC_VER #pragma warning(pop) -} +#endif // Initializer & Finalizer static filter::Transform* filterTransformInstance; diff --git a/source/filter-transform.h b/source/filter-transform.hpp similarity index 89% rename from source/filter-transform.h rename to source/filter-transform.hpp index 8a961f3c..0e914c84 100644 --- a/source/filter-transform.h +++ b/source/filter-transform.hpp @@ -20,11 +20,11 @@ #pragma once #include #include -#include "gs-mipmapper.h" -#include "gs-rendertarget.h" -#include "gs-texture.h" -#include "gs-vertexbuffer.h" -#include "plugin.h" +#include "gs-mipmapper.hpp" +#include "gs-rendertarget.hpp" +#include "gs-texture.hpp" +#include "gs-vertexbuffer.hpp" +#include "plugin.hpp" namespace filter { class Transform { @@ -78,12 +78,10 @@ namespace filter { // 3D Information uint32_t rotation_order; - struct { - std::unique_ptr position; - std::unique_ptr rotation; - std::unique_ptr scale; - std::unique_ptr shear; - }; + std::unique_ptr position; + std::unique_ptr rotation; + std::unique_ptr scale; + std::unique_ptr shear; public: Instance(obs_data_t*, obs_source_t*); diff --git a/source/gfx-effect-source.cpp b/source/gfx-effect-source.cpp index a0687982..de57e2e8 100644 --- a/source/gfx-effect-source.cpp +++ b/source/gfx-effect-source.cpp @@ -15,10 +15,23 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -#include "gfx-effect-source.h" +#include "gfx-effect-source.hpp" #include +#include +#include "strings.hpp" +#include +#include +#include + +// OBS +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4201) +#endif #include -#include "strings.h" +#ifdef _MSC_VER +#pragma warning(pop) +#endif bool gfx::effect_source::property_type_modified(void*, obs_properties_t* props, obs_property_t*, obs_data_t* sett) { diff --git a/source/gfx-effect-source.h b/source/gfx-effect-source.hpp similarity index 95% rename from source/gfx-effect-source.h rename to source/gfx-effect-source.hpp index 6ef3ad4e..13cc8f82 100644 --- a/source/gfx-effect-source.h +++ b/source/gfx-effect-source.hpp @@ -21,16 +21,18 @@ #include #include #include -#include "gfx-source-texture.h" -#include "gs-effect.h" -#include "gs-mipmapper.h" -#include "gs-rendertarget.h" -#include "gs-texture.h" -#include "gs-vertexbuffer.h" +#include "gfx-source-texture.hpp" +#include "gs-effect.hpp" +#include "gs-mipmapper.hpp" +#include "gs-rendertarget.hpp" +#include "gs-texture.hpp" +#include "gs-vertexbuffer.hpp" -extern "C" { +// OBS +#pragma warning(push) +#pragma warning(disable : 4201) #include -} +#pragma warning(pop) // Data Defines #define D_TYPE "CustomShader.Type" diff --git a/source/gfx-source-texture.cpp b/source/gfx-source-texture.cpp index a5a25763..bf4a4993 100644 --- a/source/gfx-source-texture.cpp +++ b/source/gfx-source-texture.cpp @@ -15,7 +15,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -#include "gfx-source-texture.h" +#include "gfx-source-texture.hpp" gfx::source_texture::~source_texture() { diff --git a/source/gfx-source-texture.h b/source/gfx-source-texture.hpp similarity index 92% rename from source/gfx-source-texture.h rename to source/gfx-source-texture.hpp index ccbdafcc..89d7768e 100644 --- a/source/gfx-source-texture.h +++ b/source/gfx-source-texture.hpp @@ -18,13 +18,15 @@ #pragma once #include #include -#include "gs-rendertarget.h" -#include "gs-texture.h" +#include "gs-rendertarget.hpp" +#include "gs-texture.hpp" #include "obs-source.hpp" -extern "C" { +// OBS +#pragma warning(push) +#pragma warning(disable : 4201) #include -} +#pragma warning(pop) namespace gfx { class source_texture { diff --git a/source/gs-effect.cpp b/source/gs-effect.cpp index 2033001f..636384af 100644 --- a/source/gs-effect.cpp +++ b/source/gs-effect.cpp @@ -17,15 +17,18 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "gs-effect.h" +#include "gs-effect.hpp" #include -extern "C" { +// OBS +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4201) +#endif #include +#ifdef _MSC_VER #pragma warning(pop) -} +#endif gs::effect::effect() : m_effect(nullptr) {} diff --git a/source/gs-effect.h b/source/gs-effect.hpp similarity index 97% rename from source/gs-effect.h rename to source/gs-effect.hpp index f2facb7b..aca249f8 100644 --- a/source/gs-effect.h +++ b/source/gs-effect.hpp @@ -18,14 +18,13 @@ */ #pragma once -#include +#include #include #include #include -#include "gs-sampler.h" -#include "gs-texture.h" +#include "gs-sampler.hpp" +#include "gs-texture.hpp" -extern "C" { #pragma warning(push) #pragma warning(disable : 4201) #include @@ -34,7 +33,6 @@ extern "C" { #include #include #pragma warning(pop) -} namespace gs { class effect_parameter { diff --git a/source/gs-helper.cpp b/source/gs-helper.cpp index e1089326..00842586 100644 --- a/source/gs-helper.cpp +++ b/source/gs-helper.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "gs-helper.h" +#include "gs-helper.hpp" gs_effect_param* gs_effect_get_param(gs_effect_t* effect, const char* name) { diff --git a/source/gs-helper.h b/source/gs-helper.hpp similarity index 95% rename from source/gs-helper.h rename to source/gs-helper.hpp index 182130a7..f35f2c21 100644 --- a/source/gs-helper.h +++ b/source/gs-helper.hpp @@ -19,13 +19,13 @@ #pragma once #include -#include "plugin.h" -extern "C" { +#include "plugin.hpp" + +// OBS #pragma warning(push) #pragma warning(disable : 4201) -#include "graphics/graphics.h" +#include #pragma warning(pop) -} gs_effect_param* gs_effect_get_param(gs_effect_t* effect, const char* name); bool gs_set_param_int(gs_effect_t* effect, const char* name, int value); diff --git a/source/gs-indexbuffer.cpp b/source/gs-indexbuffer.cpp index b88e311c..8f0729d6 100644 --- a/source/gs-indexbuffer.cpp +++ b/source/gs-indexbuffer.cpp @@ -17,14 +17,18 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "gs-indexbuffer.h" -#include "gs-limits.h" -extern "C" { +#include "gs-indexbuffer.hpp" +#include "gs-limits.hpp" + +// OBS +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4201) +#endif #include +#ifdef _MSC_VER #pragma warning(pop) -} +#endif gs::index_buffer::index_buffer(uint32_t maximumVertices) { diff --git a/source/gs-indexbuffer.h b/source/gs-indexbuffer.hpp similarity index 97% rename from source/gs-indexbuffer.h rename to source/gs-indexbuffer.hpp index fb07aa8c..b8a6ae1d 100644 --- a/source/gs-indexbuffer.h +++ b/source/gs-indexbuffer.hpp @@ -18,14 +18,13 @@ */ #pragma once -#include +#include #include -extern "C" { + #pragma warning(push) #pragma warning(disable : 4201) #include #pragma warning(pop) -} namespace gs { class index_buffer : public std::vector { diff --git a/source/gs-limits.h b/source/gs-limits.hpp similarity index 97% rename from source/gs-limits.h rename to source/gs-limits.hpp index b8c0ae19..3b878ba8 100644 --- a/source/gs-limits.h +++ b/source/gs-limits.hpp @@ -18,7 +18,7 @@ */ #pragma once -#include +#include namespace gs { static const uint32_t MAXIMUM_VERTICES = 0xFFFFFFu; diff --git a/source/gs-mipmapper.cpp b/source/gs-mipmapper.cpp index 746af575..47c08cef 100644 --- a/source/gs-mipmapper.cpp +++ b/source/gs-mipmapper.cpp @@ -17,20 +17,26 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "gs-mipmapper.h" -#include "plugin.h" +#include "gs-mipmapper.hpp" +#include "plugin.hpp" -extern "C" { +// OBS +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4201) +#endif #include #include #include +#ifdef _MSC_VER #pragma warning(pop) -#if defined(WIN32) || defined(WIN64) -#include #endif + +#if defined(WIN32) || defined(WIN64) +extern "C" { +#include } +#endif // Here be dragons! // This is to add support for mipmap generation which is by default not possible with libobs. @@ -146,7 +152,9 @@ void gs::mipmapper::rebuild(std::shared_ptr source, std::shared_ptr // Render graphics_t* ctx = gs_get_context(); +#if defined(WIN32) || defined(WIN64) gs_d3d11_device* dev = reinterpret_cast(ctx->device); +#endif int device_type = gs_get_device_type(); void* sobj = gs_texture_get_obj(source->get_object()); void* tobj = gs_texture_get_obj(target->get_object()); diff --git a/source/gs-mipmapper.h b/source/gs-mipmapper.hpp similarity index 92% rename from source/gs-mipmapper.h rename to source/gs-mipmapper.hpp index 994bb6b4..dda42cde 100644 --- a/source/gs-mipmapper.h +++ b/source/gs-mipmapper.hpp @@ -18,17 +18,16 @@ */ #pragma once -#include "gs-effect.h" -#include "gs-rendertarget.h" -#include "gs-texture.h" -#include "gs-vertexbuffer.h" +#include "gs-effect.hpp" +#include "gs-rendertarget.hpp" +#include "gs-texture.hpp" +#include "gs-vertexbuffer.hpp" -extern "C" { +// OBS #pragma warning(push) #pragma warning(disable : 4201) #include #pragma warning(pop) -} namespace gs { class mipmapper { diff --git a/source/gs-rendertarget.cpp b/source/gs-rendertarget.cpp index 73187fc9..6f8c614e 100644 --- a/source/gs-rendertarget.cpp +++ b/source/gs-rendertarget.cpp @@ -17,16 +17,19 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "gs-rendertarget.h" +#include "gs-rendertarget.hpp" #include -extern "C" { +// OBS +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4201) +#endif #include #include +#ifdef _MSC_VER #pragma warning(pop) -} +#endif gs::rendertarget::~rendertarget() { diff --git a/source/gs-rendertarget.h b/source/gs-rendertarget.hpp similarity index 97% rename from source/gs-rendertarget.h rename to source/gs-rendertarget.hpp index 97b16f72..9263ee27 100644 --- a/source/gs-rendertarget.h +++ b/source/gs-rendertarget.hpp @@ -20,16 +20,17 @@ #pragma once #include #include -#include "gs-texture.h" +#include "gs-texture.hpp" -extern "C" { +// OBS #pragma warning(push) #pragma warning(disable : 4201) #include #pragma warning(pop) -} namespace gs { + class rendertarget_op; + class rendertarget { friend class rendertarget_op; diff --git a/source/gs-sampler.cpp b/source/gs-sampler.cpp index 64eef2c9..c3477bfc 100644 --- a/source/gs-sampler.cpp +++ b/source/gs-sampler.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "gs-sampler.h" +#include "gs-sampler.hpp" gs::sampler::sampler() { diff --git a/source/gs-sampler.h b/source/gs-sampler.hpp similarity index 98% rename from source/gs-sampler.h rename to source/gs-sampler.hpp index b1b7a804..ba2d824e 100644 --- a/source/gs-sampler.h +++ b/source/gs-sampler.hpp @@ -18,13 +18,13 @@ */ #pragma once -#include -extern "C" { +#include + +// OBS #pragma warning(push) #pragma warning(disable : 4201) #include #pragma warning(pop) -} namespace gs { class sampler { diff --git a/source/gs-texture.cpp b/source/gs-texture.cpp index d78078b1..bfb13a93 100644 --- a/source/gs-texture.cpp +++ b/source/gs-texture.cpp @@ -17,19 +17,22 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "gs-texture.h" +#include "gs-texture.hpp" #include #include #include -#include "util-math.h" +#include "util-math.hpp" -extern "C" { +// OBS +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4201) +#endif #include #include +#ifdef _MSC_VER #pragma warning(pop) -} +#endif gs::texture::texture(uint32_t width, uint32_t height, gs_color_format format, uint32_t mip_levels, const uint8_t** mip_data, gs::texture::flags texture_flags) diff --git a/source/gs-texture.h b/source/gs-texture.hpp similarity index 98% rename from source/gs-texture.h rename to source/gs-texture.hpp index 6143e35d..b30af0f5 100644 --- a/source/gs-texture.h +++ b/source/gs-texture.hpp @@ -20,14 +20,13 @@ #pragma once #include #include -#include "utility.h" +#include "utility.hpp" -extern "C" { +// OBS #pragma warning(push) #pragma warning(disable : 4201) #include #pragma warning(pop) -} namespace gs { class texture { diff --git a/source/gs-vertex.cpp b/source/gs-vertex.cpp index 744e0ea0..7af34e9f 100644 --- a/source/gs-vertex.cpp +++ b/source/gs-vertex.cpp @@ -17,8 +17,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "gs-vertex.h" -#include "util-memory.h" +#include "gs-vertex.hpp" +#include "util-memory.hpp" gs::vertex::vertex() : hasStore(true), store(nullptr), position(nullptr), normal(nullptr), tangent(nullptr), color(nullptr) diff --git a/source/gs-vertex.h b/source/gs-vertex.hpp similarity index 97% rename from source/gs-vertex.h rename to source/gs-vertex.hpp index 8c21db3a..7cfa3627 100644 --- a/source/gs-vertex.h +++ b/source/gs-vertex.hpp @@ -20,13 +20,13 @@ #pragma once #include #include -#include "gs-limits.h" -extern "C" { +#include "gs-limits.hpp" + +// OBS #pragma warning(push) #pragma warning(disable : 4201) #include #pragma warning(pop) -} namespace gs { struct vertex { diff --git a/source/gs-vertexbuffer.cpp b/source/gs-vertexbuffer.cpp index 76d0a46c..4a769a51 100644 --- a/source/gs-vertexbuffer.cpp +++ b/source/gs-vertexbuffer.cpp @@ -17,15 +17,19 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "gs-vertexbuffer.h" +#include "gs-vertexbuffer.hpp" #include -#include "util-memory.h" -extern "C" { +#include "util-memory.hpp" + +// OBS +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4201) +#endif #include +#ifdef _MSC_VER #pragma warning(pop) -} +#endif gs::vertex_buffer::~vertex_buffer() { @@ -56,7 +60,7 @@ gs::vertex_buffer::~vertex_buffer() m_layerdata = nullptr; } if (m_vertexbufferdata) { - std::memset(m_vertexbufferdata, 0, sizeof(gs_vb_data)); + memset(m_vertexbufferdata, 0, sizeof(gs_vb_data)); if (!m_vertexbuffer) { gs_vbdata_destroy(m_vertexbufferdata); m_vertexbufferdata = nullptr; @@ -94,12 +98,12 @@ gs::vertex_buffer::vertex_buffer(uint32_t vertices, uint8_t uvlayers) m_vertexbufferdata->colors = m_colors = (uint32_t*)util::malloc_aligned(16, sizeof(uint32_t) * m_capacity); // cppcheck-suppress memsetClassFloat - std::memset(m_positions, 0, sizeof(vec3) * m_capacity); + memset(m_positions, 0, sizeof(vec3) * m_capacity); // cppcheck-suppress memsetClassFloat - std::memset(m_normals, 0, sizeof(vec3) * m_capacity); + memset(m_normals, 0, sizeof(vec3) * m_capacity); // cppcheck-suppress memsetClassFloat - std::memset(m_tangents, 0, sizeof(vec3) * m_capacity); - std::memset(m_colors, 0, sizeof(uint32_t) * m_capacity); + memset(m_tangents, 0, sizeof(vec3) * m_capacity); + memset(m_colors, 0, sizeof(uint32_t) * m_capacity); m_vertexbufferdata->num_tex = m_layers; if (m_layers > 0) { @@ -108,7 +112,7 @@ gs::vertex_buffer::vertex_buffer(uint32_t vertices, uint8_t uvlayers) for (size_t n = 0; n < m_layers; n++) { m_layerdata[n].array = m_uvs[n] = (vec4*)util::malloc_aligned(16, sizeof(vec4) * m_capacity); m_layerdata[n].width = 4; - std::memset(m_uvs[n], 0, sizeof(vec4) * m_capacity); + memset(m_uvs[n], 0, sizeof(vec4) * m_capacity); } } else { m_vertexbufferdata->tvarray = nullptr; @@ -117,7 +121,7 @@ gs::vertex_buffer::vertex_buffer(uint32_t vertices, uint8_t uvlayers) // Allocate GPU obs_enter_graphics(); m_vertexbuffer = gs_vertexbuffer_create(m_vertexbufferdata, GS_DYNAMIC); - std::memset(m_vertexbufferdata, 0, sizeof(gs_vb_data)); + memset(m_vertexbufferdata, 0, sizeof(gs_vb_data)); m_vertexbufferdata->num = m_capacity; m_vertexbufferdata->num_tex = m_layers; obs_leave_graphics(); @@ -138,24 +142,24 @@ gs::vertex_buffer::vertex_buffer(gs_vertbuffer_t* vb) this->set_uv_layers((uint32_t)vbd->num_tex); if (vbd->points != nullptr) - std::memcpy(m_positions, vbd->points, vbd->num * sizeof(vec3)); + memcpy(m_positions, vbd->points, vbd->num * sizeof(vec3)); if (vbd->normals != nullptr) - std::memcpy(m_normals, vbd->normals, vbd->num * sizeof(vec3)); + memcpy(m_normals, vbd->normals, vbd->num * sizeof(vec3)); if (vbd->tangents != nullptr) - std::memcpy(m_tangents, vbd->tangents, vbd->num * sizeof(vec3)); + memcpy(m_tangents, vbd->tangents, vbd->num * sizeof(vec3)); if (vbd->colors != nullptr) - std::memcpy(m_colors, vbd->colors, vbd->num * sizeof(uint32_t)); + memcpy(m_colors, vbd->colors, vbd->num * sizeof(uint32_t)); if (vbd->tvarray != nullptr) { for (size_t n = 0; n < vbd->num_tex; n++) { if (vbd->tvarray[n].array != nullptr && vbd->tvarray[n].width <= 4 && vbd->tvarray[n].width > 0) { if (vbd->tvarray[n].width == 4) { - std::memcpy(m_uvs[n], vbd->tvarray[n].array, vbd->num * sizeof(vec4)); + memcpy(m_uvs[n], vbd->tvarray[n].array, vbd->num * sizeof(vec4)); } else { for (size_t idx = 0; idx < m_capacity; idx++) { float* mem = reinterpret_cast(vbd->tvarray[n].array) + (idx * vbd->tvarray[n].width); // cppcheck-suppress memsetClassFloat - std::memset(&m_uvs[n][idx], 0, sizeof(vec4)); - std::memcpy(&m_uvs[n][idx], mem, vbd->tvarray[n].width); + memset(&m_uvs[n][idx], 0, sizeof(vec4)); + memcpy(&m_uvs[n][idx], mem, vbd->tvarray[n].width); } } } @@ -168,12 +172,12 @@ gs::vertex_buffer::vertex_buffer(gs_vertbuffer_t* vb) gs::vertex_buffer::vertex_buffer(vertex_buffer const& other) : vertex_buffer(other.m_capacity) { // Copy Constructor - std::memcpy(m_positions, other.m_positions, m_capacity * sizeof(vec3)); - std::memcpy(m_normals, other.m_normals, m_capacity * sizeof(vec3)); - std::memcpy(m_tangents, other.m_tangents, m_capacity * sizeof(vec3)); - std::memcpy(m_colors, other.m_colors, m_capacity * sizeof(vec3)); + memcpy(m_positions, other.m_positions, m_capacity * sizeof(vec3)); + memcpy(m_normals, other.m_normals, m_capacity * sizeof(vec3)); + memcpy(m_tangents, other.m_tangents, m_capacity * sizeof(vec3)); + memcpy(m_colors, other.m_colors, m_capacity * sizeof(vec3)); for (size_t n = 0; n < MAXIMUM_UVW_LAYERS; n++) { - std::memcpy(m_uvs[n], other.m_uvs[n], m_capacity * sizeof(vec3)); + memcpy(m_uvs[n], other.m_uvs[n], m_capacity * sizeof(vec3)); } } @@ -225,7 +229,7 @@ void gs::vertex_buffer::operator=(vertex_buffer const&& other) m_layerdata = nullptr; } if (m_vertexbufferdata) { - std::memset(m_vertexbufferdata, 0, sizeof(gs_vb_data)); + memset(m_vertexbufferdata, 0, sizeof(gs_vb_data)); if (!m_vertexbuffer) { gs_vbdata_destroy(m_vertexbufferdata); m_vertexbufferdata = nullptr; @@ -338,7 +342,7 @@ gs_vertbuffer_t* gs::vertex_buffer::update(bool refreshGPU) // Update VertexBuffer data. obs_enter_graphics(); m_vertexbufferdata = gs_vertexbuffer_get_data(m_vertexbuffer); - std::memset(m_vertexbufferdata, 0, sizeof(gs_vb_data)); + memset(m_vertexbufferdata, 0, sizeof(gs_vb_data)); m_vertexbufferdata->num = m_capacity; m_vertexbufferdata->points = m_positions; m_vertexbufferdata->normals = m_normals; @@ -356,7 +360,7 @@ gs_vertbuffer_t* gs::vertex_buffer::update(bool refreshGPU) obs_leave_graphics(); // WORKAROUND: OBS Studio 20.x and below incorrectly deletes data that it doesn't own. - std::memset(m_vertexbufferdata, 0, sizeof(gs_vb_data)); + memset(m_vertexbufferdata, 0, sizeof(gs_vb_data)); m_vertexbufferdata->num = m_capacity; m_vertexbufferdata->num_tex = m_layers; for (uint32_t n = 0; n < m_layers; n++) { diff --git a/source/gs-vertexbuffer.h b/source/gs-vertexbuffer.hpp similarity index 97% rename from source/gs-vertexbuffer.h rename to source/gs-vertexbuffer.hpp index ab1574bd..2f1ecf6e 100644 --- a/source/gs-vertexbuffer.h +++ b/source/gs-vertexbuffer.hpp @@ -19,17 +19,16 @@ #pragma once #include -#include "gs-limits.h" -#include "gs-vertex.h" -#include "util-math.h" -#include "util-memory.h" +#include "gs-limits.hpp" +#include "gs-vertex.hpp" +#include "util-math.hpp" +#include "util-memory.hpp" -extern "C" { +// OBS #pragma warning(push) #pragma warning(disable : 4201) #include #pragma warning(pop) -} namespace gs { class vertex_buffer { diff --git a/source/obs-audio-capture.cpp b/source/obs-audio-capture.cpp index c7485eeb..278c2648 100644 --- a/source/obs-audio-capture.cpp +++ b/source/obs-audio-capture.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "obs-audio-capture.h" +#include "obs-audio-capture.hpp" void obs::audio_capture::audio_capture_cb(void* data, obs_source_t*, const struct audio_data* audio, bool muted) { diff --git a/source/obs-audio-capture.h b/source/obs-audio-capture.hpp similarity index 94% rename from source/obs-audio-capture.h rename to source/obs-audio-capture.hpp index 85de49b8..2b8963f6 100644 --- a/source/obs-audio-capture.h +++ b/source/obs-audio-capture.hpp @@ -19,7 +19,12 @@ #pragma once #include + +// OBS +#pragma warning(push) +#pragma warning(disable : 4201) #include +#pragma warning(pop) namespace obs { typedef std::function audio_capture_callback_t; diff --git a/source/obs-source.hpp b/source/obs-source.hpp index 694319b0..b515586e 100644 --- a/source/obs-source.hpp +++ b/source/obs-source.hpp @@ -25,9 +25,11 @@ #include #include "util-event.hpp" -extern "C" { -#include "obs.h" -} +// OBS +#pragma warning(push) +#pragma warning(disable : 4201) +#include +#pragma warning(pop) namespace obs { class source { diff --git a/source/obs-tools.hpp b/source/obs-tools.hpp index 5f2a3997..e39c197d 100644 --- a/source/obs-tools.hpp +++ b/source/obs-tools.hpp @@ -24,9 +24,11 @@ #include #include -extern "C" { -#include "obs.h" -} +// OBS +#pragma warning(push) +#pragma warning(disable : 4201) +#include +#pragma warning(pop) namespace obs { namespace tools { diff --git a/source/plugin.cpp b/source/plugin.cpp index 96b28e95..48eae768 100644 --- a/source/plugin.cpp +++ b/source/plugin.cpp @@ -17,11 +17,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "plugin.h" -#include "filter-blur.h" -#include "filter-displacement.h" -#include "filter-shape.h" -#include "filter-transform.h" +#include "plugin.hpp" +#include "filter-blur.hpp" +#include "filter-displacement.hpp" +#include "filter-shape.hpp" +#include "filter-transform.hpp" filter::Displacement* filterDisplacement; filter::Shape* filterShape; @@ -50,10 +50,10 @@ MODULE_EXPORT void obs_module_unload(void) } #ifdef _WIN32 -#define NOMINMAX -#define NOINOUT - +// Windows Only +extern "C" { #include +} BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID) { diff --git a/source/plugin.h b/source/plugin.hpp similarity index 90% rename from source/plugin.h rename to source/plugin.hpp index c91219a5..d00a6f5b 100644 --- a/source/plugin.h +++ b/source/plugin.hpp @@ -19,16 +19,14 @@ #pragma once #include -#include +#include #include -extern "C" { #pragma warning(push) #pragma warning(disable : 4201) #include "obs-module.h" #include "util/platform.h" #pragma warning(pop) -} // Plugin #define PLUGIN_NAME "Stream Effects" @@ -44,16 +42,6 @@ extern "C" { #define vstr(s) dstr(s) #define dstr(s) #s -#define clamp(val, low, high) (val > high ? high : (val < low ? low : val)) -#ifdef max -#undef max -#endif -#define max(val, high) (val > high ? val : high) -#ifdef min -#undef min -#endif -#define min(val, low) (val < low ? val : low) - #ifndef __FUNCTION_NAME__ #if defined(_WIN32) || defined(_WIN64) //WINDOWS #define __FUNCTION_NAME__ __FUNCTION__ diff --git a/source/source-mirror.cpp b/source/source-mirror.cpp index 1f0af2b3..a5542c33 100644 --- a/source/source-mirror.cpp +++ b/source/source-mirror.cpp @@ -17,19 +17,25 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "source-mirror.h" +#include "source-mirror.hpp" #include #include #include #include #include #include "obs-tools.hpp" -#include "strings.h" +#include "strings.hpp" -extern "C" { +// OBS +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4201) +#endif #include #include -} +#ifdef _MSC_VER +#pragma warning(pop) +#endif #define S_SOURCE_MIRROR "Source.Mirror" #define P_SOURCE "Source.Mirror.Source" @@ -109,7 +115,7 @@ bool Source::MirrorAddon::modified_properties(obs_properties_t* pr, obs_property obs_source_t* target = obs_get_source_by_name(obs_data_get_string(data, P_SOURCE)); if (target) { std::vector buf(256); - sprintf_s(buf.data(), buf.size(), "%ldx%ld\0", obs_source_get_width(target), obs_source_get_height(target)); + snprintf(buf.data(), buf.size(), "%ldx%ld\0", obs_source_get_width(target), obs_source_get_height(target)); obs_data_set_string(data, P_SOURCE_SIZE, buf.data()); } else { obs_data_set_string(data, P_SOURCE_SIZE, "0x0"); diff --git a/source/source-mirror.h b/source/source-mirror.hpp similarity index 94% rename from source/source-mirror.h rename to source/source-mirror.hpp index 13f5e586..99c26d90 100644 --- a/source/source-mirror.h +++ b/source/source-mirror.hpp @@ -23,16 +23,18 @@ #include #include #include -#include "gfx-source-texture.h" -#include "gs-rendertarget.h" -#include "gs-sampler.h" -#include "obs-audio-capture.h" +#include "gfx-source-texture.hpp" +#include "gs-rendertarget.hpp" +#include "gs-sampler.hpp" +#include "obs-audio-capture.hpp" #include "obs-source.hpp" -#include "plugin.h" +#include "plugin.hpp" -extern "C" { +// OBS +#pragma warning(push) +#pragma warning(disable : 4201) #include -} +#pragma warning(pop) namespace Source { class MirrorAddon { diff --git a/source/strings.h b/source/strings.hpp similarity index 98% rename from source/strings.h rename to source/strings.hpp index 3dbfde5e..cba054c7 100644 --- a/source/strings.h +++ b/source/strings.hpp @@ -18,7 +18,7 @@ */ #pragma once -#include "plugin.h" +#include "plugin.hpp" #define P_TRANSLATE(x) obs_module_text(x) #define P_DESC(x) x ".Description" diff --git a/source/util-event.hpp b/source/util-event.hpp index 815f50b6..c00ed5c0 100644 --- a/source/util-event.hpp +++ b/source/util-event.hpp @@ -62,4 +62,4 @@ namespace util { listeners.clear(); } }; -}; // namespace util +} // namespace util diff --git a/source/util-math.cpp b/source/util-math.cpp index b3b8005f..b2462dae 100644 --- a/source/util-math.cpp +++ b/source/util-math.cpp @@ -17,50 +17,49 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "util-math.h" +#include "util-math.hpp" #include -#include -#include -#include "util-memory.h" +#include +#include "util-memory.hpp" void* util::vec3a::operator new(size_t count) { - return _aligned_malloc(count, 16); + return aligned_alloc(count, 16); } void* util::vec3a::operator new[](size_t count) { - return _aligned_malloc(count, 16); + return aligned_alloc(count, 16); } void util::vec3a::operator delete(void* p) { - _aligned_free(p); + aligned_free(p); } void util::vec3a::operator delete[](void* p) { - _aligned_free(p); + aligned_free(p); } void* util::vec4a::operator new(size_t count) { - return _aligned_malloc(count, 16); + return aligned_alloc(count, 16); } void* util::vec4a::operator new[](size_t count) { - return _aligned_malloc(count, 16); + return aligned_alloc(count, 16); } void util::vec4a::operator delete(void* p) { - _aligned_free(p); + aligned_free(p); } void util::vec4a::operator delete[](void* p) { - _aligned_free(p); + aligned_free(p); } std::pair util::SizeFromString(std::string text, bool allowSquare) diff --git a/source/util-math.h b/source/util-math.hpp similarity index 78% rename from source/util-math.h rename to source/util-math.hpp index dffe6f2b..bb445918 100644 --- a/source/util-math.h +++ b/source/util-math.hpp @@ -18,15 +18,18 @@ */ #pragma once -#include +#include #include #include #include // OBS +#pragma warning(push) +#pragma warning(disable : 4201) #include #include #include +#pragma warning(pop) // Constants #define PI 3.1415926535897932384626433832795 @@ -60,18 +63,24 @@ inline size_t GetNearestPowerOfTwoBelow(size_t v) } namespace util { - __declspec(align(16)) struct vec3a : public vec3 { - static void* vec3a::operator new(size_t count); - static void* vec3a::operator new[](size_t count); - static void vec3a::operator delete(void* p); - static void vec3a::operator delete[](void* p); + #ifdef _MSC_VER + __declspec(align(16)) + #endif + struct vec3a : public vec3 { + static void* operator new(size_t count); + static void* operator new[](size_t count); + static void operator delete(void* p); + static void operator delete[](void* p); }; - __declspec(align(16)) struct vec4a : public vec4 { - static void* vec4a::operator new(size_t count); - static void* vec4a::operator new[](size_t count); - static void vec4a::operator delete(void* p); - static void vec4a::operator delete[](void* p); + #ifdef _MSC_VER + __declspec(align(16)) + #endif + struct vec4a : public vec4 { + static void* operator new(size_t count); + static void* operator new[](size_t count); + static void operator delete(void* p); + static void operator delete[](void* p); }; std::pair SizeFromString(std::string text, bool allowSquare = true); @@ -108,15 +117,15 @@ namespace util { inline bool is_power_of_two(x v) \ { \ return is_power_of_two_loop(v); \ - }; - is_power_of_two_as_loop(int8_t); - is_power_of_two_as_loop(uint8_t); - is_power_of_two_as_loop(int16_t); - is_power_of_two_as_loop(uint16_t); - is_power_of_two_as_loop(int32_t); - is_power_of_two_as_loop(uint32_t); - is_power_of_two_as_loop(int64_t); - is_power_of_two_as_loop(uint64_t); + } + is_power_of_two_as_loop(int8_t) + is_power_of_two_as_loop(uint8_t) + is_power_of_two_as_loop(int16_t) + is_power_of_two_as_loop(uint16_t) + is_power_of_two_as_loop(int32_t) + is_power_of_two_as_loop(uint32_t) + is_power_of_two_as_loop(int64_t) + is_power_of_two_as_loop(uint64_t) #undef is_power_of_two_as_loop #pragma pop_macro("is_power_of_two_as_loop") diff --git a/source/util-memory.cpp b/source/util-memory.cpp index 42b8d536..c155e612 100644 --- a/source/util-memory.cpp +++ b/source/util-memory.cpp @@ -17,18 +17,15 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "util-memory.h" +#include "util-memory.hpp" #include + #define USE_STD_ALLOC_FREE void* util::malloc_aligned(size_t align, size_t size) { #ifdef USE_STD_ALLOC_FREE -#if defined(_MSC_VER) - return _aligned_malloc(size, align); -#else - return aligned_malloc(align, size); -#endif + return aligned_alloc(align, size); #else // Ensure that we have space for the pointer and the data. size_t asize = aligned_offset(align, size + (sizeof(void*) * 2)); @@ -50,11 +47,7 @@ void* util::malloc_aligned(size_t align, size_t size) void util::free_aligned(void* mem) { #ifdef USE_STD_ALLOC_FREE -#if defined(_MSC_VER) - _aligned_free(mem); -#else - free(mem); -#endif + aligned_free(mem); #else void* ptr = reinterpret_cast(*reinterpret_cast(static_cast(mem) - sizeof(void*))); free(ptr); diff --git a/source/util-memory.h b/source/util-memory.hpp similarity index 94% rename from source/util-memory.h rename to source/util-memory.hpp index aa124b33..693472f1 100644 --- a/source/util-memory.h +++ b/source/util-memory.hpp @@ -18,8 +18,14 @@ */ #pragma once -#include -#include +#include + +#ifdef _MSC_VER +#define aligned_alloc _aligned_malloc +#define aligned_free _aligned_free +#else +#define aligned_free free +#endif namespace util { inline size_t aligned_offset(size_t align, size_t pos) diff --git a/source/utility.cpp b/source/utility.cpp index afc5e352..9dcff495 100644 --- a/source/utility.cpp +++ b/source/utility.cpp @@ -17,4 +17,4 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "utility.h" +#include "utility.hpp" diff --git a/source/utility.h b/source/utility.hpp similarity index 100% rename from source/utility.h rename to source/utility.hpp