From 2e7f0e8b226fdeea3306e2e0eef22a8f200ae16b Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 18 Apr 2021 01:04:53 +0300 Subject: [PATCH] Refactor texture ID generation into a function --- source/core/texture.cpp | 14 +++++++++++--- source/core/texture.h | 1 + source/core/texture2d.cpp | 7 +------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/source/core/texture.cpp b/source/core/texture.cpp index 3a4b1096..3eb48b8b 100644 --- a/source/core/texture.cpp +++ b/source/core/texture.cpp @@ -34,10 +34,8 @@ Texture::Texture(GLenum t, ResourceManager *m): { if(m) set_manager(m); - else if(ARB_direct_state_access) - glCreateTextures(target, 1, &id); else - glGenTextures(1, &id); + generate_id(); } Texture::~Texture() @@ -49,6 +47,16 @@ Texture::~Texture() glDeleteTextures(1, &id); } +void Texture::generate_id() +{ + if(id) + throw invalid_operation("Texture::generate_id"); + if(ARB_direct_state_access) + glCreateTextures(target, 1, &id); + else + glGenTextures(1, &id); +} + void Texture::set_format(PixelFormat fmt) { PixelComponents comp = get_components(fmt); diff --git a/source/core/texture.h b/source/core/texture.h index c4e72031..bca0d409 100644 --- a/source/core/texture.h +++ b/source/core/texture.h @@ -90,6 +90,7 @@ public: ~Texture(); protected: + void generate_id(); void set_format(PixelFormat); void apply_swizzle(); void set_parameter_i(GLenum, int) const; diff --git a/source/core/texture2d.cpp b/source/core/texture2d.cpp index d2addda7..0f06790c 100644 --- a/source/core/texture2d.cpp +++ b/source/core/texture2d.cpp @@ -290,12 +290,7 @@ bool Texture2D::AsyncLoader::process() } if(!texture.id) - { - if(ARB_direct_state_access) - glCreateTextures(texture.target, 1, &texture.id); - else - glGenTextures(1, &texture.id); - } + texture.generate_id(); texture.image(image, 0, true); } -- 2.45.2