From 624bdda6a350ef2f19bc0025e5d572f98b7ab0a8 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sat, 21 Dec 2019 18:06:17 +0100 Subject: [PATCH] gs-texture: Reduce context lock time and improve code --- source/obs/gs/gs-texture.cpp | 38 ++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/source/obs/gs/gs-texture.cpp b/source/obs/gs/gs-texture.cpp index e555e9c2..400d57d8 100644 --- a/source/obs/gs/gs-texture.cpp +++ b/source/obs/gs/gs-texture.cpp @@ -35,6 +35,16 @@ #pragma warning(pop) #endif +static uint32_t decode_flags(gs::texture::flags texture_flags) +{ + uint32_t flags = 0; + if (exact(texture_flags, gs::texture::flags::Dynamic)) + flags |= GS_DYNAMIC; + if (exact(texture_flags, gs::texture::flags::BuildMipMaps)) + flags |= GS_BUILD_MIPMAPS; + return flags; +} + 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) { @@ -51,11 +61,10 @@ gs::texture::texture(uint32_t width, uint32_t height, gs_color_format format, ui throw std::logic_error("mip mapping requires power of two dimensions"); } - auto gctx = gs::context(); - _texture = gs_texture_create( - width, height, format, mip_levels, mip_data, - (((texture_flags & flags::Dynamic) == flags::Dynamic) ? GS_DYNAMIC : 0) - | (((texture_flags & flags::BuildMipMaps) == flags::BuildMipMaps) ? GS_BUILD_MIPMAPS : 0)); + { + auto gctx = gs::context(); + _texture = gs_texture_create(width, height, format, mip_levels, mip_data, decode_flags(texture_flags)); + } if (!_texture) throw std::runtime_error("Failed to create texture."); @@ -83,11 +92,11 @@ gs::texture::texture(uint32_t width, uint32_t height, uint32_t depth, gs_color_f throw std::logic_error("mip mapping requires power of two dimensions"); } - auto gctx = gs::context(); - _texture = gs_voltexture_create( - width, height, depth, format, mip_levels, mip_data, - (((texture_flags & flags::Dynamic) == flags::Dynamic) ? GS_DYNAMIC : 0) - | (((texture_flags & flags::BuildMipMaps) == flags::BuildMipMaps) ? GS_BUILD_MIPMAPS : 0)); + { + auto gctx = gs::context(); + _texture = + gs_voltexture_create(width, height, depth, format, mip_levels, mip_data, decode_flags(texture_flags)); + } if (!_texture) throw std::runtime_error("Failed to create texture."); @@ -109,11 +118,10 @@ gs::texture::texture(uint32_t size, gs_color_format format, uint32_t mip_levels, throw std::logic_error("mip mapping requires power of two dimensions"); } - auto gctx = gs::context(); - _texture = gs_cubetexture_create( - size, format, mip_levels, mip_data, - (((texture_flags & flags::Dynamic) == flags::Dynamic) ? GS_DYNAMIC : 0) - | (((texture_flags & flags::BuildMipMaps) == flags::BuildMipMaps) ? GS_BUILD_MIPMAPS : 0)); + { + auto gctx = gs::context(); + _texture = gs_cubetexture_create(size, format, mip_levels, mip_data, decode_flags(texture_flags)); + } if (!_texture) throw std::runtime_error("Failed to create texture.");