相关疑难解决方法(0)

16位浮点数和GL_HALF_FLOAT

我正在寻找/编写一个16位浮点数的C++实现,用于OpenGL顶点缓冲区(纹理坐标,法线等).这是我目前的要求:

  • 必须是16位(显然).
  • 必须能够使用GL_HALF_FLOAT上传到OpenGL顶点缓冲区.
  • 必须能够表示超过-1.0 - +1.0的数字(否则我只会使用GL_SHORT标准化).
  • 必须能够转换为普通的32位浮点数.
  • 算术运算并不重要 - 我只关心存储.
  • 速度不是主要问题,但正确性是.

这是我到目前为止的接口:

class half
{
public:
    half(void) : data(0) {}
    half(const half& h) : data(h.data) {}
    half(const unsigned short& s) : data(s) {}
    half(const float& f) : data(fromFloat(f)) {}
    half(const double& d) : data(fromDouble(d)) {}

    inline operator const float() { return toFloat(data); }
    inline operator const double() { return toDouble(data); }

    inline const half operator=(const float& rhs) { data = fromFloat(rhs); return *this; }
    inline const half operator=(const double& rhs) …
Run Code Online (Sandbox Code Playgroud)

c++ opengl floating-point

9
推荐指数
1
解决办法
6931
查看次数

标签 统计

c++ ×1

floating-point ×1

opengl ×1