summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar tfarley2015-05-28 23:32:10 -0400
committerGravatar tfarley2015-06-08 19:18:18 -0400
commitfa2c92a3ac51962710e77d38c9f6f8a5cf8773be (patch)
tree2fb068d72212ac20be856a5189690b2b647c5a13 /src
parentImplemented glColorMask (diff)
downloadyuzu-fa2c92a3ac51962710e77d38c9f6f8a5cf8773be.tar.gz
yuzu-fa2c92a3ac51962710e77d38c9f6f8a5cf8773be.tar.xz
yuzu-fa2c92a3ac51962710e77d38c9f6f8a5cf8773be.zip
Depth format fix (crush3d intro/black screens)
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp92
1 files changed, 46 insertions, 46 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 2f55bfd76..6779d17cf 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -491,7 +491,7 @@ void RasterizerOpenGL::ReconfigureDepthTexture(DepthTextureInfo& texture, Pica::
491 case Pica::Regs::DepthFormat::D24: 491 case Pica::Regs::DepthFormat::D24:
492 internal_format = GL_DEPTH_COMPONENT24; 492 internal_format = GL_DEPTH_COMPONENT24;
493 texture.gl_format = GL_DEPTH_COMPONENT; 493 texture.gl_format = GL_DEPTH_COMPONENT;
494 texture.gl_type = GL_UNSIGNED_INT_24_8; 494 texture.gl_type = GL_UNSIGNED_INT;
495 break; 495 break;
496 496
497 case Pica::Regs::DepthFormat::D24S8: 497 case Pica::Regs::DepthFormat::D24S8:
@@ -763,7 +763,7 @@ void RasterizerOpenGL::ReloadColorBuffer() {
763 for (int x = 0; x < fb_color_texture.width; ++x) { 763 for (int x = 0; x < fb_color_texture.width; ++x) {
764 const u32 coarse_y = y & ~7; 764 const u32 coarse_y = y & ~7;
765 u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_color_texture.width * bytes_per_pixel; 765 u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_color_texture.width * bytes_per_pixel;
766 u32 gl_px_idx = x * bytes_per_pixel + y * fb_color_texture.width * bytes_per_pixel; 766 u32 gl_px_idx = (x + y * fb_color_texture.width) * bytes_per_pixel;
767 767
768 u8* pixel = color_buffer + dst_offset; 768 u8* pixel = color_buffer + dst_offset;
769 memcpy(&temp_fb_color_buffer[gl_px_idx], pixel, bytes_per_pixel); 769 memcpy(&temp_fb_color_buffer[gl_px_idx], pixel, bytes_per_pixel);
@@ -794,29 +794,29 @@ void RasterizerOpenGL::ReloadDepthBuffer() {
794 794
795 std::unique_ptr<u8[]> temp_fb_depth_buffer(new u8[fb_depth_texture.width * fb_depth_texture.height * gl_bpp]); 795 std::unique_ptr<u8[]> temp_fb_depth_buffer(new u8[fb_depth_texture.width * fb_depth_texture.height * gl_bpp]);
796 796
797 for (int y = 0; y < fb_depth_texture.height; ++y) { 797 u8* temp_fb_depth_data = bytes_per_pixel == 3 ? (temp_fb_depth_buffer.get() + 1) : temp_fb_depth_buffer.get();
798 for (int x = 0; x < fb_depth_texture.width; ++x) { 798
799 const u32 coarse_y = y & ~7; 799 if (fb_depth_texture.format == Pica::Regs::DepthFormat::D24S8) {
800 u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_depth_texture.width * bytes_per_pixel; 800 for (int y = 0; y < fb_depth_texture.height; ++y) {
801 u32 gl_px_idx = x + y * fb_depth_texture.width; 801 for (int x = 0; x < fb_depth_texture.width; ++x) {
802 802 const u32 coarse_y = y & ~7;
803 switch (fb_depth_texture.format) { 803 u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_depth_texture.width * bytes_per_pixel;
804 case Pica::Regs::DepthFormat::D16: 804 u32 gl_px_idx = (x + y * fb_depth_texture.width);
805 ((u16*)temp_fb_depth_buffer.get())[gl_px_idx] = Color::DecodeD16(depth_buffer + dst_offset); 805
806 break; 806 u8* pixel = depth_buffer + dst_offset;
807 case Pica::Regs::DepthFormat::D24: 807 u32 depth_stencil = *(u32*)pixel;
808 ((u32*)temp_fb_depth_buffer.get())[gl_px_idx] = Color::DecodeD24(depth_buffer + dst_offset); 808 ((u32*)temp_fb_depth_data)[gl_px_idx] = (depth_stencil << 8) | (depth_stencil >> 24);
809 break;
810 case Pica::Regs::DepthFormat::D24S8:
811 {
812 Math::Vec2<u32> depth_stencil = Color::DecodeD24S8(depth_buffer + dst_offset);
813 ((u32*)temp_fb_depth_buffer.get())[gl_px_idx] = (depth_stencil.x << 8) | depth_stencil.y;
814 break;
815 } 809 }
816 default: 810 }
817 LOG_CRITICAL(Render_OpenGL, "Unknown memory framebuffer depth format %x", fb_depth_texture.format); 811 } else {
818 UNIMPLEMENTED(); 812 for (int y = 0; y < fb_depth_texture.height; ++y) {
819 break; 813 for (int x = 0; x < fb_depth_texture.width; ++x) {
814 const u32 coarse_y = y & ~7;
815 u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_depth_texture.width * bytes_per_pixel;
816 u32 gl_px_idx = (x + y * fb_depth_texture.width) * gl_bpp;
817
818 u8* pixel = depth_buffer + dst_offset;
819 memcpy(&temp_fb_depth_data[gl_px_idx], pixel, bytes_per_pixel);
820 } 820 }
821 } 821 }
822 } 822 }
@@ -881,29 +881,29 @@ void RasterizerOpenGL::CommitDepthBuffer() {
881 glActiveTexture(GL_TEXTURE0); 881 glActiveTexture(GL_TEXTURE0);
882 glGetTexImage(GL_TEXTURE_2D, 0, fb_depth_texture.gl_format, fb_depth_texture.gl_type, temp_gl_depth_buffer.get()); 882 glGetTexImage(GL_TEXTURE_2D, 0, fb_depth_texture.gl_format, fb_depth_texture.gl_type, temp_gl_depth_buffer.get());
883 883
884 for (int y = 0; y < fb_depth_texture.height; ++y) { 884 u8* temp_gl_depth_data = bytes_per_pixel == 3 ? (temp_gl_depth_buffer.get() + 1) : temp_gl_depth_buffer.get();
885 for (int x = 0; x < fb_depth_texture.width; ++x) { 885
886 const u32 coarse_y = y & ~7; 886 if (fb_depth_texture.format == Pica::Regs::DepthFormat::D24S8) {
887 u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_depth_texture.width * bytes_per_pixel; 887 for (int y = 0; y < fb_depth_texture.height; ++y) {
888 u32 gl_px_idx = x + y * fb_depth_texture.width; 888 for (int x = 0; x < fb_depth_texture.width; ++x) {
889 889 const u32 coarse_y = y & ~7;
890 switch (fb_depth_texture.format) { 890 u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_depth_texture.width * bytes_per_pixel;
891 case Pica::Regs::DepthFormat::D16: 891 u32 gl_px_idx = (x + y * fb_depth_texture.width);
892 Color::EncodeD16(((u16*)temp_gl_depth_buffer.get())[gl_px_idx], depth_buffer + dst_offset); 892
893 break; 893 u8* pixel = depth_buffer + dst_offset;
894 case Pica::Regs::DepthFormat::D24: 894 u32 depth_stencil = ((u32*)temp_gl_depth_data)[gl_px_idx];
895 Color::EncodeD24(((u32*)temp_gl_depth_buffer.get())[gl_px_idx], depth_buffer + dst_offset); 895 *(u32*)pixel = (depth_stencil >> 8) | (depth_stencil << 24);
896 break;
897 case Pica::Regs::DepthFormat::D24S8:
898 {
899 u32 depth_stencil = ((u32*)temp_gl_depth_buffer.get())[gl_px_idx];
900 Color::EncodeD24S8((depth_stencil >> 8), depth_stencil & 0xFF, depth_buffer + dst_offset);
901 break;
902 } 896 }
903 default: 897 }
904 LOG_CRITICAL(Render_OpenGL, "Unknown framebuffer depth format %x", fb_depth_texture.format); 898 } else {
905 UNIMPLEMENTED(); 899 for (int y = 0; y < fb_depth_texture.height; ++y) {
906 break; 900 for (int x = 0; x < fb_depth_texture.width; ++x) {
901 const u32 coarse_y = y & ~7;
902 u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_depth_texture.width * bytes_per_pixel;
903 u32 gl_px_idx = (x + y * fb_depth_texture.width) * gl_bpp;
904
905 u8* pixel = depth_buffer + dst_offset;
906 memcpy(pixel, &temp_gl_depth_data[gl_px_idx], bytes_per_pixel);
907 } 907 }
908 } 908 }
909 } 909 }