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

Method Draw

common/render_shaders_text.go:254–306  ·  view source on GitHub ↗
(ren *RenderComponent, space *SpaceComponent)

Source from the content-addressed store, hash-verified

252}
253
254func (l *textShader) Draw(ren *RenderComponent, space *SpaceComponent) {
255 txt, ok := ren.Drawable.(Text)
256 if !ok {
257 unsupportedType(ren.Drawable)
258 }
259
260 if l.lastBuffer != ren.Buffer || ren.Buffer == nil {
261 l.updateBuffer(ren, space)
262
263 engo.Gl.BindBuffer(engo.Gl.ARRAY_BUFFER, ren.Buffer)
264 engo.Gl.VertexAttribPointer(l.inPosition, 2, engo.Gl.FLOAT, false, 20, 0)
265 engo.Gl.VertexAttribPointer(l.inTexCoords, 2, engo.Gl.FLOAT, false, 20, 8)
266 engo.Gl.VertexAttribPointer(l.inColor, 4, engo.Gl.UNSIGNED_BYTE, true, 20, 16)
267
268 l.lastBuffer = ren.Buffer
269 }
270
271 atlas, ok := atlasCache[*txt.Font]
272 if !ok {
273 // Generate texture first
274 atlas = txt.Font.generateFontAtlas(UnicodeCap)
275 atlasCache[*txt.Font] = atlas
276 }
277
278 if atlas.Texture != l.lastTexture {
279 engo.Gl.BindTexture(engo.Gl.TEXTURE_2D, atlas.Texture)
280 l.lastTexture = atlas.Texture
281 }
282
283 engo.Gl.TexParameteri(engo.Gl.TEXTURE_2D, engo.Gl.TEXTURE_WRAP_S, engo.Gl.CLAMP_TO_EDGE)
284 engo.Gl.TexParameteri(engo.Gl.TEXTURE_2D, engo.Gl.TEXTURE_WRAP_T, engo.Gl.CLAMP_TO_EDGE)
285
286 if space.Rotation != 0 {
287 sin, cos := math.Sincos(space.Rotation * math.Pi / 180)
288
289 l.modelMatrix[0] = ren.Scale.X * engo.GetGlobalScale().X * cos
290 l.modelMatrix[1] = ren.Scale.X * engo.GetGlobalScale().X * sin
291 l.modelMatrix[3] = ren.Scale.Y * engo.GetGlobalScale().Y * -sin
292 l.modelMatrix[4] = ren.Scale.Y * engo.GetGlobalScale().Y * cos
293 } else {
294 l.modelMatrix[0] = ren.Scale.X * engo.GetGlobalScale().X
295 l.modelMatrix[1] = 0
296 l.modelMatrix[3] = 0
297 l.modelMatrix[4] = ren.Scale.Y * engo.GetGlobalScale().Y
298 }
299
300 l.modelMatrix[6] = space.Position.X * engo.GetGlobalScale().X
301 l.modelMatrix[7] = space.Position.Y * engo.GetGlobalScale().Y
302
303 engo.Gl.UniformMatrix3fv(l.matrixModel, false, l.modelMatrix)
304
305 engo.Gl.DrawElements(engo.Gl.TRIANGLES, 6*len(txt.Text), engo.Gl.UNSIGNED_SHORT, 0)
306}
307
308func (l *textShader) Post() {
309 l.lastBuffer = nil

Callers

nothing calls this directly

Calls 5

updateBufferMethod · 0.95
SincosFunction · 0.92
GetGlobalScaleFunction · 0.92
generateFontAtlasMethod · 0.80
unsupportedTypeFunction · 0.70

Tested by

no test coverage detected