Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在OpenGL ES顶点数组中使用GL_SHORT代替GL_FLOAT_Iphone_Opengl Es - Fatal编程技术网

Iphone 在OpenGL ES顶点数组中使用GL_SHORT代替GL_FLOAT

Iphone 在OpenGL ES顶点数组中使用GL_SHORT代替GL_FLOAT,iphone,opengl-es,Iphone,Opengl Es,我有一个立方体的顶点数组 float vertex_coordinates [] = { -12.43796, -12.43796, 12.43796, -12.43796, 12.43796, 12.43796, 12.43796, 12.43796, 12.43796, 12.43796, 12.43796, 12.43796, 12.43796, -12.43796, 12.43796, -12.43796, -12.43796, 12.43796, 12.43796, -12.4379

我有一个立方体的顶点数组

float vertex_coordinates [] = {

-12.43796, -12.43796, 12.43796, -12.43796, 12.43796, 12.43796, 12.43796, 12.43796, 12.43796,
12.43796, 12.43796, 12.43796, 12.43796, -12.43796, 12.43796, -12.43796, -12.43796, 12.43796,
12.43796, -12.43796, -12.43796, 12.43796, 12.43796, -12.43796, -12.43796, 12.43796, -12.43796,
-12.43796, 12.43796, -12.43796, -12.43796, -12.43796, -12.43796, 12.43796, -12.43796, -12.43796,
-12.43796, -12.43796, -12.43796, -12.43796, 12.43796, -12.43796, -12.43796, 12.43796, 12.43796,
-12.43796, 12.43796, 12.43796, -12.43796, -12.43796, 12.43796, -12.43796, -12.43796, -12.43796,
12.43796, -12.43796, 12.43796, 12.43796, 12.43796, 12.43796, 12.43796, 12.43796, -12.43796,
12.43796, 12.43796, -12.43796, 12.43796, -12.43796, -12.43796, 12.43796, -12.43796, 12.43796,
-12.43796, 12.43796, 12.43796, -12.43796, 12.43796, -12.43796, 12.43796, 12.43796, -12.43796,
12.43796, 12.43796, -12.43796, 12.43796, 12.43796, 12.43796, -12.43796, 12.43796, 12.43796,
-12.43796, -12.43796, -12.43796, -12.43796, -12.43796, 12.43796, 12.43796, -12.43796, 12.43796,
12.43796, -12.43796, 12.43796, 12.43796, -12.43796, -12.43796, -12.43796, -12.43796, -12.43796,

};
目前,我使用

glVertexPointer(3, GL_FLOAT, 0, vertex__coordinates);

// texture pointer ...

// colour pointer

glDrawArrays(GL_TRIANGLES, 0, size);
如何将顶点数组转换为渲染完全相同的值 多维数据集,但使用
GL_SHORT
作为glVertexPointer的第二个参数,以加速 我的代码?

使用(+-)1代替(+-)12.43796

然后在12.43996的modelview矩阵上应用glScalef操作


然而,我怀疑这会加速你的代码。它所能做的就是将顶点数组减小到其原始大小的一半。

在预处理步骤中,我们计算对象的最小值和最大值,并使用该值在短时间内最大限度地利用精度:

float modelMin[3] = {FLT_MAX, FLT_MAX, FLT_MAX}; //or std::numeric_limits<float>
float modelMax[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX};
for (int i = 0; i < size; ++i) {
    for (int j = 0; j < 3; ++j) {
        const float v = vertex_coordinates[i * 3 + j];
        modelMin[j] = std::min(modelMin[j], v);
        modelMax[j] = std::max(modelMax[j], v);
    }
}

short* short_coordinates = new short[size * 3];
for (int i = 0; i < size; ++i) {
    for (int j = 0; j < 3; ++j) {
        const float src = vertex_coordinates[i * 3 + j];
        short& dst = short_coordinats[i * 3 + j];
        dst = (short)floorf(((src - modelMin[j]) / (modelMax[j] - modelMin[j])) * 65536.0f - 32768.0f + 0.5f);
    }
}
float modelMin[3]={FLT_MAX,FLT_MAX,FLT_MAX}//或标准::数值限制
float modelMax[3]={-FLT_MAX,-FLT_MAX,-FLT_MAX};
对于(int i=0;i
在绘图时,我们执行以下操作:

const float scale[3], bias[3];
for (int i = 0; i < 3; ++i) {
    scale[i] = (modelMax[j] - modelMin[j]) / 65536.0f;
    bias[i] = (32768.0f / 65536.0f) * (modelMax[j] - modelMin[j]) + modelMin[j];
}

glTranslatef(bias[0], bias[1], bias[2]);
glScalef(scale[0], scale[1], scale[2]);
glVertexPointer(3, GL_SHORT, 0, short_coordinates);
glDrawArrays(GL_TRIANGLES, 0, size);
const float scale[3],bias[3];
对于(int i=0;i<3;++i){
比例[i]=(modelMax[j]-modelMin[j])/65536.0f;
偏差[i]=(32768.0f/65536.0f)*(modelMax[j]-modelMin[j])+modelMin[j];
}
GLTRANSTEF(偏差[0],偏差[1],偏差[2]);
glScalef(标度[0],标度[1],标度[2]);
glVertexPointer(3,GL_短,0,短_坐标);
gldrawArray(GL_三角形,0,大小);

/A.B.

谢谢!然而,如果我有多个不同大小的立方体(例如+-6),我将如何应用这种逻辑?在iPhone上,顶点数组大小的减小会显著提高性能。从浮动切换到短裤本身将渲染性能提高了30%。Dimitris,要将其应用于各种情况,只需将浮点值规范化为+-32767。找到任何顶点坐标的最大绝对值,然后将所有顶点值乘以32767除以该值。然后,您可以调整模型视图或投影矩阵以匹配新的缩放尺寸。Brad的建议有效,但前提是您的模型大致以(0,0,0)为中心。如果不是的话,你需要一个常规的刻度和偏差。