使用GLfixed替代GLint、GLfloat替代float是否具备合理性?
Let’s unpack your questions one by one—this is a great dive into OpenGL’s legacy type system!
What’s the point of GLfixed if it’s just defined as GLint?
You’re right that GLfixed is a typedef for GLint, but the key difference is semantics, not storage size. Back in the early days of OpenGL (and especially in embedded OpenGL ES 1.x), many GPUs didn’t have hardware support for floating-point operations. To get around this, GLfixed was designed as a 16.16 fixed-point number:
- The upper 16 bits represent the integer part of the number
- The lower 16 bits represent the fractional part (scaled by 65536, since 2^16 = 65536)
For example:
0x10000as aGLfixedequals 1.0 (integer 1, fractional 0)0x00001as aGLfixedequals ~0.00001526 (1/65536)- A
GLintwith value1is just the integer 1, with no fractional context
So even though it’s the same underlying type, GLfixed signals that you’re working with fixed-point arithmetic, which had dedicated OpenGL functions (like glVertex3x for fixed-point vertices) to handle the scaling correctly. Modern GPUs have excellent floating-point support, so GLfixed is mostly a legacy type now, but it’s still around for backward compatibility.
What about GLfloat in OpenGL?
GLfloat is indeed a typedef for the standard C float (almost always 4 bytes on modern systems). It’s the go-to type for most OpenGL operations today because:
- Modern GPUs have hardware-accelerated floating-point units (FPUs) that handle these efficiently
- It offers more precision and flexibility than fixed-point for complex calculations (like lighting, transformations, and texture sampling)
- All modern OpenGL core profiles prioritize floating-point types, with fixed-point functions being deprecated or removed
You mentioned thinking it’s a "constant with certain features"—I think you’re picking up on the fact that GLfloat is a standardized type across platforms, unlike C’s int which varies by CPU architecture. OpenGL defines types like GLint, GLfloat, and GLfixed to ensure consistent behavior no matter what CPU/GPU you’re targeting.
内容的提问来源于stack exchange,提问作者anon

