MCPcopy Create free account
hub / github.com/defold/defold / ResetRenderStateIfChanged

Function ResetRenderStateIfChanged

engine/render/src/render/render.cpp:419–488  ·  view source on GitHub ↗

This function will compare the values in ps_orig and ps_now and reset the render state that is different between them It is expected that the first parameter is the "default" state, i.e the values from that pipeline will be used

Source from the content-addressed store, hash-verified

417 // This function will compare the values in ps_orig and ps_now and reset the render state that is different between them
418 // It is expected that the first parameter is the "default" state, i.e the values from that pipeline will be used
419 static void ResetRenderStateIfChanged(dmGraphics::HContext graphics_context, dmGraphics::PipelineState ps_orig, dmGraphics::PipelineState ps_now)
420 {
421 #define HAS_CHANGED(name) (ps_now.name != ps_orig.name)
422
423 if (HAS_CHANGED(m_BlendSrcFactor) || HAS_CHANGED(m_BlendDstFactor) ||
424 HAS_CHANGED(m_BlendSrcFactorAlpha) || HAS_CHANGED(m_BlendDstFactorAlpha))
425 {
426 dmGraphics::SetBlendFuncSeparate(graphics_context,
427 (dmGraphics::BlendFactor) ps_orig.m_BlendSrcFactor,
428 (dmGraphics::BlendFactor) ps_orig.m_BlendDstFactor,
429 (dmGraphics::BlendFactor) ps_orig.m_BlendSrcFactorAlpha,
430 (dmGraphics::BlendFactor) ps_orig.m_BlendDstFactorAlpha);
431 }
432
433 if (HAS_CHANGED(m_BlendEquationColor) || HAS_CHANGED(m_BlendEquationAlpha))
434 {
435 dmGraphics::SetBlendEquationSeparate(graphics_context,
436 (dmGraphics::BlendEquation) ps_orig.m_BlendEquationColor,
437 (dmGraphics::BlendEquation) ps_orig.m_BlendEquationAlpha);
438 }
439
440 if (HAS_CHANGED(m_FaceWinding))
441 {
442 dmGraphics::SetFaceWinding(graphics_context, (dmGraphics::FaceWinding) ps_orig.m_FaceWinding);
443 }
444
445 if (HAS_CHANGED(m_StencilWriteMask))
446 {
447 dmGraphics::SetStencilMask(graphics_context, ps_orig.m_StencilWriteMask);
448 }
449
450 if (HAS_CHANGED(m_WriteColorMask))
451 {
452 dmGraphics::SetColorMask(graphics_context,
453 ps_orig.m_WriteColorMask & (1<<3),
454 ps_orig.m_WriteColorMask & (1<<2),
455 ps_orig.m_WriteColorMask & (1<<1),
456 ps_orig.m_WriteColorMask & (1<<0));
457 }
458
459 if (HAS_CHANGED(m_StencilFrontTestFunc) || HAS_CHANGED(m_StencilReference) || HAS_CHANGED(m_StencilCompareMask))
460 {
461 dmGraphics::SetStencilFuncSeparate(graphics_context, dmGraphics::FACE_TYPE_FRONT,
462 (dmGraphics::CompareFunc) ps_orig.m_StencilFrontTestFunc, ps_orig.m_StencilReference, ps_orig.m_StencilCompareMask);
463 }
464
465 if (HAS_CHANGED(m_StencilBackTestFunc) || HAS_CHANGED(m_StencilReference) || HAS_CHANGED(m_StencilCompareMask))
466 {
467 dmGraphics::SetStencilFuncSeparate(graphics_context, dmGraphics::FACE_TYPE_BACK,
468 (dmGraphics::CompareFunc) ps_orig.m_StencilBackTestFunc, ps_orig.m_StencilReference, ps_orig.m_StencilCompareMask);
469 }
470
471 if (HAS_CHANGED(m_StencilFrontOpFail) || HAS_CHANGED(m_StencilFrontOpDepthFail) || HAS_CHANGED(m_StencilFrontOpPass))
472 {
473 dmGraphics::SetStencilOpSeparate(graphics_context, dmGraphics::FACE_TYPE_FRONT,
474 (dmGraphics::StencilOp) ps_orig.m_StencilFrontOpFail,
475 (dmGraphics::StencilOp) ps_orig.m_StencilFrontOpDepthFail,
476 (dmGraphics::StencilOp) ps_orig.m_StencilFrontOpPass);

Callers 2

ApplyRenderStateFunction · 0.85
DrawFunction · 0.85

Calls 7

SetBlendFuncSeparateFunction · 0.85
SetBlendEquationSeparateFunction · 0.85
SetFaceWindingFunction · 0.85
SetStencilMaskFunction · 0.85
SetColorMaskFunction · 0.85
SetStencilFuncSeparateFunction · 0.85
SetStencilOpSeparateFunction · 0.85

Tested by

no test coverage detected