Skip to main content
gamedev.net
🔒 Locked

Performance problems

Started by PhanThomas 6 replies 650+ views
Original Post
PhanThomas
PhanThomas
Ok the code: void FadeOut565(LPDIRECTDRAWSURFACE7 _lpdds, RECT *_rect, float _pct) { DDSURFACEDESC2 ddsd; // surface description struct USHORT* buffer; // pointer to surface memory USHORT color; // holds color valu of pixel UCHAR r=0, g=0, b=0; // r/g/b components of pixel DWORD pitch; // memory pitch // init ddsd struct INIT_DX_STRUCT(ddsd); // lock surface _lpdds->Lock(_rect, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, 0); // get memory ptr buffer = (USHORT*)ddsd.lpSurface; // get pitch (ddsd.lPitch is in bytes) pitch = ddsd.lPitch/2; // adjust the pointer buffer -= _rect->left; // go through every line for(int y=_rect->top; y<_rect->bottom; y++) { // go through every pixel for(int x=_rect->left; x<_rect->right; x++) { // get color value color = buffer[x]; // extract the components r = (color & 0xF800) >> 11; g = (color & 0x07E0) >> 5; b = (color & 0x001F); // recalculate the values r = (UCHAR)((float)r*_pct); g = (UCHAR)((float)g*_pct); b = (UCHAR)((float)b*_pct); // write new pixel on surface buffer[x] = RGB_16BIT565(r, g, b); } // advance pointer buffer += pitch; } // unlock the surface _lpdds->Unlock(_rect); } // end of FadeOut565 This function is supposed to fade to black. But I only get 1FPS when it is performed? Is the code sh** or what else? 2nd question: When I blit a single 640*480 surface on the primary I only get about 45FPS. Is this normal too?
TheSalmon
TheSalmon
Hmmm, perhaps you should try using look-up tables.
---Mikael Lax
harrys
harrys

try to replace:
color = buffer[x];
with
color = *buffer;


// recalculate the values
r = (UCHAR)((float)r*_pct);
g = (UCHAR)((float)g*_pct);
b = (UCHAR)((float)b*_pct);

Here you should use shifting or Lookup tables like thesalomon suggested:

try to replace:

buffer[x] = RGB_16BIT565(r, g, b);
with
*buffer++=RGB_16BIT565(r, g, b);


There is an article about further optimization in Developer Resources Section here...

Edited by - harrys on January 6, 2001 11:33:35 AM
harrys
harrys
quote:
Original post by Psychocatt

There was an article on performing a fade using the video card''s gamma control: Using Gamma Controls to Perform a Fade. This may get you what you need. Hope this helps.



This would of course be the fastest possible method...

But better do not use gamma, when running in windowed mode ;-)
Domenic
Domenic
Don''t quote me on this, but I think that the gamma controls only work if the hardware supports them, and in Andre''s book TotWGPG, he says he doesn''t have any computers that support gamma controls, and at XGDC I heard he has 6 up-to-date computers. So... if the gamma controls on this thread are the same as the ones in TotWGPG, I suggest not using them.

-Domenic-
Geek^n
-Domenic-Geek^n
PhanThomas
PhanThomas
quote:
Original post by TheSalmon

Hmmm, perhaps you should try using look-up tables.


Well, I tried clut out and they were 300% faster. So i actually got 3FPS. Before I did the fade manually I did it with gamma controll. This is much faster, really. I just wanted to see if I can do the fade myself. But because it''s so slow I'' ll stick with DD''s gammacontroll.
harrys
harrys

quote:

Well, I tried clut out and they were 300% faster. So i actually got 3FPS. Before I did the fade manually I did it with gamma controll. This is much faster, really. I just wanted to see if I can do the fade myself. But because it''s so slow I'' ll stick with DD''s gammacontroll.



I overlooked that your are reading from videomemory - you should never do this because its slow. If you cant get the screen contents from any other place, copy it to an array in main memory once, fade it, and copy it back to screen, fade again, copy to screen etc. do not read it again...


Topic Locked

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

Sign in to reply to this topic.