X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexture2d.cpp;h=559167f8ba4d5eefc017e6e158d76dec55127cf6;hb=a8a04ddd95e57a8f103c04dba317addc32866689;hp=7ce18d00a9fa075b5df6b2a5ea1dac741411165f;hpb=1955e583d7eeeb0a2ff054d90c3694f575d9a08d;p=libs%2Fgl.git diff --git a/source/texture2d.cpp b/source/texture2d.cpp index 7ce18d00..559167f8 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,29 @@ 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< _bind(!ARB_direct_state_access, this); if(ARB_direct_state_access) - glTextureStorage2D(id, n_levels, ifmt, width, height); + glTextureStorage2D(id, levels, ifmt, width, height); else - { - BindRestore _bind(this); - glTexStorage2D(target, n_levels, ifmt, width, height); - } - allocated |= (1<(pixel_buffer.map(WRITE_ONLY)); + pixel_buffer.storage(n_bytes); + mapped_address = reinterpret_cast(pixel_buffer.map()); } else if(phase==2) { @@ -263,8 +278,13 @@ bool Texture2D::AsyncLoader::process() } if(!texture.id) - glGenTextures(1, &texture.id); - texture.image(image, srgb_conversion, true); + { + if(ARB_direct_state_access) + glCreateTextures(texture.target, 1, &texture.id); + else + glGenTextures(1, &texture.id); + } + texture.image(image, 0, srgb_conversion, true); } ++phase;