MCPcopy Index your code
hub / github.com/EngoEngine/engo / Setup

Method Setup

common/render_shaders_blendmap.go:135–189  ·  view source on GitHub ↗
(w *ecs.World)

Source from the content-addressed store, hash-verified

133}
134
135func (s *blendmapShader) Setup(w *ecs.World) error {
136 if s.BatchSize > MaxSprites {
137 return fmt.Errorf("%d is greater than the maximum batch size of %d", s.BatchSize, MaxSprites)
138 }
139 if s.BatchSize <= 0 {
140 s.BatchSize = MaxSprites
141 }
142 // Create the vertex buffer for batching.
143 s.vertices = make([]float32, s.BatchSize*blendmapSpriteSize)
144 s.vertexBuffer = engo.Gl.CreateBuffer()
145 // Create and populate indices buffer. The size of the buffer depends on the batch size.
146 // These should never change, so we can just initialize them once here and be done with it.
147 numIndicies := s.BatchSize * 6
148 s.indices = make([]uint16, numIndicies)
149 for i, j := 0, 0; i < numIndicies; i, j = i+6, j+4 {
150 s.indices[i+0] = uint16(j + 0)
151 s.indices[i+1] = uint16(j + 1)
152 s.indices[i+2] = uint16(j + 2)
153 s.indices[i+3] = uint16(j + 0)
154 s.indices[i+4] = uint16(j + 2)
155 s.indices[i+5] = uint16(j + 3)
156 }
157 var err error
158 s.program, err = LoadShader(blendmapVertexShader, blendmapFragmentShader)
159 if err != nil {
160 return err
161 }
162 s.indexBuffer = engo.Gl.CreateBuffer()
163 engo.Gl.BindBuffer(engo.Gl.ELEMENT_ARRAY_BUFFER, s.indexBuffer)
164 engo.Gl.BufferData(engo.Gl.ELEMENT_ARRAY_BUFFER, s.indices, engo.Gl.STATIC_DRAW)
165
166 s.inPosition = engo.Gl.GetAttribLocation(s.program, "in_Position")
167 s.inTexCoords = engo.Gl.GetAttribLocation(s.program, "in_TexCoords")
168 s.inColor = engo.Gl.GetAttribLocation(s.program, "in_Color")
169
170 s.matrixProjView = engo.Gl.GetUniformLocation(s.program, "matrixProjView")
171
172 s.uf_BlendMap = engo.Gl.GetUniformLocation(s.program, "uf_BlendMap")
173 s.uf_Fallback = engo.Gl.GetUniformLocation(s.program, "uf_Fallback")
174 s.uf_RChannel = engo.Gl.GetUniformLocation(s.program, "uf_RChannel")
175 s.uf_GChannel = engo.Gl.GetUniformLocation(s.program, "uf_GChannel")
176 s.uf_BChannel = engo.Gl.GetUniformLocation(s.program, "uf_BChannel")
177
178 s.uf_scaleFB = engo.Gl.GetUniformLocation(s.program, "uf_scaleFB")
179 s.uf_scaleR = engo.Gl.GetUniformLocation(s.program, "uf_scaleR")
180 s.uf_scaleG = engo.Gl.GetUniformLocation(s.program, "uf_scaleG")
181 s.uf_scaleB = engo.Gl.GetUniformLocation(s.program, "uf_scaleB")
182
183 s.projectionMatrix = engo.IdentityMatrix()
184 s.viewMatrix = engo.IdentityMatrix()
185 s.modelMatrix = engo.IdentityMatrix()
186 s.cullingMatrix = engo.IdentityMatrix()
187
188 return nil
189}
190
191func (s *blendmapShader) Pre() {
192 engo.Gl.Enable(engo.Gl.BLEND)

Callers

nothing calls this directly

Calls 2

IdentityMatrixFunction · 0.92
LoadShaderFunction · 0.85

Tested by

no test coverage detected