MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / bindMesh_

Method bindMesh_

source/MRViewer/MRRenderMeshObject.cpp:393–506  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

391}
392
393void RenderMeshObject::bindMesh_( GLStaticHolder::ShaderType shaderType )
394{
395 MR_TIMER;
396 auto shader = GLStaticHolder::getShaderId( shaderType );
397 GL_EXEC( glBindVertexArray( meshArrayObjId_ ) );
398 GL_EXEC( glUseProgram( shader ) );
399
400 auto positions = loadVertPosBuffer_();
401 bindVertexAttribArray( shader, "position", vertPosBuffer_, positions, 3, positions.dirty(), positions.glSize() != 0 );
402
403 auto normals = loadVertNormalsBuffer_();
404 bindVertexAttribArray( shader, "normal", vertNormalsBuffer_, normals, 3, normals.dirty(), normals.glSize() != 0 );
405
406 auto colormaps = loadVertColorsBuffer_();
407 bindVertexAttribArray( shader, "K", vertColorsBuffer_, colormaps, 4, colormaps.dirty(), colormaps.glSize() != 0 );
408
409 auto uvs = loadVertUVBuffer_();
410 bindVertexAttribArray( shader, "texcoord", vertUVBuffer_, uvs, 2, uvs.dirty(), uvs.glSize() != 0 );
411
412 auto faces = loadFaceIndicesBuffer_();
413 facesIndicesBuffer_.loadDataOpt( GL_ELEMENT_ARRAY_BUFFER, faces.dirty(), faces );
414
415 GL_EXEC( glActiveTexture( GL_TEXTURE0 ) );
416
417 if ( bool( dirty_ & DIRTY_TEXTURE ) )
418 {
419 dirty_ &= ~DIRTY_TEXTURE;
420 if ( objMesh_->hasAncillaryTexture() )
421 {
422 const auto& texture = objMesh_->getAncillaryTexture();
423
424 textureArray_.loadDataOpt( true,
425 {
426 .resolution = GlTexture2::ToResolution( texture.resolution ),
427 .internalFormat = GL_RGBA,
428 .format = GL_RGBA,
429 .type = GL_UNSIGNED_BYTE,
430 .wrap = texture.wrap,
431 .filter = texture.filter
432 },
433 texture.pixels );
434 }
435 else
436 {
437 const auto& textures = objMesh_->getTextures();
438
439 auto res = textures.empty() ? Vector2i() : textures.front().resolution;
440 auto wrap = textures.empty() ? WrapType::Clamp : textures.front().wrap;
441 auto filter = textures.empty() ? FilterType::Linear : textures.front().filter;
442
443 auto& buffer = GLStaticHolder::getStaticGLBuffer();
444 auto texSize = res.x * res.y;
445 auto pixels = buffer.prepareBuffer<Color>( size_t( texSize * textures.size() ) );
446 size_t numTex = 0;
447 for ( const auto& tex : textures )
448 std::copy( tex.pixels.begin(), tex.pixels.end(), &pixels[texSize * numTex++] );
449
450 GlTexture2DArray::Settings settings;

Callers

nothing calls this directly

Calls 12

calcTextureResFunction · 0.85
dirtyMethod · 0.80
glSizeMethod · 0.80
bindVertexAttribArrayFunction · 0.70
loadDataOptMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
loadDataMethod · 0.45
bindMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected