2

我不清楚在创建 NSOpenGLPixelFormat 时为 NSOpenGLPFAColorSize 设置什么值。从文档中可以看出:

值是一个非负缓冲区大小规范。首选与指定大小最接近的颜色缓冲区。如果未指定,OpenGL 会选择与屏幕匹配的颜色大小。

但这是否意味着每个像素的位数?还是每个组件的位数?例如,如果将其设置为 24 并解释为每像素位数,则这意味着每种 RGBA 颜色的每个分量都有 6 位,整个 RGBA 像素总共有 24 位。

但是,如果将其解释为每个分量的位数,那么这将意味着每个红色、绿色、蓝色和 alpha 分量都有 24 位,以构成 96 位 RGBA 像素。

我倾向于认为这意味着每个组件的位数,因为我在示例代码中看到的值范围为 8、16、24、32 ,当解释为每个组件的位数时,除了 24 之外的所有值都是有意义的。最好有一些明确的答案。

注意:经过编辑以反映 OpenGL 中的像素是 RGBA 而不是 RGB。

4

1 回答 1

3

After scouring the documentation further I came across the NSOpenGLPFAColorFloat attribute, which according to the documentation:

A Boolean attribute. If present, this attribute indicates that only renderers that are capable using buffers storing floating point pixels are considered. This should be accompanied by a NSOpenGLPFAColorSize of 64 (for half float pixel components) or 128 (for full float pixel components). Note, not all hardware supports floating point color buffers thus the returned pixel format could be NULL.

With that additional information it must mean bits per pixel.

I did some experimenting as well, setting NSOpenGLPFAColorSize to each of 8, 16, 24 & 32 and then checking what I got back. In each case I was returned a pixel format with NSOpenGLPFAColorSize set to 32 - meaning 32-bits per RGBA pixel. Just passing NSOpenGLPFAColorFloat with nothing set for the Color Size is enough to get back a pixel format with 64-bits per pixel.

于 2013-03-14T00:09:33.347 回答