2017-04-23 04:44:34 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "VideoBackends/Software/SWTexture.h"
|
|
|
|
|
2017-08-24 02:46:23 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include "VideoBackends/Software/CopyRegion.h"
|
|
|
|
|
2017-04-23 04:44:34 +00:00
|
|
|
namespace SW
|
|
|
|
{
|
2017-10-02 05:21:10 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
struct Pixel
|
|
|
|
{
|
|
|
|
u8 r;
|
|
|
|
u8 g;
|
|
|
|
u8 b;
|
|
|
|
u8 a;
|
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
}
|
2017-04-23 04:44:34 +00:00
|
|
|
SWTexture::SWTexture(const TextureConfig& tex_config) : AbstractTexture(tex_config)
|
|
|
|
{
|
2017-10-02 05:21:10 +00:00
|
|
|
m_data.resize(tex_config.width * tex_config.height * 4);
|
2017-04-23 04:44:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SWTexture::Bind(unsigned int stage)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SWTexture::CopyRectangleFromTexture(const AbstractTexture* source,
|
|
|
|
const MathUtil::Rectangle<int>& srcrect,
|
|
|
|
const MathUtil::Rectangle<int>& dstrect)
|
|
|
|
{
|
2017-09-03 02:30:34 +00:00
|
|
|
const SWTexture* software_source_texture = static_cast<const SWTexture*>(source);
|
2017-08-24 02:46:23 +00:00
|
|
|
|
|
|
|
if (srcrect.GetWidth() == dstrect.GetWidth() && srcrect.GetHeight() == dstrect.GetHeight())
|
|
|
|
{
|
2017-09-03 02:30:34 +00:00
|
|
|
m_data.assign(software_source_texture->GetData(),
|
|
|
|
software_source_texture->GetData() + m_data.size());
|
2017-08-24 02:46:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-02 05:33:47 +00:00
|
|
|
CopyRegion(reinterpret_cast<const Pixel*>(software_source_texture->GetData()), srcrect,
|
|
|
|
reinterpret_cast<Pixel*>(GetData()), dstrect);
|
2017-08-24 02:46:23 +00:00
|
|
|
}
|
2017-04-23 04:44:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SWTexture::Load(u32 level, u32 width, u32 height, u32 row_length, const u8* buffer,
|
|
|
|
size_t buffer_size)
|
|
|
|
{
|
2017-08-24 02:46:23 +00:00
|
|
|
m_data.assign(buffer, buffer + buffer_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
const u8* SWTexture::GetData() const
|
|
|
|
{
|
|
|
|
return m_data.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
u8* SWTexture::GetData()
|
|
|
|
{
|
|
|
|
return m_data.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<AbstractTexture::RawTextureInfo> SWTexture::MapFullImpl()
|
|
|
|
{
|
2017-09-03 02:30:34 +00:00
|
|
|
return AbstractTexture::RawTextureInfo{GetData(), m_config.width * 4, m_config.width,
|
|
|
|
m_config.height};
|
2017-04-23 04:44:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace SW
|