TriangleAccessor::TriangleAccessor(const Rendering::Mesh * _mesh, uint32_t _triangleIndex) : mesh(_mesh), triangleIndex(_triangleIndex) { const Rendering::VertexAttribute & posAttr = mesh->getVertexDescription().getAttribute(Rendering::VertexAttributeIds::POSITION); const uint16_t offset = posAttr.getOffset(); vertexPositions[0] = reinterpret_cast<const float *>(getVertexData(0) + offset); vertexPositions[1] = reinterpret_cast<const float *>(getVertexData(1) + offset); vertexPositions[2] = reinterpret_cast<const float *>(getVertexData(2) + offset); }
void MeshBase::updateBBox() { optix::float3* vertices_f3 = reinterpret_cast<optix::float3*>( getVertexData() ); int num_vertices = getNumVertices(); optix::Aabb new_bbox; for( int i = 0; i < num_vertices; ++i ) { new_bbox.include( vertices_f3[i] ); } reinterpret_cast<optix::float3*>(m_bbox_min)[0] = new_bbox.m_min; reinterpret_cast<optix::float3*>(m_bbox_max)[0] = new_bbox.m_max; }
const vector<Vertex>& Scene::getVertexData() { this->vertexData.clear(); for (auto nodePair : this->childNodes) { auto pNode = nodePair.second; auto& nodeVertexData = pNode->getVertexData(); if (vertexData.capacity() < vertexData.size() + nodeVertexData.size()) this->vertexData.reserve(vertexData.size() + nodeVertexData.size()); this->vertexData.insert(vertexData.end(), nodeVertexData.begin(), nodeVertexData.end()); } return this->vertexData; }
void Drawable::init() { { GLuint l_vao, l_vbo, l_ebo; GLRUN(glGenVertexArrays(1, &l_vao)); *vao = l_vao; GLRUN(glGenBuffers(1, &l_vbo)); *vbo = l_vbo; if (indices.size() > 0) { GLRUN(glGenBuffers(1, &l_ebo)); *ebo = l_ebo; } } GLRUN(glBindVertexArray(*vao)); GLRUN(glBindBuffer(GL_ARRAY_BUFFER, *vbo)); std::vector<GLfloat> vertexData = getVertexData(); GLRUN(glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*vertexData.size(), vertexData.data(), GL_STATIC_DRAW)); GLRUN(glVertexAttribPointer(0, Vertex::VERTEX_POSITIONS, GL_FLOAT, GL_FALSE, Vertex::VERTEX_SIZE * sizeof(GLfloat), (GLvoid*)0)); GLRUN(glEnableVertexAttribArray(0)); GLRUN(glVertexAttribPointer(1, Vertex::VERTEX_NORMALS, GL_FLOAT, GL_FALSE, Vertex::VERTEX_SIZE * sizeof(GLfloat), (GLvoid*)(Vertex::VERTEX_POSITIONS * sizeof(GLfloat)))); GLRUN(glEnableVertexAttribArray(1)); GLRUN(glVertexAttribPointer(2, Vertex::VERTEX_TEXCOORDS, GL_FLOAT, GL_FALSE, Vertex::VERTEX_SIZE * sizeof(GLfloat), (GLvoid*)((Vertex::VERTEX_POSITIONS + Vertex::VERTEX_NORMALS) * sizeof(GLfloat)))); GLRUN(glEnableVertexAttribArray(2)); if (indices.size() > 0) { GLRUN(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *ebo)); GLRUN(glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint)*indices.size(), indices.data(), GL_STATIC_DRAW)); } GLRUN(glBindBuffer(GL_ARRAY_BUFFER, 0)); GLRUN(glBindVertexArray(0)); }
void CompactSubGeometry::uploadData() { m_activeBuffer->uploadFromVector(getVertexData(), 0, m_numVertices); m_activeDataInvalid = false; }