]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture1d.cpp
Remove remaining deprecated things from the core classes
[libs/gl.git] / source / core / texture1d.cpp
index 4c58d4701639d777b0471b846acc7717d480c90b..7c3f02ab5f97988af099937eb6ed52254542b332 100644 (file)
@@ -1,4 +1,3 @@
-#include <msp/core/raii.h>
 #include <msp/gl/extensions/arb_direct_state_access.h>
 #include <msp/gl/extensions/arb_texture_storage.h>
 #include <msp/gl/extensions/msp_texture1d.h>
@@ -42,36 +41,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,42 +71,22 @@ 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);
-
-       if(auto_gen_mipmap && level==0)
-       {
-               generate_mipmap_();
-               allocated |= (1<<levels)-1;
-       }
-
-       glBindTexture(target, 0);
-}
+       bind_scratch();
 
-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;
 }
 
-void Texture1D::image(unsigned level, PixelComponents comp, DataType type, const void *data)
-{
-       if(comp!=get_components(format) || type!=get_component_type(format))
-               throw incompatible_data("Texture1D::image");
-       image(level, data);
-}
-
 void Texture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
 {
        if(width==0)
@@ -127,34 +94,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)
-{
-       if(comp!=get_components(format) || type!=get_component_type(format))
-               throw incompatible_data("Texture1D::sub_image");
-       sub_image(level, x, wd, data);
+       }
 }
 
 void Texture1D::image(const Graphics::Image &img, unsigned lv)
@@ -181,7 +131,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;
 }