C++ 从.dae加载顶点会使我的程序变慢,为什么?

C++ 从.dae加载顶点会使我的程序变慢,为什么?,c++,parsing,opengl,collada,C++,Parsing,Opengl,Collada,我已经编写了一系列函数来加载collada(.dae)文档,但问题是opengl glut(控制台)窗口对键盘响应响应缓慢,我只使用了string.h、stdlib.h和fstream.h,当然还有gl/glut.h。我的程序的主要功能有: Void LoadModel() { COLLADA ca; double digits[3]; ca.OpenFile(char fname); ca.EnterLibGeo();// get the position of <library_geo

我已经编写了一系列函数来加载collada(.dae)文档,但问题是opengl glut(控制台)窗口对键盘响应响应缓慢,我只使用了string.h、stdlib.h和fstream.h,当然还有gl/glut.h。我的程序的主要功能有:

Void LoadModel()
{
COLLADA ca;
double digits[3];
ca.OpenFile(char fname);
ca.EnterLibGeo();// get the position of <library_geometries>
ca.GetFloats();// search for the <float_array> from start to end, and saves thier position in the file
ca.GetAtrributes("count", char Attrib); //same as collada dom's function but its mine
Int run=atoi(Attrib); // to convert the attributes of count which is string in the file to integer
glBegin(GL_TRIANGLES);
for (int i=0;i<=run;i++)
{
MakeFloats(digits); // will convert string digits to floating point values, this function uses the starting position and ending position which GetFloats() stored in variables
glVertex3f(digits[0], digits[1], digitd[2]);
}
glEnd();
glFlush();
}
Void LoadModel()
{
羽衣甘蓝;
两位数[3];
ca.OpenFile(char-fname);
ca.EnterLibGeo();//获取
ca.GetFloats();//从头到尾搜索,并将其保存在文件中的位置
ca.getatributes(“count”,char Attrib);//与collada dom的函数相同,但它是我的
Int run=atoi(Attrib);//将文件中的字符串count的属性转换为整数
glBegin(GL_三角形);

对于(int i=0;i磁盘IO相对较慢,很可能是您看到的较慢。您应该尝试从绘图功能中删除任何不必要的工作。仅在启动时加载文件一次,然后将数据保存在内存中。如果您根据按键加载不同的文件,则可以提前加载所有文件,或者根据需要加载一次。

磁盘IO i它相对较慢,很可能是您看到的较慢。您应该尝试从绘图功能中删除任何不必要的工作。只在启动时加载文件一次,然后将数据保存在内存中。如果您根据按键加载不同的文件,则可以预先加载所有文件,或者根据需要加载一次。

您正在读取文件eac每次渲染网格时结束;不要这样做

相反,只需读取一次文件并将模型保存在内存中(可能需要进行一些预处理以简化渲染)

基于示例加载网格的VBO方法是:

COLLADA ca;
double digits[3];
ca.OpenFile(char fname);
ca.EnterLibGeo();// get the position of <library_geometries>
ca.GetFloats();// search for the <float_array> from start to end, and saves thier position in the file
ca.GetAtrributes("count", char Attrib); //same as collada dom's function but its mine
Int run=atoi(Attrib); // to convert the attributes of count which is string in the file to integer

int vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, run*3*sizeof(float), 0, GL_STATIC_DRAW);
do{
    void* ptr = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
    for (int i=0;i<=run;i++)
    {
        MakeFloats(digits); // will convert string digits to floating point values, this function uses the starting position and ending position which GetFloats() stored in variables
        memcpy(ptr+i*3*sizeof(float), digits, 3*sizeof(float));
    }
}while(!glUnmapBuffer(GL_ARRAY_BUFFER));//if buffer got corrupted then remap and do again
COLLADA-ca;
两位数[3];
ca.OpenFile(char-fname);
ca.EnterLibGeo();//获取
ca.GetFloats();//从头到尾搜索,并将其保存在文件中的位置
ca.getatributes(“count”,char Attrib);//与collada dom的函数相同,但它是我的
Int run=atoi(Attrib);//将文件中的字符串count的属性转换为整数
国际vbo;
glGenBuffers(1,&vbo);
glBindBuffer(GL_数组_BUFFER,vbo);
glBufferData(GL_数组_缓冲区,运行*3*sizeof(浮点),0,GL_静态_绘制);
做{
void*ptr=glMapBuffer(GL\u数组\u缓冲区,仅GL\u写区);

对于(int i=0;i,每次渲染网格时,您都在读取文件的每一端;不要这样做

相反,只需读取一次文件并将模型保存在内存中(可能需要进行一些预处理以简化渲染)

基于示例加载网格的VBO方法是:

COLLADA ca;
double digits[3];
ca.OpenFile(char fname);
ca.EnterLibGeo();// get the position of <library_geometries>
ca.GetFloats();// search for the <float_array> from start to end, and saves thier position in the file
ca.GetAtrributes("count", char Attrib); //same as collada dom's function but its mine
Int run=atoi(Attrib); // to convert the attributes of count which is string in the file to integer

int vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, run*3*sizeof(float), 0, GL_STATIC_DRAW);
do{
    void* ptr = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
    for (int i=0;i<=run;i++)
    {
        MakeFloats(digits); // will convert string digits to floating point values, this function uses the starting position and ending position which GetFloats() stored in variables
        memcpy(ptr+i*3*sizeof(float), digits, 3*sizeof(float));
    }
}while(!glUnmapBuffer(GL_ARRAY_BUFFER));//if buffer got corrupted then remap and do again
COLLADA-ca;
两位数[3];
ca.OpenFile(char-fname);
ca.EnterLibGeo();//获取
ca.GetFloats();//从头到尾搜索,并将其保存在文件中的位置
ca.getatributes(“count”,char Attrib);//与collada dom的函数相同,但它是我的
Int run=atoi(Attrib);//将文件中的字符串count的属性转换为整数
国际vbo;
glGenBuffers(1,&vbo);
glBindBuffer(GL_数组_BUFFER,vbo);
glBufferData(GL_数组_缓冲区,运行*3*sizeof(浮点),0,GL_静态_绘制);
做{
void*ptr=glMapBuffer(GL\u数组\u缓冲区,仅GL\u写区);

对于(int i=0;i我该怎么做?我试着这样做:我使用了一个全局int变量来计算函数运行次数,并放入了一个if函数,但这会导致模型无法旋转,有什么解决方案吗?我该怎么做?我试着这样做:我使用了一个全局int变量来计算函数运行次数,并放入了一个if函数,但这会导致模型无法旋转旋转,任何解决方案??谢谢棘轮,石头金属,我认为这应该帮助我,我知道,但不知道如何防止它,谢谢!!谢谢棘轮,石头金属,我认为这应该帮助我,我知道,但不知道如何防止它,谢谢!!