LoadTexture loads the texture specified by its index.
(texIdx int)
| 736 | |
| 737 | // LoadTexture loads the texture specified by its index. |
| 738 | func (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. |
| 767 | func (g *GLTF) applySampler(samplerIdx int, tex *texture.Texture2D) error { |
no test coverage detected