I rolled in to the forums just to ask few questions - greetz all BTW.
Let's say, i got the STL list of something like this:
class blit
{
GLuint tex_id; // or, list_id if it would be faster
float x; //x position of texture wanted output place
float y; //y position of texture wanted output place
float w; //width
float h; //height
float dir; //direction rotated around z-axis
}
My render function creates such list, and I want a wrapper func to run through the list and draw all "blit" elements AFAP;
conditions are:
1. Textures of same type must be drawn in order;
2. Types of textures must be drawn in order
(so, I output all textures with tex_id equal to list.front().tex_id, and erase them from the list, then pop the front element, and do the same for each of tex_id's in the list)
What I need:
void StartDrawingSequence(); // function called before the "blitting block"
void StartDrawingTexture(GLuint tex); // function called once for each unique tex_id in the list
void OutputTexture(float x, y, w, h, dir); // blits at [x,y] texture set by last called StartDrawingTexture
//sized [w,h] and rotated z-axis around its centre by dir degrees
void EndDrawingSequence();//After drawing all of the blit elements we can do some cleanup to go back
//to the state the app was before StartDrawingSequence call.
I kwow how to do it to just make it work, but FPS drops down by half if i draw more than 15 blit objects (even if they are same tex_id and even if I compile some parts of sequence and use glCallList...)
I tried many many variants but it gets me nowhere - ogl_technique_demo from nehe site runs at 73fps with any settings while even simple 2D textures make my app fall below 40fps.
Questions are:
1. What shall i put in those functions to make them optimal?
2. What may make my code slower than 3D apps of other people?
3. Is this the best possible aproach to the 2D render - (texture-grouped draw-list)?
I'll try to put my code here just for comparision right after I'll strip all of non-OGL specific data.
#include <list>
class EBlit
{
public:
unsigned int tex_id;
float x;
float y;
float w;
float h;
float dir;
EBlit(unsigned int _id,float _x,float _y,float _w,float _h,float _dir);
};
std::list<EBlit> EList;
void EDrawList()
{
std::list<EBlit>::iterator it1;
unsigned int t_id;
//StartDrawingSequence part
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glColor4f(1,1,1,1);
//~StartDrawingSequence part
for ( it1=EList.begin() ; it1 != EList.end(); it1=EList.begin() )
{
t_id= (*it1).tex_id;
//StartDrawingTexture part
glBindTexture(GL_TEXTURE_2D,t_id);
//~StartDrawingTexture part
for(;it1!=EList.end();)
{
if((*it1).tex_id != t_id){it1++;continue;}
//OutputTexture part
glPushMatrix();
glTranslatef((*it1).x,(*it1).y,0);
glRotatef((*it1).dir,0,0,1);
glBegin(GL_QUADS);
glTexCoord2f(1.0f,1.0f); glVertex2f((*it1).w,-(*it1).h);
glTexCoord2f(0.0f,1.0f); glVertex2f(-(*it1).w,-(*it1).h);
glTexCoord2f(0.0f,0.0f); glVertex2f(-(*it1).w,(*it1).h);
glTexCoord2f(1.0f,0.0f); glVertex2f((*it1).w,(*it1).h);
glEnd();
glPopMatrix();
//~OutputTexture part
it1=EList.erase(it1);
}
}
//EndDrawingSequence part
glDisable(GL_TEXTURE_2D);
//~EndDrawingSequence part
return;
}
[Edited by - YanPL on March 22, 2008 9:45:48 AM]