mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Renderer: Move cull mode to a rasterization state object
Also moves logic for primitive handling to VideoCommon.
This commit is contained in:
@ -221,7 +221,8 @@ void ProgramShaderCache::UploadConstants()
|
||||
}
|
||||
}
|
||||
|
||||
SHADER* ProgramShaderCache::SetShader(u32 primitive_type, const GLVertexFormat* vertex_format)
|
||||
SHADER* ProgramShaderCache::SetShader(PrimitiveType primitive_type,
|
||||
const GLVertexFormat* vertex_format)
|
||||
{
|
||||
if (g_ActiveConfig.bDisableSpecializedShaders)
|
||||
return SetUberShader(primitive_type, vertex_format);
|
||||
@ -292,7 +293,8 @@ SHADER* ProgramShaderCache::SetShader(u32 primitive_type, const GLVertexFormat*
|
||||
return &last_entry->shader;
|
||||
}
|
||||
|
||||
SHADER* ProgramShaderCache::SetUberShader(u32 primitive_type, const GLVertexFormat* vertex_format)
|
||||
SHADER* ProgramShaderCache::SetUberShader(PrimitiveType primitive_type,
|
||||
const GLVertexFormat* vertex_format)
|
||||
{
|
||||
UBERSHADERUID uid;
|
||||
std::memset(&uid, 0, sizeof(uid));
|
||||
@ -1295,7 +1297,7 @@ void ProgramShaderCache::DestroyPrerenderArrays(SharedContextData* data)
|
||||
}
|
||||
}
|
||||
|
||||
void ProgramShaderCache::DrawPrerenderArray(const SHADER& shader, u32 primitive_type)
|
||||
void ProgramShaderCache::DrawPrerenderArray(const SHADER& shader, PrimitiveType primitive_type)
|
||||
{
|
||||
// This is called on a worker thread, so we don't want to use the normal binding process.
|
||||
glUseProgram(shader.glprogid);
|
||||
@ -1303,15 +1305,18 @@ void ProgramShaderCache::DrawPrerenderArray(const SHADER& shader, u32 primitive_
|
||||
// The number of primitives drawn depends on the type.
|
||||
switch (primitive_type)
|
||||
{
|
||||
case PRIMITIVE_POINTS:
|
||||
case PrimitiveType::Points:
|
||||
glDrawElements(GL_POINTS, 1, GL_UNSIGNED_SHORT, nullptr);
|
||||
break;
|
||||
case PRIMITIVE_LINES:
|
||||
case PrimitiveType::Lines:
|
||||
glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, nullptr);
|
||||
break;
|
||||
case PRIMITIVE_TRIANGLES:
|
||||
case PrimitiveType::Triangles:
|
||||
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, nullptr);
|
||||
break;
|
||||
case PrimitiveType::TriangleStrip:
|
||||
glDrawElements(GL_TRIANGLE_STRIP, 3, GL_UNSIGNED_SHORT, nullptr);
|
||||
break;
|
||||
}
|
||||
|
||||
// Has to be finished by the time the main thread picks it up.
|
||||
|
@ -94,8 +94,8 @@ public:
|
||||
};
|
||||
|
||||
static PCacheEntry GetShaderProgram();
|
||||
static SHADER* SetShader(u32 primitive_type, const GLVertexFormat* vertex_format);
|
||||
static SHADER* SetUberShader(u32 primitive_type, const GLVertexFormat* vertex_format);
|
||||
static SHADER* SetShader(PrimitiveType primitive_type, const GLVertexFormat* vertex_format);
|
||||
static SHADER* SetUberShader(PrimitiveType primitive_type, const GLVertexFormat* vertex_format);
|
||||
static void BindVertexFormat(const GLVertexFormat* vertex_format);
|
||||
static void InvalidateVertexFormat();
|
||||
static void BindLastVertexFormat();
|
||||
@ -198,7 +198,7 @@ private:
|
||||
static void DestroyShaders();
|
||||
static void CreatePrerenderArrays(SharedContextData* data);
|
||||
static void DestroyPrerenderArrays(SharedContextData* data);
|
||||
static void DrawPrerenderArray(const SHADER& shader, u32 primitive_type);
|
||||
static void DrawPrerenderArray(const SHADER& shader, PrimitiveType primitive_type);
|
||||
|
||||
static PCache pshaders;
|
||||
static UberPCache ubershaders;
|
||||
|
@ -1785,7 +1785,7 @@ void Renderer::RestoreAPIState()
|
||||
glEnable(GL_CLIP_DISTANCE0);
|
||||
glEnable(GL_CLIP_DISTANCE1);
|
||||
}
|
||||
SetGenerationMode();
|
||||
BPFunctions::SetGenerationMode();
|
||||
BPFunctions::SetScissor();
|
||||
BPFunctions::SetDepthMode();
|
||||
BPFunctions::SetBlendMode();
|
||||
@ -1798,14 +1798,14 @@ void Renderer::RestoreAPIState()
|
||||
OGLTexture::SetStage();
|
||||
}
|
||||
|
||||
void Renderer::SetGenerationMode()
|
||||
void Renderer::SetRasterizationState(const RasterizationState& state)
|
||||
{
|
||||
// none, ccw, cw, ccw
|
||||
if (bpmem.genMode.cullmode > 0)
|
||||
if (state.cullmode != GenMode::CULL_NONE)
|
||||
{
|
||||
// TODO: GX_CULL_ALL not supported, yet!
|
||||
glEnable(GL_CULL_FACE);
|
||||
glFrontFace(bpmem.genMode.cullmode == 2 ? GL_CCW : GL_CW);
|
||||
glFrontFace(state.cullmode == GenMode::CULL_FRONT ? GL_CCW : GL_CW);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -79,7 +79,7 @@ public:
|
||||
|
||||
void SetBlendingState(const BlendingState& state) override;
|
||||
void SetScissorRect(const EFBRectangle& rc) override;
|
||||
void SetGenerationMode() override;
|
||||
void SetRasterizationState(const RasterizationState& state) override;
|
||||
void SetDepthState(const DepthState& state) override;
|
||||
void SetSamplerState(int stage, int texindex, bool custom_tex) override;
|
||||
void SetInterlacingMode() override;
|
||||
|
@ -114,17 +114,17 @@ void VertexManager::Draw(u32 stride)
|
||||
|
||||
switch (m_current_primitive_type)
|
||||
{
|
||||
case PRIMITIVE_POINTS:
|
||||
case PrimitiveType::Points:
|
||||
primitive_mode = GL_POINTS;
|
||||
glDisable(GL_CULL_FACE);
|
||||
break;
|
||||
case PRIMITIVE_LINES:
|
||||
case PrimitiveType::Lines:
|
||||
primitive_mode = GL_LINES;
|
||||
glDisable(GL_CULL_FACE);
|
||||
break;
|
||||
case PRIMITIVE_TRIANGLES:
|
||||
primitive_mode =
|
||||
g_ActiveConfig.backend_info.bSupportsPrimitiveRestart ? GL_TRIANGLE_STRIP : GL_TRIANGLES;
|
||||
case PrimitiveType::Triangles:
|
||||
primitive_mode = GL_TRIANGLES;
|
||||
break;
|
||||
case PrimitiveType::TriangleStrip:
|
||||
primitive_mode = GL_TRIANGLE_STRIP;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -140,9 +140,6 @@ void VertexManager::Draw(u32 stride)
|
||||
}
|
||||
|
||||
INCSTAT(stats.thisFrame.numDrawCalls);
|
||||
|
||||
if (m_current_primitive_type != PRIMITIVE_TRIANGLES)
|
||||
static_cast<Renderer*>(g_renderer.get())->SetGenerationMode();
|
||||
}
|
||||
|
||||
void VertexManager::vFlush()
|
||||
|
Reference in New Issue
Block a user