Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualsayezz

Posted 22 January 2013 - 07:51 AM

The double/tripper buffer trick didn't helped me. Maybe I'm doing something wrong. Heres what I have so far, does anyone see an error?:

IDirect3DSurface9 *pRenderTarget = NULL;LPDIRECT3DSURFACE9 buffers[3];int n = 0;...void dumb_buffer(LPDIRECT3DDEVICE9 pDevice){ // is called each frame	if(init){ // is called only on the first run, so I dont have to create the Surface on each step         pDevice->GetRenderTarget(0,&pRenderTarget);         pRenderTarget->GetDesc(&rtDesc);  	pDevice->CreateOffscreenPlainSurface(rtDesc.Width, rtDesc.Height,rtDesc.Format, D3DPOOL_SYSTEMMEM, &buffers[0], NULL);	pDevice->CreateOffscreenPlainSurface(rtDesc.Width, rtDesc.Height,rtDesc.Format, D3DPOOL_SYSTEMMEM, &buffers[1], NULL);	pDevice->CreateOffscreenPlainSurface(rtDesc.Width, rtDesc.Height,rtDesc.Format, D3DPOOL_SYSTEMMEM, &buffers[2], NULL);	}		pDevice->GetRenderTargetData(pRenderTarget,buffers[n]); 	int prev= 0;	        if(n ==2){		prev = 1;	} else if(n ==1){		prev = 0;	} else if(n==0){		prev = 2;	}	if(buffers[prev] != NULL){		buffers[prev]->LockRect(&rect,0,  D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK);		bits = (unsigned char*)rect.pBits;		buffers[prev]->UnlockRect();	}        n++;        if(n>=3){	    n=0;        }  }

I have read in an other post that i should not lock the actual buffer but the previouse one, so there is more time to transfer the data:

"By locking the buffer used on the previous frame, you give the driver more time to get the data transferred to the system memory copy - when you LockRect() the surface, the driver has to make sure that it's finished with the surface so it can yield it to the CPU. It introduces a frame of lag because you're processing the data from the previous frame, but it should improve performance." http://www.gamedev.net/topic/576721-directx9-depth-buffer-to-memory-fast/

I have read something about "Vertex Buffers". Should I maybe use them ?

Thanks!

Is there something faster then

pDevice->GetRenderTargetData(pRenderTarget,buffer)

Because when using this, my game flickers, not much but you can notice it. When using

pDevice->GetFrontBufferData(0,buffer)

its the same.

And

pDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &buffer)

does not work at all :(


#1sayezz

Posted 17 January 2013 - 05:20 AM

The double/tripper buffer trick didn't helped me. Maybe I'm doing something wrong. Heres what I have so far, does anyone see an error?:

IDirect3DSurface9 *pRenderTarget = NULL;
LPDIRECT3DSURFACE9 buffers[3];
int n = 0;
...
void dumb_buffer(LPDIRECT3DDEVICE9 pDevice){ // is called each frame
	if(init){ // is called only on the first run, so I dont have to create the Surface on each step

         pDevice->GetRenderTarget(0,&pRenderTarget);
         pRenderTarget->GetDesc(&rtDesc);
  
	pDevice->CreateOffscreenPlainSurface(rtDesc.Width, rtDesc.Height,rtDesc.Format, D3DPOOL_SYSTEMMEM, &buffers[0], NULL);
	pDevice->CreateOffscreenPlainSurface(rtDesc.Width, rtDesc.Height,rtDesc.Format, D3DPOOL_SYSTEMMEM, &buffers[1], NULL);
	pDevice->CreateOffscreenPlainSurface(rtDesc.Width, rtDesc.Height,rtDesc.Format, D3DPOOL_SYSTEMMEM, &buffers[2], NULL);
	}
	
	pDevice->GetRenderTargetData(pRenderTarget,buffers[n]); 
	int prev= 0;
	
        if(n ==2){
		prev = 1;
	} else if(n ==1){
		prev = 0;
	} else if(n==0){
		prev = 2;
	}

	if(buffers[prev] != NULL){
		buffers[prev]->LockRect(&rect,0,  D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK);
		bits = (unsigned char*)rect.pBits;
		buffers[prev]->UnlockRect();
	}

        n++;
        if(n>=3){
	    n=0;
        }  
}

I have read in an other post that i should not lock the actual buffer but the previouse one, so there is more time to transfer the data:

 

"By locking the buffer used on the previous frame, you give the driver more time to get the data transferred to the system memory copy - when you LockRect() the surface, the driver has to make sure that it's finished with the surface so it can yield it to the CPU. It introduces a frame of lag because you're processing the data from the previous frame, but it should improve performance." http://www.gamedev.net/topic/576721-directx9-depth-buffer-to-memory-fast/

 

I have read something about "Vertex Buffers". Should I maybe use them ?

 

Thanks!


PARTNERS