I have a GameStateNode, and this have 2 GameState as child, Well…
This childrens create a same and new BlendState instance for each one, This not appear be a good implementation because really this use the SAME equation, and i dont need create two diferents instances.
Then, i try fix this, instancing the BlendState object in the GameStateNode, using this code:
Then, i try fix this, instancing the BlendState object in the GameStateNode, using this code...
For starters, you are not instancing anything with this code. You are simply assigning a reference which will make them share the same renderstate object. There is nothing inherently wrong with this, just be aware that children inherit renderstates from their parents so if you just want the child nodes to use the same renderstate you can just leave it in the parent.
The null pointer exception is most likely due to gs being null. Perhaps getChild("parentuState") is not returning your gamestate. Is the name spelled correctly?
.... just be aware that children inherit renderstates from their parents so if you just want the child nodes to use the same renderstate you can just leave it in the parent.
....
Great, that basically solved my problem. I was passing the blendstate to all the children and found it very "dirty". Now I just set it once and that's that. Not sure how I managed to overlook that in the first place :)
However, I still have 2 or maybe 3 other blendstates that are most likely are going to be configured the same, so I guess my original question stays the same;
Is there any point why I should always use the same blendstate as much as possible or is it OK if I create a new blendstate for some part of the code (e.g. the GUI) if that means I have a better structured program? Where would you draw the line? e.g. 5 blendstates is fine, 100 is (obviously) too much?