Mem2Sprite Speed.

Previous topic - Next topic

ByteByter

So why is Mem2Sprite slower than the function setpixel?
I would think that changing the values while in an array and then copying the array to the output buffer(I'm assuming this is how mem2sprite works...kind of similar to the win api function setdibits) would be faster then setpixel.(not sure what method setpixel uses...just in every basic language I have ever used setpixel is almost always the slowest method of graphics output I know.)
Code (glbasic) Select

GLOBAL Rnum#
DIM sprArray%[640*480]
//SetPixel Method
Regen:
IF KEY(16) THEN END

FOR I=0 TO (640*480)-1
Rnum#=RND(100)
IF Rnum#=2 THEN SETPIXEL RND(640),RND(480),RGB(255,255,255)
NEXT
PRINT "SetPixel Method",0,0
SHOWSCREEN
IF KEY(30) THEN GOTO RegenB
GOTO Regen
//Mem2Sprite Method
RegenB:
REDIM sprArray%[640*480]
IF KEY(16) THEN END
   FOR I=0 TO (640*480)-1
      Rnum#=RND(100)
      IF Rnum#=2 THEN sprArray%[I]=INTEGER(0xffffffff)
      NEXT
MEM2SPRITE(sprArray%[],0,640,480)
DRAWSPRITE 0,0,0
PRINT "Mem2Sprite Method",0,0
SHOWSCREEN
REDIM sprArray%[0] //fastest way to reset everything back to 0
IF KEY(30) THEN GOTO Regen
GOTO RegenB


...although it's not much faster it is quiet obvious even without writing an fps counter setpixel pulls off a few more fps.

Kitty Hello

you're comparing apples to pears (there's a better English expression for that I guess).
You're uploading < 1024x512 texture (must be power of 2) to the graphics card -> you have to time that against:
Code (glbasic) Select

FOR x=0 TO 640
FOR y=0 TO 480
SETPIXEL x,y,z
NEXT;NEXT


then MEM2SPRITE is faster. For 2x2 pixels, SETPIXEL might be faster.

ByteByter

Yes It is indeed much faster at redrawing the entire surface using mem2sprite.
average of 125/1000th(8 fps) of a second in between calls at a resolution of  1024x512. :good:
Where as SetPixel was 6.7 seconds(.14 fps) on average to redraw the entire surface.
...My bad. :(