Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectDraw Clippers

Started by ZomeonE Dec 15, 1999 at 3:05 PM 19 replies 2.4k views
Original Post
ZomeonE
ZomeonE
I'm have a 2d scrolling function, which uses a clipper on the backbuffer and normal ->Blt(...) to draw the tiles on the screen. But it's SLOW, really SLOW.
So I'm wondering: are clippers slow? or is it just my code that is?
ZomeonE
ZomeonE
Please answer this simple question:

Are DDraw clippers slow???

Gorky
Gorky
Clippers should not really be impacting your preformance.
Do a comparison of: FPS with them and without them(If it doesn't crash)

Perhaps your misusing them? How many do you have attached to the backbuffer?

mason
mason
In my experience, they can be awfully slow.

My game uses clippers extensively, and there's a noticeable drop in performance when using certain drivers on my V550. I've found that the RIVA drivers tend to handle clippers fairly well, and that the default Viper drivers do not.

If anyone has any other information on this, I'd love to hear it.

Mason McCuskey
Spin Studios
www.spin-studios.com

Founder, Cuttlefish Industries
The Cuttlefish Engine lets anyone develop great games for iPad, iPhone, Android, WP7, the web, and more!
ZomeonE
ZomeonE
I've only got one attached to the backbuffer and I'm not missusing them in any way I know. Anyway, I've written something without clippers and here is the code. But there's one problem. The Blt(...) function won't work with a source RECT.


RECT dest;
RECT src;
int i=1, ii=1;
int dx, dy;

if (pos_x < 0) pos_x = 0;
if (pos_y < 0) pos_y = 0;

pos_x+=2;
pos_y+=2;

dx = pos_x - ((pos_x / TILE_WIDTH)*TILE_WIDTH);
dy = pos_y - ((pos_y / TILE_HEIGHT)*TILE_HEIGHT);

src.top = 1;
src.left = 1;
src.bottom = TILE_HEIGHT;
src.right = TILE_WIDTH;

for (i=0;i<=8;i++)
{
dest.top = i * TILE_HEIGHT - dy;
if (i==0) dest.top = 0;
dest.bottom = i * TILE_HEIGHT - dy + TILE_HEIGHT;
src.top = 0;
if (i==0) src.top = TILE_HEIGHT - dy;
src.bottom = TILE_HEIGHT;
for (ii=0;ii<=11;ii++)
{
dest.left = ii * TILE_WIDTH - dx;
if (ii==0) dest.left = 0;
dest.right = ii * TILE_WIDTH - dx + TILE_WIDTH;
src.left = 0;
if (ii==0) src.left = TILE_WIDTH - dx;
src.right = TILE_WIDTH;
primsurf->Blt(&dest, bitmap, &src, NULL, NULL);
}
}

while(primsurf->Flip(NULL, DDFLIP_WAIT)!=DD_OK);

ZomeonE
ZomeonE
Please help me!
UraniumRod
UraniumRod
why dont you make your own its not that hard really

------------------

------------------------------"My sword is like a menacing cloud, but instead of rain, blood will pour in its path." - Sehabeddin, Turkish Military Commander 1438.
mason
mason
The problem with writing your own is that the DDraw clippers do more than you think.

They can clip against a *series* of rectangles, including ones that partially overlap each other. Because of this, they're a great tool in GUI design.

If all you need is simple "draw only inside this rectangle" clipping, writing your own is an option... but if you need more complex clipping, the speed hit may be worth the development time saved.

Mason McCuskey
Spin Studios
www.spin-studios.com

Founder, Cuttlefish Industries
The Cuttlefish Engine lets anyone develop great games for iPad, iPhone, Android, WP7, the web, and more!
Gorky
Gorky
I have to agree with mason.
For what you are doing, create you're own clipper, the use bltfast vs blt.

You might also try to combine a run of tiles, into one single blt. That could get you a preformance increase.

ZomeonE
ZomeonE
Ok, but can't i use a souce rect and a dest rect with the Blt function to make "a form of clippers"??

primsurf->Blt(&dest_rect, bitmap, &src_rect, NULL, NULL);

STG
STG
Why not use bltfast?

Last time I wrote a tile based thing I used bltfast changed the rect to only display teh bits of tiles needed on the edge of the screen and it ran realy well.

ZomeonE
ZomeonE
I can't get it to work, do u have an example that you can send to me?
Please!

zomeone@usa.net

Stark
Stark
HRESULT rVal; // DirectDraw return value
RECT rcSource; // Tile size & position on surface

rcSource.left = xPos;
rcSource.top = yPos;
rcSource.right = xPos + TILEWIDTH;
rcSource.bottom = yPos + TILEHEIGHT;

// Clip right side
if (destX + TILEWIDTH > WINDOWWIDTH)
rcSource.right = rcSource.right - (destX + TILEWIDTH - WINDOWWIDTH);

// Clip bottom side
if (destY + TILEHEIGHT > WINDOWHEIGHT)
rcSource.bottom = rcSource.bottom - (destY + TILEHEIGHT - WINDOWHEIGHT);

// Clip left side
if (destX <= 0)
rcSource.left = rcSource.left + (-destX)

// Clip top side
if (destY <= 0)
rcSource.top = rcSource.top + (-destY)

if (FAILED(rVal = (lpDestSurface->BltFast(destX, destY, lpSourceSurface, &rcSource, NULL)))
return rVal;
.
.
.

[This message has been edited by Stark (edited December 14, 1999).]

Stark
Stark
I'm really not to sure how well that'll work, 'cause I'm at work and doing this all from memory and on a napkin beside me. hehehe

So, hope it does the trick. Good luck.

ZomeonE
ZomeonE
Thanks alot!

I havn't had any time to test it yet, but I will. I'm not sure why the BltFast function doesn't work. It doesn't blit anything...nothing. I'm using 640x480x16, loaded a 16 bit bitmap and try to blit it to the backbuffer. But it doesn't work with the source rect. The

Blt(&dest, surface, NULL, NULL, NULL)

works but not

Blt(&dest, surface, &src, NULL, NULL)
of
BltFast(....)

what's the problem?

ZomeonE
ZomeonE
oops

it should be

Blt(&dest, surface, &src, NULL, NULL)
or
BltFast(....)

Gorky
Gorky
Are you receiving an error message from the operation?
Also rememeber to not attach a clipper to the backbuffer surface, if you plan on using BltFast
ZomeonE
ZomeonE
Where should i put the clipper?

Anyway, I'm not using clippers and I've read that BltFast doesn't work with clippers. I think I read it in the Dx reference!

ZomeonE
ZomeonE
Ok, I mean like this:


+-------+
| | <- source surface
| +---+
| | | <- source rect
+---+---+

That won't resize the image when it is blitted right?
It will only blit the part of the source surface specified in the source rect to the destination surface. Tell me if I'm wrong!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.