Original Post
I'm putting together a small engine just to play around with in Managed DirectX 9 for C# 2005, but this whole concept applies to DX in general. I've made a class dedicated to the output of 2D graphics on the screen such as fonts and shapes. My draw rectangle subroutine is displayed below: What I want to ask is this: This sub can be called once, twice or even three times from the same variable and still render to the screen, except for the fact that everytime it's rendered is sets the position again. I'm concerned about any decrease in framerate or CPU/RAM usage. What happens? Is it wise to do it this way? I'll show a small example of how it's used: So this code will draw 4 rectangles. I would prefer it as the above way instead of: How should I do it?
private CustomVertex.TransformedColored[] vRectangle = new CustomVertex.TransformedColored[5];
public void DrawRectangle(float Left, float Top, float Width, float Height, Color Colour)
{
vRectangle[0].Position = new Vector4(Left, Top, 1.0f, 1.0f); vRectangle[0].Color = Colour.ToArgb();
vRectangle[1].Position = new Vector4(Left + Width, Top, 1.0f, 1.0f); vRectangle[1].Color = Colour.ToArgb();
vRectangle[2].Position = new Vector4(Left + Width, Top + Height, 1.0f, 1.0f); vRectangle[2].Color = Colour.ToArgb();
vRectangle[3].Position = new Vector4(Left, Top + Height, 1.0f, 1.0f); vRectangle[3].Color = Colour.ToArgb();
vRectangle[4].Position = new Vector4(Left, Top, 1.0f, 1.0f); vRectangle[4].Color = Colour.ToArgb();
SWGraphics.D3DDev.VertexFormat = CustomVertex.TransformedColored.Format;
SWGraphics.D3DDev.DrawUserPrimitives(PrimitiveType.LineStrip, 4, vRectangle);
}
public CScreen Screen = null;
Screen.DrawRectangle(Blah Blah);
Screen.DrawRectangle(Blah Blah);
Screen.DrawRectangle(Blah Blah);
Screen.DrawRectangle(Blah Blah);
// This way would mean I can set up the size, colour, etc. before I render,
// possibly increasing framerate? This way is too long though.
public CScreen Screen1 = null;
public CScreen Screen2 = null;
public CScreen Screen3 = null;
public CScreen Screen4 = null;
Screen1.DrawRectangle(Blah Blah);
Screen2.DrawRectangle(Blah Blah);
Screen3.DrawRectangle(Blah Blah);
Screen4.DrawRectangle(Blah Blah);