MCPcopy
hub / github.com/EngoEngine/engo / generateBufferContent

Method generateBufferContent

common/render_shaders_text.go:177–252  ·  view source on GitHub ↗
(ren *RenderComponent, space *SpaceComponent, buffer []float32)

Source from the content-addressed store, hash-verified

175}
176
177func (l *textShader) generateBufferContent(ren *RenderComponent, space *SpaceComponent, buffer []float32) bool {
178 var changed bool
179
180 tint := colorToFloat32(ren.Color)
181 txt, ok := ren.Drawable.(Text)
182 if !ok {
183 unsupportedType(ren.Drawable)
184 return false
185 }
186
187 atlas, ok := atlasCache[*txt.Font]
188 if !ok {
189 // Generate texture first
190 atlas = txt.Font.generateFontAtlas(UnicodeCap)
191 atlasCache[*txt.Font] = atlas
192 }
193
194 var currentX float32
195 var currentY float32
196
197 var modifier float32 = 1
198 if txt.RightToLeft {
199 modifier = -1
200 }
201
202 letterSpace := float32(txt.Font.Size) * txt.LetterSpacing
203 lineSpace := txt.LineSpacing * atlas.Height['X']
204
205 for index, char := range txt.Text {
206 // TODO: this might not work for all characters
207 switch {
208 case char == '\n':
209 currentX = 0
210 currentY += atlas.Height['X'] + lineSpace
211 continue
212 case char < 32: // all system stuff should be ignored
213 continue
214 }
215
216 offset := 20 * index
217 xoff := atlas.OffsetX[char]
218 yoff := atlas.OffsetY[char]
219
220 // These five are at 0, 0:
221 setBufferValue(buffer, 0+offset, currentX+xoff, &changed)
222 setBufferValue(buffer, 1+offset, currentY+yoff, &changed)
223 setBufferValue(buffer, 2+offset, atlas.XLocation[char]/atlas.TotalWidth, &changed)
224 setBufferValue(buffer, 3+offset, atlas.YLocation[char]/atlas.TotalHeight, &changed)
225 setBufferValue(buffer, 4+offset, tint, &changed)
226
227 // These five are at 1, 0:
228 setBufferValue(buffer, 5+offset, currentX+xoff+atlas.Width[char]+letterSpace, &changed)
229 setBufferValue(buffer, 6+offset, currentY+yoff, &changed)
230 setBufferValue(buffer, 7+offset, (atlas.XLocation[char]+atlas.Width[char])/atlas.TotalWidth, &changed)
231 setBufferValue(buffer, 8+offset, atlas.YLocation[char]/atlas.TotalHeight, &changed)
232 setBufferValue(buffer, 9+offset, tint, &changed)
233
234 // These five are at 1, 1:

Callers 1

updateBufferMethod · 0.95

Calls 4

colorToFloat32Function · 0.85
setBufferValueFunction · 0.85
generateFontAtlasMethod · 0.80
unsupportedTypeFunction · 0.70

Tested by

no test coverage detected