Jump to content
  • Advertisement

Archived

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

uber_n00b

Faster polygon class?

This topic is 5314 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
Advertisement
i believe thats vertex buffer...

edit: or vertex buffer object if you please

[edited by - Ademan555 on May 29, 2004 5:02:29 PM]

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
A piece of crap Geforce FX go5100 (32MB VRAM) My point wasn''t the FPS but rather the FPS relative to my program (16000 multitextured poly''s at 32 FPS)

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

  • 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!