gs-texture: Reduce context lock time and improve code

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2019-12-21 18:06:17 +01:00
parent aa59806322
commit 624bdda6a3

View file

@ -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.");