0
就乾脆把它,我有以下問題:GLSL - 數組索引越界的
我想實現在GLSL堆棧,但它不斷給我下面的錯誤:
warning C1068: array index out of bounds.
error C1068: array index out of bounds.
我的代碼如下:
//---------------------------
// Utility
//---------------------------
uint PackColor(vec3 color)
{
uint value = 0 << 24; // Alpha
value = value + uint(color.r) << 16; // Red
value = value + uint(color.g) << 8; // Green
value = value + uint(color.b); // Blue
return value;
}
//
// Stack.glsl ~ Contains a Stack and StackEntry structure for holding multiple rays to be evaluated.
// Date: 11-09-2014
// Authors: Christian Veenman, Tom van Dijkhuizen
// Type: Library
//
#define MAX_STACK_SIZE 64
struct StackEntry
{
uint depth;
float fraction;
Ray ray;
};
struct Stack
{
int current;
StackEntry entries[MAX_STACK_SIZE];
};
// Pushes an element on the stack.
void Push(Stack stack, StackEntry entry)
{
stack.entries[stack.current] = entry;
stack.current = stack.current + 1;
}
// Pops an element from the stack.
StackEntry Pop(Stack stack)
{
stack.current = stack.current - 1;
return stack.entries[stack.current];
}
// Checks if the stack is empty
bool isEmpty(Stack stack)
{
if(stack.current == 0)
return true;
else
return false;
}
Screen screen;
Stack stack;
void main()
{
// Init stack
stack.current = 0;
for(int i = 0; i < stack.entries.length; i++)
stack.entries[i] = StackEntry(0, 0, Ray(vec3(0,0,0),vec3(0,0,0)));
// Init screen
screen.width = 1280;
screen.height = 1024;
// Screen coordinates
uint x = gl_GlobalInvocationID.x;
uint y = gl_GlobalInvocationID.y;
Push(stack, StackEntry(0, 1.0f, Ray(vec3(1,0,0),vec3(1,0,0))));
StackEntry entry = Pop(stack);
entry.ray.direction *= 255;
uint RGBA = PackColor(entry.ray.direction);
pixels[(screen.height - y - 1)*screen.width + x] = RGBA;
}
我真的是如何發生這個錯誤一無所知。爲什麼有些警告和一些錯誤?
我希望你能幫助我,或者向我提供一個關於如何在GLSL中創建堆棧的解決方案或方向。
編輯:這不是完整的代碼,因爲我不包括雷部分,但這應該是唯一相關的代碼。
您粘貼的代碼到目前爲止有一些嚴重的isseus。你甚至沒有一個堆棧可以使用。 – derhass 2014-09-27 16:43:18
當然,還有一個全局堆棧變量,那麼我也會添加其餘的代碼。 (我省略了它,因爲否則它會變得無關緊要) – 2014-09-27 17:19:20
@derhass btw!屏幕是隻有一個寬度和高度的結構,但我認爲這是明顯的權利? – 2014-09-27 17:21:26