]> 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 4c58d4701639d777b0471b846acc7717d480c90b..df8dd06c75c705e06b31547b0501ea4a86e1c1fb 100644 (file)
@@ -42,36 +42,24 @@ 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;
 
        if(ARB_texture_storage)
        {
+               GLenum fmt = get_gl_pixelformat(storage_fmt);
                if(ARB_direct_state_access)
-                       glTextureStorage1D(id, levels, storage_fmt, width);
+                       glTextureStorage1D(id, levels, fmt, width);
                else
-                       glTexStorage1D(target, levels, storage_fmt, width);
+               {
+                       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)
@@ -84,31 +72,18 @@ 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);
                apply_swizzle();
        }
 
-       PixelComponents comp = get_components(storage_fmt);
+       GLenum fmt = get_gl_pixelformat(storage_fmt);
+       GLenum comp = get_gl_components(get_components(storage_fmt));
        GLenum type = get_gl_type(get_component_type(storage_fmt));
-       glTexImage1D(target, level, storage_fmt, get_level_size(level), 0, comp, type, data);
+       glTexImage1D(target, level, fmt, get_level_size(level), 0, comp, type, data);
 
        allocated |= 1<<level;
 }
@@ -127,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);
-
-       PixelComponents comp = get_components(storage_fmt);
+       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)
@@ -181,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;
 }