}
}
-void VulkanTexture::stage_pixels(void *staging, const void *data, size_t count)
-{
- const Texture &self = *static_cast<const Texture *>(this);
-
- if(self.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(self.storage_fmt);
- copy(src, src+data_size, static_cast<char *>(staging));
- }
-}
-
void VulkanTexture::generate_mipmap()
{
unsigned n_levels = static_cast<const Texture *>(this)->n_levels;
void create_mip_views() const;
void require_swizzle() { }
- void stage_pixels(void *, const void *, size_t);
-
void generate_mipmap();
virtual void fill_mipmap_blit(unsigned, void *) = 0;
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;
void set_format(PixelFormat);
static unsigned count_levels(unsigned);
+ void stage_pixels(void *, const void *, std::size_t);
+
public:
PixelFormat get_format() const { return format; }
}
else if(phase==2)
{
- if(raw_data)
+ if(texture.swizzle==RGBA_TO_RGB)
+ {
+ const void *data;
+ if(raw_data)
+ {
+ raw_data->load();
+ data = raw_data->get_data();
+ }
+ else
+ {
+ image.load(*img_loader);
+ data = image.get_pixels();
+ }
+ texture.stage_pixels(transfer.get_address(), data, texture.width*texture.height);
+ }
+ else if(raw_data)
raw_data->load_into(transfer.get_address());
else
image.load_into(*img_loader, transfer.get_address());