我试图理解使用之间的区别GL_INT_2_10_10_10_REV
对于我的数据的正常情况 V.S.GLbyte
。目前我正在将法线加载到glm::vec4
我这样包装它:
int32_t floatToSignedNormalizedByte(float x, float y, float z, float w)
{
int32_t result = 0;
const int16_t maxValue = static_cast<int16_t>(std::numeric_limits<int8_t>::max());
const int16_t negativeValueScale = maxValue + 1;
result |= static_cast<int8_t>(x < 0 ? x * negativeValueScale : x * maxValue);
result |= static_cast<int8_t>(y < 0 ? y * negativeValueScale : y * maxValue) << 8;
result |= static_cast<int8_t>(z < 0 ? z * negativeValueScale : z * maxValue) << 16;
result |= static_cast<int8_t>(w < 0 ? w * negativeValueScale : w * maxValue) << 24;
return result;
}
正常情况下,我会调用:
//Location, component count, type, normalized, stride, offset
glVertexAttribPointer(location, 4, GL_BYTE, true, format.getVertexSize(), format.getFieldOffset(field, dataBasePtr));
我的问题是,考虑到我平常的包装方式,我应该使用GL_INT_2_10_10_10_REV
作为我的类型(替换 GL_BYTE)?我理解使用GL_INT_2_10_10_10_REV
意味着每个组件获得 10 位而不是 8 位,这很好,因为我实际上只需要 xyz 组件。哪一个更好,为什么?如果我使用GL_INT_2_10_10_10_REV
,我猜组件数仍然是 4?