X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexture2d.cpp;h=47e0c7434d0ef56c7fbf892b0ee45a31f4552710;hb=96340a856489e026b27377482b358c7ca2cf74b6;hp=8d6e8471edb72574340e6e870514bfb652a13113;hpb=3c46227c280bc4cd8a4487c648f2f080d5b4f7ea;p=libs%2Fgl.git diff --git a/source/texture2d.cpp b/source/texture2d.cpp index 8d6e8471..47e0c743 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -46,7 +46,7 @@ Texture2D::~Texture2D() set_manager(0); } -void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht) +void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned lv) { if(width>0) throw invalid_operation("Texture2D::storage"); @@ -56,26 +56,30 @@ void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht) set_internal_format(fmt); width = wd; height = ht; + levels = get_n_levels(); + if(lv>0) + levels = min(levels, lv); } void Texture2D::allocate(unsigned level) { if(width==0 || height==0) throw invalid_operation("Texture2D::allocate"); + if(level>=levels) + throw invalid_argument("Texture2D::allocate"); if(allocated&(1<(pixel_buffer.map(WRITE_ONLY)); + pixel_buffer.storage(n_bytes); + mapped_address = reinterpret_cast(pixel_buffer.map()); } else if(phase==2) { @@ -265,7 +271,12 @@ bool Texture2D::AsyncLoader::process() } if(!texture.id) - glGenTextures(1, &texture.id); + { + if(ARB_direct_state_access) + glCreateTextures(texture.target, 1, &texture.id); + else + glGenTextures(1, &texture.id); + } texture.image(image, srgb_conversion, true); }