Which way to fill grid renderer with right data?

Started by
-1 comments, last by Waterlimon 11 years, 3 months ago
I have 2 classes, a grid renderer that needs lets say texture data for each tile in a grid to render it, and a class that owns such a grid renderer and needs to provide that data.

Which way is the [absolutely best in all contexts] - way to go about passing the data:
1. Grid renderer creates an empty grid with verticies
*I need to either initialize the vertices to an acceptable state in case data is not provided for each vertex by the filler class, or somehow check that data for all vertices has been provided before sending to GPU
eg.
//in filler class
GridRenderer.TellWhatTileLooksLike(x,y,texture);

2.Grid renderer takes in a lambda which it calls for each vertex/cell/whatever
*All data is guaranteed to be filled, and as such i dont need to initialize them to 0/some other acceptable state, nor do i need to check that all data has been filled.
eg.
//In filler class
GridRenderer<[](x,y){return GetTileTexture(x,y);}> renderer;

3.Unknown way


If the answer is 2, what would be the answer if we DIDNT have lambdas?


Additional question:
How do i tell the filler class what parameters/return value the lambda needs? Is there syntax to specify that in the template thing?
EDIT: Should i use std::function here? EDIT2: yep std::function seems to work. Imagine all of this additional question and these edits have that line over them (what was it called?), indicating you should ignore this last question, as i dont want to use full editor because it eats all the spacing and this non-full editor doesnt have much text formatting features...

o3o

This topic is closed to new replies.

Advertisement