gs-texture: Allow creation from existing gs_texture_t*

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2018-03-05 15:10:19 +01:00
parent 01bf510a28
commit 7d065c131d
2 changed files with 21 additions and 12 deletions

View file

@ -178,7 +178,7 @@ GS::Texture::Texture(Texture& other) {
} }
GS::Texture::~Texture() { GS::Texture::~Texture() {
if (m_texture) { if (m_isOwner && m_texture) {
obs_enter_graphics(); obs_enter_graphics();
switch (gs_get_texture_type(m_texture)) { switch (gs_get_texture_type(m_texture)) {
case GS_TEXTURE_2D: case GS_TEXTURE_2D:

View file

@ -29,6 +29,10 @@ extern "C" {
namespace GS { namespace GS {
class Texture { class Texture {
protected:
gs_texture_t * m_texture;
bool m_isOwner = true;
public: public:
enum Type : uint8_t { enum Type : uint8_t {
Normal, Normal,
@ -54,7 +58,8 @@ namespace GS {
* \param mip_data * \param mip_data
* \param flags * \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 * \brief Create a new volume texture from data
@ -69,7 +74,8 @@ namespace GS {
* \param mip_data * \param mip_data
* \param flags * \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 * \brief Create a new cube texture from data
@ -82,7 +88,8 @@ namespace GS {
* \param mip_data * \param mip_data
* \param flags * \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 * \brief Load a texture from a file
@ -94,7 +101,12 @@ namespace GS {
* *
* \param file File to create the texture from. * \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 * \brief Copy an existing texture
@ -139,8 +151,5 @@ namespace GS {
* \return gs_texture_t* * \return gs_texture_t*
*/ */
gs_texture_t* GetObject(); gs_texture_t* GetObject();
protected:
gs_texture_t* m_texture;
}; };
} }