X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexture2d.cpp;h=08383526728bb7a239b8551c910c75c6a2ff2f03;hb=a9bf08d7c8d54204b76f91dab95052b737595bea;hp=7ce18d00a9fa075b5df6b2a5ea1dac741411165f;hpb=1955e583d7eeeb0a2ff054d90c3694f575d9a08d;p=libs%2Fgl.git diff --git a/source/texture2d.cpp b/source/texture2d.cpp index 7ce18d00..08383526 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,24 +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) { @@ -263,7 +270,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); }