Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AndrewAMD, SBGuy, Petra, flink, 1 invisible), 699 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
clear part of a bmap #456786
12/09/15 20:09
12/09/15 20:09
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Hey there,

I'm looking for a (fast) way to clear a rectangular area of an ARGB8 bmap.
bmap_blit doesn't really work for me because of it's bad performance.

any ideas?


POTATO-MAN saves the day! - Random
Re: clear part of a bmap [Re: Kartoffel] #456790
12/10/15 00:54
12/10/15 00:54

M
Malice
Unregistered
Malice
Unregistered
M



No sure what you would like to achieve

Few Ideas,

1)Tack a higher layer panel->bmap over the lower panel->bmap (assumes panels)
2) draw a draw_quad over the area.

Re: clear part of a bmap [Re: ] #456801
12/10/15 08:14
12/10/15 08:14
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
I think if you check the BMAP struct in atypes.h you can access the actual bytes (maybe called as finalbits) to handle my a loop of memsets (resulting in areay loop length instead of areax*areay). But the BMAP should be locked/unlocked.
By the way, bmap_blit() is not okay for bmaps having an alpha channel at all.
Please tell me if succeeded, I would use it too. laugh

Last edited by sivan; 12/10/15 08:15.

Free world editor for 3D Gamestudio: MapBuilder Editor
Re: clear part of a bmap [Re: sivan] #456805
12/10/15 12:41
12/10/15 12:41
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
well, the problem with bmap_blit is that it's done on the cpu, same with accessing the bmap's content via code. I'm trying to implement a dynamic texture atlas for my own interface system, but I need a fast way (a gpu-side approach, preferrably) for filling (rectangular) areas of a bmap with only transparent pixels.


POTATO-MAN saves the day! - Random
Re: clear part of a bmap [Re: Kartoffel] #456806
12/10/15 12:50
12/10/15 12:50
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
If it was possible to set values in script (like dimensions), then use bmap_process and paint on the bitmap according to those values, then that would be the fastest way I assume.
I haven't tried that in a long time but I think the material/ effect only receives those values once per frame. Maybe it's possible to use some directX function? I don't know.
Should you try that and figure it out, please tell me the results.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: clear part of a bmap [Re: Kartoffel] #456807
12/10/15 12:54
12/10/15 12:54
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline
Serious User
Reconnoiter  Offline
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
This seems like the same idea as Sivan's, but maybe it helps you or gives you more ideas (ps this example is in c# but my quess is that it is possible in c too):

http://stackoverflow.com/questions/6020406/travel-through-pixels-in-bmp

Re: clear part of a bmap [Re: Reconnoiter] #456808
12/10/15 13:39
12/10/15 13:39
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Thanks for your ideas and suggestions, I'll try messing around with these approaches later and let you know if it works. laugh

I guess bmap_process should be the fastest as Superku said. The biggest Problem with this method is that you have to render the whole bmap, even if you're just clearing a small part of it.
However, since I'm currently working towards low-res graphics this could be a solution that's good enough.


POTATO-MAN saves the day! - Random
Re: clear part of a bmap [Re: Kartoffel] #456813
12/10/15 18:50
12/10/15 18:50
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Here's a bmap_process implementation:

the shader file "ppBmapClearRect.fx"
Code:
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

Code:
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));

Last edited by Kartoffel; 12/10/15 18:53.

POTATO-MAN saves the day! - Random

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1