]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture1d.cpp
Use a scratch binding to modify textures and buffers
[libs/gl.git] / source / core / texture1d.cpp
index 71c736f04da4ecb7971d22461434169445614f6b..1dbe36eb293e6b02d6a01608b23fb546938eb71a 100644 (file)
@@ -2,7 +2,6 @@
 #include <msp/gl/extensions/arb_direct_state_access.h>
 #include <msp/gl/extensions/arb_texture_storage.h>
 #include <msp/gl/extensions/msp_texture1d.h>
-#include "bindable.h"
 #include "error.h"
 #include "texture1d.h"
 
@@ -48,11 +47,14 @@ void Texture1D::allocate(unsigned level)
 
        if(ARB_texture_storage)
        {
-               Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
+               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;
        }
@@ -67,12 +69,10 @@ void Texture1D::image(unsigned level, const void *data)
        if(level>=levels)
                throw out_of_range("Texture1D::image");
 
-       unsigned w = get_level_size(level);
-
        if(ARB_texture_storage)
-               return sub_image(level, 0, w, data);
+               return sub_image(level, 0, get_level_size(level), data);
 
-       BindRestore _bind(this);
+       bind_scratch();
 
        if(!allocated)
        {
@@ -80,9 +80,10 @@ void Texture1D::image(unsigned level, const void *data)
                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, w, 0, comp, type, data);
+       glTexImage1D(target, level, fmt, get_level_size(level), 0, comp, type, data);
 
        allocated |= 1<<level;
        if(auto_gen_mipmap && level==0)
@@ -106,15 +107,17 @@ void Texture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
        if(level>=levels)
                throw out_of_range("Texture1D::sub_image");
 
-       Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
        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();