2D Layer & mask style

Hello, what s possible to code to generate a multilayer 2d texture with mask such as a bitmap software with layers & masks does. If I want to apply a mask on a specific layer, what's the process : disable blend, draw mask, apply blend use func and draw layer on top ? But what happens if I must draw multiple layers on top of each other ?
Thanks