MCPcopy
hub / github.com/g3n/engine / LoadTexture

Method LoadTexture

loader/gltf/loader.go:738–764  ·  view source on GitHub ↗

LoadTexture loads the texture specified by its index.

(texIdx int)

Source from the content-addressed store, hash-verified

736
737// LoadTexture loads the texture specified by its index.
738func (g *GLTF) LoadTexture(texIdx int) (*texture.Texture2D, error) {
739
740 // Check if provided texture index is valid
741 if texIdx < 0 || texIdx >= len(g.Textures) {
742 return nil, fmt.Errorf("invalid texture index")
743 }
744 texData := g.Textures[texIdx]
745 // NOTE: Textures can't be cached because they have their own uniforms
746 log.Debug("Loading Texture %d", texIdx)
747
748 // Load texture image
749 img, err := g.LoadImage(texData.Source)
750 if err != nil {
751 return nil, err
752 }
753 tex := texture.NewTexture2DFromRGBA(img)
754
755 // Get sampler and apply texture parameters
756 if texData.Sampler != nil {
757 err = g.applySampler(*texData.Sampler, tex)
758 if err != nil {
759 return nil, err
760 }
761 }
762
763 return tex, nil
764}
765
766// applySamplers applies the specified Sampler to the provided texture.
767func (g *GLTF) applySampler(samplerIdx int, tex *texture.Texture2D) error {

Callers 2

loadMaterialPBRMethod · 0.95
loadMaterialCommonMethod · 0.95

Calls 4

LoadImageMethod · 0.95
applySamplerMethod · 0.95
NewTexture2DFromRGBAFunction · 0.92
DebugMethod · 0.80

Tested by

no test coverage detected