void ofApp::drawRectangle(float x, float y, float w, float h) { static ofVbo vbo; vector<ofVec3f> vertices = { ofVec3f(x, y, 0), ofVec3f(x + w, y, 0), ofVec3f(x + w, y + h, 0) , ofVec3f(x, y + h, 0) }; vector<ofFloatColor> colors(4, ofGetStyle().color); if (!vbo.getIsAllocated()) { vector<ofVec2f> texCoords = { ofVec2f(0, 0), ofVec2f(1, 0), ofVec2f(1, 1), ofVec2f(0, 1) }; vector<ofVec3f> normals(4, ofVec3f(0, 0, 1)); vector<ofIndexType> indices = { 0, 2, 1, 0, 3, 2 }; vbo.setVertexData(&vertices[0].x, 3, vertices.size(), GL_DYNAMIC_DRAW); vbo.setColorData(&colors[0].r, colors.size(), GL_DYNAMIC_DRAW); vbo.setTexCoordData(&texCoords[0].x, texCoords.size(), GL_STATIC_DRAW); vbo.setNormalData(&normals[0].x, normals.size(), GL_STATIC_DRAW); vbo.setIndexData(&indices[0], indices.size(), GL_STATIC_DRAW); } else { vbo.updateVertexData(&vertices[0].x, vertices.size()); vbo.updateColorData(&colors[0].r, colors.size()); } vbo.drawElements(GL_TRIANGLES, vbo.getNumIndices()); }
int ofxKinectV2::getVbo(ofVbo& vbo) { auto& vertices = pcVertices[indexFront]; auto& colors = pcColors[indexFront]; if (!vbo.getIsAllocated()) { vector<ofVec2f> texCoords; for (int y = 0; y < DEPTH_HEIGHT; y++) { float coord_y = (float)y / DEPTH_HEIGHT; for (int x = 0; x < DEPTH_WIDTH; x++) { float coord_x = (float)x / DEPTH_HEIGHT; texCoords.emplace_back(coord_x, coord_y); } } vbo.setTexCoordData(&texCoords[0], texCoords.size(), GL_STATIC_DRAW); vbo.setVertexData(&vertices[0].x, 4, vertices.size(), GL_DYNAMIC_DRAW); vbo.setColorData(&colors[0], colors.size(), GL_DYNAMIC_DRAW); vbo.setIndexBuffer(indicesBuffer); } else { vbo.updateVertexData(&vertices[0].x, vertices.size()); vbo.updateColorData(&colors[0].r, colors.size()); } auto& depth = frameRawDepth[indexFront]; if (depth.getWidth() && depth.getHeight()) { { std::lock_guard<std::mutex> guard(mutex); depthTexture.loadData(&depth[0], DEPTH_WIDTH, DEPTH_HEIGHT, GL_RED); //vector<float> dd(512 * 424); //memcpy(&dd[0], depth.getData(), sizeof(float) * dd.size()); } depthTexture.bindAsImage(0, GL_READ_ONLY); indicesBuffer.bindBase(GL_SHADER_STORAGE_BUFFER, 0); atomicCounter.bindBase(GL_ATOMIC_COUNTER_BUFFER, 0); computeIndices.begin(); computeIndices.setUniform1i("bUseUserMap", 0); computeIndices.dispatchCompute(DEPTH_WIDTH / 32, DEPTH_HEIGHT / 8, 1); computeIndices.end(); indicesBuffer.unbindBase(GL_SHADER_STORAGE_BUFFER, 0); atomicCounter.unbindBase(GL_ATOMIC_COUNTER_BUFFER, 0); #if 0 auto atomic = atomicCounter.map<int>(GL_READ_ONLY); int num = atomic[0]; atomicCounter.unmap(); cout << "atomic: " << num << endl; #endif int data = 0; atomicCounter.updateData(0, sizeof(int), &data); } return indicesBuffer.size() / sizeof(int); }