Skip to content

Commit a9fdcd9

Browse files
committed
OpenGL renderer:
- Disabled dump vertex data. - Fixed fragment constants loader. - Fixed fbo creation. - Implemented texture filtering.
1 parent 0568782 commit a9fdcd9

File tree

6 files changed

+153
-24
lines changed

6 files changed

+153
-24
lines changed
268 KB
Binary file not shown.

rpcs3/Emu/GS/GL/GLBuffers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ u32 GLrbo::GetId(u32 num) const
178178
return m_id[num];
179179
}
180180

181-
GLfbo::GLfbo()
181+
GLfbo::GLfbo() : m_id(0)
182182
{
183183
}
184184

@@ -188,7 +188,7 @@ GLfbo::~GLfbo()
188188

189189
void GLfbo::Create()
190190
{
191-
if(m_id)
191+
if(IsCreated())
192192
{
193193
return;
194194
}

rpcs3/Emu/GS/GL/GLGSRender.cpp

Lines changed: 100 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "Emu/Cell/PPCInstrTable.h"
44

55
#define CMD_DEBUG 0
6-
#define DUMP_VERTEX_DATA 1
6+
#define DUMP_VERTEX_DATA 0
77

88
#if CMD_DEBUG
99
#define CMD_LOG ConLog.Write
@@ -477,9 +477,7 @@ void GLGSRender::InitFragmentData()
477477
{
478478
const TransformConstant& c = m_fragment_constants[i];
479479

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;
483481

484482
const wxString name = wxString::Format("fc%u", id);
485483
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
563561
m_fbo.Bind(GL_READ_FRAMEBUFFER);
564562
m_fbo.Bind(GL_DRAW_FRAMEBUFFER, 0);
565563
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,
568566
GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
569567
m_fbo.Bind();
568+
checkForGlError("m_fbo.Blit");
570569
}
571570

572571
m_frame->Flip();
572+
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
573573
}
574574

575575
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
708708
break;
709709

710710
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+
}
712725
break;
713726

714727
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
801814
}
802815
*/
803816

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)
805822
{
806823
m_rbo.Create(2);
807824
checkForGlError("m_rbo.Create");
808825
m_rbo.Bind(0);
809826
m_rbo.Storage(GL_RGBA, m_width, m_height);
810827
checkForGlError("m_rbo.Storage(GL_RGBA)");
811828
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);
813830
checkForGlError("m_rbo.Storage(GL_DEPTH24_STENCIL8)");
814831
m_fbo.Create();
815832
checkForGlError("m_fbo.Create");
@@ -854,11 +871,24 @@ void GLGSRender::DoCmd(const u32 fcmd, const u32 cmd, mem32_t& args, const u32 c
854871
break;
855872

856873
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];
858887
break;
859888

860889
case NV4097_SET_CULL_FACE:
861-
glCullFace(args[0]);
890+
m_set_cull_face = true;
891+
m_cull_face = args[0];
862892
break;
863893

864894
case NV4097_SET_VIEWPORT_VERTICAL:
@@ -922,6 +952,7 @@ void GLGSRender::DoCmd(const u32 fcmd, const u32 cmd, mem32_t& args, const u32 c
922952
if (a0 & 0x2) f |= GL_STENCIL_BUFFER_BIT;
923953
if (a0 & 0xF0) f |= GL_COLOR_BUFFER_BIT;
924954
glClear(f);
955+
checkForGlError("glClear");
925956
/*
926957
if(m_set_clear_surface)
927958
{
@@ -1088,6 +1119,7 @@ void GLGSRender::DoCmd(const u32 fcmd, const u32 cmd, mem32_t& args, const u32 c
10881119
m_clear_color_g / 255.0f,
10891120
m_clear_color_b / 255.0f,
10901121
m_clear_color_a / 255.0f);
1122+
checkForGlError("glClearColor");
10911123
}
10921124
break;
10931125

@@ -1190,7 +1222,7 @@ void GLGSRender::DoCmd(const u32 fcmd, const u32 cmd, mem32_t& args, const u32 c
11901222
break;
11911223

11921224
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;
11941226
break;
11951227

11961228
case NV4097_SET_DITHER_ENABLE:
@@ -1546,9 +1578,46 @@ void GLGSRender::DoCmd(const u32 fcmd, const u32 cmd, mem32_t& args, const u32 c
15461578
break;
15471579

15481580
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+
15491590
case NV4097_SET_ZCULL_CONTROL0:
1591+
{
1592+
m_set_depth_func = true;
1593+
m_depth_func = args[0] >> 4;
1594+
}
1595+
break;
1596+
15501597
case NV4097_SET_ZCULL_CONTROL1:
1598+
{
1599+
//TODO
1600+
}
1601+
break;
1602+
15511603
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+
}
15521621
break;
15531622

15541623
case NV4097_GET_REPORT:
@@ -1800,8 +1869,9 @@ bool GLGSRender::LoadProgram()
18001869
else
18011870
{
18021871
m_program.Create(m_cur_vertex_prog->id, m_cur_shader_prog->id);
1872+
checkForGlError("m_program.Create");
18031873
m_prog_buffer.Add(m_program, *m_cur_shader_prog, *m_cur_vertex_prog);
1804-
1874+
checkForGlError("m_prog_buffer.Add");
18051875
m_program.Use();
18061876

18071877
GLint r = GL_FALSE;
@@ -1833,9 +1903,7 @@ void GLGSRender::ExecCMD()
18331903
{
18341904
if(m_set_surface_clip_horizontal && m_set_surface_clip_vertical)
18351905
{
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);
18391907
}
18401908

18411909
if(m_set_color_mask)
@@ -1885,7 +1953,7 @@ void GLGSRender::ExecCMD()
18851953
Enable(m_set_depth_bounds_test, GL_DEPTH_CLAMP);
18861954
Enable(m_set_blend, GL_BLEND);
18871955
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);
18891957
Enable(m_set_dither, GL_DITHER);
18901958
Enable(m_set_stencil_test, GL_STENCIL_TEST);
18911959
Enable(m_set_line_smooth, GL_LINE_SMOOTH);
@@ -1991,15 +2059,30 @@ void GLGSRender::ExecCMD()
19912059
checkForGlError("glBlendColor");
19922060
}
19932061

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+
19942074
if(m_set_fog_mode)
19952075
{
19962076
glFogi(GL_FOG_MODE, m_fog_mode);
2077+
checkForGlError("glFogi(GL_FOG_MODE)");
19972078
}
19982079

19992080
if(m_set_fog_params)
20002081
{
20012082
glFogf(GL_FOG_START, m_fog_param0);
2083+
checkForGlError("glFogf(GL_FOG_START)");
20022084
glFogf(GL_FOG_END, m_fog_param1);
2085+
checkForGlError("glFogf(GL_FOG_END)");
20032086
}
20042087

20052088
if(m_indexed_array.m_count && m_draw_array_count)

rpcs3/Emu/GS/GL/GLGSRender.h

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ class GLTexture
4141
u8 m_aniso_bias;
4242
u8 m_signed_remap;
4343

44+
u16 m_bias;
45+
u8 m_min_filter;
46+
u8 m_mag_filter;
47+
u8 m_conv;
48+
u8 m_a_signed;
49+
u8 m_r_signed;
50+
u8 m_g_signed;
51+
u8 m_b_signed;
52+
4453
u32 m_remap;
4554

4655
public:
@@ -127,6 +136,18 @@ class GLTexture
127136
m_pitch = pitch;
128137
}
129138

139+
void SetFilter(u16 bias, u8 min, u8 mag, u8 conv, u8 a_signed, u8 r_signed, u8 g_signed, u8 b_signed)
140+
{
141+
m_bias = bias;
142+
m_min_filter = min;
143+
m_mag_filter = mag;
144+
m_conv = conv;
145+
m_a_signed = a_signed;
146+
m_r_signed = r_signed;
147+
m_g_signed = g_signed;
148+
m_b_signed = b_signed;
149+
}
150+
130151
u32 GetFormat() const { return m_format; }
131152

132153
void SetOffset(const u32 offset)
@@ -289,13 +310,25 @@ class GLTexture
289310
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GetGlWrap(m_wrapr));
290311
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, gl_tex_zfunc[m_zfunc]);
291312

292-
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, m_aniso_bias);
313+
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, m_bias);
293314
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, m_minlod);
294315
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, m_maxlod);
295316
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, m_maxaniso);
296317

297-
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
298-
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
318+
static const int gl_tex_filter[] =
319+
{
320+
GL_NEAREST,
321+
GL_NEAREST,
322+
GL_LINEAR,
323+
GL_NEAREST_MIPMAP_NEAREST,
324+
GL_LINEAR_MIPMAP_NEAREST,
325+
GL_NEAREST_MIPMAP_LINEAR,
326+
GL_LINEAR_MIPMAP_LINEAR,
327+
GL_NEAREST,
328+
};
329+
330+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_tex_filter[m_min_filter]);
331+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_filter[m_mag_filter]);
299332
//Unbind();
300333
}
301334

rpcs3/Emu/GS/GSRender.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ u32 GSRender::GetAddress(u32 offset, u8 location)
9494
}
9595

9696
ConLog.Error("GetAddress(offset=0x%x, location=0x%x", location);
97+
assert(0);
9798
return 0;
9899
}
99100

rpcs3/Emu/GS/RSXThread.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ExecRSXCMDdata
2222
bool m_set_depth_bounds_test;
2323
bool m_depth_test_enable;
2424
bool m_set_logic_op;
25-
bool m_set_cull_face;
25+
bool m_set_cull_face_enable;
2626
bool m_set_dither;
2727
bool m_set_stencil_test;
2828
bool m_set_line_smooth;
@@ -196,6 +196,15 @@ class ExecRSXCMDdata
196196
u16 m_surface_clip_y;
197197
u16 m_surface_clip_h;
198198

199+
bool m_set_cull_face;
200+
u32 m_cull_face;
201+
202+
bool m_set_alpha_func;
203+
u32 m_alpha_func;
204+
205+
bool m_set_alpha_ref;
206+
u32 m_alpha_ref;
207+
199208
u8 m_begin_end;
200209

201210
public:
@@ -222,7 +231,7 @@ class ExecRSXCMDdata
222231
m_set_blend_sfactor = false;
223232
m_set_blend_dfactor = false;
224233
m_set_logic_op = false;
225-
m_set_cull_face = false;
234+
m_set_cull_face_enable = false;
226235
m_set_dither = false;
227236
m_set_stencil_test = false;
228237
m_set_stencil_mask = false;
@@ -259,6 +268,9 @@ class ExecRSXCMDdata
259268
m_set_context_dma_z = false;
260269
m_set_surface_clip_horizontal = false;
261270
m_set_surface_clip_vertical = false;
271+
m_set_cull_face = false;
272+
m_set_alpha_func = false;
273+
m_set_alpha_ref = false;
262274
m_begin_end = 0;
263275
}
264276

0 commit comments

Comments
 (0)