X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Ftexture1d.cpp;h=7685d39e99abaeca025ae1c4750b6a53903ff08a;hb=9b3bce7ae76ff8c0c81315d2505ea96bf422a318;hp=742857be725b4ed205b369c43d823f5b0812af14;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266;p=libs%2Fgl.git diff --git a/source/core/texture1d.cpp b/source/core/texture1d.cpp index 742857be..7685d39e 100644 --- a/source/core/texture1d.cpp +++ b/source/core/texture1d.cpp @@ -22,7 +22,11 @@ Texture1D::Texture1D(): void Texture1D::storage(PixelFormat fmt, unsigned wd, unsigned lv) { if(width>0) - throw invalid_operation("Texture1D::storage"); + { + if(fmt!=format || wd!=width || (lv && lv!=levels)) + throw incompatible_data("Texture1D::storage"); + return; + } if(wd==0) throw invalid_argument("Texture1D::storage"); @@ -39,12 +43,27 @@ 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< _bind(!ARB_direct_state_access, this); if(ARB_direct_state_access) glTextureStorage1D(id, levels, storage_fmt, width); else @@ -53,21 +72,35 @@ void Texture1D::allocate(unsigned level) allocated |= (1<=levels) + throw out_of_range("Texture1D::image"); if(ARB_texture_storage) - return sub_image(level, 0, w, data); + return sub_image(level, 0, get_level_size(level), data); - BindRestore _bind(this); + glActiveTexture(GL_TEXTURE0); + glBindTexture(target, id); + image_(level, data); + + if(auto_gen_mipmap && level==0) + { + generate_mipmap_(); + allocated |= (1<=levels) + throw out_of_range("Texture1D::sub_image"); + + bool direct = (ARB_direct_state_access && (ARB_texture_storage || (allocated&(1< _bind(!ARB_direct_state_access, this); - allocate(level); + allocate_(level); PixelComponents comp = get_components(storage_fmt); - DataType type = get_component_type(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 glTexSubImage1D(target, level, x, wd, comp, type, data); if(auto_gen_mipmap && level==0) - generate_mipmap(); + generate_mipmap_(); + + if(!direct) + glBindTexture(target, 0); } void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelComponents comp, DataType type, const void *data) @@ -126,10 +165,7 @@ void Texture1D::image(const Graphics::Image &img, unsigned lv) unsigned w = img.get_width(); PixelFormat fmt = pixelformat_from_image(img); - if(width==0) - storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, lv); - else if(w!=width) - throw incompatible_data("Texture1D::image"); + storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, lv); image(0, img.get_pixels()); }