Drawing a large number of individual pixels per frame

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
kefka
Prole
Posts: 9
Joined: Thu Feb 17, 2011 3:34 am

Drawing a large number of individual pixels per frame

Post by kefka »

Hey guys,

I'm currently working on implementing some procedural cave generation systems in Love2D. The map is being represented by a 256x256 array of tiles -- that is, 65000 number values cooresponding to tile types. In a game setting, theres no way I'd be drawing all of these tiles on the screen at once. But just for fun, lets say I want to draw a representation of this entire map (65000 tiles) every frame, in a simple way, like one colored pixel per tile.

I've been digging through the API trying to find the optimal way to solve this problem. My first attempt was the most primitive, which I knew would likely be worst case, but I still wanted to see the performance: calling love.graphics.point() for each tile. The result is about 15fps on my machine. Next, I tried calling love.graphics.point() on an offscreen buffer, then drawing that each frame. The results were better, but still only about 20fps.

So far its looking like to me like the best way to go about doing this would be maintaining an ImageData object and calling setPixel when i want to update a tile coordinate?

Thoughts?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Drawing a large number of individual pixels per frame

Post by kikito »

Framebuffers.

If you want to be fancy, you could have framebuffers at different "zoom levels", and interchange them - like google maps does, changing to different resolution images when you zoom out.
When I write def I mean function.
kefka
Prole
Posts: 9
Joined: Thu Feb 17, 2011 3:34 am

Re: Drawing a large number of individual pixels per frame

Post by kefka »

Like i said, tried using a framebuffer, but I still think the overhead is with the large number of love.graphics.point() calls. It barely improved my performance. Haven't tried manipulating ImageData directly, but will do that tomorrow.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Drawing a large number of individual pixels per frame

Post by kikito »

Are you generating the framebuffer on every frame, by any chance?
When I write def I mean function.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Drawing a large number of individual pixels per frame

Post by T-Bone »

Probably, drawing on a framebuffer once and then drawing just that framebuffer should be running at 60 fps even on a crappy computer, even if the framebuffer is quite large.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Drawing a large number of individual pixels per frame

Post by Taehl »

As others have said, make sure you're only creating your framebuffer once.

An alternate (probably faster and more compatible) method would be to render your map as a simple image. You could use something like:

Code: Select all

function makeMap( x, y )
	-- Replace the condition with whatever you use to know if a tile is there or not
	-- You could even have different colors for different tile types, etc.
	if map[x] and map[x][y] then return 255,255,255,255		-- Tiles are white
	else return 0,0,0,255		-- Empty space is black
	end
end

gameMap = love.image.newImageData(256, 256)
gameMap:mapPixel( makeMap )
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: Drawing a large number of individual pixels per frame

Post by kraftman »

How big are your tiles? Depending on how often you would need to redraw the image, the imagedata solution could be better, since not all computers support framebuffers.
User avatar
trookat
Prole
Posts: 18
Joined: Sun Nov 14, 2010 12:32 pm
Location: Western Australia
Contact:

Re: Drawing a large number of individual pixels per frame

Post by trookat »

i use love.graphics.rectangle to draw dummy tiles it seems to scale well
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Drawing a large number of individual pixels per frame

Post by tentus »

I've had really good luck using love.graphics.newImageData in Kurosuke, I heartily recommend it: I don't think there's a single computer on the forums that doesn't support it (unlike framebuffers). In Kurosuke I draw chunks of terrain to PO2 imageData, and after that it runs quite speedily (about 300FPS on my crappy Intel 82945G).
Kurosuke needs beta testers
kefka
Prole
Posts: 9
Joined: Thu Feb 17, 2011 3:34 am

Re: Drawing a large number of individual pixels per frame

Post by kefka »

kikito wrote:Are you generating the framebuffer on every frame, by any chance?
I am, because I'm looking for a solution where I can dynamically display the map. However I suppose what I can do is only call newPoint on the framebuffer when a tile's data changes.

Thanks for all the suggestions, I will profile this method against the ImageData method and post my results.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 12 guests