Displaying Graphics a line by line Preview
While checking out Steve's latest ray tracer, I started thinking about the preview mode. Which display the ray traced image scan line by scan line. In the ray tracer this drawn to an off screen FX image, which is then drawn to the display at the end of each scanline. Which involves drawing the FX image to the screen and syncing the display. . But if we draw the fx image we're actually copying all the pixel data to the output every scanline. This impacts the rendering performance; what we could do is just draw the line from the image to the screen. We're still syncing but we're not copying the data every row.
[pbcode]
width=1400
height=700
openscreen width,height,32,1
screen = newfximage(Width,height)
global Colour
TestCount=3
t=timer()
For lp=1 to TestCount
Preview1(Screen,Width,height)
next
t1=timer()-t
t=timer()
For lp=1 to TestCount
Preview2(Screen,Width,height)
next
t2=timer()-t
cls
print t1
print t2
sync
waitkey
Function Preview1(Screen,Width,height)
For ylp=0 to height-1
rendertoimage Screen
lockbuffer
ThisRGB=Point(0,0)
for xlp=0 to width-1
fastdot xlp,ylp,colour
colour+=Xlp
next
unlockbuffer
rendertoscreen
drawimage Screen,0,0,false
sync
next
EndFunction
Function Preview2(Screen,Width,height)
For ylp=0 to height-1
rendertoimage Screen
lockbuffer
ThisRGB=Point(0,0)
for xlp=0 to width-1
fastdot xlp,ylp,colour
colour+=Xlp
next
unlockbuffer
rendertoscreen
ScreenViewport 0,ylp,Width,ylp+1
drawimage Screen,0,0,false
sync
next
ScreenViewport 0,0,Width,height
EndFunction
[/pbcode]
Links:
https://PlayBASIC.com (https://playbasic.com)