applySamplers applies the specified Sampler to the provided texture.
(samplerIdx int, tex *texture.Texture2D)
| 765 | |
| 766 | // applySamplers applies the specified Sampler to the provided texture. |
| 767 | func (g *GLTF) applySampler(samplerIdx int, tex *texture.Texture2D) error { |
| 768 | |
| 769 | log.Debug("Applying Sampler %d", samplerIdx) |
| 770 | // Check if provided sampler index is valid |
| 771 | if samplerIdx < 0 || samplerIdx >= len(g.Samplers) { |
| 772 | return fmt.Errorf("invalid sampler index") |
| 773 | } |
| 774 | sampler := g.Samplers[samplerIdx] |
| 775 | |
| 776 | // Magnification filter |
| 777 | magFilter := gls.LINEAR |
| 778 | if sampler.MagFilter != nil { |
| 779 | magFilter = *sampler.MagFilter |
| 780 | } |
| 781 | tex.SetMagFilter(uint32(magFilter)) |
| 782 | |
| 783 | // Minification filter |
| 784 | minFilter := gls.LINEAR_MIPMAP_LINEAR |
| 785 | if sampler.MinFilter != nil { |
| 786 | minFilter = *sampler.MinFilter |
| 787 | } |
| 788 | tex.SetMinFilter(uint32(minFilter)) |
| 789 | |
| 790 | // S coordinate wrapping mode |
| 791 | wrapS := gls.REPEAT |
| 792 | if sampler.WrapS != nil { |
| 793 | wrapS = *sampler.WrapS |
| 794 | } |
| 795 | tex.SetWrapS(uint32(wrapS)) |
| 796 | |
| 797 | // T coordinate wrapping mode |
| 798 | wrapT := gls.REPEAT |
| 799 | if sampler.WrapT != nil { |
| 800 | wrapT = *sampler.WrapT |
| 801 | } |
| 802 | tex.SetWrapT(uint32(wrapT)) |
| 803 | |
| 804 | return nil |
| 805 | } |
| 806 | |
| 807 | // LoadImage loads the image specified by the index of GLTF.Images. |
| 808 | // Image can be loaded from binary chunk file or data URI or external file.. |
no test coverage detected