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

Method SetProgram

renderer/shaman.go:126–170  ·  view source on GitHub ↗

SetProgram sets the shader program to satisfy the specified specs. Returns an indication if the current shader has changed and a possible error when creating a new shader program. Receives a copy of the specs because it changes the fields which specify the number of lights depending on the UseLights

(s *ShaderSpecs)

Source from the content-addressed store, hash-verified

124// Receives a copy of the specs because it changes the fields which specify the
125// number of lights depending on the UseLights flags.
126func (sm *Shaman) SetProgram(s *ShaderSpecs) (bool, error) {
127
128 // Checks material use lights bit mask
129 var specs ShaderSpecs
130 specs.copy(s)
131 if (specs.UseLights & material.UseLightAmbient) == 0 {
132 specs.AmbientLightsMax = 0
133 }
134 if (specs.UseLights & material.UseLightDirectional) == 0 {
135 specs.DirLightsMax = 0
136 }
137 if (specs.UseLights & material.UseLightPoint) == 0 {
138 specs.PointLightsMax = 0
139 }
140 if (specs.UseLights & material.UseLightSpot) == 0 {
141 specs.SpotLightsMax = 0
142 }
143
144 // If current shader specs are the same as the specified specs, nothing to do.
145 if sm.specs.equals(&specs) {
146 return false, nil
147 }
148
149 // Search for compiled program with the specified specs
150 for _, pinfo := range sm.programs {
151 if pinfo.specs.equals(&specs) {
152 sm.gs.UseProgram(pinfo.program)
153 sm.specs = specs
154 return true, nil
155 }
156 }
157
158 // Generates new program with the specified specs
159 prog, err := sm.GenProgram(&specs)
160 if err != nil {
161 return false, err
162 }
163 log.Debug("Created new shader:%v", specs.Name)
164
165 // Save specs as current specs, adds new program to the list and activates the program
166 sm.specs = specs
167 sm.programs = append(sm.programs, ProgSpecs{prog, specs})
168 sm.gs.UseProgram(prog)
169 return true, nil
170}
171
172// GenProgram generates shader program from the specified specs
173func (sm *Shaman) GenProgram(specs *ShaderSpecs) (*gls.Program, error) {

Callers 1

renderGraphicMaterialMethod · 0.80

Calls 5

copyMethod · 0.95
GenProgramMethod · 0.95
equalsMethod · 0.80
DebugMethod · 0.80
UseProgramMethod · 0.45

Tested by

no test coverage detected