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

View file

@ -34,15 +34,15 @@ void DumpTGA(std::string filename, short width, short height, u8* raw_data) {
fclose(fout); fclose(fout);
} }
template<typename T> template<int size>
void CopyTextureAndTile(const T* src, T* dst, unsigned int width, unsigned int height) { 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 y = 0; y + 8 <= height; y += 8) {
for (unsigned int x = 0; x + 8 <= width; x += 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 yy = 0; yy < 8; ++yy) {
for (unsigned int xx = 0; xx < 8; ++xx) { 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; 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<2>(const u8* src, u8* 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<3>(const u8* src, u8* 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<4>(const u8* src, u8* dst, unsigned int width, unsigned int height);
template<typename T> template<int size>
void CopyTextureAndUntile(const T* src, T* dst, unsigned int width, unsigned int height) { 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 y = 0; y + 8 <= height; y += 8) {
for (unsigned int x = 0; x + 8 <= width; x += 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 yy = 0; yy < 8; ++yy) {
for (unsigned int xx = 0; xx < 8; ++xx) { 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; 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<2>(const u8* src, u8* 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<3>(const u8* src, u8* 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<4>(const u8* src, u8* dst, unsigned int width, unsigned int height);
} // namespace } // 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 * Copies the texture data from the source address to the destination address, applying a
* Morton-order transformation while copying. * Morton-order transformation while copying.
* *
* @param T Type of the source and destination pointers, the swizzling process depends on the size * @param T Byte size of a pixel in the source and destination pointers.
* of this parameter.
* @param src Pointer to the source texture data. * @param src Pointer to the source texture data.
* @param dst Pointer to which the texture will be copied. * @param dst Pointer to which the texture will be copied.
* @param width Width of the texture, should be a multiple of 8. * @param width Width of the texture, should be a multiple of 8.
* @param height Height of the texture, should be a multiple of 8. * @param height Height of the texture, should be a multiple of 8.
*/ */
template<typename T> template<int size>
void CopyTextureAndTile(const T* src, T* dst, unsigned int width, unsigned int height); void CopyTextureAndTile(const u8* src, u8* dst, unsigned int width, unsigned int height);
/** /**
* Copies texture data while undoing the transformation applied by `CopyTextureAndTile`. * 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 * @param T Byte size of a pixel in the source and destination pointers.
* of this parameter.
* @param src Pointer to the source texture data. * @param src Pointer to the source texture data.
* @param dst Pointer to which the texture will be copied. * @param dst Pointer to which the texture will be copied.
* @param width Width of the texture, should be a multiple of 8. * @param width Width of the texture, should be a multiple of 8.
* @param height Height of the texture, should be a multiple of 8. * @param height Height of the texture, should be a multiple of 8.
*/ */
template<typename T> template<int size>
void CopyTextureAndUntile(const T* src, T* dst, unsigned int width, unsigned int height); 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 * Calculates the offset of the position of the pixel in Morton order