|
3 | 3 | #include "Emu/Cell/PPCInstrTable.h" |
4 | 4 |
|
5 | 5 | #define CMD_DEBUG 0 |
6 | | -#define DUMP_VERTEX_DATA 1 |
| 6 | +#define DUMP_VERTEX_DATA 0 |
7 | 7 |
|
8 | 8 | #if CMD_DEBUG |
9 | 9 | #define CMD_LOG ConLog.Write |
@@ -477,9 +477,7 @@ void GLGSRender::InitFragmentData() |
477 | 477 | { |
478 | 478 | const TransformConstant& c = m_fragment_constants[i]; |
479 | 479 |
|
480 | | - u32 id = c.id - m_cur_shader_prog->offset; |
481 | | - if(id < 32) |
482 | | - id = 32; |
| 480 | + u32 id = c.id - m_cur_shader_prog->offset + 2 * 4 * 4; |
483 | 481 |
|
484 | 482 | const wxString name = wxString::Format("fc%u", id); |
485 | 483 | const int l = m_program.GetLocation(name); |
@@ -563,13 +561,15 @@ void GLGSRender::DoCmd(const u32 fcmd, const u32 cmd, mem32_t& args, const u32 c |
563 | 561 | m_fbo.Bind(GL_READ_FRAMEBUFFER); |
564 | 562 | m_fbo.Bind(GL_DRAW_FRAMEBUFFER, 0); |
565 | 563 | m_fbo.Blit( |
566 | | - 0, 0, m_width, m_height, |
567 | | - 0, 0, m_width, m_height, |
| 564 | + m_surface_clip_x, m_surface_clip_y, m_surface_clip_x + m_surface_clip_w, m_surface_clip_y + m_surface_clip_h, |
| 565 | + m_surface_clip_x, m_surface_clip_y, m_surface_clip_x + m_surface_clip_w, m_surface_clip_y + m_surface_clip_h, |
568 | 566 | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
569 | 567 | m_fbo.Bind(); |
| 568 | + checkForGlError("m_fbo.Blit"); |
570 | 569 | } |
571 | 570 |
|
572 | 571 | m_frame->Flip(); |
| 572 | + glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
573 | 573 | } |
574 | 574 |
|
575 | 575 | m_gcm_current_buffer = args[0]; |
@@ -708,7 +708,20 @@ void GLGSRender::DoCmd(const u32 fcmd, const u32 cmd, mem32_t& args, const u32 c |
708 | 708 | break; |
709 | 709 |
|
710 | 710 | case_16(NV4097_SET_TEXTURE_FILTER, 0x20): |
711 | | - //TODO |
| 711 | + { |
| 712 | + GLTexture& tex = m_frame->GetTexture(index); |
| 713 | + u32 a0 = args[0]; |
| 714 | + u16 bias = a0 & 0x1fff; |
| 715 | + u8 conv = (a0 >> 13) & 0xf; |
| 716 | + u8 min = (a0 >> 16) & 0x7; |
| 717 | + u8 mag = (a0 >> 24) & 0x7; |
| 718 | + u8 a_signed = (a0 >> 28) & 0x1; |
| 719 | + u8 r_signed = (a0 >> 29) & 0x1; |
| 720 | + u8 g_signed = (a0 >> 30) & 0x1; |
| 721 | + u8 b_signed = (a0 >> 31) & 0x1; |
| 722 | + |
| 723 | + tex.SetFilter(bias, min, mag, conv, a_signed, r_signed, g_signed, b_signed); |
| 724 | + } |
712 | 725 | break; |
713 | 726 |
|
714 | 727 | case_16(NV4097_SET_TEXTURE_ADDRESS, 0x20): |
@@ -801,15 +814,19 @@ void GLGSRender::DoCmd(const u32 fcmd, const u32 cmd, mem32_t& args, const u32 c |
801 | 814 | } |
802 | 815 | */ |
803 | 816 |
|
804 | | - if(0) |
| 817 | + gcmBuffer* buffers = (gcmBuffer*)Memory.GetMemFromAddr(m_gcm_buffers_addr); |
| 818 | + m_width = re(buffers[m_gcm_current_buffer].width); |
| 819 | + m_height = re(buffers[m_gcm_current_buffer].height); |
| 820 | + |
| 821 | + if(1) |
805 | 822 | { |
806 | 823 | m_rbo.Create(2); |
807 | 824 | checkForGlError("m_rbo.Create"); |
808 | 825 | m_rbo.Bind(0); |
809 | 826 | m_rbo.Storage(GL_RGBA, m_width, m_height); |
810 | 827 | checkForGlError("m_rbo.Storage(GL_RGBA)"); |
811 | 828 | m_rbo.Bind(1); |
812 | | - m_rbo.Storage(GL_DEPTH_STENCIL, m_width, m_height); |
| 829 | + m_rbo.Storage(GL_DEPTH24_STENCIL8, m_width, m_height); |
813 | 830 | checkForGlError("m_rbo.Storage(GL_DEPTH24_STENCIL8)"); |
814 | 831 | m_fbo.Create(); |
815 | 832 | checkForGlError("m_fbo.Create"); |
@@ -854,11 +871,24 @@ void GLGSRender::DoCmd(const u32 fcmd, const u32 cmd, mem32_t& args, const u32 c |
854 | 871 | break; |
855 | 872 |
|
856 | 873 | case NV4097_SET_ALPHA_FUNC: |
857 | | - glAlphaFunc(args[0], args[1]); |
| 874 | + m_set_alpha_func = true; |
| 875 | + m_alpha_func = args[0]; |
| 876 | + |
| 877 | + if(count >= 2) |
| 878 | + { |
| 879 | + m_set_alpha_ref = true; |
| 880 | + m_alpha_ref = args[1]; |
| 881 | + } |
| 882 | + break; |
| 883 | + |
| 884 | + case NV4097_SET_ALPHA_REF: |
| 885 | + m_set_alpha_ref = true; |
| 886 | + m_alpha_ref = args[0]; |
858 | 887 | break; |
859 | 888 |
|
860 | 889 | case NV4097_SET_CULL_FACE: |
861 | | - glCullFace(args[0]); |
| 890 | + m_set_cull_face = true; |
| 891 | + m_cull_face = args[0]; |
862 | 892 | break; |
863 | 893 |
|
864 | 894 | case NV4097_SET_VIEWPORT_VERTICAL: |
@@ -922,6 +952,7 @@ void GLGSRender::DoCmd(const u32 fcmd, const u32 cmd, mem32_t& args, const u32 c |
922 | 952 | if (a0 & 0x2) f |= GL_STENCIL_BUFFER_BIT; |
923 | 953 | if (a0 & 0xF0) f |= GL_COLOR_BUFFER_BIT; |
924 | 954 | glClear(f); |
| 955 | + checkForGlError("glClear"); |
925 | 956 | /* |
926 | 957 | if(m_set_clear_surface) |
927 | 958 | { |
@@ -1088,6 +1119,7 @@ void GLGSRender::DoCmd(const u32 fcmd, const u32 cmd, mem32_t& args, const u32 c |
1088 | 1119 | m_clear_color_g / 255.0f, |
1089 | 1120 | m_clear_color_b / 255.0f, |
1090 | 1121 | m_clear_color_a / 255.0f); |
| 1122 | + checkForGlError("glClearColor"); |
1091 | 1123 | } |
1092 | 1124 | break; |
1093 | 1125 |
|
@@ -1190,7 +1222,7 @@ void GLGSRender::DoCmd(const u32 fcmd, const u32 cmd, mem32_t& args, const u32 c |
1190 | 1222 | break; |
1191 | 1223 |
|
1192 | 1224 | case NV4097_SET_CULL_FACE_ENABLE: |
1193 | | - m_set_cull_face = args[0] ? true : false; |
| 1225 | + m_set_cull_face_enable = args[0] ? true : false; |
1194 | 1226 | break; |
1195 | 1227 |
|
1196 | 1228 | case NV4097_SET_DITHER_ENABLE: |
@@ -1546,9 +1578,46 @@ void GLGSRender::DoCmd(const u32 fcmd, const u32 cmd, mem32_t& args, const u32 c |
1546 | 1578 | break; |
1547 | 1579 |
|
1548 | 1580 | case NV4097_SET_ZSTENCIL_CLEAR_VALUE: |
| 1581 | + { |
| 1582 | + u32 clear_valuei = args[0]; |
| 1583 | + //double clear_valuef = (double)clear_valuei / 0xffffffff; |
| 1584 | + //glClearDepth(clear_valuef); |
| 1585 | + glClearStencil(clear_valuei); |
| 1586 | + glClear(GL_STENCIL_BUFFER_BIT); |
| 1587 | + } |
| 1588 | + break; |
| 1589 | + |
1549 | 1590 | case NV4097_SET_ZCULL_CONTROL0: |
| 1591 | + { |
| 1592 | + m_set_depth_func = true; |
| 1593 | + m_depth_func = args[0] >> 4; |
| 1594 | + } |
| 1595 | + break; |
| 1596 | + |
1550 | 1597 | case NV4097_SET_ZCULL_CONTROL1: |
| 1598 | + { |
| 1599 | + //TODO |
| 1600 | + } |
| 1601 | + break; |
| 1602 | + |
1551 | 1603 | case NV4097_SET_SCULL_CONTROL: |
| 1604 | + { |
| 1605 | + u32 a0 = args[0]; |
| 1606 | + m_set_stencil_func = m_set_stencil_func_ref = m_set_stencil_func_mask = true; |
| 1607 | + |
| 1608 | + m_stencil_func = a0 & 0xffff; |
| 1609 | + m_stencil_func_ref = (a0 >> 16) & 0xff; |
| 1610 | + m_stencil_func_mask = (a0 >> 24) & 0xff; |
| 1611 | + } |
| 1612 | + break; |
| 1613 | + |
| 1614 | + case NV4097_SET_ZCULL_EN: |
| 1615 | + { |
| 1616 | + u32 a0 = args[0]; |
| 1617 | + |
| 1618 | + m_depth_test_enable = a0 & 0x1 ? true : false; |
| 1619 | + m_set_stencil_test = a0 & 0x2 ? true : false; |
| 1620 | + } |
1552 | 1621 | break; |
1553 | 1622 |
|
1554 | 1623 | case NV4097_GET_REPORT: |
@@ -1800,8 +1869,9 @@ bool GLGSRender::LoadProgram() |
1800 | 1869 | else |
1801 | 1870 | { |
1802 | 1871 | m_program.Create(m_cur_vertex_prog->id, m_cur_shader_prog->id); |
| 1872 | + checkForGlError("m_program.Create"); |
1803 | 1873 | m_prog_buffer.Add(m_program, *m_cur_shader_prog, *m_cur_vertex_prog); |
1804 | | - |
| 1874 | + checkForGlError("m_prog_buffer.Add"); |
1805 | 1875 | m_program.Use(); |
1806 | 1876 |
|
1807 | 1877 | GLint r = GL_FALSE; |
@@ -1833,9 +1903,7 @@ void GLGSRender::ExecCMD() |
1833 | 1903 | { |
1834 | 1904 | if(m_set_surface_clip_horizontal && m_set_surface_clip_vertical) |
1835 | 1905 | { |
1836 | | - m_width = m_surface_clip_w; |
1837 | | - m_height = m_surface_clip_h; |
1838 | | - //ConLog.Write("width: %d, height: %d, x: %d, y: %d", m_width, m_height, m_surface_clip_x, m_surface_clip_y); |
| 1906 | + //ConLog.Write("surface clip width: %d, height: %d, x: %d, y: %d", m_width, m_height, m_surface_clip_x, m_surface_clip_y); |
1839 | 1907 | } |
1840 | 1908 |
|
1841 | 1909 | if(m_set_color_mask) |
@@ -1885,7 +1953,7 @@ void GLGSRender::ExecCMD() |
1885 | 1953 | Enable(m_set_depth_bounds_test, GL_DEPTH_CLAMP); |
1886 | 1954 | Enable(m_set_blend, GL_BLEND); |
1887 | 1955 | Enable(m_set_logic_op, GL_LOGIC_OP); |
1888 | | - Enable(m_set_cull_face, GL_CULL_FACE); |
| 1956 | + Enable(m_set_cull_face_enable, GL_CULL_FACE); |
1889 | 1957 | Enable(m_set_dither, GL_DITHER); |
1890 | 1958 | Enable(m_set_stencil_test, GL_STENCIL_TEST); |
1891 | 1959 | Enable(m_set_line_smooth, GL_LINE_SMOOTH); |
@@ -1991,15 +2059,30 @@ void GLGSRender::ExecCMD() |
1991 | 2059 | checkForGlError("glBlendColor"); |
1992 | 2060 | } |
1993 | 2061 |
|
| 2062 | + if(m_set_cull_face) |
| 2063 | + { |
| 2064 | + glCullFace(m_cull_face); |
| 2065 | + checkForGlError("glCullFace"); |
| 2066 | + } |
| 2067 | + |
| 2068 | + if(m_set_alpha_func && m_set_alpha_ref) |
| 2069 | + { |
| 2070 | + glAlphaFunc(m_alpha_func, m_alpha_ref); |
| 2071 | + checkForGlError("glAlphaFunc"); |
| 2072 | + } |
| 2073 | + |
1994 | 2074 | if(m_set_fog_mode) |
1995 | 2075 | { |
1996 | 2076 | glFogi(GL_FOG_MODE, m_fog_mode); |
| 2077 | + checkForGlError("glFogi(GL_FOG_MODE)"); |
1997 | 2078 | } |
1998 | 2079 |
|
1999 | 2080 | if(m_set_fog_params) |
2000 | 2081 | { |
2001 | 2082 | glFogf(GL_FOG_START, m_fog_param0); |
| 2083 | + checkForGlError("glFogf(GL_FOG_START)"); |
2002 | 2084 | glFogf(GL_FOG_END, m_fog_param1); |
| 2085 | + checkForGlError("glFogf(GL_FOG_END)"); |
2003 | 2086 | } |
2004 | 2087 |
|
2005 | 2088 | if(m_indexed_array.m_count && m_draw_array_count) |
|
0 commit comments