]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture1d.cpp
Use standard fixed-size integer types
[libs/gl.git] / source / core / texture1d.cpp
index feff9f9883f3f1b39921193fd75eb4c4e5effde4..df8dd06c75c705e06b31547b0501ea4a86e1c1fb 100644 (file)
@@ -42,22 +42,6 @@ void Texture1D::allocate(unsigned level)
                throw invalid_operation("Texture1D::allocate");
        if(level>=levels)
                throw invalid_argument("Texture1D::allocate");
-
-       bool direct = ARB_texture_storage && ARB_direct_state_access;
-       if(!direct)
-       {
-               glActiveTexture(GL_TEXTURE0);
-               glBindTexture(target, id);
-       }
-
-       allocate_(level);
-
-       if(!direct)
-               glBindTexture(target, 0);
-}
-
-void Texture1D::allocate_(unsigned level)
-{
        if(allocated&(1<<level))
                return;
 
@@ -67,12 +51,15 @@ void Texture1D::allocate_(unsigned level)
                if(ARB_direct_state_access)
                        glTextureStorage1D(id, levels, fmt, width);
                else
+               {
+                       bind_scratch();
                        glTexStorage1D(target, levels, fmt, width);
+               }
                apply_swizzle();
                allocated |= (1<<levels)-1;
        }
        else
-               image_(level, 0);
+               image(level, 0);
 }
 
 void Texture1D::image(unsigned level, const void *data)
@@ -85,22 +72,8 @@ void Texture1D::image(unsigned level, const void *data)
        if(ARB_texture_storage)
                return sub_image(level, 0, get_level_size(level), data);
 
-       glActiveTexture(GL_TEXTURE0);
-       glBindTexture(target, id);
-
-       image_(level, data);
+       bind_scratch();
 
-       if(auto_gen_mipmap && level==0)
-       {
-               generate_mipmap_();
-               allocated |= (1<<levels)-1;
-       }
-
-       glBindTexture(target, 0);
-}
-
-void Texture1D::image_(unsigned level, const void *data)
-{
        if(!allocated)
        {
                glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
@@ -129,27 +102,17 @@ void Texture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
        if(level>=levels)
                throw out_of_range("Texture1D::sub_image");
 
-       bool direct = (ARB_direct_state_access && (ARB_texture_storage || (allocated&(1<<level))));
-       if(!direct)
-       {
-               glActiveTexture(GL_TEXTURE0);
-               glBindTexture(target, id);
-       }
-
-       allocate_(level);
+       allocate(level);
 
        GLenum comp = get_gl_components(get_components(storage_fmt));
        GLenum type = get_gl_type(get_component_type(storage_fmt));
        if(ARB_direct_state_access)
                glTextureSubImage1D(id, level, x, wd, comp, type, data);
        else
+       {
+               bind_scratch();
                glTexSubImage1D(target, level, x, wd, comp, type, data);
-
-       if(auto_gen_mipmap && level==0)
-               generate_mipmap_();
-
-       if(!direct)
-               glBindTexture(target, 0);
+       }
 }
 
 void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelComponents comp, DataType type, const void *data)
@@ -183,7 +146,7 @@ unsigned Texture1D::get_level_size(unsigned level) const
        return width>>level;
 }
 
-UInt64 Texture1D::get_data_size() const
+uint64_t Texture1D::get_data_size() const
 {
        return id ? width*get_pixel_size(storage_fmt) : 0;
 }