我正在开发一个OpenGL图形引擎,它可以精确地渲染透明网格。完整项目可用
here
. 导致此问题的代码位于排序着色器内(请参阅TODO注释):
int listBegin = listsHeads[getPixelBufferIndex()];
if(listBegin != -1)
{
// Sort linked list using bubble sort
bool swapped;
do
{
// Start at list head
swapped = false;
int previousNode = listBegin;
int currentNode = listsNodes[listBegin].nextNode;
// Loop until list end
while(currentNode != -1)
{
// Furthest first
float previousDepth = listsNodes[previousNode].depth;
float currentDepth = listsNodes[currentNode].depth;
// TODO fix crash on nVidia
if(previousDepth < currentDepth)
{
swapped = true;
FragmentNode temp;
temp.color = listsNodes[currentNode].color;
temp.meshId = listsNodes[currentNode].meshId;
listsNodes[currentNode].color = listsNodes[previousNode].color;
listsNodes[currentNode].depth = previousDepth;
listsNodes[currentNode].meshId = listsNodes[previousNode].meshId;
listsNodes[previousNode].color = temp.color;
listsNodes[previousNode].depth = currentDepth;
listsNodes[previousNode].meshId = temp.meshId;
}
previousNode = currentNode;
currentNode = listsNodes[currentNode].nextNode;
}
}
while(swapped);
}
如果我删除了内部,如果程序不再崩溃,那么结果当然是不正确的,因为列表没有排序。
知道吗?这是我想要的输出: