Jump to content
  • Advertisement
Sign in to follow this  
designlord

Any tricks to speed up CopyRect() or alternative??

This topic is 4764 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All, I'm writing a 2D game that uses 1024x1024 size surfaces and map tiles to them for rendering backgrounds. Here is the code I'm using. I have it set up so it only updates when you can see the next surface in the direction your character is moving with a possible of 4 total in view at once. This appears to really lag out slower machines quite a bit when it updates. Any tricks I'm missing, or a better way? Would looping through with memset for each tile be any quicker? Thanks

Temp_Texture = *g_EmitterPin[m_iParentPinIndex].GetTexture( m_iFrameCount );

D3DLOCKED_RECT lockRect;

if ( D3D_OK != Temp_Texture->GetSurfaceLevel(0, &pTexSurface) )
{

  SetError( " Particle GetSurfaceLevel Failed " );
}

// Create a clean surface to clear the texture with.
LPDIRECT3DSURFACE8 pCleanSurface = 0;


if ( D3D_OK != g_pDevice->CreateImageSurface( 1024, 1024, D3DFMT_A8R8G8B8, &pCleanSurface) )
SetError( " Particle CreateImageSurface Failed " );


if ( D3D_OK != pCleanSurface->LockRect( &lockRect, NULL, 0) )
SetError( " Particle LockRect Failed " );

memset( (BYTE*)lockRect.pBits, 0, 1024 * lockRect.Pitch );

if ( D3D_OK != pCleanSurface->UnlockRect() )
SetError( " Particle UnlockRect Failed " );


if ( D3D_OK !=  g_pDevice->CopyRects( pCleanSurface, NULL, 0,pTexSurface, NULL ) )
SetError( " Particle CopyRects Failed LTTS" );
pCleanSurface->Release();


if ( bTextureSet_2 == true )
{

 g_pDevice->CopyRects( TileSet_Trees, Rect_Source, 1024, pTexSurface, Point_Dest );
}
else
{
	g_pDevice->CopyRects( TileSet_Forest, Rect_Source, 1024, pTexSurface, Point_Dest );
}

Share this post


Link to post
Share on other sites
Advertisement
StretchRect() will take better advantage of hardware acceleration. The downside is, there are more restrictions based on the driver for your graphics hardware so you may need multiple paths.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!