This commit is contained in:
Subv 2015-10-20 22:14:57 -05:00
parent bda2234553
commit 3c4618bfd4
3 changed files with 32 additions and 34 deletions

View file

@ -851,18 +851,18 @@ void RasterizerOpenGL::ReloadColorBuffer() {
using VideoCore::CopyTextureAndUntile;
switch (bytes_per_pixel) {
case 4:
CopyTextureAndUntile<u32>(reinterpret_cast<u32*>(color_buffer),
reinterpret_cast<u32*>(temp_fb_color_buffer.get()),
CopyTextureAndUntile<4>(color_buffer,
temp_fb_color_buffer.get(),
fb_color_texture.width, fb_color_texture.height);
break;
case 3:
CopyTextureAndUntile<u24_be>(reinterpret_cast<u24_be*>(color_buffer),
reinterpret_cast<u24_be*>(temp_fb_color_buffer.get()),
CopyTextureAndUntile<3>(color_buffer,
temp_fb_color_buffer.get(),
fb_color_texture.width, fb_color_texture.height);
break;
case 2:
CopyTextureAndUntile<u16>(reinterpret_cast<u16*>(color_buffer),
reinterpret_cast<u16*>(temp_fb_color_buffer.get()),
CopyTextureAndUntile<2>(color_buffer,
temp_fb_color_buffer.get(),
fb_color_texture.width, fb_color_texture.height);
break;
default:
@ -974,18 +974,18 @@ void RasterizerOpenGL::CommitColorBuffer() {
using VideoCore::CopyTextureAndTile;
switch (bytes_per_pixel) {
case 4:
CopyTextureAndTile<u32>(reinterpret_cast<u32*>(temp_gl_color_buffer.get()),
reinterpret_cast<u32*>(color_buffer),
CopyTextureAndTile<4>(temp_gl_color_buffer.get(),
color_buffer,
fb_color_texture.width, fb_color_texture.height);
break;
case 3:
CopyTextureAndTile<u24_be>(reinterpret_cast<u24_be*>(temp_gl_color_buffer.get()),
reinterpret_cast<u24_be*>(color_buffer),
CopyTextureAndTile<3>(temp_gl_color_buffer.get(),
color_buffer,
fb_color_texture.width, fb_color_texture.height);
break;
case 2:
CopyTextureAndTile<u16>(reinterpret_cast<u16*>(temp_gl_color_buffer.get()),
reinterpret_cast<u16*>(color_buffer),
CopyTextureAndTile<2>(temp_gl_color_buffer.get(),
color_buffer,
fb_color_texture.width, fb_color_texture.height);
break;
default:

View file

@ -34,15 +34,15 @@ void DumpTGA(std::string filename, short width, short height, u8* raw_data) {
fclose(fout);
}
template<typename T>
void CopyTextureAndTile(const T* src, T* dst, unsigned int width, unsigned int height) {
template<int size>
void CopyTextureAndTile(const u8* src, u8* dst, unsigned int width, unsigned int height) {
for (unsigned int y = 0; y + 8 <= height; y += 8) {
for (unsigned int x = 0; x + 8 <= width; x += 8) {
const T* line = &src[y * width + x];
const u8* line = &src[y * width + x];
for (unsigned int yy = 0; yy < 8; ++yy) {
for (unsigned int xx = 0; xx < 8; ++xx) {
dst[morton_lut[yy * 8 + xx]] = line[xx];
memcpy(dst + size * morton_lut[yy * 8 + xx], line + size * xx, size);
}
line += width;
}
@ -52,19 +52,19 @@ void CopyTextureAndTile(const T* src, T* dst, unsigned int width, unsigned int h
}
}
template void CopyTextureAndTile<u16>(const u16* src, u16* dst, unsigned int width, unsigned int height);
template void CopyTextureAndTile<u24_be>(const u24_be* src, u24_be* dst, unsigned int width, unsigned int height);
template void CopyTextureAndTile<u32>(const u32* src, u32* dst, unsigned int width, unsigned int height);
template void CopyTextureAndTile<2>(const u8* src, u8* dst, unsigned int width, unsigned int height);
template void CopyTextureAndTile<3>(const u8* src, u8* dst, unsigned int width, unsigned int height);
template void CopyTextureAndTile<4>(const u8* src, u8* dst, unsigned int width, unsigned int height);
template<typename T>
void CopyTextureAndUntile(const T* src, T* dst, unsigned int width, unsigned int height) {
template<int size>
void CopyTextureAndUntile(const u8* src, u8* dst, unsigned int width, unsigned int height) {
for (unsigned int y = 0; y + 8 <= height; y += 8) {
for (unsigned int x = 0; x + 8 <= width; x += 8) {
T* line = &dst[y * width + x];
u8* line = &dst[y * width + x];
for (unsigned int yy = 0; yy < 8; ++yy) {
for (unsigned int xx = 0; xx < 8; ++xx) {
line[xx] = src[morton_lut[yy * 8 + xx]];
memcpy(line + size * xx, src + size * morton_lut[yy * 8 + xx], size);
}
line += width;
}
@ -74,8 +74,8 @@ void CopyTextureAndUntile(const T* src, T* dst, unsigned int width, unsigned int
}
}
template void CopyTextureAndUntile<u16>(const u16* src, u16* dst, unsigned int width, unsigned int height);
template void CopyTextureAndUntile<u24_be>(const u24_be* src, u24_be* dst, unsigned int width, unsigned int height);
template void CopyTextureAndUntile<u32>(const u32* src, u32* dst, unsigned int width, unsigned int height);
template void CopyTextureAndUntile<2>(const u8* src, u8* dst, unsigned int width, unsigned int height);
template void CopyTextureAndUntile<3>(const u8* src, u8* dst, unsigned int width, unsigned int height);
template void CopyTextureAndUntile<4>(const u8* src, u8* dst, unsigned int width, unsigned int height);
} // namespace

View file

@ -60,28 +60,26 @@ static inline u32 MortonInterleave(u32 x, u32 y) {
* Copies the texture data from the source address to the destination address, applying a
* Morton-order transformation while copying.
*
* @param T Type of the source and destination pointers, the swizzling process depends on the size
* of this parameter.
* @param T Byte size of a pixel in the source and destination pointers.
* @param src Pointer to the source texture data.
* @param dst Pointer to which the texture will be copied.
* @param width Width of the texture, should be a multiple of 8.
* @param height Height of the texture, should be a multiple of 8.
*/
template<typename T>
void CopyTextureAndTile(const T* src, T* dst, unsigned int width, unsigned int height);
template<int size>
void CopyTextureAndTile(const u8* src, u8* dst, unsigned int width, unsigned int height);
/**
* Copies texture data while undoing the transformation applied by `CopyTextureAndTile`.
*
* @param T Type of the source and destination pointers, the swizzling process depends on the size
* of this parameter.
* @param T Byte size of a pixel in the source and destination pointers.
* @param src Pointer to the source texture data.
* @param dst Pointer to which the texture will be copied.
* @param width Width of the texture, should be a multiple of 8.
* @param height Height of the texture, should be a multiple of 8.
*/
template<typename T>
void CopyTextureAndUntile(const T* src, T* dst, unsigned int width, unsigned int height);
template<int size>
void CopyTextureAndUntile(const u8* src, u8* dst, unsigned int width, unsigned int height);
/**
* Calculates the offset of the position of the pixel in Morton order