diff options
| author | 2015-12-09 20:35:15 -0800 | |
|---|---|---|
| committer | 2015-12-09 20:35:15 -0800 | |
| commit | 402692c08d7abf5e2ac3a9b039ac00670fc45ae1 (patch) | |
| tree | f13604c0bcadbad87f55b9157ad98bab1ac3765e /src | |
| parent | Merge pull request #1269 from Subv/triangle_fan (diff) | |
| parent | OpenGL: Flip framebuffers during transfer rather than when rendering (diff) | |
| download | yuzu-402692c08d7abf5e2ac3a9b039ac00670fc45ae1.tar.gz yuzu-402692c08d7abf5e2ac3a9b039ac00670fc45ae1.tar.xz yuzu-402692c08d7abf5e2ac3a9b039ac00670fc45ae1.zip | |
Merge pull request #1267 from yuriks/flipped-framebuffer
OpenGL: Flip framebuffers during transfer rather than when rendering
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 21 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_state.cpp | 5 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_state.h | 1 |
4 files changed, 17 insertions, 12 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 681fdca8d..092351dce 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -587,12 +587,12 @@ void RasterizerOpenGL::SyncCullMode() { | |||
| 587 | 587 | ||
| 588 | case Pica::Regs::CullMode::KeepClockWise: | 588 | case Pica::Regs::CullMode::KeepClockWise: |
| 589 | state.cull.enabled = true; | 589 | state.cull.enabled = true; |
| 590 | state.cull.mode = GL_BACK; | 590 | state.cull.front_face = GL_CW; |
| 591 | break; | 591 | break; |
| 592 | 592 | ||
| 593 | case Pica::Regs::CullMode::KeepCounterClockWise: | 593 | case Pica::Regs::CullMode::KeepCounterClockWise: |
| 594 | state.cull.enabled = true; | 594 | state.cull.enabled = true; |
| 595 | state.cull.mode = GL_FRONT; | 595 | state.cull.front_face = GL_CCW; |
| 596 | break; | 596 | break; |
| 597 | 597 | ||
| 598 | default: | 598 | default: |
| @@ -683,9 +683,8 @@ void RasterizerOpenGL::SyncDrawState() { | |||
| 683 | // OpenGL uses different y coordinates, so negate corner offset and flip origin | 683 | // OpenGL uses different y coordinates, so negate corner offset and flip origin |
| 684 | // TODO: Ensure viewport_corner.x should not be negated or origin flipped | 684 | // TODO: Ensure viewport_corner.x should not be negated or origin flipped |
| 685 | // TODO: Use floating-point viewports for accuracy if supported | 685 | // TODO: Use floating-point viewports for accuracy if supported |
| 686 | glViewport((GLsizei)static_cast<float>(regs.viewport_corner.x), | 686 | glViewport((GLsizei)regs.viewport_corner.x, |
| 687 | -(GLsizei)static_cast<float>(regs.viewport_corner.y) | 687 | (GLsizei)regs.viewport_corner.y, |
| 688 | + regs.framebuffer.GetHeight() - viewport_height, | ||
| 689 | viewport_width, viewport_height); | 688 | viewport_width, viewport_height); |
| 690 | 689 | ||
| 691 | // Sync bound texture(s), upload if not cached | 690 | // Sync bound texture(s), upload if not cached |
| @@ -724,7 +723,7 @@ void RasterizerOpenGL::ReloadColorBuffer() { | |||
| 724 | for (int x = 0; x < fb_color_texture.width; ++x) { | 723 | for (int x = 0; x < fb_color_texture.width; ++x) { |
| 725 | const u32 coarse_y = y & ~7; | 724 | const u32 coarse_y = y & ~7; |
| 726 | u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_color_texture.width * bytes_per_pixel; | 725 | u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_color_texture.width * bytes_per_pixel; |
| 727 | u32 gl_pixel_index = (x + y * fb_color_texture.width) * bytes_per_pixel; | 726 | u32 gl_pixel_index = (x + (fb_color_texture.height - 1 - y) * fb_color_texture.width) * bytes_per_pixel; |
| 728 | 727 | ||
| 729 | u8* pixel = color_buffer + dst_offset; | 728 | u8* pixel = color_buffer + dst_offset; |
| 730 | memcpy(&temp_fb_color_buffer[gl_pixel_index], pixel, bytes_per_pixel); | 729 | memcpy(&temp_fb_color_buffer[gl_pixel_index], pixel, bytes_per_pixel); |
| @@ -770,7 +769,7 @@ void RasterizerOpenGL::ReloadDepthBuffer() { | |||
| 770 | for (int x = 0; x < fb_depth_texture.width; ++x) { | 769 | for (int x = 0; x < fb_depth_texture.width; ++x) { |
| 771 | const u32 coarse_y = y & ~7; | 770 | const u32 coarse_y = y & ~7; |
| 772 | u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_depth_texture.width * bytes_per_pixel; | 771 | u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_depth_texture.width * bytes_per_pixel; |
| 773 | u32 gl_pixel_index = (x + y * fb_depth_texture.width); | 772 | u32 gl_pixel_index = (x + (fb_depth_texture.height - 1 - y) * fb_depth_texture.width); |
| 774 | 773 | ||
| 775 | u8* pixel = depth_buffer + dst_offset; | 774 | u8* pixel = depth_buffer + dst_offset; |
| 776 | u32 depth_stencil = *(u32*)pixel; | 775 | u32 depth_stencil = *(u32*)pixel; |
| @@ -782,7 +781,7 @@ void RasterizerOpenGL::ReloadDepthBuffer() { | |||
| 782 | for (int x = 0; x < fb_depth_texture.width; ++x) { | 781 | for (int x = 0; x < fb_depth_texture.width; ++x) { |
| 783 | const u32 coarse_y = y & ~7; | 782 | const u32 coarse_y = y & ~7; |
| 784 | u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_depth_texture.width * bytes_per_pixel; | 783 | u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_depth_texture.width * bytes_per_pixel; |
| 785 | u32 gl_pixel_index = (x + y * fb_depth_texture.width) * gl_bpp; | 784 | u32 gl_pixel_index = (x + (fb_depth_texture.height - 1 - y) * fb_depth_texture.width) * gl_bpp; |
| 786 | 785 | ||
| 787 | u8* pixel = depth_buffer + dst_offset; | 786 | u8* pixel = depth_buffer + dst_offset; |
| 788 | memcpy(&temp_fb_depth_data[gl_pixel_index], pixel, bytes_per_pixel); | 787 | memcpy(&temp_fb_depth_data[gl_pixel_index], pixel, bytes_per_pixel); |
| @@ -837,7 +836,7 @@ void RasterizerOpenGL::CommitColorBuffer() { | |||
| 837 | for (int x = 0; x < fb_color_texture.width; ++x) { | 836 | for (int x = 0; x < fb_color_texture.width; ++x) { |
| 838 | const u32 coarse_y = y & ~7; | 837 | const u32 coarse_y = y & ~7; |
| 839 | u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_color_texture.width * bytes_per_pixel; | 838 | u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_color_texture.width * bytes_per_pixel; |
| 840 | u32 gl_pixel_index = x * bytes_per_pixel + y * fb_color_texture.width * bytes_per_pixel; | 839 | u32 gl_pixel_index = x * bytes_per_pixel + (fb_color_texture.height - 1 - y) * fb_color_texture.width * bytes_per_pixel; |
| 841 | 840 | ||
| 842 | u8* pixel = color_buffer + dst_offset; | 841 | u8* pixel = color_buffer + dst_offset; |
| 843 | memcpy(pixel, &temp_gl_color_buffer[gl_pixel_index], bytes_per_pixel); | 842 | memcpy(pixel, &temp_gl_color_buffer[gl_pixel_index], bytes_per_pixel); |
| @@ -879,7 +878,7 @@ void RasterizerOpenGL::CommitDepthBuffer() { | |||
| 879 | for (int x = 0; x < fb_depth_texture.width; ++x) { | 878 | for (int x = 0; x < fb_depth_texture.width; ++x) { |
| 880 | const u32 coarse_y = y & ~7; | 879 | const u32 coarse_y = y & ~7; |
| 881 | u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_depth_texture.width * bytes_per_pixel; | 880 | u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_depth_texture.width * bytes_per_pixel; |
| 882 | u32 gl_pixel_index = (x + y * fb_depth_texture.width); | 881 | u32 gl_pixel_index = (x + (fb_depth_texture.height - 1 - y) * fb_depth_texture.width); |
| 883 | 882 | ||
| 884 | u8* pixel = depth_buffer + dst_offset; | 883 | u8* pixel = depth_buffer + dst_offset; |
| 885 | u32 depth_stencil = ((u32*)temp_gl_depth_data)[gl_pixel_index]; | 884 | u32 depth_stencil = ((u32*)temp_gl_depth_data)[gl_pixel_index]; |
| @@ -891,7 +890,7 @@ void RasterizerOpenGL::CommitDepthBuffer() { | |||
| 891 | for (int x = 0; x < fb_depth_texture.width; ++x) { | 890 | for (int x = 0; x < fb_depth_texture.width; ++x) { |
| 892 | const u32 coarse_y = y & ~7; | 891 | const u32 coarse_y = y & ~7; |
| 893 | u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_depth_texture.width * bytes_per_pixel; | 892 | u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * fb_depth_texture.width * bytes_per_pixel; |
| 894 | u32 gl_pixel_index = (x + y * fb_depth_texture.width) * gl_bpp; | 893 | u32 gl_pixel_index = (x + (fb_depth_texture.height - 1 - y) * fb_depth_texture.width) * gl_bpp; |
| 895 | 894 | ||
| 896 | u8* pixel = depth_buffer + dst_offset; | 895 | u8* pixel = depth_buffer + dst_offset; |
| 897 | memcpy(pixel, &temp_gl_depth_data[gl_pixel_index], bytes_per_pixel); | 896 | memcpy(pixel, &temp_gl_depth_data[gl_pixel_index], bytes_per_pixel); |
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 498c506e7..38de5d469 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp | |||
| @@ -382,7 +382,7 @@ void main() { | |||
| 382 | texcoord[0] = vert_texcoord0; | 382 | texcoord[0] = vert_texcoord0; |
| 383 | texcoord[1] = vert_texcoord1; | 383 | texcoord[1] = vert_texcoord1; |
| 384 | texcoord[2] = vert_texcoord2; | 384 | texcoord[2] = vert_texcoord2; |
| 385 | gl_Position = vec4(vert_position.x, -vert_position.y, -vert_position.z, vert_position.w); | 385 | gl_Position = vec4(vert_position.x, vert_position.y, -vert_position.z, vert_position.w); |
| 386 | } | 386 | } |
| 387 | )"; | 387 | )"; |
| 388 | 388 | ||
diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp index c44497fc3..a82372995 100644 --- a/src/video_core/renderer_opengl/gl_state.cpp +++ b/src/video_core/renderer_opengl/gl_state.cpp | |||
| @@ -11,6 +11,7 @@ OpenGLState::OpenGLState() { | |||
| 11 | // These all match default OpenGL values | 11 | // These all match default OpenGL values |
| 12 | cull.enabled = false; | 12 | cull.enabled = false; |
| 13 | cull.mode = GL_BACK; | 13 | cull.mode = GL_BACK; |
| 14 | cull.front_face = GL_CCW; | ||
| 14 | 15 | ||
| 15 | depth.test_enabled = false; | 16 | depth.test_enabled = false; |
| 16 | depth.test_func = GL_LESS; | 17 | depth.test_func = GL_LESS; |
| @@ -67,6 +68,10 @@ void OpenGLState::Apply() { | |||
| 67 | glCullFace(cull.mode); | 68 | glCullFace(cull.mode); |
| 68 | } | 69 | } |
| 69 | 70 | ||
| 71 | if (cull.front_face != cur_state.cull.front_face) { | ||
| 72 | glFrontFace(cull.front_face); | ||
| 73 | } | ||
| 74 | |||
| 70 | // Depth test | 75 | // Depth test |
| 71 | if (depth.test_enabled != cur_state.depth.test_enabled) { | 76 | if (depth.test_enabled != cur_state.depth.test_enabled) { |
| 72 | if (depth.test_enabled) { | 77 | if (depth.test_enabled) { |
diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h index 84b3d49bc..b8ab45bb8 100644 --- a/src/video_core/renderer_opengl/gl_state.h +++ b/src/video_core/renderer_opengl/gl_state.h | |||
| @@ -11,6 +11,7 @@ public: | |||
| 11 | struct { | 11 | struct { |
| 12 | bool enabled; // GL_CULL_FACE | 12 | bool enabled; // GL_CULL_FACE |
| 13 | GLenum mode; // GL_CULL_FACE_MODE | 13 | GLenum mode; // GL_CULL_FACE_MODE |
| 14 | GLenum front_face; // GL_FRONT_FACE | ||
| 14 | } cull; | 15 | } cull; |
| 15 | 16 | ||
| 16 | struct { | 17 | struct { |