diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index f280a6cdb..cb07139bb 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -851,18 +851,18 @@ void RasterizerOpenGL::ReloadColorBuffer() { using VideoCore::CopyTextureAndUntile; switch (bytes_per_pixel) { case 4: - CopyTextureAndUntile(reinterpret_cast(color_buffer), - reinterpret_cast(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(reinterpret_cast(color_buffer), - reinterpret_cast(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(reinterpret_cast(color_buffer), - reinterpret_cast(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(reinterpret_cast(temp_gl_color_buffer.get()), - reinterpret_cast(color_buffer), + CopyTextureAndTile<4>(temp_gl_color_buffer.get(), + color_buffer, fb_color_texture.width, fb_color_texture.height); break; case 3: - CopyTextureAndTile(reinterpret_cast(temp_gl_color_buffer.get()), - reinterpret_cast(color_buffer), + CopyTextureAndTile<3>(temp_gl_color_buffer.get(), + color_buffer, fb_color_texture.width, fb_color_texture.height); break; case 2: - CopyTextureAndTile(reinterpret_cast(temp_gl_color_buffer.get()), - reinterpret_cast(color_buffer), + CopyTextureAndTile<2>(temp_gl_color_buffer.get(), + color_buffer, fb_color_texture.width, fb_color_texture.height); break; default: diff --git a/src/video_core/utils.cpp b/src/video_core/utils.cpp index a8c3afc7f..9c2929d10 100644 --- a/src/video_core/utils.cpp +++ b/src/video_core/utils.cpp @@ -34,15 +34,15 @@ void DumpTGA(std::string filename, short width, short height, u8* raw_data) { fclose(fout); } -template -void CopyTextureAndTile(const T* src, T* dst, unsigned int width, unsigned int height) { +template +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(const u16* src, u16* dst, unsigned int width, unsigned int height); -template void CopyTextureAndTile(const u24_be* src, u24_be* dst, unsigned int width, unsigned int height); -template void CopyTextureAndTile(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 -void CopyTextureAndUntile(const T* src, T* dst, unsigned int width, unsigned int height) { +template +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(const u16* src, u16* dst, unsigned int width, unsigned int height); -template void CopyTextureAndUntile(const u24_be* src, u24_be* dst, unsigned int width, unsigned int height); -template void CopyTextureAndUntile(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 diff --git a/src/video_core/utils.h b/src/video_core/utils.h index 812d3818f..2827e5b7a 100644 --- a/src/video_core/utils.h +++ b/src/video_core/utils.h @@ -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 -void CopyTextureAndTile(const T* src, T* dst, unsigned int width, unsigned int height); +template +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 -void CopyTextureAndUntile(const T* src, T* dst, unsigned int width, unsigned int height); +template +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