Jump to content

  • Log In with Google      Sign In   
  • Create Account

X-Shiryu

Member Since 11 Jul 2010
Offline Last Active Aug 21 2013 03:13 PM

#4946827 Help about design a Render Class

Posted by X-Shiryu on 06 June 2012 - 12:17 PM

I did something similiar what you have proposing to do, but at time i had some issues about Text class, because of some specifics attributes and implementations.

Thinking now, i can solve some problems, for example, implementing SetText for preparing data of model object, and passing that object for Video class to render.

Implementing this way, can solve most of problems: dependency, virtual methods, and separated implementation for each type.
Concentrated implementation i think will more easy to make some 'Sprite' (now treated as Model) Batch by texture.

So now i can have class Model like this.
class Model
{
	 private:
		 vector<Position> position; // x y
		  vector<Position> text_cord; // u v
		  vector<Color> color;  
		  Texture* texture;

	 	 //Or make some Vertex class with each of this attributes and create vector<Vertex> object here
}

class Text
{
		private:
		 Model model;
	 	 Font* font; //Font class have pointer for Texture
		 void SetText( String text )
		 {
				//acesssing object model atributes for preparing data to pass to vertex buffer in future,
				//based on each char of text
		 }
	 	
	 	 const Model& GetModel(); //to pass to Video
}
//So in my Video (or Render) class everything will be handled like a model
class Video
{
	 private:
	 	 vector<Model*> models; //Reference of all models objects to be rendered
	 public:
	 	 void AddToDraw(const Model& model) //Or simply call this 'Draw' not 'AddToDraw'
	 	 {
	 	 	 	 this->push_back(model);
		   }
	 	
	 	 //At end of loop i call
	 	 void Render()
	 	 {
	 	 	 //1º >> Calculate the size of Vertex e Index Buffer here(i using one BIG dynamic for both) based on size of Models
	 	 	 //check for current size, if necessary recreate Vertex Buffer and Index Buffer with incresed size - One time by Loop

	 	 	 //2º >> Pass geometry data to Vertex and Index Buffer using Lock in both - One time by Loop
	 	 	 //there is some problem locking both at same time, to iterate over models one time, not two separately for each Buffer?
	 	 	
	 	 	 //3º >> The actual code for rendering models: process matrix, check for texture will be used
	 	 	 //Vertex Buffer position (SetStreamSource) and Vertex Declaration, shader etc...
	 	 	 	 	 	
	 	 	 //Clean Model List for next loop
	 	 }
	
}

int main()
{
	 //Loading model geometry
	 while(AppRun)
	 {
	 	 Video.Draw(model0);
	 	 Video.Draw(model1);
	 	 Video.Draw(model2);
	 	 Video.Draw(model3);

	 	 ....

	 	 video.Render();
	 }
}




PARTNERS