]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture.cpp
Refactor texture ID generation into a function
[libs/gl.git] / source / core / texture.cpp
index f6594ab14c7e5143434ac0823c862427c70f2c9d..3eb48b8b2eb426dafebd1791ab11d4fba09b4c63 100644 (file)
@@ -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);
@@ -75,7 +83,7 @@ void Texture::set_format(PixelFormat fmt)
        default:;
        }
 
-       PixelFormat st_fmt = make_pixelformat(st_comp, get_component_type(fmt));
+       PixelFormat st_fmt = make_pixelformat(st_comp, get_component_type(fmt), is_srgb(fmt));
        require_pixelformat(st_fmt);
        if(swiz!=NO_SWIZZLE)
                static Require _req(ARB_texture_swizzle);
@@ -287,7 +295,7 @@ void Texture::Loader::init()
        levels = 0;
 
        add("external_image", &Loader::external_image);
-       add("external_image_srgb", &Loader::external_image);
+       add("external_image_srgb", &Loader::external_image_srgb);
        add("filter", &Loader::filter);
        add("generate_mipmap", &Loader::generate_mipmap);
        add("image_data", &Loader::image_data);
@@ -309,7 +317,7 @@ unsigned Texture::Loader::get_levels() const
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-void Texture::Loader::load_external_image(Graphics::Image &img, const std::string &fn)
+void Texture::Loader::load_external_image(Graphics::Image &img, const string &fn)
 {
        RefPtr<IO::Seekable> io = get_collection().open_raw(fn);
        if(!io)