我有一个OpenGL程序,它显示出(巨大的)可重复性不足。在片段着色器中,我查找特定的条件。如果满足该条件,我将与该片段相关联的世界空间坐标写入SSBO,这是我从顶点着色器中保留的。
我的问题是,从程序的一次重复到下一次重复,对SSBO的写操作的数量变化很大。如果多个着色器想要同时写入SSBO,会不会不总是这样呢?
我不从其他着色器读取SSBO。因此,这不是读/写同步的问题。只有当我返回到CPU应用程序时,我才读取SSBO。
我在NVIDIA GTX645卡上使用OpenGL 4.3。
发布于 2017-01-29 22:54:57
在CPU应用程序中:
//Create one Shader Storage Buffer Object for vertices of detected points
GLuint Detected_Vertices_SSBO;
glGenBuffers(1,&Detected_Vertices_SSBO);
glBindBuffer(GL_SHADER_STORAGE_BUFFER,Detected_Vertices_SSBO);
glBufferData(GL_SHADER_STORAGE_BUFFER,(sizeN-NbTotalreflectionPoints.at(i))*sizeof(glm::vec4),NULL,GL_DYNAMIC_DRAW);
sprintf(OpenGLErrorMessage,"%s\n","Error on Vertices SSBO at creation time.");
QueryForOpenGLErrors(OpenGLErrorMessage);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER,0,Detected_Vertices_SSBO);
sprintf(OpenGLErrorMessage,"%s\n","Error on Vertices SSBO at binding time.");
QueryForOpenGLErrors(OpenGLErrorMessage);
//Create one Shader Storage Buffer Object for colors of detected points
GLuint Detected_Vertices_Colors_SSBO;
glGenBuffers(1,&Detected_Vertices_Colors_SSBO);
glBindBuffer(GL_SHADER_STORAGE_BUFFER,Detected_Vertices_Colors_SSBO);
glBufferData(GL_SHADER_STORAGE_BUFFER,(sizeN-NbTotalreflectionPoints.at(i))*sizeof(glm::vec4),NULL,GL_DYNAMIC_DRAW);
sprintf(OpenGLErrorMessage,"%s\n","Error on Colors of Vertices SSBO at creation time.");
QueryForOpenGLErrors(OpenGLErrorMessage);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER,1,Detected_Vertices_Colors_SSBO);
sprintf(OpenGLErrorMessage,"%s\n","Error on Vertices Colors SSBO at binding time.");
QueryForOpenGLErrors(OpenGLErrorMessage);
….
glDrawArrays(GL_POINTS, 2*3+NbTargets1*12*3, NbPoints); //
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
glFinish();
…
glBindBuffer(GL_SHADER_STORAGE_BUFFER, Detected_Vertices_SSBO);
glm::vec4 * SSBO_Position_ptr = (glm::vec4*)glMapBuffer(GL_SHADER_STORAGE_BUFFER,GL_READ_ONLY);
sprintf(OpenGLErrorMessage,"%s\n","Error on Vertices SSBO at mapping time.");
QueryForOpenGLErrors(OpenGLErrorMessage);
glFinish();
glBindBuffer(GL_SHADER_STORAGE_BUFFER, Detected_Vertices_Colors_SSBO);
glm::vec4 * SSBO_Color_ptr = (glm::vec4*)glMapBuffer(GL_SHADER_STORAGE_BUFFER,GL_READ_ONLY);
sprintf(OpenGLErrorMessage,"%s\n","Error on Vertices Colors SSBO at mapping time.");
QueryForOpenGLErrors(OpenGLErrorMessage);
glFinish();
然后,在片段着色器中:
#version 430 core
布局(Early_fragment_tests)在;
// Interpolated values from the vertex shaders
in vec4 fragmentColor;
in vec4 worldspace;
//SSBO's for detected points and their colors
layout (binding=0, std430) coherent buffer detected_vertices_storage
{
vec4 detected_vertices[];
}Positions;
layout (binding=1, std430) coherent buffer detected_vertices_colors_storage
{
vec4 detected_vertices_colors[];
}Colors;
...
Positions.detected_vertices[int(round(Condition * ((gl_FragCoord.y-0.5)*1024.0+(gl_FragCoord.x-0.5))/(1024.0*1024.0)*NbOfCosines))] = worldspace;
Colors.detected_vertices_colors[int(round(Condition * ((gl_FragCoord.y-0.5)*1024.0+(gl_FragCoord.x-0.5))/(1024.0*1024.0)*NbOfCosines))] = color;
其中条件=0或1。
我希望这能有所帮助。我很遗憾地告诉大家,我在stackoverflow中的格式化方面仍然有很多问题。我一定是太老了!
https://stackoverflow.com/questions/41915604
复制相似问题