Jump to content
  • Advertisement
Sign in to follow this  
The_Nerd

OpenGL Surious speed decrese when I apply material

This topic is 5401 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I call this function before (and when) drawing my objects in OpenGL, my FPS drops by about 330! WOW! Help!
list<Ner3DMaterialLayer *>::iterator VID_ApplyMaterial(list<Ner3DMaterialLayer *>::iterator BeginItr, list<Ner3DMaterialLayer *>::iterator EndItr, uint16 *uipCount)
{
	list<Ner3DMaterialLayer *>::iterator TempItr;
	list<Ner3DBlendMode>::iterator BlendItr, BEndItr;
	
	(*uipCount)=0;
	if (BeginItr==NULL||BeginItr==EndItr) return NULL;
	for (;BeginItr!=EndItr;BeginItr++)
	{
		++(*uipCount);
		glActiveTextureARB(GL_TEXTURE0_ARB+((*uipCount)-1));
		glEnable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
    	VID_BindGLTexture((*BeginItr)->Texture->iGLIndex);
		
		glBlendFunc((*BeginItr)->BlendSFactor, (*BeginItr)->BlendDFactor);
		
		glMatrixMode(GL_TEXTURE);
		glLoadIdentity();
		glTranslatef(0.5, 0.5, 0.5);
		if ((*BeginItr)->Trans.Scale) 
		{
		      (*BeginItr)->Trans.Scale->fCurrent[1]);
			glScalef((*BeginItr)->Trans.Scale->fCurrent[0],(*BeginItr)->Trans.Scale->fCurrent[1],(*BeginItr)->Trans.Scale->fCurrent[2]); 
		}
		if ((*BeginItr)->Trans.Rotate)
		{
			glRotatef((*BeginItr)->Trans.Rotate->fCurrent[0], 1, 0, 0);
			glRotatef((*BeginItr)->Trans.Rotate->fCurrent[1], 0, 1, 0);
			glRotatef((*BeginItr)->Trans.Rotate->fCurrent[2], 0, 0, 1);
		}
		glTranslatef(-0.5, -0.5, -0.5); 
		if (((*BeginItr)->Trans.Offset&&(*BeginItr)->Trans.Offset->uiSize>=3&&(*BeginItr)->Trans.Offset->fCurrent)) 
			glTranslatef((*BeginItr)->Trans.Offset->fCurrent[0],(*BeginItr)->Trans.Offset->fCurrent[1],(*BeginItr)->Trans.Offset->fCurrent[2]);
		glMatrixMode(GL_MODELVIEW);
		if ((*BeginItr)->Trans.Color[0])
			glColor4f((*BeginItr)->Trans.Color[0]->fCurrent[0], (*BeginItr)->Trans.Color[0]->fCurrent[1], (*BeginItr)->Trans.Color[0]->fCurrent[2], (*BeginItr)->Trans.Color[0]->fCurrent[3]);
		
		if ((*BeginItr)->Blending.size() > 0)
		{
			for (BlendItr=(*BeginItr)->Blending.begin(), BEndItr=(*BeginItr)->Blending.end();BlendItr!=BEndItr;BlendItr++)
				glTexEnvi((*BlendItr).target, (*BlendItr).pname, (*BlendItr).param);
		}
		else
			glDisable(GL_BLEND);
		
		TempItr=BeginItr;
		++TempItr;
		if (TempItr==EndItr) return NULL;
		if ((*TempItr)->Trans.Color[0]) return TempItr;				
	}
return NULL;
}
/*------------------------------------------------------------------------------------------------------------------*/
I am not t guru at OpenGL or nothing...

Share this post


Link to post
Share on other sites
Advertisement
What was the original FPS and what is the FPS when it dropped down. If it was from 1200 to 900, don't worry bout it at all.

I find it hard to follow your code, dont understand some parts of it, or why you are doing how you are doing it. But you can try putting state changes (if they dont change) into a display list and then calling that list.

Share this post


Link to post
Share on other sites
330fps aoint helpful. 33percent is but anyways.
youre doing a lot of state changes in that function (which are quite expensive)
try to minimize them eg
A/ do u need to eanble blending for EACH material (not to mention turning on blending for a material that doesnt need it is gonna hurt as well)
B/ do u need to set texturematrix with each material?
C/ sort your materials in order, weight shaders/textures changes the heaviest.
D/ dont set a state if the current state is already it
eg use
if (currenttextureunit0 != housetextureID )
bind housetextureID

not
bind housetextureID (regardless of what is the current texture)

Share this post


Link to post
Share on other sites
alright. I'll try that zedzeek.

nts: My origional FPS is about 460, then when I draw allot of quads with the material applied it drops to about 90. That isn't good enough for me!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!