计算着色器

struct col{
uint x;
uint y;
uint z;
uint w;
};


layout ( binding = 0 ) buffer bmp{
uvec4 color[];
};


layout(local_size_x = 1) in;


void main(void)
{

uint ID = gl_WorkGroupID.y * gl_NumWorkGroups.x + gl_WorkGroupID.x;

//color[ID] = col(ID * 3,ID * 3 + 1,ID * 3 + 2);


//color[ID] = col(ID * 4,ID * 4 + 1,ID * 4 + 2,ID * 4 + 3);


color[ID] = uvec4(gl_WorkGroupID.x, gl_WorkGroupID.y, gl_NumWorkGroups.x, ID);

}


以上计算着色器当color类型为uvec3或者自定义类型col时,无法正确执行,有没有谁知道怎么回事?谢谢!


对应以下C++代码:

#define EC (4)
const unsigned char * bc = (const unsigned char *)bmp;
ShaderStorageBufferObject ssbo( bmp.W() * bmp.H() * EC * sizeof(int), 0, Buffer::USAGE::DYNAMIC_DRAW);
ssbo.Bind(Buffer::BIND_TARGET::COPY_READ_BUFFER);
unsigned int (*bia)[4288][2848][EC] = (unsigned int (*)[4288][2848][EC])ssbo.MapBuffer(Buffer::BIND_TARGET::COPY_READ_BUFFER,Buffer::MAP_FLAG::READ_WRITE);
unsigned int *bi = (unsigned int *)bia;
for(int i = 0; i < bmp.W() * bmp.H() * EC; ++i)
{
//bi[i] = *bc;
bi[i] = i/EC + i%EC;
}
ssbo.UnmapBuffer(Buffer::BIND_TARGET::COPY_READ_BUFFER);
ssbo.UnBind(Buffer::BIND_TARGET::COPY_READ_BUFFER);
ssbo.BindBase(0);
std::string cstr;
ShaderM::ReadShaderSourceFromFile("shaders/computer.glsl/bmp.glsl", cstr);
CMPProg cmpp(cstr.data());
cmpp.UseProgram();

//cmpp.Dispatch(1,1,16);
cmpp.Dispatch(bmp.W() ,bmp.H() ,1);
//glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT);
glMemoryBarrier(GL_ALL_BARRIER_BITS);
ssbo.Bind(Buffer::BIND_TARGET::COPY_READ_BUFFER);
bia = (unsigned int (*)[4288][2848][EC])ssbo.MapBuffer(Buffer::BIND_TARGET::COPY_READ_BUFFER,Buffer::MAP_FLAG::READ_WRITE);

ssbo.UnmapBuffer(Buffer::BIND_TARGET::COPY_READ_BUFFER);
ssbo.UnBind(Buffer::BIND_TARGET::COPY_READ_BUFFER);


阅读更多
个人分类: OpenGL C++ GLSL
上一篇OpenGL 利用framebuffer实现快速精确的点选拾取
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭