Here's a bmap_process implementation:
the shader file "ppBmapClearRect.fx"
const float4 vecSkill1;
//==========
const texture TargetMap;
sampler2D smpTex = sampler_state
{
Texture = <TargetMap>;
MipFilter = Point;
MagFilter = Point;
MinFilter = Point;
AddressU = Clamp;
AddressV = Clamp;
};
//==========
float4 PShader(in float4 vPos : VPOS) : COLOR0
{
if(clamp(vPos.x, vecSkill1.x, vecSkill1.y) != vPos.x || clamp(vPos.y, vecSkill1.z, vecSkill1.w) != vPos.y)
clip(-1);
return float4(0, 0, 0, 0);
}
//==========
technique Tech_PP
{
pass Pass_1
{
AlphaBlendEnable = False;
PixelShader = compile ps_3_0 PShader();
}
}
and the functions
MATERIAL * ppBmapClearRect = { effect = "ppBmapClearRect.fx"; }
//
// clear a rectangular part of a bmap (parameters: size and offset)
void bmap_clear_rect(BMAP * bmap, int size_x, int size_y, int offset_x, int offset_y)
{
ppBmapClearRect->skill1 = floatv(offset_x);
ppBmapClearRect->skill2 = floatv(offset_x + size_x);
ppBmapClearRect->skill3 = floatv(offset_y);
ppBmapClearRect->skill4 = floatv(offset_y + size_y);
bmap_process(bmap, bmap, ppBmapClearRect);
}
// clear a rectangular part of a bmap (parameters: min and max x,y)
void bmap_clear_rect_minmax(BMAP * bmap, int left, int top, int right, int bottom)
{
ppBmapClearRect->skill1 = floatv(left);
ppBmapClearRect->skill2 = floatv(right);
ppBmapClearRect->skill3 = floatv(top);
ppBmapClearRect->skill4 = floatv(bottom);
bmap_process(bmap, bmap, ppBmapClearRect);
}
edit: note that the coordinates start with 0, 0 as the top left corner
There are however some things to consider:
- there are some issues with bmaps after you used bmap_process (most likely because they somehow stay a rendertarget after the processing is done)
This causes the bmap to lose it's content when changing the resolution and sometimes when tabbing out and in to your game in fullscreenmode
after you've used bmap_process you can use
bmap_to_format(your_bmap, bmap_format(your_bmap)); to force a redraw of your bmap, which will solve this problem.
- if your bmap is bigger than your engine window resolution you have to increase the zbuffer scale like so:
bmap_zbuffer(bmap_createblack(2048, 2048, 8888));