add gl_wireframe and gl_wireframecolor

This commit is contained in:
Ricardo Luís Vaz Silva 2025-01-09 09:25:52 -03:00 committed by Magnus Norddahl
commit c72bad053f
14 changed files with 151 additions and 64 deletions

View file

@ -71,15 +71,37 @@ void VkRenderState::ClearScreen()
mCommandBuffer->draw(4, 1, vertices.second, 0);
}
void VkRenderState::Draw(int dt, int index, int count, bool apply)
void VkRenderState::DoDraw(int dt, int index, int count, bool apply)
{
if (apply || mNeedApply)
Apply(dt);
#ifdef __APPLE__
// moltenvk doesn't support drawing triangle fans
if (dt == DT_TriangleFan)
{
IBuffer* oldIndexBuffer = mIndexBuffer;
mIndexBuffer = fb->GetBufferManager()->FanToTrisIndexBuffer.get();
mCommandBuffer->draw(count, 1, index, 0);
if (apply || mNeedApply)
Apply(DT_Triangles);
else
ApplyVertexBuffers();
mCommandBuffer->drawIndexed((count - 2) * 3, 1, 0, index, 0);
mIndexBuffer = oldIndexBuffer;
}
else
{
#endif
if (apply || mNeedApply)
Apply(dt);
mCommandBuffer->draw(count, 1, index, 0);
#ifdef __APPLE__
}
#endif
}
void VkRenderState::DrawIndexed(int dt, int index, int count, bool apply)
void VkRenderState::DoDrawIndexed(int dt, int index, int count, bool apply)
{
if (apply || mNeedApply)
Apply(dt);
@ -226,10 +248,11 @@ void VkRenderState::ApplyRenderPass(int dt)
// Find a pipeline that matches our state
VkPipelineKey pipelineKey;
pipelineKey.DrawType = dt;
pipelineKey.DrawLine = mDrawLine || mWireframe;
pipelineKey.VertexFormat = mVertexBuffer ? static_cast<VkHardwareVertexBuffer*>(mVertexBuffer)->VertexFormat : mRSBuffers->Flatbuffer.VertexFormat;
pipelineKey.RenderStyle = mRenderStyle;
pipelineKey.DepthTest = mDepthTest;
pipelineKey.DepthWrite = mDepthTest && mDepthWrite;
pipelineKey.DepthTest = mDepthTest && !mWireframe;
pipelineKey.DepthWrite = mDepthTest && !mWireframe && mDepthWrite;
pipelineKey.DepthFunc = mDepthFunc;
pipelineKey.DepthClamp = mDepthClamp;
pipelineKey.DepthBias = !(mBias.mFactor == 0 && mBias.mUnits == 0);
@ -247,7 +270,7 @@ void VkRenderState::ApplyRenderPass(int dt)
{
int effectState = mMaterial.mOverrideShader >= 0 ? mMaterial.mOverrideShader : (mMaterial.mMaterial ? mMaterial.mMaterial->GetShaderIndex() : 0);
pipelineKey.ShaderKey.SpecialEffect = EFF_NONE;
pipelineKey.ShaderKey.EffectState = mTextureEnabled ? effectState : SHADER_NoTexture;
pipelineKey.ShaderKey.EffectState = (mTextureEnabled && !mWireframe) ? effectState : SHADER_NoTexture;
if (r_skipmats && pipelineKey.ShaderKey.EffectState >= 3 && pipelineKey.ShaderKey.EffectState <= 4)
pipelineKey.ShaderKey.EffectState = 0;
pipelineKey.ShaderKey.AlphaTest = mSurfaceUniforms.uAlphaThreshold >= 0.f;
@ -1080,15 +1103,16 @@ void VkRenderState::ApplyLevelMeshPipeline(VulkanCommandBuffer* cmdbuffer, VkPip
pipelineKey.ShaderKey.GBufferPass = mRenderTarget.DrawBuffers > 1;
// State overridden by the renderstate drawing the mesh
pipelineKey.DepthTest = mDepthTest;
pipelineKey.DepthWrite = mDepthTest && mDepthWrite;
pipelineKey.DrawLine = mDrawLine || mWireframe;
pipelineKey.DepthTest = mDepthTest && !mWireframe;
pipelineKey.DepthWrite = mDepthTest && !mWireframe && mDepthWrite;
pipelineKey.DepthClamp = mDepthClamp;
pipelineKey.DepthBias = !(mBias.mFactor == 0 && mBias.mUnits == 0);
pipelineKey.StencilTest = mStencilTest;
pipelineKey.StencilPassOp = mStencilOp;
pipelineKey.ColorMask = mColorMask;
pipelineKey.CullMode = mCullMode;
if (!mTextureEnabled)
if (!mTextureEnabled || mWireframe)
pipelineKey.ShaderKey.EffectState = SHADER_NoTexture;
mPipelineKey = pipelineKey;
@ -1110,30 +1134,3 @@ void VkRenderState::ApplyLevelMeshPipeline(VulkanCommandBuffer* cmdbuffer, VkPip
cmdbuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 2, descriptors->GetBindlessSet());
cmdbuffer->pushConstants(layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, (uint32_t)sizeof(PushConstants), &pushConstants);
}
/////////////////////////////////////////////////////////////////////////////
void VkRenderStateMolten::Draw(int dt, int index, int count, bool apply)
{
if (dt == DT_TriangleFan)
{
IBuffer* oldIndexBuffer = mIndexBuffer;
mIndexBuffer = fb->GetBufferManager()->FanToTrisIndexBuffer.get();
if (apply || mNeedApply)
Apply(DT_Triangles);
else
ApplyVertexBuffers();
mCommandBuffer->drawIndexed((count - 2) * 3, 1, 0, index, 0);
mIndexBuffer = oldIndexBuffer;
}
else
{
if (apply || mNeedApply)
Apply(dt);
mCommandBuffer->draw(count, 1, index, 0);
}
}