X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Ftexture.cpp;h=a65715e716a26c6fbc283655c37c0382fc795010;hb=e1be82a4dfce8d90358c506f65be09da4dc9d5ec;hp=5f21229fa8abc2d80c3e0029364bb519bd961bee;hpb=b274dc87db4422498e72823649358114dfca0096;p=libs%2Fgl.git diff --git a/source/core/texture.cpp b/source/core/texture.cpp index 5f21229f..a65715e7 100644 --- a/source/core/texture.cpp +++ b/source/core/texture.cpp @@ -15,39 +15,14 @@ namespace Msp { namespace GL { Texture::Texture(unsigned t): - TextureBackend(t), - format(NO_PIXELFORMAT), - storage_fmt(format), - swizzle(NO_SWIZZLE), - use_srgb_format(false), - auto_gen_mipmap(false) + TextureBackend(t) { } void Texture::set_format(PixelFormat fmt) { PixelComponents comp = get_components(fmt); - PixelComponents st_comp = comp; - FormatSwizzle swiz = NO_SWIZZLE; - switch(comp) - { - case LUMINANCE: - st_comp = RED; - swiz = R_TO_LUMINANCE; - break; - case LUMINANCE_ALPHA: - st_comp = RG; - swiz = RG_TO_LUMINANCE_ALPHA; - break; - case BGR: - st_comp = RGB; - swiz = RGB_TO_BGR; - break; - case BGRA: - st_comp = RGBA; - swiz = RGB_TO_BGR; - break; - default:; - } + ComponentSwizzle swiz = get_required_swizzle(comp); + PixelComponents st_comp = unswizzle_components(comp, swiz); PixelFormat st_fmt = make_pixelformat(st_comp, get_component_type(fmt), is_srgb(fmt)); require_pixelformat(st_fmt); @@ -59,6 +34,48 @@ void Texture::set_format(PixelFormat fmt) swizzle = swiz; } +unsigned Texture::count_levels(unsigned size) +{ + unsigned n = 0; + for(; size; size>>=1, ++n) ; + return n; +} + +void Texture::stage_pixels(void *staging, const void *data, size_t count) +{ + if(swizzle==RGBA_TO_RGB) + { + const uint32_t *src = static_cast(data); + uint32_t *dst = static_cast(staging); + size_t i = 0; + for(; i+3>24)|(src[1]<<8)|0xFF000000; + dst[2] = (src[1]>>16)|(src[2]<<16)|0xFF000000; + dst[3] = (src[2]>>8)|0xFF000000; + src += 3; + dst += 4; + } + + if(i(src); + for(; i(data); + size_t data_size = count*get_pixel_size(storage_fmt); + copy(src, src+data_size, static_cast(staging)); + } +} + void Texture::load_image(const string &fn, unsigned lv) { Graphics::Image img;