MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / drawDrawable

Method drawDrawable

source/rendering/StarDrawablePainter.cpp:10–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8}
9
10void DrawablePainter::drawDrawable(Drawable const& drawable) {
11 Vec4B color = drawable.color.toRgba();
12 auto& primitives = m_renderer->immediatePrimitives();
13
14 if (auto linePart = drawable.part.ptr<Drawable::LinePart>()) {
15 auto line = linePart->line;
16 line.translate(drawable.position);
17 Vec2F left = Vec2F(vnorm(line.diff())).rot90() * linePart->width / 2.0f;
18
19 float fullbright = drawable.fullbright ? 0.0f : 1.0f;
20 auto& primitive = primitives.emplace_back(std::in_place_type_t<RenderQuad>(),
21 line.min() + left,
22 line.min() - left,
23 line.max() - left,
24 line.max() + left,
25 color, fullbright);
26 if (auto* endColor = linePart->endColor.ptr()) {
27 RenderQuad& quad = primitive.get<RenderQuad>();
28 quad.c.color = quad.d.color = endColor->toRgba();
29 }
30 } else if (auto polyPart = drawable.part.ptr<Drawable::PolyPart>()) {
31 PolyF poly = polyPart->poly;
32 poly.translate(drawable.position);
33
34 primitives.emplace_back(std::in_place_type_t<RenderPoly>(), poly.vertexes(), color, 0.0f);
35
36 } else if (auto imagePart = drawable.part.ptr<Drawable::ImagePart>()) {
37 TexturePtr texture = m_textureGroup->loadTexture(imagePart->image);
38
39 Vec2F position = drawable.position;
40 Vec2F textureSize(texture->size());
41 Mat3F transformation = imagePart->transformation;
42 Vec2F lowerLeft = { transformation[0][2] += position.x(), transformation[1][2] += position.y() };
43 Vec2F lowerRight = transformation * Vec2F(textureSize.x(), 0.f);
44 Vec2F upperRight = transformation * textureSize;
45 Vec2F upperLeft = transformation * Vec2F(0.f, textureSize.y());
46
47 float param1 = drawable.fullbright ? 0.0f : 1.0f;
48
49 primitives.emplace_back(std::in_place_type_t<RenderQuad>(), std::move(texture),
50 lowerLeft, Vec2F{0, 0},
51 lowerRight, Vec2F{textureSize[0], 0},
52 upperRight, Vec2F{textureSize[0], textureSize[1]},
53 upperLeft, Vec2F{0, textureSize[1]},
54 color, param1);
55 }
56}
57
58void DrawablePainter::cleanup(int64_t textureTimeout) {
59 m_textureGroup->cleanup(textureTimeout);

Callers

nothing calls this directly

Calls 13

vnormFunction · 0.85
toRgbaMethod · 0.80
rot90Method · 0.80
loadTextureMethod · 0.80
xMethod · 0.80
yMethod · 0.80
translateMethod · 0.45
diffMethod · 0.45
emplace_backMethod · 0.45
minMethod · 0.45
maxMethod · 0.45
ptrMethod · 0.45

Tested by

no test coverage detected