ofBufferObject PosBuff,IndexBuffer;
ofVbo ObjsVbo;
const static int PolysCount = 1;//Only one production
float PosB[PolysCount*3*4];//xyz*VertexCount
vector<int> Polysindexs;
SetupFunction
↓This is vertex information of tetrahedron.
compute.setupShaderFromFile(GL_COMPUTE_SHADER,"shader.glsl");
compute.linkProgram();
ofVec3f p_1=ofVec3f(-TriSize, -TriSize, -TriSize);
ofVec3f p_2=ofVec3f(-TriSize, +TriSize, TriSize);
ofVec3f p_3=ofVec3f(TriSize, -TriSize, +TriSize);
ofVec3f p_4=ofVec3f(TriSize, TriSize, -TriSize);
PosB[0] = p_1.x;PosB[1] = p_1.y; PosB[2] = p_1.z;
PosB[3] = p_2.x;PosB[4] = p_2.y; PosB[5] = p_2.z;
PosB[6] = p_3.x;PosB[7] = p_3.y; PosB[8] = p_3.z;
PosB[9] = p_4.x;PosB[10] = p_4.y;PosB[11] = p_4.z;
Polysindexs.push_back((u *_c) + 0); Polysindexs.push_back((u*_c) + 1); Polysindexs.push_back((u*_c) + 3);
Polysindexs.push_back((u *_c) + 3); Polysindexs.push_back((u*_c) + 1); Polysindexs.push_back((u*_c) + 2);
Polysindexs.push_back((u *_c) + 0); Polysindexs.push_back((u*_c) + 3); Polysindexs.push_back((u*_c) + 2);
Polysindexs.push_back((u *_c) + 0); Polysindexs.push_back((u*_c) + 1); Polysindexs.push_back((u*_c) + 2);
PosBuff.allocate(PosB,GL_DYNAMIC_DRAW);
IndexBuffer.allocate(Polysindexs, GL_DYNAMIC_DRAW);
ObjsVbo.setVertexBuffer(PosBuff,3,0);
ObjsVbo.setIndexBuffer(IndexBuffer);
PosBuff.bindBase(GL_SHADER_STORAGE_BUFFER, 0);
ObjsShader.begin();
ObjsShader.setUniform1i("ObjsCount",PolysCount);
ObjsShader.end();
Update
ObjsShader.begin();
ObjsShader.dispatchCompute(PolysCount,3,0);
ObjsShader.end();
Draw
ObjsVbo.draw(GL_TRIANGLES,0, PolysCount*4);
Shader
#version 430
layout(std140,binding=0) buffer ddd{
vec3 pos[];
};
uniform uint ObjsCount;
layout(local_size_x = 4) in;
void main() {
pos[gl_GlobalInvocationID.x].xyz += vec3(0,0.0,0.0);//Don't Move;
}
This is the rendering result.
How do I become an tetrahedron?