RSX: refactor glEnable cmd

This commit is contained in:
raven02 2014-12-30 23:33:43 +08:00 committed by raven02
parent 99a9a1e38d
commit 3e3665a13b
5 changed files with 118 additions and 73 deletions

View File

@ -797,18 +797,6 @@ GLGSRender::~GLGSRender()
m_frame->DeleteContext(m_context); m_frame->DeleteContext(m_context);
} }
void GLGSRender::Enable(bool enable, const u32 cap)
{
if (enable)
{
glEnable(cap);
}
else
{
glDisable(cap);
}
}
extern CellGcmContextData current_context; extern CellGcmContextData current_context;
void GLGSRender::Close() void GLGSRender::Close()
@ -1640,6 +1628,99 @@ void GLGSRender::InitDrawBuffers()
} }
} }
void GLGSRender::Enable(u32 cmd, u32 enable)
{
switch (cmd) {
case NV4097_SET_DITHER_ENABLE:
enable ? glEnable(GL_DITHER) : glDisable(GL_DITHER);
break;
case NV4097_SET_ALPHA_TEST_ENABLE:
enable ? glEnable(GL_ALPHA_TEST) : glDisable(GL_ALPHA_TEST);
break;
case NV4097_SET_STENCIL_TEST_ENABLE:
enable ? glEnable(GL_STENCIL_TEST) : glDisable(GL_STENCIL_TEST);
break;
case NV4097_SET_DEPTH_TEST_ENABLE:
enable ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
break;
case NV4097_SET_CULL_FACE_ENABLE:
enable ? glEnable(GL_CULL_FACE) : glDisable(GL_CULL_FACE);
break;
case NV4097_SET_BLEND_ENABLE:
enable ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
break;
case NV4097_SET_POLY_OFFSET_FILL_ENABLE:
enable ? glEnable(GL_POLYGON_OFFSET_FILL) : glDisable(GL_POLYGON_OFFSET_FILL);
break;
case NV4097_SET_POLY_OFFSET_LINE_ENABLE:
enable ? glEnable(GL_POLYGON_OFFSET_LINE) : glDisable(GL_POLYGON_OFFSET_LINE);
break;
case NV4097_SET_POLY_OFFSET_POINT_ENABLE:
enable ? glEnable(GL_POLYGON_OFFSET_POINT) : glDisable(GL_POLYGON_OFFSET_POINT);
break;
case NV4097_SET_LOGIC_OP_ENABLE:
enable ? glEnable(GL_LOGIC_OP) : glDisable(GL_LOGIC_OP);
break;
case NV4097_SET_SPECULAR_ENABLE:
enable ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING);
break;
case NV4097_SET_LINE_SMOOTH_ENABLE:
enable ? glEnable(GL_LINE_SMOOTH) : glDisable(GL_LINE_SMOOTH);
break;
case NV4097_SET_POLY_SMOOTH_ENABLE:
enable ? glEnable(GL_POLYGON_SMOOTH) : glDisable(GL_POLYGON_SMOOTH);
break;
case NV4097_SET_RESTART_INDEX:
enable ? glEnable(GL_PRIMITIVE_RESTART) : glDisable(GL_PRIMITIVE_RESTART);
break;
case NV4097_SET_POINT_SPRITE_CONTROL:
enable ? glEnable(GL_POINT_SPRITE) : glDisable(GL_POINT_SPRITE);
break;
case NV4097_SET_LINE_STIPPLE:
enable ? glEnable(GL_LINE_STIPPLE) : glDisable(GL_LINE_STIPPLE);
break;
case NV4097_SET_POLYGON_STIPPLE:
enable ? glEnable(GL_POLYGON_STIPPLE) : glDisable(GL_POLYGON_STIPPLE);
break;
case NV4097_SET_DEPTH_BOUNDS_TEST_ENABLE:
enable ? glEnable(GL_DEPTH_BOUNDS_TEST_EXT) : glDisable(GL_DEPTH_BOUNDS_TEST_EXT);
break;
case NV4097_SET_USER_CLIP_PLANE_CONTROL:
u32 clip_plane_0 = enable & 0xf;
u32 clip_plane_1 = (enable >> 4) & 0xf;
u32 clip_plane_2 = (enable >> 8) & 0xf;
u32 clip_plane_3 = (enable >> 12) & 0xf;
u32 clip_plane_4 = (enable >> 16) & 0xf;
u32 clip_plane_5 = enable >> 20;
clip_plane_0 ? glEnable(GL_CLIP_PLANE0) : glDisable(GL_CLIP_PLANE0);
clip_plane_1 ? glEnable(GL_CLIP_PLANE1) : glDisable(GL_CLIP_PLANE1);
clip_plane_2 ? glEnable(GL_CLIP_PLANE2) : glDisable(GL_CLIP_PLANE2);
clip_plane_3 ? glEnable(GL_CLIP_PLANE3) : glDisable(GL_CLIP_PLANE3);
clip_plane_4 ? glEnable(GL_CLIP_PLANE4) : glDisable(GL_CLIP_PLANE4);
clip_plane_5 ? glEnable(GL_CLIP_PLANE5) : glDisable(GL_CLIP_PLANE5);
break;
}
}
void GLGSRender::ClearColor(u32 a, u32 r, u32 g, u32 b) void GLGSRender::ClearColor(u32 a, u32 r, u32 g, u32 b)
{ {
glClearColor(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f); glClearColor(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
@ -1690,40 +1771,6 @@ void GLGSRender::ExecCMD()
InitDrawBuffers(); InitDrawBuffers();
Enable(m_set_depth_test, GL_DEPTH_TEST);
Enable(m_set_alpha_test, GL_ALPHA_TEST);
Enable(m_set_depth_bounds_test, GL_DEPTH_BOUNDS_TEST_EXT);
Enable(m_set_blend || m_set_blend_mrt1 || m_set_blend_mrt2 || m_set_blend_mrt3, GL_BLEND);
Enable(m_set_scissor_horizontal && m_set_scissor_vertical, GL_SCISSOR_TEST);
Enable(m_set_logic_op, GL_LOGIC_OP);
Enable(m_set_cull_face, GL_CULL_FACE);
Enable(m_set_dither, GL_DITHER);
Enable(m_set_stencil_test, GL_STENCIL_TEST);
Enable(m_set_line_smooth, GL_LINE_SMOOTH);
Enable(m_set_poly_smooth, GL_POLYGON_SMOOTH);
Enable(m_set_point_sprite_control, GL_POINT_SPRITE);
Enable(m_set_specular, GL_LIGHTING);
Enable(m_set_poly_offset_fill, GL_POLYGON_OFFSET_FILL);
Enable(m_set_poly_offset_line, GL_POLYGON_OFFSET_LINE);
Enable(m_set_poly_offset_point, GL_POLYGON_OFFSET_POINT);
Enable(m_set_restart_index, GL_PRIMITIVE_RESTART);
Enable(m_set_line_stipple, GL_LINE_STIPPLE);
Enable(m_set_polygon_stipple, GL_POLYGON_STIPPLE);
if (m_set_clip_plane)
{
Enable(m_clip_plane_0, GL_CLIP_PLANE0);
Enable(m_clip_plane_1, GL_CLIP_PLANE1);
Enable(m_clip_plane_2, GL_CLIP_PLANE2);
Enable(m_clip_plane_3, GL_CLIP_PLANE3);
Enable(m_clip_plane_4, GL_CLIP_PLANE4);
Enable(m_clip_plane_5, GL_CLIP_PLANE5);
checkForGlError("m_set_clip_plane");
}
checkForGlError("glEnable");
if (m_set_front_polygon_mode) if (m_set_front_polygon_mode)
{ {
glPolygonMode(GL_FRONT, m_front_polygon_mode); glPolygonMode(GL_FRONT, m_front_polygon_mode);

View File

@ -171,7 +171,6 @@ private:
void InitVertexData(); void InitVertexData();
void InitFragmentData(); void InitFragmentData();
void Enable(bool enable, const u32 cap);
virtual void Close(); virtual void Close();
bool LoadProgram(); bool LoadProgram();
void WriteBuffers(); void WriteBuffers();
@ -191,6 +190,7 @@ protected:
virtual void OnExitThread(); virtual void OnExitThread();
virtual void OnReset(); virtual void OnReset();
virtual void ExecCMD(); virtual void ExecCMD();
virtual void Enable(u32 cmd, u32 enable);
virtual void ClearColor(u32 a, u32 r, u32 g, u32 b); virtual void ClearColor(u32 a, u32 r, u32 g, u32 b);
virtual void ClearStencil(u32 stencil); virtual void ClearStencil(u32 stencil);
virtual void ClearDepth(u32 depth); virtual void ClearDepth(u32 depth);

View File

@ -31,6 +31,10 @@ private:
{ {
} }
virtual void Enable(u32 cmd, u32 enable)
{
}
virtual void ClearColor(u32 a, u32 r, u32 g, u32 b) virtual void ClearColor(u32 a, u32 r, u32 g, u32 b)
{ {
} }

View File

@ -557,7 +557,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
// Alpha testing // Alpha testing
case NV4097_SET_ALPHA_TEST_ENABLE: case NV4097_SET_ALPHA_TEST_ENABLE:
{ {
m_set_alpha_test = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
@ -586,7 +586,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
// Cull face // Cull face
case NV4097_SET_CULL_FACE_ENABLE: case NV4097_SET_CULL_FACE_ENABLE:
{ {
m_set_cull_face = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
@ -606,7 +606,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
// Blending // Blending
case NV4097_SET_BLEND_ENABLE: case NV4097_SET_BLEND_ENABLE:
{ {
m_set_blend = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
@ -680,7 +680,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
// Depth bound testing // Depth bound testing
case NV4097_SET_DEPTH_BOUNDS_TEST_ENABLE: case NV4097_SET_DEPTH_BOUNDS_TEST_ENABLE:
{ {
m_set_depth_bounds_test = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
@ -769,7 +769,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
// Depth testing // Depth testing
case NV4097_SET_DEPTH_TEST_ENABLE: case NV4097_SET_DEPTH_TEST_ENABLE:
{ {
m_set_depth_test = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
@ -804,19 +804,19 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
case NV4097_SET_POLY_OFFSET_FILL_ENABLE: case NV4097_SET_POLY_OFFSET_FILL_ENABLE:
{ {
m_set_poly_offset_fill = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
case NV4097_SET_POLY_OFFSET_LINE_ENABLE: case NV4097_SET_POLY_OFFSET_LINE_ENABLE:
{ {
m_set_poly_offset_line = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
case NV4097_SET_POLY_OFFSET_POINT_ENABLE: case NV4097_SET_POLY_OFFSET_POINT_ENABLE:
{ {
m_set_poly_offset_point = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
@ -1218,7 +1218,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
// Logic Ops // Logic Ops
case NV4097_SET_LOGIC_OP_ENABLE: case NV4097_SET_LOGIC_OP_ENABLE:
{ {
m_set_logic_op = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
@ -1231,14 +1231,14 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
// Dithering // Dithering
case NV4097_SET_DITHER_ENABLE: case NV4097_SET_DITHER_ENABLE:
{ {
m_set_dither = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
// Stencil testing // Stencil testing
case NV4097_SET_STENCIL_TEST_ENABLE: case NV4097_SET_STENCIL_TEST_ENABLE:
{ {
m_set_stencil_test = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
@ -1384,7 +1384,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
// Primitive restart index // Primitive restart index
case NV4097_SET_RESTART_INDEX_ENABLE: case NV4097_SET_RESTART_INDEX_ENABLE:
{ {
m_set_restart_index = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
@ -1415,7 +1415,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
case NV4097_SET_POINT_SPRITE_CONTROL: case NV4097_SET_POINT_SPRITE_CONTROL:
{ {
m_set_point_sprite_control = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
// TODO: // TODO:
//(cmd)[1] = CELL_GCM_ENDIAN_SWAP((enable) | ((rmode) << 1) | (texcoordMask)); //(cmd)[1] = CELL_GCM_ENDIAN_SWAP((enable) | ((rmode) << 1) | (texcoordMask));
@ -1425,7 +1425,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
// Lighting // Lighting
case NV4097_SET_SPECULAR_ENABLE: case NV4097_SET_SPECULAR_ENABLE:
{ {
m_set_specular = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
@ -1683,13 +1683,13 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
// Line/Polygon smoothing // Line/Polygon smoothing
case NV4097_SET_LINE_SMOOTH_ENABLE: case NV4097_SET_LINE_SMOOTH_ENABLE:
{ {
m_set_line_smooth = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
case NV4097_SET_POLY_SMOOTH_ENABLE: case NV4097_SET_POLY_SMOOTH_ENABLE:
{ {
m_set_poly_smooth = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
@ -1705,7 +1705,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
// Line/Polygon stipple // Line/Polygon stipple
case NV4097_SET_LINE_STIPPLE: case NV4097_SET_LINE_STIPPLE:
{ {
m_set_line_stipple = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
@ -1720,7 +1720,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
case NV4097_SET_POLYGON_STIPPLE: case NV4097_SET_POLYGON_STIPPLE:
{ {
m_set_polygon_stipple = ARGS(0) ? true : false; Enable(cmd, ARGS(0));
} }
break; break;
@ -1836,14 +1836,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
// Clip Plane // Clip Plane
case NV4097_SET_USER_CLIP_PLANE_CONTROL: case NV4097_SET_USER_CLIP_PLANE_CONTROL:
{ {
const u32 a0 = ARGS(0); Enable(cmd, ARGS(0));
m_set_clip_plane = true;
m_clip_plane_0 = (a0 & 0xf) ? true : false;
m_clip_plane_1 = ((a0 >> 4)) & 0xf ? true : false;
m_clip_plane_2 = ((a0 >> 8)) & 0xf ? true : false;
m_clip_plane_3 = ((a0 >> 12)) & 0xf ? true : false;
m_clip_plane_4 = ((a0 >> 16)) & 0xf ? true : false;
m_clip_plane_5 = (a0 >> 20) ? true : false;
} }
break; break;

View File

@ -632,6 +632,7 @@ protected:
virtual void OnExitThread() = 0; virtual void OnExitThread() = 0;
virtual void OnReset() = 0; virtual void OnReset() = 0;
virtual void ExecCMD() = 0; virtual void ExecCMD() = 0;
virtual void Enable(u32 cmd, u32 enable) = 0;
virtual void ClearColor(u32 a, u32 r, u32 g, u32 b) = 0; virtual void ClearColor(u32 a, u32 r, u32 g, u32 b) = 0;
virtual void ClearStencil(u32 stencil) = 0; virtual void ClearStencil(u32 stencil) = 0;
virtual void ClearDepth(u32 depth) = 0; virtual void ClearDepth(u32 depth) = 0;