From 7d065c131d6b4459b58eaebb9b8b8aeb8360979d Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Mon, 5 Mar 2018 15:10:19 +0100 Subject: [PATCH] gs-texture: Allow creation from existing gs_texture_t* --- source/gs-texture.cpp | 2 +- source/gs-texture.h | 31 ++++++++++++++++++++----------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/source/gs-texture.cpp b/source/gs-texture.cpp index 43923166..baa25806 100644 --- a/source/gs-texture.cpp +++ b/source/gs-texture.cpp @@ -178,7 +178,7 @@ GS::Texture::Texture(Texture& other) { } GS::Texture::~Texture() { - if (m_texture) { + if (m_isOwner && m_texture) { obs_enter_graphics(); switch (gs_get_texture_type(m_texture)) { case GS_TEXTURE_2D: diff --git a/source/gs-texture.h b/source/gs-texture.h index d8d42082..319fc639 100644 --- a/source/gs-texture.h +++ b/source/gs-texture.h @@ -21,14 +21,18 @@ #include #include extern "C" { - #pragma warning( push ) - #pragma warning( disable: 4201 ) - #include - #pragma warning( pop ) +#pragma warning( push ) +#pragma warning( disable: 4201 ) +#include +#pragma warning( pop ) } namespace GS { class Texture { + protected: + gs_texture_t * m_texture; + bool m_isOwner = true; + public: enum Type : uint8_t { Normal, @@ -54,7 +58,8 @@ namespace GS { * \param mip_data * \param flags */ - Texture(uint32_t width, uint32_t height, gs_color_format format, uint32_t mip_levels, const uint8_t **mip_data, uint32_t flags); + Texture(uint32_t width, uint32_t height, gs_color_format format, uint32_t mip_levels, + const uint8_t **mip_data, uint32_t flags); /*! * \brief Create a new volume texture from data @@ -69,7 +74,8 @@ namespace GS { * \param mip_data * \param flags */ - Texture(uint32_t width, uint32_t height, uint32_t depth, gs_color_format format, uint32_t mip_levels, const uint8_t **mip_data, uint32_t flags); + Texture(uint32_t width, uint32_t height, uint32_t depth, gs_color_format format, uint32_t mip_levels, + const uint8_t **mip_data, uint32_t flags); /*! * \brief Create a new cube texture from data @@ -82,7 +88,8 @@ namespace GS { * \param mip_data * \param flags */ - Texture(uint32_t size, gs_color_format format, uint32_t mip_levels, const uint8_t **mip_data, uint32_t flags); + Texture(uint32_t size, gs_color_format format, uint32_t mip_levels, const uint8_t **mip_data, + uint32_t flags); /*! * \brief Load a texture from a file @@ -94,7 +101,12 @@ namespace GS { * * \param file File to create the texture from. */ - Texture(std::string file);// { LoadFromFile(file); } + Texture(std::string file); + + /*! + * \brief Create a texture from an existing gs_texture_t object. + */ + Texture(gs_texture_t* tex, bool takeOwnership = false) : m_texture(tex), m_isOwner(takeOwnership) {} /*! * \brief Copy an existing texture @@ -139,8 +151,5 @@ namespace GS { * \return gs_texture_t* */ gs_texture_t* GetObject(); - - protected: - gs_texture_t* m_texture; }; }