Writepixelfast....way to slow

BlitzPlus Forums/BlitzPlus Programming/Writepixelfast....way to slow

Actually, if you use an array the FPS is almost as fast as when you take UpdateBank() out of the loop.

; fast bank to backbuffer refresh 
; by skidracer 

Const DWIDTH=800 
Const DHEIGHT=600 

Global tick 

Graphics DWIDTH,DHEIGHT,32 

Dim image(DWIDTH,DHEIGHT) 

While Not KeyHit(1) 
	; calc fps 
	fcount=(fcount+1) 
	If fcount=20 
		t=MilliSecs() 
		fps#=20000.0/(t-ftime) 
		ftime=t 
		fcount=0 
	EndIf 
	; update screen 
	UpdateArray() 
	CopyArrayToBuffer(BackBuffer()) 
	Text 0,0,"fps="+fps 
	Flip 
Wend 

End 

Function CopyArrayToBuffer(buffer) 
	; lock the image for byte transfer 
	LockBuffer buffer 
	; test locked imagebuffer is 32 bits per pixel 
	If LockedFormat(buffer)<>4 
		UnlockBuffer buffer 
		Notify("this test is 32 bit display mode only") 
		End 
	EndIf 
	; cache buffer variables 
	imagebank=LockedPixels(buffer) 
	pitch=LockedPitch(buffer) 
	; copy bank to image line by line 
	
	For y=0 To DHEIGHT-1 
		yoff=y*pitch 
		For x=0 To DWIDTH-1 
			PokeInt imagebank,yoff+(x*4),image(x,y) 
		Next 
	Next 
	
	UnlockBuffer buffer 
End Function 

Function UpdateArray() 
	argb=tick 
	tick=tick+1 
	For y=0 To DHEIGHT-1 
		For x=0 To DWIDTH-1 
			argb=x+y+argb 
			image(x,y)=argb 
		Next 
	Next 
End Function