GPWiki.org
GPWiki.org
It is currently Sat May 25, 2013 7:50 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Wed Jan 25, 2012 1:26 pm 
Funky Monkey

Joined: Thu Sep 09, 2004 1:17 pm
Posts: 1553
Location: burrowed
I currently have my rendering set up like this

Code:
class Model
{
      public void Render()
      {
// Scale, Rotation and Position are
         Matrix m = Matrix.Scale(Scale) *
            Matrix.RotationX(Rotation.X * Calc.Rad) *
            Matrix.RotationY(Rotation.Y * Calc.Rad) *
            Matrix.RotationZ(Rotation.Z * Calc.Rad) *
             Matrix.Translation(Position.X, Position.Y, Position.Z) * RotationMatrix;

// Push the matrix onto the stack - not using the GL Matrix stack
         Game.CurrentScene.PushMatrix(ref m);
         
         if(Texture != null)
            shader.Set("texture", Texture);

// Uploads all uniforms and projection/view matrices
         shader.Begin();


// Only upload texture data when it is given
         if (texcrdBufferId > 0)
         {
            GL.BindBuffer(BufferTarget.ArrayBuffer, texcrdBufferId);
            int tloc = GL.GetAttribLocation(shader.program, "TexCoord");
            GL.EnableVertexAttribArray(tloc);
            GL.VertexAttribPointer(tloc, 2, VertexAttribPointerType.Float, false, 0, 0);
         }

         GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBufferId);
         int vloc = GL.GetAttribLocation(shader.program, "Vertex");
         GL.EnableVertexAttribArray(vloc);
         GL.VertexAttribPointer(vloc, 3, VertexAttribPointerType.Float, false, 0, 0);
         
         if (normalBufferId > 0)
         {
            GL.BindBuffer(BufferTarget.ArrayBuffer, normalBufferId);
            int nloc = GL.GetAttribLocation(shader.program, "Normal");
            GL.EnableVertexAttribArray(nloc);
            GL.VertexAttribPointer(nloc, 3, VertexAttribPointerType.Float, false, 0, 0);
         }

         if (colorBufferId > 0)
         {
            GL.BindBuffer(BufferTarget.ArrayBuffer, colorBufferId);
            int cloc = GL.GetAttribLocation(shader.program, "Color");
            GL.EnableVertexAttribArray(cloc);
            GL.VertexAttribPointer(cloc, 4, VertexAttribPointerType.Float, false, 0, 0);
         }

         GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBufferId);
         GL.DrawElements(BeginMode.Triangles, indices.Length, DrawElementsType.UnsignedInt, IntPtr.Zero);

         shader.End();
         Game.CurrentScene.PopMatrix();
      }
}


So basically every geometry i have is an instance of the model class, which is basically a vbo plus some usability methods.
If i am to draw say 1000 quads (if each being an instance of the same model with render called 1000 times), this Render method is executed every time. I see there is a lot of possible redundancy going on, but i'm not quite sure how to solve this problem, maybe with some kind of batch drawing.

The problems i have most with are the matrices/the stack, since they are different for each and every object.

What i read at another place was for particle systems it would be handy to store them all in one VBO, meaning storing all positions as attributes aswell, and have them dynamic or stream.
So what i take from this i could push more geometry into the vbo as i need it. but removing them accurately again would be quite a terrible act, and since i haven't worked in that regard with vbo's yet i can't say if that would even work.

Long story short, the problems are handling geometry and the corresponding information data (positioning/orientation/shaderdata) not for single instances but for mass drawing.

_________________
Long pork is people!

wzl's burrow


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group