Archived

This topic is now archived and is closed to further replies.

Faster polygon class?

This topic is 4944 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

(Figures the other OpenGL forum got tired of my posts ). This is pretty much just a stripped down version of the polygon class featured on NeHe (minus the parts I couldn''t implement on my own). Is there ANY way I could possibly make this class go faster? I''m at a mere 30 FPS at 16000 two-textured-polygons and well that''s slow (not sure at what the fill rate is though). Here is the source and please even it if requires a radical change I''ll do it ^_^.
extern PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2fARB;
extern PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;

#ifndef POLYGON_H_
#define POLYGON_H_

class CPoly
{
public:
	CPoly(): Vertices(NULL), m_nVertices(0), texles(NULL), details(NULL){}
	void Draw();
	CVector3 *GetVerts();
	int GetVertCount();
	void SetVerts(CVector3 *verts);
	void SetVertCount(int num){m_nVertices=num;}
	CVector3 GetPoint(int j){return Vertices[j];}
	CVector3 Normal;
private:
	CVector3 *Vertices;
	CVector3 *texles;
	CVector3 *details;
	int m_nVertices;
};

void CPoly::SetVerts(CVector3 *verts)
{
	Vertices=verts;
	texles = new CVector3[m_nVertices];
	details = new CVector3[m_nVertices];
	Normal = Cross(Vertices[0]-Vertices[1], Vertices[2]-Vertices[1]);
	Normal = Normalize(Normal);
	if(Normal.y < 0)
		Normal = Normal * -1;
	for(int i=0;i<m_nVertices;i++)
	{
		texles[i].x=verts[i].x/4096.0f;
		texles[i].y=verts[i].z/4096.0f;
		details[i].x=verts[i].x/96;
		details[i].y=verts[i].z/96;
	}
}

CVector3 * CPoly::GetVerts()
{
	return Vertices;
}

int CPoly::GetVertCount()
{
	return m_nVertices;
}
void CPoly::Draw()
{
	int vertices=m_nVertices;
	glBegin(GL_POLYGON);
	while(vertices--)
	{
		glMultiTexCoord2fARB(GL_TEXTURE0_ARB, texles[vertices].x, texles[vertices].y);
		glMultiTexCoord2fARB(GL_TEXTURE1_ARB, details[vertices].x, details[vertices].y);
		glVertex3f(Vertices[vertices].x, Vertices[vertices].y, Vertices[vertices].z);
	}
	glEnd();
}
#endif
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.

Share this post


Link to post
Share on other sites
I''m looking into lesson 45 now, but I have a concern about Lesson 12 in that I hope to be able to use vertex shaders, so doesn''t that pretty much throw that out the window? I''m not sure about 45 though. I ran that program and it runs non-textured polygons at 15 fps (32768 polys). I see no speed boost, but it may be due to something else.

Share this post


Link to post
Share on other sites
This probally wont work since I''m writing of the top of my head but try. I think DrawArrays works better with large amounts of data like 4K triangles in a bunch.


void CPoly::Draw()
{
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2,GL_FLOAT,sizeof(CVector3),&texles[0].x); //I assume x y z are in order in CVector3

glClientActiveTextureARB(GL_TEXTURE1_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2,GL_FLOAT,sizeof(CVector3),&details[0].x);
glVertexPointer(3,GL_FLOAT,sizeof(CVector3),&Vertices[0].x);
glDrawArrays(GL_POLYGON,0,m_nVertices);
}

Share this post


Link to post
Share on other sites
I would just like to say thank you. I am only done implementing half of the suggestions here (namely converting to Lesson 45 map loading et al), and the performance is already up significantly: 32000 multitextured polygons going 40-60FPS.

Share this post


Link to post
Share on other sites
try staying away from polygons. hardware likes triangles and everything else would have to first be turned into triangles. also polygons have the annoying habit that unlike triangles they can easily be screwed up and arent on a simple plane anymore. so i guess theres a reason why even nvidia exsamples use a triangle strips instead of a quad (though i cant imagine the difference will be that huge).

Share this post


Link to post
Share on other sites
i store my data twice once the world data in polygon classes for collision detection and the static render data in system memory
if the gfx hardware supports VBOs i store it there

for models you only need to store the transformation matrices in system memory

@Trienco: i don t use triangles for collision detection since it would be too computitional expensive

Share this post


Link to post
Share on other sites