]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / core / texture.cpp
index 73dd39b6c5cf79a5662a31ff3846b8981fc677b6..a65715e716a26c6fbc283655c37c0382fc795010 100644 (file)
@@ -34,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<const uint32_t *>(data);
+               uint32_t *dst = static_cast<uint32_t *>(staging);
+               size_t i = 0;
+               for(; i+3<count; i+=4)
+               {
+                       dst[0] = src[0]|0xFF000000;
+                       dst[1] = (src[0]>>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<count)
+               {
+                       const uint8_t *src_bytes = reinterpret_cast<const uint8_t *>(src);
+                       for(; i<count; ++i)
+                       {
+                               *dst++ = src_bytes[0]|(src_bytes[1]<<8)|(src_bytes[2]<<16)|0xFF000000;
+                               src_bytes += 3;
+                       }
+               }
+       }
+       else
+       {
+               const char *src = static_cast<const char *>(data);
+               size_t data_size = count*get_pixel_size(storage_fmt);
+               copy(src, src+data_size, static_cast<char *>(staging));
+       }
+}
+
 void Texture::load_image(const string &fn, unsigned lv)
 {
        Graphics::Image img;