在OpenGL中使用抗锯齿功能进行颜色选择?

| 我在OpenGL中遇到颜色选择和抗锯齿的问题。激活AA后,glReadPixels的结果在对象边缘和对象相交处显然是错误的。例如: 我在框#32(RGBA:32,0,0,0)附近渲染框#28(RGBA:28,0,0,0)。使用AA时,由于AA算法,我会得到一个错误的ReadPixel值(例如30),该值在立方体和三角形重叠的地方,或者在框边上为14。 我有大约40万个需要拾取的对象(这是一个拼图游戏)。能够按形状选择对象至关重要。 我曾尝试使用glDisable(GL_MULTISAMPLE)禁用AA,但是它不适用于某些AA模式(我看这取决于AA的实现方式-SS,MS,CS ..) 那么,如何选择基础对象? 暂时禁用AA的方法? 使用不同的缓冲区甚至渲染上下文? 还有其他建议吗?     
已邀请:
为什么不使用FBO作为选择缓冲区?     
我使用这种技巧:不仅拾取一个像素,而且拾取点周围的所有3x3 = 9像素。如果它们都相同,那么我们是安全的。否则,它必须处于边缘,我们可以跳过它。
int renderer::pick_(int x, int y)
{
    static_assert(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__,
            \"only works on little-endian architecture\");
    static_assert(sizeof(int) == 4,
            \"only works on architecture that has int size of 4\");

    // sort of edge detection. selection only happens at non-edge
    // since the edge may cause anti-aliasing glitch
    int ids[3*3];
    glReadPixels(x-1, y-1, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, ids);
    for (auto& id: ids) id &= 0x00FFFFFF;       // mask out alpha
    if (ids[0] == 0x00FFFFFF) return -1;        // pure white for background

    // prevent anti-aliasing glitch
    bool same = true;
    for (auto id: ids) same = (same && id == ids[0]);
    if (same) return ids[0];

    return -2;                                  // edge
}
    

要回复问题请先登录注册