/** loads specified mesh from file. If loading of 3 uvs is selected then layer of atlas is */ InternalMeshInfo ModelLoader::load(const std::string &name){ if(not scene){ error("No scene for ModelLoader"); hardPause(); return {}; } InternalMeshInfo info {(u32)vertex.size(), (u32)texcoord.size(), (u32)normal.size(), (u32)tangent.size(), (u32)indices.size()}; auto meshes = find(name); if(meshes.empty()){ error("no mesh:", name); return {}; } for(auto mesh : meshes){ InternalMeshInfo subinfo {(u32)vertex.size(), (u32)texcoord.size(), (u32)normal.size(), (u32)tangent.size(), (u32)indices.size()}; copyIndices(mesh); copyVertices(mesh); copyTexcoords(mesh); copyNormals(mesh); copyTangents(mesh); info.count = indices.size() - info.iID; info.vertexCount = (vertex.size() - info.vID)/4; subinfo.count = indices.size() - subinfo.iID; subinfo.vertexCount = (vertex.size() - subinfo.vID)/4; if(getLayer) setTextureLayer(subinfo, getLayer(getTextureName(mesh))); } return info; }
GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, Buffer *buffer, const void *indices, TranslatedIndexData *translated) { if(!mStreamingBuffer) { return GL_OUT_OF_MEMORY; } intptr_t offset = reinterpret_cast<intptr_t>(indices); if(buffer != NULL) { if(typeSize(type) * count + offset > static_cast<std::size_t>(buffer->size())) { return GL_INVALID_OPERATION; } indices = static_cast<const GLubyte*>(buffer->data()) + offset; } StreamingIndexBuffer *streamingBuffer = mStreamingBuffer; sw::Resource *staticBuffer = buffer ? buffer->getResource() : NULL; if(staticBuffer) { computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex); translated->indexBuffer = staticBuffer; translated->indexOffset = offset; } else { unsigned int streamOffset = 0; int convertCount = count; streamingBuffer->reserveSpace(convertCount * typeSize(type), type); void *output = streamingBuffer->map(typeSize(type) * convertCount, &streamOffset); if(output == NULL) { ERR("Failed to map index buffer."); return GL_OUT_OF_MEMORY; } copyIndices(type, staticBuffer ? buffer->data() : indices, convertCount, output); streamingBuffer->unmap(); computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex); translated->indexBuffer = streamingBuffer->getResource(); translated->indexOffset = streamOffset; } return GL_NO_ERROR; }