Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/application/StarRenderer.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
commit6352e8e3196f78388b6c771073f9e03eaa612673 (patch)
treee23772f79a7fbc41bc9108951e9e136857484bf4 /source/application/StarRenderer.cpp
parent6741a057e5639280d85d0f88ba26f000baa58f61 (diff)
everything everywhere
all at once
Diffstat (limited to 'source/application/StarRenderer.cpp')
-rw-r--r--source/application/StarRenderer.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/source/application/StarRenderer.cpp b/source/application/StarRenderer.cpp
new file mode 100644
index 0000000..51b11c7
--- /dev/null
+++ b/source/application/StarRenderer.cpp
@@ -0,0 +1,60 @@
+#include "StarRenderer.hpp"
+
+namespace Star {
+
+EnumMap<TextureAddressing> const TextureAddressingNames{
+ {TextureAddressing::Clamp, "Clamp"},
+ {TextureAddressing::Wrap, "Wrap"}
+};
+
+EnumMap<TextureFiltering> const TextureFilteringNames{
+ {TextureFiltering::Nearest, "Nearest"},
+ {TextureFiltering::Linear, "Linear"}
+};
+
+RenderQuad renderTexturedRect(TexturePtr texture, Vec2F minPosition, float textureScale, Vec4B color, float param1) {
+ if (!texture)
+ throw RendererException("renderTexturedRect called with null texture");
+
+ auto textureSize = Vec2F(texture->size());
+ return {
+ move(texture),
+ RenderVertex{minPosition, Vec2F(0, 0), color, param1},
+ RenderVertex{minPosition + Vec2F(textureSize[0], 0) * textureScale, Vec2F(textureSize[0], 0), color, param1},
+ RenderVertex{minPosition + Vec2F(textureSize[0], textureSize[1]) * textureScale, Vec2F(textureSize[0], textureSize[1]), color, param1},
+ RenderVertex{minPosition + Vec2F(0, textureSize[1]) * textureScale, Vec2F(0, textureSize[1]), color, param1}
+ };
+}
+
+RenderQuad renderTexturedRect(TexturePtr texture, RectF const& screenCoords, Vec4B color, float param1) {
+ if (!texture)
+ throw RendererException("renderTexturedRect called with null texture");
+
+ auto textureSize = Vec2F(texture->size());
+ return {
+ move(texture),
+ RenderVertex{{screenCoords.xMin(), screenCoords.yMin()}, Vec2F(0, 0), color, param1},
+ RenderVertex{{screenCoords.xMax(), screenCoords.yMin()}, Vec2F(textureSize[0], 0), color, param1},
+ RenderVertex{{screenCoords.xMax(), screenCoords.yMax()}, Vec2F(textureSize[0], textureSize[1]), color, param1},
+ RenderVertex{{screenCoords.xMin(), screenCoords.yMax()}, Vec2F(0, textureSize[1]), color, param1}
+ };
+}
+
+RenderQuad renderFlatRect(RectF const& rect, Vec4B color, float param1) {
+ return {
+ {},
+ RenderVertex{{rect.xMin(), rect.yMin()}, {}, color, param1},
+ RenderVertex{{rect.xMax(), rect.yMin()}, {}, color, param1},
+ RenderVertex{{rect.xMax(), rect.yMax()}, {}, color, param1},
+ RenderVertex{{rect.xMin(), rect.yMax()}, {}, color, param1}
+ };
+}
+
+RenderPoly renderFlatPoly(PolyF const& poly, Vec4B color, float param1) {
+ RenderPoly renderPoly;
+ for (auto const& v : poly)
+ renderPoly.vertexes.append({v, {}, color, param1});
+ return renderPoly;
+}
+
+}