0

对于我正在开发的应用程序,我需要能够

  • 绘制不同宽度和颜色的线条
  • 绘制纯色填充三角形
  • 绘制纹理(无 alpha)四边形

很简单……但是……

所有坐标在像素空间中都是整数,并且非常重要:glReading 从两台不同机器上的帧缓冲区中的所有像素,使用两个不同的显卡,运行两个不同的操作系统(Linux 和 freebsd),必须产生完全相同的位序列(给定适当的常量格式转换)。

我认为使用 opengl 和硬件加速不可能安全地实现这一点,因为我敢打赌,不同的显卡(来自不同的供应商)可能会实现不同的光栅化算法。(OpenGl 规范对此很清楚,因为他们提出了一种算法,但他们也声明在某些情况下实现可能会有所不同)。此外,我真的不需要硬件加速,因为我将渲染非常低速和简单的图形。

你认为我可以通过禁用硬件加速来实现这一点吗?在 linux 下会发生什么情况,我会默认使用 MESA 软件光栅化器吗?在那种情况下,我能确定它总是有效还是我遗漏了什么?

4

1 回答 1

3

That you're reading back in rendered pixels and strongly depend on their mathematical exactness/reproducability sounds like a design flaw. What's the purpose of this action? If you, for example, need to extract some information from the image, why don't you try to extract this information from the abstract, vectorized information prior to rendering?

Anyhow, if you depend on external rendering code and there's no way to make your reading code more robust to small errors, you're signing up for lots of pain and maintenance work. Other people could break your code with every tiny patch, because that kind of pixel exactness to the bit-level is usually a non-issue when they're doing their unit tests etc. Let alone the infinite permutations of hard- and software layers that are possible, and all might have influence on the exact pixel bits.

If you only need those two operatios: lines (with different widths and colors) and quads (with/without texture), I recommend writing your own rendering/rasterizer code which operates on a 8 bit uint array representing the image pixels (R8G8B8). The operations you're proposing aren't too nasty, so if performance is unimportant, this might actually be the better way to go on the long run.

于 2012-04-19T16:09:35.050 回答