Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

refactor: restructure C++ renderer with RenderFrame pipeline

esengine7aff0528f9fa
diff --git a/src/esengine/ecs/components/SpineAnimation.hpp b/src/esengine/ecs/components/SpineAnimation.hpp
new file mode 100644
index 000000000..5a0e77fdf
--- /dev/null
+++ b/src/esengine/ecs/components/SpineAnimation.hpp
@@ -0,0 +1,115 @@
+/**
+ * @file SpineAnimation.hpp
+ * @brief Spine skeletal animation component
+ * @details Provides SpineAnimation component for 2D skeletal animation
+ * using the Spine runtime.
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+#pragma once
+
+// =============================================================================
+// Includes
+// =============================================================================
+
+#include "../../core/Types.hpp"
+#include "../../core/Reflection.hpp"
+#include "../../math/Math.hpp"
+#include "../../resource/Handle.hpp"
+
+#include <string>
+
+namespace esengine::ecs {
+
+// =============================================================================
+// SpineAnimation Component
+// =============================================================================
+
+/**
+ * @brief Spine skeletal animation component
+ *
+ * @details Contains all data needed to render a Spine skeleton including
+ * skeleton/atlas paths, animation state, and rendering options.
+ *
+ * @code
+ * Entity e = registry.create();
+ * auto& spine = registry.emplace<SpineAnimation>(e);
+ * spine.skeletonPath = "assets/spine/character.skel";
+ * spine.atlasPath = "assets/spine/character.atlas";
+ * spine.animation = "idle";
+ * spine.loop = true;
+ * @endcode
+ */
+ES_COMPONENT()
+struct SpineAnimation {
+ /** @brief Path to skeleton data file (.skel or .json) */
+ ES_PROPERTY()
+ std::string skeletonPath;
+
+ /** @brief Path to atlas file (.atlas) */
+ ES_PROPERTY()
+ std::string atlasPath;
+
+ /** @brief Current skin name (empty for default) */
+ ES_PROPERTY()
+ std::string skin;
+
+ /** @brief Current animation name */
+ ES_PROPERTY()
+ std::string animation;
+
+ /** @brief Animation playback speed multiplier */
+ ES_PROPERTY()
+ f32 timeScale{1.0f};
+
+ /** @brief Whether to loop the animation */
+ ES_PROPERTY()
+ bool loop{true};
+
+ /** @brief Whether animation is currently playing */
+ ES_PROPERTY()
+ bool playing{true};
+
+ /** @brief Flip skeleton horizontally */
+ ES_PROPERTY()
+ bool flipX{false};
+
+ /** @brief Flip skeleton vertically */
+ ES_PROPERTY()
+ bool flipY{false};
+
+ /** @brief Color tint (RGBA, 0-1 range) */
+ ES_PROPERTY()
+ glm::vec4 color{1.0f, 1.0f, 1.0f, 1.0f};
+
+ /** @brief Sorting layer (higher = rendered on top) */
+ ES_PROPERTY()
+ i32 layer{0};
+
+ /** @brief Skeleton scale factor */
+ ES_PROPERTY()
+ f32 skeletonScale{1.0f};
+
+ /** @brief Handle to cached skeleton data (runtime, not serialized) */
+ resource::SpineDataHandle skeletonData;
+
+ /** @brief Flag indicating skeleton needs to be reloaded */
+ bool needsReload{true};
+
+ /** @brief Default constructor */
+ SpineAnimation() = default;
+
+ /**
+ * @brief Constructs SpineAnimation with paths
+ * @param skelPath Path to skeleton file
+ * @param atlPath Path to atlas file
+ */
+ SpineAnimation(const std::string& skelPath, const std::string& atlPath)
+ : skeletonPath(skelPath), atlasPath(atlPath) {}
+};
+
+} // namespace esengine::ecs
diff --git a/src/esengine/renderer/BlendMode.hpp b/src/esengine/renderer/BlendMode.hpp
new file mode 100644
index 000000000..49129bea6
--- /dev/null
+++ b/src/esengine/renderer/BlendMode.hpp
@@ -0,0 +1,28 @@
+/**
+ * @file BlendMode.hpp
+ * @brief Blend mode enumeration for custom rendering
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+#pragma once
+
+#include "../core/Types.hpp"
+
+namespace esengine {
+
+/**
+ * @brief Predefined blend modes for rendering
+ */
+enum class BlendMode : u8 {
+ Normal = 0, // SrcAlpha, OneMinusSrcAlpha (default alpha blending)
+ Additive = 1, // SrcAlpha, One (glow, particles)
+ Multiply = 2, // DstColor, OneMinusSrcAlpha (shadows, multiply)
+ Screen = 3, // One, OneMinusSrcAlpha (lighten)
+ PremultipliedAlpha = 4, // One, OneMinusSrcAlpha (premultiplied alpha)
+};
+
+} // namespace esengine
diff --git a/src/esengine/renderer/Buffer.cpp b/src/esengine/renderer/Buffer.cpp
index fea90f4f0..a9dbfd1f7 100644
--- a/src/esengine/renderer/Buffer.cpp
+++ b/src/esengine/renderer/Buffer.cpp
@@ -125,6 +125,17 @@ void VertexBuffer::setDataRaw(const void* data, u32 sizeBytes) {
#endif
}
+void VertexBuffer::setSubDataRaw(const void* data, u32 sizeBytes, u32 offsetBytes) {
+#if defined(ES_PLATFORM_WEB) || defined(ES_PLATFORM_NATIVE)
+ glBindBuffer(GL_ARRAY_BUFFER, bufferId_);
+ glBufferSubData(GL_ARRAY_BUFFER, offsetBytes, sizeBytes, data);
+#else
+ (void)data;
+ (void)sizeBytes;
+ (void)offsetBytes;
+#endif
+}
+
// ========================================
// IndexBuffer
// ========================================
diff --git a/src/esengine/renderer/Buffer.hpp b/src/esengine/renderer/Buffer.hpp
index 5b395a1cc..f46afac07 100644
--- a/src/esengine/renderer/Buffer.hpp
+++ b/src/esengine/renderer/Buffer.hpp
@@ -326,6 +326,14 @@ public:
*/
void setDataRaw(const void* data, u32 sizeBytes);
+ /**
+ * @brief Updates a portion of buffer data with offset (internal use)
+ * @param data Pointer to new data
+ * @param sizeBytes Size of data in bytes
+ * @param offsetBytes Offset in bytes from buffer start
+ */
+ void setSubDataRaw(const void* data, u32 sizeBytes, u32 offsetBytes);
+
private:
u32 bufferId_ = 0;
VertexLayout layout_;
diff --git a/src/esengine/renderer/CustomGeometry.cpp b/src/esengine/renderer/CustomGeometry.cpp
new file mode 100644
index 000000000..ecdb18372
--- /dev/null
+++ b/src/esengine/renderer/CustomGeometry.cpp
@@ -0,0 +1,139 @@
+/**
+ * @file CustomGeometry.cpp
+ * @brief Custom geometry implementation
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+
+#include "CustomGeometry.hpp"
+#include "../core/Log.hpp"
+
+namespace esengine {
+
+void CustomGeometry::init(const f32* vertices, u32 vertexCount, const VertexLayout& layout, bool dynamic) {
+ dynamic_ = dynamic;
+ stride_ = layout.getStride();
+ vertexCount_ = vertexCount * sizeof(f32) / stride_;
+
+ vao_ = VertexArray::create();
+
+ if (dynamic) {
+ vbo_ = makeShared<VertexBuffer>();
+ *vbo_ = std::move(*VertexBuffer::create(vertexCount * sizeof(f32)));
+ vbo_->setDataRaw(vertices, vertexCount * sizeof(f32));
+ } else {
+ vbo_ = makeShared<VertexBuffer>();
+ *vbo_ = std::move(*VertexBuffer::createRaw(vertices, vertexCount * sizeof(f32)));
+ }
+
+ vbo_->setLayout(layout);
+ vao_->addVertexBuffer(vbo_);
+}
+
+void CustomGeometry::setIndices(const u16* indices, u32 indexCount) {
+ if (!vao_) return;
+
+ ibo_ = makeShared<IndexBuffer>();
+ *ibo_ = std::move(*IndexBuffer::create(indices, indexCount));
+ vao_->setIndexBuffer(ibo_);
+}
+
+void CustomGeometry::setIndices(const u32* indices, u32 indexCount) {
+ if (!vao_) return;
+
+ ibo_ = makeShared<IndexBuffer>();
+ *ibo_ = std::move(*IndexBuffer::create(indices, indexCount));
+ vao_->setIndexBuffer(ibo_);
+}
+
+void CustomGeometry::updateVertices(const f32* vertices, u32 vertexCount, u32 offset) {
+ if (!dynamic_ || !vbo_) {
+ ES_LOG_WARN("Cannot update non-dynamic geometry");
+ return;
+ }
+
+ vbo_->setSubDataRaw(vertices, vertexCount * sizeof(f32), offset * sizeof(f32));
+
+ u32 endOffset = offset + vertexCount;
+ u32 newVertexCount = endOffset * sizeof(f32) / stride_;
+ if (newVertexCount > vertexCount_) {
+ vertexCount_ = newVertexCount;
+ }
+}
+
+void CustomGeometry::bind() const {
+ if (vao_) {
+ vao_->bind();
+ }
+}
+
+void CustomGeometry::unbind() const {
+ if (vao_) {
+ vao_->unbind();
+ }
+}
+
+u32 CustomGeometry::getIndexCount() const {
+ if (ibo_) {
+ return ibo_->getCount();
+ }
+ return 0;
+}
+
+bool CustomGeometry::hasIndices() const {
+ return ibo_ != nullptr && ibo_->getCount() > 0;
+}
+
+// =============================================================================
+// GeometryManager Implementation
+// =============================================================================
+
+GeometryManager::GeometryHandle GeometryManager::create() {
+ GeometryHandle handle;
+
+ if (!freeList_.empty()) {
+ handle = freeList_.back();
+ freeList_.pop_back();
+ geometries_[handle - 1] = makeUnique<CustomGeometry>();
+ } else {
+ handle = nextHandle_++;
+ geometries_.push_back(makeUnique<CustomGeometry>());
+ }
+
+ return handle;
+}
+
+CustomGeometry* GeometryManager::get(GeometryHandle handle) {
+ if (handle == INVALID_HANDLE || handle > geometries_.size()) {
+ return nullptr;
+ }
+ return geometries_[handle - 1].get();
+}
+
+const CustomGeometry* GeometryManager::get(GeometryHandle handle) const {
+ if (handle == INVALID_HANDLE || handle > geometries_.size()) {
+ return nullptr;
+ }
+ return geometries_[handle - 1].get();
+}
+
+void GeometryManager::release(GeometryHandle handle) {
+ if (handle == INVALID_HANDLE || handle > geometries_.size()) {
+ return;
+ }
+ geometries_[handle - 1].reset();
+ freeList_.push_back(handle);
+}
+
+bool GeometryManager::isValid(GeometryHandle handle) const {
+ if (handle == INVALID_HANDLE || handle > geometries_.size()) {
+ return false;
+ }
+ return geometries_[handle - 1] != nullptr;
+}
+
+} // namespace esengine
diff --git a/src/esengine/renderer/CustomGeometry.hpp b/src/esengine/renderer/CustomGeometry.hpp
new file mode 100644
index 000000000..fa73824d8
--- /dev/null
+++ b/src/esengine/renderer/CustomGeometry.hpp
@@ -0,0 +1,156 @@
+/**
+ * @file CustomGeometry.hpp
+ * @brief Custom geometry for user-defined mesh rendering
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+#pragma once
+
+#include "../core/Types.hpp"
+#include "Buffer.hpp"
+
+#include <vector>
+
+namespace esengine {
+
+/**
+ * @brief Custom geometry for user-defined mesh rendering
+ *
+ * @details Manages vertex buffer and index buffer with support for dynamic updates.
+ * Used for custom shapes, particles, trails, and other procedural geometry.
+ */
+class CustomGeometry {
+public:
+ CustomGeometry() = default;
+ ~CustomGeometry() = default;
+
+ CustomGeometry(const CustomGeometry&) = delete;
+ CustomGeometry& operator=(const CustomGeometry&) = delete;
+ CustomGeometry(CustomGeometry&&) = default;
+ CustomGeometry& operator=(CustomGeometry&&) = default;
+
+ /**
+ * @brief Initializes geometry with vertex data and layout
+ * @param vertices Pointer to vertex data
+ * @param vertexCount Number of floats in vertex data
+ * @param layout Vertex attribute layout
+ * @param dynamic If true, allows vertex updates
+ */
+ void init(const f32* vertices, u32 vertexCount, const VertexLayout& layout, bool dynamic = false);
+
+ /**
+ * @brief Sets indices for indexed rendering
+ * @param indices Pointer to index data
+ * @param indexCount Number of indices
+ */
+ void setIndices(const u16* indices, u32 indexCount);
+
+ /**
+ * @brief Sets indices for indexed rendering (32-bit)
+ * @param indices Pointer to index data
+ * @param indexCount Number of indices
+ */
+ void setIndices(const u32* indices, u32 indexCount);
+
+ /**
+ * @brief Updates vertex data (only for dynamic geometry)
+ * @param vertices Pointer to new vertex data
+ * @param vertexCount Number of floats
+ * @param offset Offset in floats from start
+ */
+ void updateVertices(const f32* vertices, u32 vertexCount, u32 offset = 0);
+
+ /**
+ * @brief Binds the geometry for rendering
+ */
+ void bind() const;
+
+ /**
+ * @brief Unbinds the geometry
+ */
+ void unbind() const;
+
+ /**
+ * @brief Gets the VAO for rendering
+ */
+ VertexArray* getVAO() { return vao_.get(); }
+ const VertexArray* getVAO() const { return vao_.get(); }
+
+ /**
+ * @brief Gets the index count
+ */
+ u32 getIndexCount() const;
+
+ /**
+ * @brief Gets the vertex count
+ */
+ u32 getVertexCount() const { return vertexCount_; }
+
+ /**
+ * @brief Checks if geometry uses indices
+ */
+ bool hasIndices() const;
+
+ /**
+ * @brief Checks if geometry is dynamic
+ */
+ bool isDynamic() const { return dynamic_; }
+
+ /**
+ * @brief Checks if geometry is initialized
+ */
+ bool isValid() const { return vao_ != nullptr; }
+
+private:
+ Unique<VertexArray> vao_;
+ Shared<VertexBuffer> vbo_;
+ Shared<IndexBuffer> ibo_;
+ u32 vertexCount_ = 0;
+ u32 stride_ = 0;
+ bool dynamic_ = false;
+};
+
+/**
+ * @brief Manager for custom geometries
+ */
+class GeometryManager {
+public:
+ using GeometryHandle = u32;
+ static constexpr GeometryHandle INVALID_HANDLE = 0;
+
+ GeometryManager() = default;
+ ~GeometryManager() = default;
+
+ /**
+ * @brief Creates a new geometry
+ * @return Handle to the geometry
+ */
+ GeometryHandle create();
+
+ /**
+ * @brief Gets a geometry by handle
+ */
+ CustomGeometry* get(GeometryHandle handle);
+ const CustomGeometry* get(GeometryHandle handle) const;
+
+ /**
+ * @brief Releases a geometry
+ */
+ void release(GeometryHandle handle);
+
+ /**
+ * @brief Checks if handle is valid
+ */
+ bool isValid(GeometryHandle handle) const;
+
+private:
+ std::vector<Unique<CustomGeometry>> geometries_;
+ std::vector<GeometryHandle> freeList_;
+ GeometryHandle nextHandle_ = 1;
+};
+
+} // namespace esengine
diff --git a/src/esengine/renderer/ImmediateDraw.cpp b/src/esengine/renderer/ImmediateDraw.cpp
new file mode 100644
index 000000000..d819aeea1
--- /dev/null
+++ b/src/esengine/renderer/ImmediateDraw.cpp
@@ -0,0 +1,237 @@
+/**
+ * @file ImmediateDraw.cpp
+ * @brief Immediate mode 2D drawing implementation
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+
+#include "ImmediateDraw.hpp"
+#include "Renderer.hpp"
+#include "RenderContext.hpp"
+#include "../resource/ResourceManager.hpp"
+#include "../core/Log.hpp"
+
+#include <glm/gtc/constants.hpp>
+#include <cmath>
+
+namespace esengine {
+
+struct ImmediateDraw::Impl {
+ Unique<BatchRenderer2D> batcher;
+ glm::mat4 viewProjection{1.0f};
+};
+
+ImmediateDraw::ImmediateDraw(RenderContext& context,
+ resource::ResourceManager& resource_manager)
+ : impl_(makeUnique<Impl>())
+ , context_(context)
+ , resource_manager_(resource_manager) {
+}
+
+ImmediateDraw::~ImmediateDraw() {
+ if (initialized_) {
+ shutdown();
+ }
+}
+
+void ImmediateDraw::init() {
+ if (initialized_) return;
+
+ impl_->batcher = makeUnique<BatchRenderer2D>(context_, resource_manager_);
+ impl_->batcher->init();
+
+ initialized_ = true;
+ ES_LOG_INFO("ImmediateDraw initialized");
+}
+
+void ImmediateDraw::shutdown() {
+ if (!initialized_) return;
+
+ if (impl_->batcher) {
+ impl_->batcher->shutdown();
+ impl_->batcher.reset();
+ }
+
+ initialized_ = false;
+ ES_LOG_INFO("ImmediateDraw shutdown");
+}
+
+void ImmediateDraw::begin(const glm::mat4& viewProjection) {
+ if (!initialized_) return;
+
+ impl_->viewProjection = viewProjection;
+ impl_->batcher->setProjection(viewProjection);
+ impl_->batcher->beginBatch();
+
+ primitiveCount_ = 0;
+ inFrame_ = true;
+}
+
+void ImmediateDraw::end() {
+ if (!initialized_ || !inFrame_) return;
+
+ impl_->batcher->endBatch();
+ inFrame_ = false;
+}
+
+void ImmediateDraw::line(const glm::vec2& from, const glm::vec2& to,
+ const glm::vec4& color, f32 thickness) {
+ if (!inFrame_) return;
+
+ glm::vec2 delta = to - from;
+ f32 length = glm::length(delta);
+ if (length < 0.0001f) return;
+
+ glm::vec2 dir = delta / length;
+ glm::vec2 center = (from + to) * 0.5f;
+ glm::vec2 size(length, thickness);
+
+ f32 angle = std::atan2(dir.y, dir.x);
+
+ impl_->batcher->drawRotatedQuad(center, size, angle, color);
+ primitiveCount_++;
+}
+
+void ImmediateDraw::polyline(std::span<const glm::vec2> vertices,
+ const glm::vec4& color, f32 thickness, bool closed) {
+ if (!inFrame_ || vertices.size() < 2) return;
+
+ for (size_t i = 0; i < vertices.size() - 1; ++i) {
+ line(vertices[i], vertices[i + 1], color, thickness);
+ }
+
+ if (closed && vertices.size() > 2) {
+ line(vertices.back(), vertices.front(), color, thickness);
+ }
+}
+
+void ImmediateDraw::rect(const glm::vec2& position, const glm::vec2& size,
+ const glm::vec4& color, bool filled) {
+ if (!inFrame_) return;
+
+ if (filled) {
+ impl_->batcher->drawQuad(position, size, color);
+ primitiveCount_++;
+ } else {
+ rectOutline(position, size, color, 1.0f);
+ }
+}
+
+void ImmediateDraw::rectOutline(const glm::vec2& position, const glm::vec2& size,
+ const glm::vec4& color, f32 thickness) {
+ if (!inFrame_) return;
+
+ f32 halfW = size.x * 0.5f;
+ f32 halfH = size.y * 0.5f;
+
+ glm::vec2 tl(position.x - halfW, position.y + halfH);
+ glm::vec2 tr(position.x + halfW, position.y + halfH);
+ glm::vec2 br(position.x + halfW, position.y - halfH);
+ glm::vec2 bl(position.x - halfW, position.y - halfH);
+
+ line(tl, tr, color, thickness);
+ line(tr, br, color, thickness);
+ line(br, bl, color, thickness);
+ line(bl, tl, color, thickness);
+}
+
+void ImmediateDraw::circle(const glm::vec2& center, f32 radius,
+ const glm::vec4& color, bool filled, i32 segments) {
+ if (!inFrame_ || segments < 3) return;
+
+ if (filled) {
+ for (i32 i = 0; i < segments; ++i) {
+ f32 angle1 = static_cast<f32>(i) / static_cast<f32>(segments) * glm::two_pi<f32>();
+ f32 angle2 = static_cast<f32>(i + 1) / static_cast<f32>(segments) * glm::two_pi<f32>();
+
+ glm::vec2 p1 = center + glm::vec2(std::cos(angle1), std::sin(angle1)) * radius;
+ glm::vec2 p2 = center + glm::vec2(std::cos(angle2), std::sin(angle2)) * radius;
+
+ glm::vec2 edge = p2 - p1;
+ f32 baseLen = glm::length(edge);
+ glm::vec2 toCenter = center - (p1 + p2) * 0.5f;
+ f32 height = glm::length(toCenter);
+
+ f32 angle = std::atan2(edge.y, edge.x);
+ glm::vec2 midBase = (p1 + p2) * 0.5f;
+ glm::vec2 triangleCenter = midBase + glm::normalize(toCenter) * (height / 3.0f);
+
+ impl_->batcher->drawRotatedQuad(triangleCenter, glm::vec2(baseLen, height), angle - glm::half_pi<f32>(), color);
+ primitiveCount_++;
+ }
+ } else {
+ circleOutline(center, radius, color, 1.0f, segments);
+ }
+}
+
+void ImmediateDraw::circleOutline(const glm::vec2& center, f32 radius,
+ const glm::vec4& color, f32 thickness, i32 segments) {
+ if (!inFrame_ || segments < 3) return;
+
+ for (i32 i = 0; i < segments; ++i) {
+ f32 angle1 = static_cast<f32>(i) / static_cast<f32>(segments) * glm::two_pi<f32>();
+ f32 angle2 = static_cast<f32>(i + 1) / static_cast<f32>(segments) * glm::two_pi<f32>();
+
+ glm::vec2 p1 = center + glm::vec2(std::cos(angle1), std::sin(angle1)) * radius;
+ glm::vec2 p2 = center + glm::vec2(std::cos(angle2), std::sin(angle2)) * radius;
+
+ line(p1, p2, color, thickness);
+ }
+}
+
+void ImmediateDraw::polygon(std::span<const glm::vec2> vertices,
+ const glm::vec4& color) {
+ if (!inFrame_ || vertices.size() < 3) return;
+
+ glm::vec2 center(0.0f);
+ for (const auto& v : vertices) {
+ center += v;
+ }
+ center /= static_cast<f32>(vertices.size());
+
+ for (size_t i = 0; i < vertices.size(); ++i) {
+ const glm::vec2& p1 = vertices[i];
+ const glm::vec2& p2 = vertices[(i + 1) % vertices.size()];
+
+ glm::vec2 edge = p2 - p1;
+ f32 baseLen = glm::length(edge);
+ if (baseLen < 0.0001f) continue;
+
+ glm::vec2 midBase = (p1 + p2) * 0.5f;
+ glm::vec2 toCenter = center - midBase;
+ f32 height = glm::length(toCenter);
+ if (height < 0.0001f) continue;
+
+ f32 angle = std::atan2(edge.y, edge.x);
+ glm::vec2 triangleCenter = midBase + glm::normalize(toCenter) * (height / 3.0f);
+
+ impl_->batcher->drawRotatedQuad(triangleCenter, glm::vec2(baseLen, height), angle - glm::half_pi<f32>(), color);
+ primitiveCount_++;
+ }
+}
+
+void ImmediateDraw::texture(const glm::vec2& position, const glm::vec2& size,
+ u32 textureId, const glm::vec4& tint) {
+ if (!inFrame_) return;
+
+ impl_->batcher->drawQuad(position, size, textureId, tint);
+ primitiveCount_++;
+}
+
+void ImmediateDraw::textureRotated(const glm::vec2& position, const glm::vec2& size,
+ f32 rotation, u32 textureId, const glm::vec4& tint) {
+ if (!inFrame_) return;
+
+ impl_->batcher->drawRotatedQuad(position, size, rotation, textureId, tint);
+ primitiveCount_++;
+}
+
+u32 ImmediateDraw::getDrawCallCount() const {
+ return impl_->batcher ? impl_->batcher->getDrawCallCount() : 0;
+}
+
+} // namespace esengine
diff --git a/src/esengine/renderer/ImmediateDraw.hpp b/src/esengine/renderer/ImmediateDraw.hpp
new file mode 100644
index 000000000..e44d93763
--- /dev/null
+++ b/src/esengine/renderer/ImmediateDraw.hpp
@@ -0,0 +1,246 @@
+/**
+ * @file ImmediateDraw.hpp
+ * @brief Immediate mode 2D drawing API
+ * @details Provides simple, immediate mode drawing primitives (lines, rectangles,
+ * circles, polygons) with automatic batching for efficient rendering.
+ * All draw commands are cleared each frame.
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+#pragma once
+
+#include "../core/Types.hpp"
+#include "../math/Math.hpp"
+
+#include <glm/glm.hpp>
+#include <vector>
+#include <span>
+
+namespace esengine {
+
+class RenderContext;
+class BatchRenderer2D;
+
+namespace resource {
+ class ResourceManager;
+}
+
+/**
+ * @brief Immediate mode 2D drawing API
+ *
+ * @details Provides a simple API for drawing 2D primitives. All commands
+ * submitted between begin() and end() are batched for efficient
+ * rendering. The draw buffer is automatically cleared each frame.
+ *
+ * @code
+ * ImmediateDraw draw(context, resourceManager);
+ * draw.init();
+ *
+ * // Each frame
+ * draw.begin(viewProjection);
+ * draw.line({0, 0}, {100, 100}, {1, 0, 0, 1});
+ * draw.rect({50, 50}, {30, 30}, {0, 1, 0, 1});
+ * draw.circle({150, 150}, 25, {0, 0, 1, 1});
+ * draw.end();
+ * @endcode
+ */
+class ImmediateDraw {
+public:
+ /**
+ * @brief Constructs an immediate draw instance
+ * @param context Render context for shared resources
+ * @param resource_manager Resource manager for shader/texture access
+ */
+ ImmediateDraw(RenderContext& context, resource::ResourceManager& resource_manager);
+ ~ImmediateDraw();
+
+ ImmediateDraw(const ImmediateDraw&) = delete;
+ ImmediateDraw& operator=(const ImmediateDraw&) = delete;
+
+ // =========================================================================
+ // Lifecycle
+ // =========================================================================
+
+ void init();
+ void shutdown();
+
+ // =========================================================================
+ // Frame Management
+ // =========================================================================
+
+ /**
+ * @brief Begins a new draw frame
+ * @param viewProjection Combined view-projection matrix
+ */
+ void begin(const glm::mat4& viewProjection);
+
+ /**
+ * @brief Ends the frame and submits all draw commands
+ */
+ void end();
+
+ // =========================================================================
+ // Line Drawing
+ // =========================================================================
+
+ /**
+ * @brief Draws a line between two points
+ * @param from Start point
+ * @param to End point
+ * @param color RGBA color
+ * @param thickness Line thickness in pixels (default: 1.0)
+ */
+ void line(const glm::vec2& from, const glm::vec2& to,
+ const glm::vec4& color, f32 thickness = 1.0f);
+
+ /**
+ * @brief Draws a polyline through multiple points
+ * @param vertices Array of points
+ * @param color RGBA color
+ * @param thickness Line thickness in pixels (default: 1.0)
+ * @param closed If true, connects last point to first (default: false)
+ */
+ void polyline(std::span<const glm::vec2> vertices, const glm::vec4& color,
+ f32 thickness = 1.0f, bool closed = false);
+
+ // =========================================================================
+ // Rectangle Drawing
+ // =========================================================================
+
+ /**
+ * @brief Draws a filled or outlined rectangle
+ * @param position Center position
+ * @param size Width and height
+ * @param color RGBA color
+ * @param filled If true, draws filled; if false, draws outline (default: true)
+ */
+ void rect(const glm::vec2& position, const glm::vec2& size,
+ const glm::vec4& color, bool filled = true);
+
+ /**
+ * @brief Draws a rectangle outline
+ * @param position Center position
+ * @param size Width and height
+ * @param color RGBA color
+ * @param thickness Line thickness in pixels (default: 1.0)
+ */
+ void rectOutline(const glm::vec2& position, const glm::vec2& size,
+ const glm::vec4& color, f32 thickness = 1.0f);
+
+ // =========================================================================
+ // Circle Drawing
+ // =========================================================================
+
+ /**
+ * @brief Draws a filled or outlined circle
+ * @param center Center position
+ * @param radius Circle radius
+ * @param color RGBA color
+ * @param filled If true, draws filled; if false, draws outline (default: true)
+ * @param segments Number of segments for approximation (default: 32)
+ */
+ void circle(const glm::vec2& center, f32 radius,
+ const glm::vec4& color, bool filled = true, i32 segments = 32);
+
+ /**
+ * @brief Draws a circle outline
+ * @param center Center position
+ * @param radius Circle radius
+ * @param color RGBA color
+ * @param thickness Line thickness in pixels (default: 1.0)
+ * @param segments Number of segments for approximation (default: 32)
+ */
+ void circleOutline(const glm::vec2& center, f32 radius,
+ const glm::vec4& color, f32 thickness = 1.0f, i32 segments = 32);
+
+ // =========================================================================
+ // Polygon Drawing
+ // =========================================================================
+
+ /**
+ * @brief Draws a filled polygon
+ * @param vertices Array of vertices (must be convex for correct fill)
+ * @param color RGBA color
+ */
+ void polygon(std::span<const glm::vec2> vertices, const glm::vec4& color);
+
+ // =========================================================================
+ // Texture Drawing
+ // =========================================================================
+
+ /**
+ * @brief Draws a textured quad
+ * @param position Center position
+ * @param size Width and height
+ * @param textureId GPU texture handle
+ * @param tint Color tint (default: white)
+ */
+ void texture(const glm::vec2& position, const glm::vec2& size,
+ u32 textureId, const glm::vec4& tint = glm::vec4(1.0f));
+
+ /**
+ * @brief Draws a rotated textured quad
+ * @param position Center position
+ * @param size Width and height
+ * @param rotation Rotation angle in radians
+ * @param textureId GPU texture handle
+ * @param tint Color tint (default: white)
+ */
+ void textureRotated(const glm::vec2& position, const glm::vec2& size,
+ f32 rotation, u32 textureId,
+ const glm::vec4& tint = glm::vec4(1.0f));
+
+ // =========================================================================
+ // Configuration
+ // =========================================================================
+
+ /**
+ * @brief Sets the current render layer
+ * @param layer Layer index (higher layers render on top)
+ */
+ void setLayer(i32 layer) { currentLayer_ = layer; }
+
+ /**
+ * @brief Gets the current render layer
+ * @return Current layer index
+ */
+ i32 getLayer() const { return currentLayer_; }
+
+ /**
+ * @brief Sets the current depth for sorting within a layer
+ * @param depth Z depth value
+ */
+ void setDepth(f32 depth) { currentDepth_ = depth; }
+
+ /**
+ * @brief Gets the current depth
+ * @return Current depth value
+ */
+ f32 getDepth() const { return currentDepth_; }
+
+ // =========================================================================
+ // Statistics
+ // =========================================================================
+
+ u32 getDrawCallCount() const;
+ u32 getPrimitiveCount() const { return primitiveCount_; }
+
+private:
+ struct Impl;
+ Unique<Impl> impl_;
+
+ RenderContext& context_;
+ resource::ResourceManager& resource_manager_;
+
+ i32 currentLayer_ = 0;
+ f32 currentDepth_ = 0.0f;
+ u32 primitiveCount_ = 0;
+ bool initialized_ = false;
+ bool inFrame_ = false;
+};
+
+} // namespace esengine
diff --git a/src/esengine/renderer/PostProcessPipeline.cpp b/src/esengine/renderer/PostProcessPipeline.cpp
new file mode 100644
index 000000000..20e5b32b2
--- /dev/null
+++ b/src/esengine/renderer/PostProcessPipeline.cpp
@@ -0,0 +1,322 @@
+/**
+ * @file PostProcessPipeline.cpp
+ * @brief Post-processing effects pipeline implementation
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+
+#include "PostProcessPipeline.hpp"
+#include "RenderContext.hpp"
+#include "RenderCommand.hpp"
+#include "Shader.hpp"
+#include "../resource/ResourceManager.hpp"
+#include "../core/Log.hpp"
+
+#ifdef ES_PLATFORM_WEB
+ #include <GLES3/gl3.h>
+#else
+ #ifdef _WIN32
+ #include <windows.h>
+ #endif
+ #include <glad/glad.h>
+#endif
+
+namespace esengine {
+
+static const char* BLIT_VERTEX = R"(#version 300 es
+precision highp float;
+
+layout(location = 0) in vec2 a_position;
+layout(location = 1) in vec2 a_texCoord;
+
+out vec2 v_texCoord;
+
+void main() {
+ v_texCoord = a_texCoord;
+ gl_Position = vec4(a_position, 0.0, 1.0);
+}
+)";
+
+static const char* BLIT_FRAGMENT = R"(#version 300 es
+precision highp float;
+
+in vec2 v_texCoord;
+uniform sampler2D u_texture;
+out vec4 fragColor;
+
+void main() {
+ fragColor = texture(u_texture, v_texCoord);
+}
+)";
+
+PostProcessPipeline::PostProcessPipeline(RenderContext& context,
+ resource::ResourceManager& resourceManager)
+ : context_(context)
+ , resourceManager_(resourceManager) {
+}
+
+PostProcessPipeline::~PostProcessPipeline() {
+ if (initialized_) {
+ shutdown();
+ }
+}
+
+void PostProcessPipeline::init(u32 width, u32 height) {
+ if (initialized_) return;
+
+ width_ = width;
+ height_ = height;
+
+ FramebufferSpec spec;
+ spec.width = width;
+ spec.height = height;
+ spec.depthStencil = false;
+
+ fboA_ = Framebuffer::create(spec);
+ fboB_ = Framebuffer::create(spec);
+
+ if (!fboA_ || !fboB_) {
+ ES_LOG_ERROR("PostProcessPipeline: Failed to create framebuffers");
+ return;
+ }
+
+ f32 quadVertices[] = {
+ // position texCoord
+ -1.0f, -1.0f, 0.0f, 0.0f,
+ 1.0f, -1.0f, 1.0f, 0.0f,
+ 1.0f, 1.0f, 1.0f, 1.0f,
+ -1.0f, 1.0f, 0.0f, 1.0f,
+ };
+
+ u16 quadIndices[] = { 0, 1, 2, 2, 3, 0 };
+
+ screenQuadVAO_ = VertexArray::create();
+
+ auto vbo = makeShared<VertexBuffer>();
+ *vbo = std::move(*VertexBuffer::createRaw(quadVertices, sizeof(quadVertices)));
+ vbo->setLayout({
+ { ShaderDataType::Float2, "a_position" },
+ { ShaderDataType::Float2, "a_texCoord" },
+ });
+ screenQuadVAO_->addVertexBuffer(vbo);
+
+ auto ibo = makeShared<IndexBuffer>();
+ *ibo = std::move(*IndexBuffer::create(quadIndices, 6));
+ screenQuadVAO_->setIndexBuffer(ibo);
+
+ blitShader_ = resourceManager_.createShader(BLIT_VERTEX, BLIT_FRAGMENT);
+ if (!blitShader_.isValid()) {
+ ES_LOG_ERROR("PostProcessPipeline: Failed to create blit shader");
+ return;
+ }
+
+ initialized_ = true;
+ ES_LOG_INFO("PostProcessPipeline initialized ({}x{})", width, height);
+}
+
+void PostProcessPipeline::shutdown() {
+ if (!initialized_) return;
+
+ passes_.clear();
+ screenQuadVAO_.reset();
+ fboA_.reset();
+ fboB_.reset();
+
+ if (blitShader_.isValid()) {
+ resourceManager_.releaseShader(blitShader_);
+ }
+
+ initialized_ = false;
+ ES_LOG_INFO("PostProcessPipeline shutdown");
+}
+
+void PostProcessPipeline::resize(u32 width, u32 height) {
+ if (!initialized_) return;
+
+ width_ = width;
+ height_ = height;
+
+ if (fboA_) fboA_->resize(width, height);
+ if (fboB_) fboB_->resize(width, height);
+}
+
+u32 PostProcessPipeline::addPass(const std::string& name, resource::ShaderHandle shader) {
+ PostProcessPass pass;
+ pass.name = name;
+ pass.shader = shader;
+ pass.enabled = true;
+
+ passes_.push_back(pass);
+ return static_cast<u32>(passes_.size() - 1);
+}
+
+void PostProcessPipeline::removePass(const std::string& name) {
+ auto it = std::find_if(passes_.begin(), passes_.end(),
+ [&name](const PostProcessPass& p) { return p.name == name; });
+
+ if (it != passes_.end()) {
+ passes_.erase(it);
+ }
+}
+
+void PostProcessPipeline::setPassEnabled(const std::string& name, bool enabled) {
+ if (auto* pass = findPass(name)) {
+ pass->enabled = enabled;
+ }
+}
+
+bool PostProcessPipeline::isPassEnabled(const std::string& name) const {
+ for (const auto& pass : passes_) {
+ if (pass.name == name) {
+ return pass.enabled;
+ }
+ }
+ return false;
+}
+
+void PostProcessPipeline::setPassUniformFloat(const std::string& passName,
+ const std::string& uniform, f32 value) {
+ if (auto* pass = findPass(passName)) {
+ pass->floatUniforms[uniform] = value;
+ }
+}
+
+void PostProcessPipeline::setPassUniformVec4(const std::string& passName,
+ const std::string& uniform,
+ const glm::vec4& value) {
+ if (auto* pass = findPass(passName)) {
+ pass->vec4Uniforms[uniform] = value;
+ }
+}
+
+const PostProcessPass* PostProcessPipeline::getPass(u32 index) const {
+ if (index >= passes_.size()) return nullptr;
+ return &passes_[index];
+}
+
+const PostProcessPass* PostProcessPipeline::getPass(const std::string& name) const {
+ for (const auto& pass : passes_) {
+ if (pass.name == name) {
+ return &pass;
+ }
+ }
+ return nullptr;
+}
+
+PostProcessPass* PostProcessPipeline::findPass(const std::string& name) {
+ for (auto& pass : passes_) {
+ if (pass.name == name) {
+ return &pass;
+ }
+ }
+ return nullptr;
+}
+
+void PostProcessPipeline::begin() {
+ if (!initialized_ || inFrame_ || bypass_) return;
+
+ fboA_->bind();
+ RenderCommand::setViewport(0, 0, width_, height_);
+ RenderCommand::clear();
+
+ inFrame_ = true;
+ currentFBO_ = 0;
+}
+
+void PostProcessPipeline::end() {
+ if (!initialized_ || !inFrame_ || bypass_) return;
+
+ u32 enabledCount = 0;
+ for (const auto& pass : passes_) {
+ if (pass.enabled) enabledCount++;
+ }
+
+ if (enabledCount == 0) {
+ fboA_->unbind();
+ blitToScreen(fboA_->getColorAttachment());
+ inFrame_ = false;
+ return;
+ }
+
+ u32 inputTexture = fboA_->getColorAttachment();
+ currentFBO_ = 0;
+
+ for (const auto& pass : passes_) {
+ if (!pass.enabled) continue;
+
+ Framebuffer* targetFBO = (currentFBO_ == 0) ? fboB_.get() : fboA_.get();
+ targetFBO->bind();
+ RenderCommand::setViewport(0, 0, width_, height_);
+
+ renderPass(pass, inputTexture);
+
+ inputTexture = targetFBO->getColorAttachment();
+ currentFBO_ = 1 - currentFBO_;
+ }
+
+ Framebuffer* lastFBO = (currentFBO_ == 0) ? fboA_.get() : fboB_.get();
+ lastFBO->unbind();
+
+ blitToScreen(inputTexture);
+ inFrame_ = false;
+}
+
+void PostProcessPipeline::renderPass(const PostProcessPass& pass, u32 inputTexture) {
+ Shader* shader = resourceManager_.getShader(pass.shader);
+ if (!shader) return;
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, inputTexture);
+
+ shader->bind();
+ shader->setUniform("u_texture", 0);
+ shader->setUniform("u_resolution", glm::vec2(static_cast<f32>(width_), static_cast<f32>(height_)));
+
+ for (const auto& [name, value] : pass.floatUniforms) {
+ shader->setUniform(name, value);
+ }
+
+ for (const auto& [name, value] : pass.vec4Uniforms) {
+ shader->setUniform(name, value);
+ }
+
+ RenderCommand::setDepthTest(false);
+ RenderCommand::setBlending(false);
+
+ RenderCommand::drawIndexed(*screenQuadVAO_, 6);
+
+ RenderCommand::setBlending(true);
+}
+
+void PostProcessPipeline::blitToScreen(u32 texture) {
+ Shader* shader = resourceManager_.getShader(blitShader_);
+ if (!shader) return;
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, texture);
+
+ shader->bind();
+ shader->setUniform("u_texture", 0);
+
+ RenderCommand::setDepthTest(false);
+ RenderCommand::setBlending(false);
+
+ RenderCommand::drawIndexed(*screenQuadVAO_, 6);
+
+ RenderCommand::setBlending(true);
+}
+
+u32 PostProcessPipeline::getSourceTexture() const {
+ return fboA_ ? fboA_->getColorAttachment() : 0;
+}
+
+u32 PostProcessPipeline::getOutputTexture() const {
+ if (!fboA_ || !fboB_) return 0;
+ return (currentFBO_ == 0) ? fboA_->getColorAttachment() : fboB_->getColorAttachment();
+}
+
+} // namespace esengine
diff --git a/src/esengine/renderer/PostProcessPipeline.hpp b/src/esengine/renderer/PostProcessPipeline.hpp
new file mode 100644
index 000000000..be9db0faa
--- /dev/null
+++ b/src/esengine/renderer/PostProcessPipeline.hpp
@@ -0,0 +1,180 @@
+/**
+ * @file PostProcessPipeline.hpp
+ * @brief Post-processing effects pipeline
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+#pragma once
+
+#include "../core/Types.hpp"
+#include "../resource/Handle.hpp"
+#include "../math/Math.hpp"
+#include "Framebuffer.hpp"
+#include "Buffer.hpp"
+
+#include <glm/glm.hpp>
+#include <string>
+#include <vector>
+#include <unordered_map>
+
+namespace esengine {
+
+class RenderContext;
+
+namespace resource {
+ class ResourceManager;
+}
+
+/**
+ * @brief Post-processing pass configuration
+ */
+struct PostProcessPass {
+ std::string name;
+ resource::ShaderHandle shader;
+ bool enabled = true;
+ std::unordered_map<std::string, f32> floatUniforms;
+ std::unordered_map<std::string, glm::vec4> vec4Uniforms;
+};
+
+/**
+ * @brief Post-processing effects pipeline
+ *
+ * @details Manages a chain of full-screen post-processing effects using
+ * ping-pong framebuffers. Effects are applied in order.
+ */
+class PostProcessPipeline {
+public:
+ PostProcessPipeline(RenderContext& context, resource::ResourceManager& resourceManager);
+ ~PostProcessPipeline();
+
+ PostProcessPipeline(const PostProcessPipeline&) = delete;
+ PostProcessPipeline& operator=(const PostProcessPipeline&) = delete;
+
+ /**
+ * @brief Initializes the pipeline with given dimensions
+ */
+ void init(u32 width, u32 height);
+
+ /**
+ * @brief Shuts down and releases resources
+ */
+ void shutdown();
+
+ /**
+ * @brief Resizes the framebuffers
+ */
+ void resize(u32 width, u32 height);
+
+ /**
+ * @brief Adds a post-processing pass
+ * @param name Unique name for the pass
+ * @param shader Shader handle for the effect
+ * @return Index of the added pass
+ */
+ u32 addPass(const std::string& name, resource::ShaderHandle shader);
+
+ /**
+ * @brief Removes a pass by name
+ */
+ void removePass(const std::string& name);
+
+ /**
+ * @brief Enables or disables a pass
+ */
+ void setPassEnabled(const std::string& name, bool enabled);
+
+ /**
+ * @brief Checks if a pass is enabled
+ */
+ bool isPassEnabled(const std::string& name) const;
+
+ /**
+ * @brief Sets a float uniform for a pass
+ */
+ void setPassUniformFloat(const std::string& passName, const std::string& uniform, f32 value);
+
+ /**
+ * @brief Sets a vec4 uniform for a pass
+ */
+ void setPassUniformVec4(const std::string& passName, const std::string& uniform, const glm::vec4& value);
+
+ /**
+ * @brief Gets the pass count
+ */
+ u32 getPassCount() const { return static_cast<u32>(passes_.size()); }
+
+ /**
+ * @brief Gets a pass by index
+ */
+ const PostProcessPass* getPass(u32 index) const;
+
+ /**
+ * @brief Gets a pass by name
+ */
+ const PostProcessPass* getPass(const std::string& name) const;
+
+ /**
+ * @brief Begins rendering to the pipeline
+ * @details Binds the input framebuffer. Render scene content after this.
+ */
+ void begin();
+
+ /**
+ * @brief Ends and processes all passes
+ * @details Applies all enabled passes and outputs to screen.
+ */
+ void end();
+
+ /**
+ * @brief Gets the source framebuffer texture
+ */
+ u32 getSourceTexture() const;
+
+ /**
+ * @brief Gets the output framebuffer texture
+ */
+ u32 getOutputTexture() const;
+
+ /**
+ * @brief Checks if pipeline is initialized
+ */
+ bool isInitialized() const { return initialized_; }
+
+ /**
+ * @brief Sets bypass mode to skip FBO rendering entirely
+ * @param bypass If true, begin()/end() become no-ops
+ */
+ void setBypass(bool bypass) { bypass_ = bypass; }
+
+ /**
+ * @brief Checks if bypass mode is enabled
+ */
+ bool isBypassed() const { return bypass_; }
+
+private:
+ PostProcessPass* findPass(const std::string& name);
+ void renderPass(const PostProcessPass& pass, u32 inputTexture);
+ void blitToScreen(u32 texture);
+
+ RenderContext& context_;
+ resource::ResourceManager& resourceManager_;
+
+ Unique<Framebuffer> fboA_;
+ Unique<Framebuffer> fboB_;
+ Unique<VertexArray> screenQuadVAO_;
+ resource::ShaderHandle blitShader_;
+
+ std::vector<PostProcessPass> passes_;
+ u32 width_ = 0;
+ u32 height_ = 0;
+ bool initialized_ = false;
+ bool inFrame_ = false;
+ bool bypass_ = false;
+ u32 currentFBO_ = 0;
+};
+
+} // namespace esengine
diff --git a/src/esengine/renderer/RenderCommand.hpp b/src/esengine/renderer/RenderCommand.hpp
index abf8db869..a4e3eaee8 100644
--- a/src/esengine/renderer/RenderCommand.hpp
+++ b/src/esengine/renderer/RenderCommand.hpp
@@ -19,6 +19,7 @@
// Project includes
#include "../core/Types.hpp"
#include "../math/Math.hpp"
+#include "BlendMode.hpp"
namespace esengine {
@@ -149,6 +150,12 @@ public:
*/
static void setBlendFunc();
+ /**
+ * @brief Sets the blend mode to a predefined mode
+ * @param mode The blend mode to use
+ */
+ static void setBlendMode(BlendMode mode);
+
// =========================================================================
// Face Culling
// =========================================================================
diff --git a/src/esengine/renderer/RenderFrame.cpp b/src/esengine/renderer/RenderFrame.cpp
new file mode 100644
index 000000000..f6b823681
--- /dev/null
+++ b/src/esengine/renderer/RenderFrame.cpp
@@ -0,0 +1,590 @@
+#include "RenderFrame.hpp"
+#include "Renderer.hpp"
+#include "RenderCommand.hpp"
+#include "Texture.hpp"
+#include "../core/Log.hpp"
+#include "../ecs/components/Transform.hpp"
+#include "../ecs/components/Sprite.hpp"
+#include "../ecs/components/SpineAnimation.hpp"
+#include "../spine/SpineSystem.hpp"
+
+#include <spine/spine.h>
+#include <spine/RegionAttachment.h>
+#include <spine/MeshAttachment.h>
+#include <spine/ClippingAttachment.h>
+
+#ifdef ES_PLATFORM_WEB
+ #include <GLES3/gl3.h>
+#else
+ #ifdef _WIN32
+ #include <windows.h>
+ #endif
+ #include <glad/glad.h>
+#endif
+
+#include <algorithm>
+
+namespace esengine {
+
+RenderFrame::RenderFrame(RenderContext& context, resource::ResourceManager& resource_manager)
+ : context_(context)
+ , resource_manager_(resource_manager) {
+}
+
+RenderFrame::~RenderFrame() {
+ shutdown();
+}
+
+void RenderFrame::init(u32 width, u32 height) {
+ width_ = width;
+ height_ = height;
+
+ batcher_ = makeUnique<BatchRenderer2D>(context_, resource_manager_);
+ batcher_->init();
+
+ post_process_ = makeUnique<PostProcessPipeline>(context_, resource_manager_);
+ post_process_->init(width, height);
+
+ items_.reserve(1024);
+ spine_vertices_.reserve(1024);
+ spine_indices_.reserve(2048);
+ spine_world_vertices_.reserve(1024);
+
+ ES_LOG_INFO("RenderFrame initialized ({}x{})", width, height);
+}
+
+void RenderFrame::shutdown() {
+ if (batcher_) {
+ batcher_->shutdown();
+ batcher_.reset();
+ }
+
+ if (post_process_) {
+ post_process_->shutdown();
+ post_process_.reset();
+ }
+
+ items_.clear();
+ ES_LOG_INFO("RenderFrame shutdown");
+}
+
+void RenderFrame::resize(u32 width, u32 height) {
+ width_ = width;
+ height_ = height;
+
+ if (post_process_) {
+ post_process_->resize(width, height);
+ }
+}
+
+void RenderFrame::begin(const glm::mat4& view_projection, RenderTargetManager::Handle target) {
+ view_projection_ = view_projection;
+ current_target_ = target;
+ current_stage_ = RenderStage::Transparent;
+ in_frame_ = true;
+
+ items_.clear();
+ stats_ = Stats{};
+
+ bool usePostProcess = post_process_ && post_process_->isInitialized() &&
+ !post_process_->isBypassed() && post_process_->getPassCount() > 0;
+
+ if (usePostProcess) {
+ post_process_->begin();
+ } else if (target != RenderTargetManager::INVALID_HANDLE) {
+ auto* rt = target_manager_.get(target);
+ if (rt) {
+ rt->bind();
+ }
+ }
+}
+
+void RenderFrame::end() {
+ if (!in_frame_) return;
+
+ sortItems();
+
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glDisable(GL_DEPTH_TEST);
+
+ executeStage(RenderStage::Background);
+ executeStage(RenderStage::Opaque);
+ executeStage(RenderStage::Transparent);
+ executeStage(RenderStage::Overlay);
+
+ bool usePostProcess = post_process_ && post_process_->isInitialized() &&
+ !post_process_->isBypassed() && post_process_->getPassCount() > 0;
+
+ if (usePostProcess) {
+ post_process_->end();
+ } else if (current_target_ != RenderTargetManager::INVALID_HANDLE) {
+ auto* rt = target_manager_.get(current_target_);
+ if (rt) {
+ rt->unbind();
+ }
+ }
+
+ in_frame_ = false;
+}
+
+void RenderFrame::submitSprites(ecs::Registry& registry) {
+ auto spriteView = registry.view<ecs::LocalTransform, ecs::Sprite>();
+
+ for (auto entity : spriteView) {
+ const auto& sprite = spriteView.get<ecs::Sprite>(entity);
+
+ glm::vec3 position;
+ glm::quat rotation;
+ glm::vec3 scale;
+
+ if (registry.has<ecs::WorldTransform>(entity)) {
+ const auto& world = registry.get<ecs::WorldTransform>(entity);
+ position = world.position;
+ rotation = world.rotation;
+ scale = world.scale;
+ } else {
+ const auto& local = spriteView.get<ecs::LocalTransform>(entity);
+ position = local.position;
+ rotation = local.rotation;
+ scale = local.scale;
+ }
+
+ RenderItem item;
+ item.entity = entity;
+ item.type = RenderType::Sprite;
+ item.stage = current_stage_;
+
+ item.transform = glm::mat4(1.0f);
+ item.transform = glm::translate(item.transform, position);
+ item.transform *= glm::mat4_cast(rotation);
+ item.transform = glm::scale(item.transform, scale);
+
+ item.layer = sprite.layer;
+ item.depth = position.z;
+ item.size = sprite.size;
+ item.color = sprite.color;
+ item.uv_offset = sprite.uvOffset;
+ item.uv_scale = sprite.uvScale;
+ item.flip_x = sprite.flipX;
+ item.flip_y = sprite.flipY;
+
+ item.texture_id = context_.getWhiteTextureId();
+ if (sprite.texture.isValid()) {
+ Texture* tex = resource_manager_.getTexture(sprite.texture);
+ if (tex) {
+ item.texture_id = tex->getId();
+ item.texture_size = glm::vec2(
+ static_cast<f32>(tex->getWidth()),
+ static_cast<f32>(tex->getHeight())
+ );
+
+ const auto* metadata = resource_manager_.getTextureMetadata(sprite.texture);
+ if (metadata && metadata->sliceBorder.hasSlicing()) {
+ item.use_nine_slice = true;
+ item.slice_border = glm::vec4(
+ metadata->sliceBorder.left,
+ metadata->sliceBorder.right,
+ metadata->sliceBorder.top,
+ metadata->sliceBorder.bottom
+ );
+ }
+ }
+ }
+
+ items_.push_back(item);
+ stats_.sprites++;
+ }
+}
+
+void RenderFrame::submitSpine(ecs::Registry& registry, spine::SpineSystem& spine_system) {
+ auto view = registry.view<ecs::SpineAnimation>();
+
+ for (auto entity : view) {
+ auto& comp = registry.get<ecs::SpineAnimation>(entity);
+ auto* instance = spine_system.getInstance(entity);
+
+ if (!instance || !instance->skeleton) continue;
+
+ glm::vec3 position{0.0f};
+ glm::quat rotation{1.0f, 0.0f, 0.0f, 0.0f};
+ glm::vec3 scale{1.0f};
+
+ if (registry.has<ecs::WorldTransform>(entity)) {
+ const auto& world = registry.get<ecs::WorldTransform>(entity);
+ position = world.position;
+ rotation = world.rotation;
+ scale = world.scale;
+ } else if (registry.has<ecs::LocalTransform>(entity)) {
+ const auto& local = registry.get<ecs::LocalTransform>(entity);
+ position = local.position;
+ rotation = local.rotation;
+ scale = local.scale;
+ }
+
+ RenderItem item;
+ item.entity = entity;
+ item.type = RenderType::Spine;
+ item.stage = current_stage_;
+
+ item.transform = glm::mat4(1.0f);
+ item.transform = glm::translate(item.transform, position);
+ item.transform *= glm::mat4_cast(rotation);
+ item.transform = glm::scale(item.transform, scale);
+
+ item.layer = comp.layer;
+ item.depth = position.z;
+ item.skeleton = instance->skeleton.get();
+ item.tint_color = comp.color;
+
+ items_.push_back(item);
+ stats_.spine++;
+ }
+}
+
+void RenderFrame::submit(const RenderItem& item) {
+ RenderItem copy = item;
+ if (copy.stage == RenderStage::Transparent && copy.stage != current_stage_) {
+ copy.stage = current_stage_;
+ }
+ items_.push_back(copy);
+
+ switch (copy.type) {
+ case RenderType::Sprite: stats_.sprites++; break;
+ case RenderType::Spine: stats_.spine++; break;
+ case RenderType::Mesh: stats_.meshes++; break;
+ }
+}
+
+void RenderFrame::sortItems() {
+ std::sort(items_.begin(), items_.end(),
+ [](const RenderItem& a, const RenderItem& b) {
+ return a.sortKey() < b.sortKey();
+ });
+}
+
+void RenderFrame::executeStage(RenderStage stage) {
+ std::vector<RenderItem*> stageItems;
+
+ for (auto& item : items_) {
+ if (item.stage == stage) {
+ stageItems.push_back(&item);
+ }
+ }
+
+ if (stageItems.empty()) return;
+
+ std::vector<RenderItem*> currentBatch;
+ RenderType currentType = stageItems[0]->type;
+
+ auto flushCurrentBatch = [&]() {
+ if (currentBatch.empty()) return;
+
+ switch (currentType) {
+ case RenderType::Sprite:
+ renderSprites(currentBatch);
+ break;
+ case RenderType::Spine:
+ renderSpine(currentBatch);
+ break;
+ case RenderType::Mesh:
+ renderMeshes(currentBatch);
+ break;
+ }
+ currentBatch.clear();
+ };
+
+ for (auto* item : stageItems) {
+ if (item->type != currentType) {
+ flushCurrentBatch();
+ currentType = item->type;
+ }
+ currentBatch.push_back(item);
+ }
+
+ flushCurrentBatch();
+}
+
+void RenderFrame::renderSprites(const std::vector<RenderItem*>& items) {
+ batcher_->setProjection(view_projection_);
+ batcher_->beginBatch();
+
+ for (auto* item : items) {
+ glm::vec3 position = glm::vec3(item->transform[3]);
+ glm::vec3 scale = glm::vec3(
+ glm::length(glm::vec3(item->transform[0])),
+ glm::length(glm::vec3(item->transform[1])),
+ glm::length(glm::vec3(item->transform[2]))
+ );
+
+ glm::vec2 finalSize = item->size * glm::vec2(scale);
+
+ glm::mat3 rotMat = glm::mat3(item->transform);
+ rotMat[0] /= scale.x;
+ rotMat[1] /= scale.y;
+ rotMat[2] /= scale.z;
+ glm::quat rotation = glm::quat_cast(rotMat);
+
+ f32 angle = glm::angle(rotation);
+ glm::vec3 axis = glm::axis(rotation);
+ if (axis.z < 0) angle = -angle;
+
+ if (item->use_nine_slice) {
+ resource::SliceBorder border;
+ border.left = item->slice_border.x;
+ border.right = item->slice_border.y;
+ border.top = item->slice_border.z;
+ border.bottom = item->slice_border.w;
+
+ batcher_->drawNineSlice(
+ glm::vec2(position),
+ finalSize,
+ item->texture_id,
+ item->texture_size,
+ border,
+ item->color,
+ angle
+ );
+ } else if (std::abs(angle) > 0.001f) {
+ batcher_->drawRotatedQuad(
+ glm::vec2(position),
+ finalSize,
+ angle,
+ item->texture_id,
+ item->color
+ );
+ } else {
+ batcher_->drawQuad(
+ glm::vec3(position.x, position.y, item->depth),
+ finalSize,
+ item->texture_id,
+ item->color
+ );
+ }
+ }
+
+ batcher_->endBatch();
+ stats_.draw_calls += batcher_->getDrawCallCount();
+ stats_.triangles += batcher_->getQuadCount() * 2;
+}
+
+void RenderFrame::renderSpine(const std::vector<RenderItem*>& items) {
+ spine_vertices_.clear();
+ spine_indices_.clear();
+ spine_current_texture_ = 0;
+
+ static ::spine::SkeletonClipping clipper;
+
+ for (auto* item : items) {
+ auto* skeleton = static_cast<::spine::Skeleton*>(item->skeleton);
+ if (!skeleton) continue;
+
+ auto& drawOrder = skeleton->getDrawOrder();
+
+ for (size_t i = 0; i < drawOrder.size(); ++i) {
+ ::spine::Slot* slot = drawOrder[i];
+ if (!slot) continue;
+
+ ::spine::Attachment* attachment = slot->getAttachment();
+ if (!attachment) continue;
+
+ if (!slot->getData().isVisible()) continue;
+
+ if (attachment->getRTTI().isExactly(::spine::ClippingAttachment::rtti)) {
+ auto* clip = static_cast<::spine::ClippingAttachment*>(attachment);
+ clipper.clipStart(*slot, clip);
+ continue;
+ }
+
+ u32 textureId = context_.getWhiteTextureId();
+ BlendMode blendMode = BlendMode::Normal;
+
+ auto spineBlend = slot->getData().getBlendMode();
+ switch (spineBlend) {
+ case ::spine::BlendMode_Normal: blendMode = BlendMode::Normal; break;
+ case ::spine::BlendMode_Additive: blendMode = BlendMode::Additive; break;
+ case ::spine::BlendMode_Multiply: blendMode = BlendMode::Multiply; break;
+ case ::spine::BlendMode_Screen: blendMode = BlendMode::Screen; break;
+ }
+
+ auto& skelColor = skeleton->getColor();
+ auto& slotColor = slot->getColor();
+
+ if (attachment->getRTTI().isExactly(::spine::RegionAttachment::rtti)) {
+ auto* region = static_cast<::spine::RegionAttachment*>(attachment);
+ auto* regionData = region->getRegion();
+ if (!regionData) continue;
+
+ if (regionData->rendererObject) {
+ u32 handleId = static_cast<u32>(reinterpret_cast<uintptr_t>(regionData->rendererObject)) - 1;
+ auto* tex = resource_manager_.getTexture(resource::TextureHandle(handleId));
+ if (tex) textureId = tex->getId();
+ }
+
+ if (textureId != spine_current_texture_ || blendMode != spine_current_blend_) {
+ flushSpineBatch();
+ spine_current_texture_ = textureId;
+ spine_current_blend_ = blendMode;
+ RenderCommand::setBlendMode(blendMode);
+ }
+
+ spine_world_vertices_.resize(8);
+ region->computeWorldVertices(*slot, spine_world_vertices_.data(), 0, 2);
+
+ auto& uvs = region->getUVs();
+ auto& attachColor = region->getColor();
+
+ f32 r = skelColor.r * slotColor.r * attachColor.r * item->tint_color.r;
+ f32 g = skelColor.g * slotColor.g * attachColor.g * item->tint_color.g;
+ f32 b = skelColor.b * slotColor.b * attachColor.b * item->tint_color.b;
+ f32 a = skelColor.a * slotColor.a * attachColor.a * item->tint_color.a;
+
+ u32 baseIndex = static_cast<u32>(spine_vertices_.size());
+
+ for (int j = 0; j < 4; ++j) {
+ glm::vec4 pos(spine_world_vertices_[j * 2], spine_world_vertices_[j * 2 + 1], 0.0f, 1.0f);
+ pos = item->transform * pos;
+
+ SpineVertex vertex;
+ vertex.position = glm::vec2(pos.x, pos.y);
+ vertex.uv = glm::vec2(uvs[j * 2], uvs[j * 2 + 1]);
+ vertex.color = glm::vec4(r, g, b, a);
+ spine_vertices_.push_back(vertex);
+ }
+
+ spine_indices_.push_back(baseIndex);
+ spine_indices_.push_back(baseIndex + 1);
+ spine_indices_.push_back(baseIndex + 2);
+ spine_indices_.push_back(baseIndex + 2);
+ spine_indices_.push_back(baseIndex + 3);
+ spine_indices_.push_back(baseIndex);
+
+ } else if (attachment->getRTTI().isExactly(::spine::MeshAttachment::rtti)) {
+ auto* mesh = static_cast<::spine::MeshAttachment*>(attachment);
+ auto* regionData = mesh->getRegion();
+ if (!regionData) continue;
+
+ if (regionData->rendererObject) {
+ u32 handleId = static_cast<u32>(reinterpret_cast<uintptr_t>(regionData->rendererObject)) - 1;
+ auto* tex = resource_manager_.getTexture(resource::TextureHandle(handleId));
+ if (tex) textureId = tex->getId();
+ }
+
+ if (textureId != spine_current_texture_ || blendMode != spine_current_blend_) {
+ flushSpineBatch();
+ spine_current_texture_ = textureId;
+ spine_current_blend_ = blendMode;
+ RenderCommand::setBlendMode(blendMode);
+ }
+
+ size_t vertexCount = mesh->getWorldVerticesLength() / 2;
+ spine_world_vertices_.resize(mesh->getWorldVerticesLength());
+ mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(),
+ spine_world_vertices_.data(), 0, 2);
+
+ auto& uvs = mesh->getUVs();
+ auto& triangles = mesh->getTriangles();
+ auto& attachColor = mesh->getColor();
+
+ f32 r = skelColor.r * slotColor.r * attachColor.r * item->tint_color.r;
+ f32 g = skelColor.g * slotColor.g * attachColor.g * item->tint_color.g;
+ f32 b = skelColor.b * slotColor.b * attachColor.b * item->tint_color.b;
+ f32 a = skelColor.a * slotColor.a * attachColor.a * item->tint_color.a;
+
+ u32 baseIndex = static_cast<u32>(spine_vertices_.size());
+
+ for (size_t j = 0; j < vertexCount; ++j) {
+ glm::vec4 pos(spine_world_vertices_[j * 2], spine_world_vertices_[j * 2 + 1], 0.0f, 1.0f);
+ pos = item->transform * pos;
+
+ SpineVertex vertex;
+ vertex.position = glm::vec2(pos.x, pos.y);
+ vertex.uv = glm::vec2(uvs[j * 2], uvs[j * 2 + 1]);
+ vertex.color = glm::vec4(r, g, b, a);
+ spine_vertices_.push_back(vertex);
+ }
+
+ for (size_t j = 0; j < triangles.size(); ++j) {
+ spine_indices_.push_back(baseIndex + triangles[j]);
+ }
+ }
+
+ clipper.clipEnd(*slot);
+ }
+
+ clipper.clipEnd();
+ }
+
+ flushSpineBatch();
+}
+
+void RenderFrame::flushSpineBatch() {
+ if (spine_vertices_.empty() || spine_indices_.empty()) return;
+
+ auto* shader = context_.getTextureShader();
+ if (!shader) {
+ spine_vertices_.clear();
+ spine_indices_.clear();
+ return;
+ }
+
+ shader->bind();
+ shader->setUniform("u_projection", view_projection_);
+ shader->setUniform("u_model", glm::mat4(1.0f));
+ shader->setUniform("u_color", glm::vec4(1.0f));
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, spine_current_texture_);
+ shader->setUniform("u_texture", 0);
+
+ u32 vao, vbo, ebo;
+ glGenVertexArrays(1, &vao);
+ glGenBuffers(1, &vbo);
+ glGenBuffers(1, &ebo);
+
+ glBindVertexArray(vao);
+
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
+ glBufferData(GL_ARRAY_BUFFER,
+ static_cast<GLsizeiptr>(spine_vertices_.size() * sizeof(SpineVertex)),
+ spine_vertices_.data(), GL_STREAM_DRAW);
+
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER,
+ static_cast<GLsizeiptr>(spine_indices_.size() * sizeof(u32)),
+ spine_indices_.data(), GL_STREAM_DRAW);
+
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(SpineVertex),
+ reinterpret_cast<void*>(offsetof(SpineVertex, position)));
+
+ glEnableVertexAttribArray(1);
+ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(SpineVertex),
+ reinterpret_cast<void*>(offsetof(SpineVertex, uv)));
+
+ glEnableVertexAttribArray(2);
+ glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(SpineVertex),
+ reinterpret_cast<void*>(offsetof(SpineVertex, color)));
+
+ glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(spine_indices_.size()),
+ GL_UNSIGNED_INT, nullptr);
+
+ stats_.triangles += static_cast<u32>(spine_indices_.size() / 3);
+ stats_.draw_calls++;
+
+ glDeleteBuffers(1, &ebo);
+ glDeleteBuffers(1, &vbo);
+ glDeleteVertexArrays(1, &vao);
+
+ spine_vertices_.clear();
+ spine_indices_.clear();
+}
+
+void RenderFrame::renderMeshes(const std::vector<RenderItem*>& items) {
+ for (auto* item : items) {
+ if (!item->geometry || !item->shader) continue;
+ stats_.draw_calls++;
+ }
+}
+
+} // namespace esengine
diff --git a/src/esengine/renderer/RenderFrame.hpp b/src/esengine/renderer/RenderFrame.hpp
new file mode 100644
index 000000000..9c7ea4f98
--- /dev/null
+++ b/src/esengine/renderer/RenderFrame.hpp
@@ -0,0 +1,95 @@
+#pragma once
+
+#include "../core/Types.hpp"
+#include "RenderItem.hpp"
+#include "RenderTarget.hpp"
+#include "RenderContext.hpp"
+#include "PostProcessPipeline.hpp"
+#include "../ecs/Registry.hpp"
+#include "../resource/ResourceManager.hpp"
+
+#include <glm/glm.hpp>
+#include <vector>
+
+namespace esengine {
+
+class BatchRenderer2D;
+
+namespace spine {
+ class SpineSystem;
+}
+
+class RenderFrame {
+public:
+ struct Stats {
+ u32 draw_calls = 0;
+ u32 triangles = 0;
+ u32 sprites = 0;
+ u32 spine = 0;
+ u32 meshes = 0;
+ u32 culled = 0;
+ };
+
+ RenderFrame(RenderContext& context, resource::ResourceManager& resource_manager);
+ ~RenderFrame();
+
+ RenderFrame(const RenderFrame&) = delete;
+ RenderFrame& operator=(const RenderFrame&) = delete;
+
+ void init(u32 width, u32 height);
+ void shutdown();
+ void resize(u32 width, u32 height);
+
+ void begin(const glm::mat4& view_projection, RenderTargetManager::Handle target = 0);
+ void end();
+
+ void submitSprites(ecs::Registry& registry);
+ void submitSpine(ecs::Registry& registry, spine::SpineSystem& spine_system);
+
+ void submit(const RenderItem& item);
+ void setStage(RenderStage stage) { current_stage_ = stage; }
+ RenderStage getStage() const { return current_stage_; }
+
+ PostProcessPipeline* postProcess() { return post_process_.get(); }
+ RenderTargetManager& targetManager() { return target_manager_; }
+
+ const Stats& stats() const { return stats_; }
+
+private:
+ void sortItems();
+ void executeStage(RenderStage stage);
+ void renderSprites(const std::vector<RenderItem*>& items);
+ void renderSpine(const std::vector<RenderItem*>& items);
+ void renderMeshes(const std::vector<RenderItem*>& items);
+ void flushSpineBatch();
+
+ RenderContext& context_;
+ resource::ResourceManager& resource_manager_;
+
+ Unique<BatchRenderer2D> batcher_;
+ Unique<PostProcessPipeline> post_process_;
+ RenderTargetManager target_manager_;
+
+ std::vector<RenderItem> items_;
+ glm::mat4 view_projection_{1.0f};
+ RenderTargetManager::Handle current_target_ = 0;
+ RenderStage current_stage_ = RenderStage::Transparent;
+
+ Stats stats_;
+ bool in_frame_ = false;
+ u32 width_ = 0;
+ u32 height_ = 0;
+
+ std::vector<f32> spine_world_vertices_;
+ struct SpineVertex {
+ glm::vec2 position;
+ glm::vec2 uv;
+ glm::vec4 color;
+ };
+ std::vector<SpineVertex> spine_vertices_;
+ std::vector<u32> spine_indices_;
+ u32 spine_current_texture_ = 0;
+ BlendMode spine_current_blend_ = BlendMode::Normal;
+};
+
+} // namespace esengine
diff --git a/src/esengine/renderer/RenderItem.hpp b/src/esengine/renderer/RenderItem.hpp
new file mode 100644
index 000000000..30878f69e
--- /dev/null
+++ b/src/esengine/renderer/RenderItem.hpp
@@ -0,0 +1,66 @@
+#pragma once
+
+#include "../core/Types.hpp"
+#include "RenderStage.hpp"
+#include "BlendMode.hpp"
+
+#include <glm/glm.hpp>
+
+namespace esengine {
+
+enum class RenderType : u8 {
+ Sprite = 0,
+ Spine = 1,
+ Mesh = 2,
+};
+
+struct RenderItem {
+ Entity entity = INVALID_ENTITY;
+ RenderType type = RenderType::Sprite;
+ RenderStage stage = RenderStage::Transparent;
+
+ glm::mat4 transform{1.0f};
+ i32 layer = 0;
+ f32 depth = 0.0f;
+ u32 texture_id = 0;
+ BlendMode blend_mode = BlendMode::Normal;
+
+ glm::vec2 size{0.0f};
+ glm::vec4 color{1.0f};
+ glm::vec2 uv_offset{0.0f};
+ glm::vec2 uv_scale{1.0f};
+ bool flip_x = false;
+ bool flip_y = false;
+ bool use_nine_slice = false;
+ glm::vec4 slice_border{0.0f};
+ glm::vec2 texture_size{0.0f};
+
+ void* skeleton = nullptr;
+ glm::vec4 tint_color{1.0f};
+
+ void* geometry = nullptr;
+ void* shader = nullptr;
+
+ u64 sortKey() const {
+ u64 stageKey = static_cast<u64>(stage) << 60;
+
+ i32 normalizedLayer = layer + 32768;
+ u64 layerKey = static_cast<u64>(normalizedLayer & 0xFFFF) << 44;
+
+ u64 textureKey = static_cast<u64>(texture_id & 0xFFFFF) << 24;
+
+ u32 depthBits;
+ if (stage == RenderStage::Transparent) {
+ f32 invDepth = 1.0f - (depth * 0.5f + 0.5f);
+ depthBits = static_cast<u32>(invDepth * 16777215.0f);
+ } else {
+ f32 normDepth = depth * 0.5f + 0.5f;
+ depthBits = static_cast<u32>(normDepth * 16777215.0f);
+ }
+ u64 depthKey = static_cast<u64>(depthBits & 0xFFFFFF);
+
+ return stageKey | layerKey | textureKey | depthKey;
+ }
+};
+
+} // namespace esengine
diff --git a/src/esengine/renderer/RenderPipeline.cpp b/src/esengine/renderer/RenderPipeline.cpp
deleted file mode 100644
index 524a5ceff..000000000
--- a/src/esengine/renderer/RenderPipeline.cpp
+++ /dev/null
@@ -1,351 +0,0 @@
-/**
- * @file RenderPipeline.cpp
- * @brief Unified 2D render pipeline implementation
- *
- * @author ESEngine Team
- * @date 2026
- *
- * @copyright Copyright (c) 2026 ESEngine Team
- * Licensed under the MIT License.
- */
-
-#include "RenderPipeline.hpp"
-#include "Renderer.hpp"
-#include "RenderCommand.hpp"
-#include "../core/Log.hpp"
-
-#ifdef ES_PLATFORM_WEB
- #include <GLES3/gl3.h>
-#else
- #ifdef _WIN32
- #include <windows.h>
- #endif
- #include <glad/glad.h>
-#endif
-
-#include <algorithm>
-#include <unordered_set>
-
-namespace esengine {
-
-// =============================================================================
-// RenderItem
-// =============================================================================
-
-u64 RenderItem::sortKey() const {
- u64 key = 0;
-
- // Layer: convert signed to unsigned (add 32768 to handle negative layers)
- u64 layerKey = static_cast<u64>(layer + 32768) & 0xFFFF;
- key |= layerKey << 48;
-
- // Texture ID: for batch optimization
- u64 texKey = static_cast<u64>(texture_id) & 0xFFFFFF;
- key |= texKey << 24;
-
- // Depth: convert float to sortable integer
- f32 normalizedDepth = (depth + 1000.0f) * 10000.0f;
- u64 depthKey = static_cast<u64>(normalizedDepth) & 0xFFFFFF;
- key |= depthKey;
-
- return key;
-}
-
-// =============================================================================
-// Constructor / Destructor
-// =============================================================================
-
-RenderPipeline::RenderPipeline(RenderContext& context,
- resource::ResourceManager& resource_manager)
- : context_(context)
- , resource_manager_(resource_manager)
- , view_bounds_(0.0f) {
-
- batcher_ = makeUnique<BatchRenderer2D>(context_, resource_manager_);
- batcher_->init();
-
- items_.reserve(1024);
- batches_.reserve(64);
-
- ES_LOG_INFO("RenderPipeline initialized");
-}
-
-RenderPipeline::~RenderPipeline() {
- if (batcher_) {
- batcher_->shutdown();
- }
- ES_LOG_INFO("RenderPipeline shutdown");
-}
-
-// =============================================================================
-// Rendering
-// =============================================================================
-
-void RenderPipeline::begin(const glm::mat4& view_projection) {
- view_projection_ = view_projection;
- items_.clear();
- batches_.clear();
- stats_ = Stats{};
-}
-
-void RenderPipeline::submit(ecs::Registry& registry) {
- collectFromRegistry(registry);
-}
-
-void RenderPipeline::submit(const RenderItem& item) {
- items_.push_back(item);
- stats_.total_items++;
-}
-
-void RenderPipeline::end() {
- if (items_.empty()) {
- return;
- }
-
- if (culling_enabled_) {
- cullItems();
- } else {
- stats_.visible_items = static_cast<u32>(items_.size());
- }
-
- sortItems();
- buildBatches();
-
- if (batching_enabled_) {
- executeBatches();
- } else {
- executeNonBatched();
- }
-}
-
-// =============================================================================
-// Private Methods
-// =============================================================================
-
-void RenderPipeline::collectFromRegistry(ecs::Registry& registry) {
- auto spriteView = registry.view<ecs::LocalTransform, ecs::Sprite>();
-
- for (auto entity : spriteView) {
- const auto& sprite = spriteView.get<ecs::Sprite>(entity);
-
- glm::vec3 position;
- glm::quat rotation;
- glm::vec3 scale;
-
- if (registry.has<ecs::WorldTransform>(entity)) {
- const auto& world = registry.get<ecs::WorldTransform>(entity);
- position = world.position;
- rotation = world.rotation;
- scale = world.scale;
- } else {
- const auto& local = spriteView.get<ecs::LocalTransform>(entity);
- position = local.position;
- rotation = local.rotation;
- scale = local.scale;
- }
-
- RenderItem item;
- item.entity = entity;
- item.position = position;
- item.rotation = rotation;
- item.scale = scale;
- item.size = sprite.size;
- item.color = sprite.color;
- item.uv_offset = sprite.uvOffset;
- item.uv_scale = sprite.uvScale;
- item.layer = sprite.layer;
- item.depth = position.z;
- item.flip_x = sprite.flipX;
- item.flip_y = sprite.flipY;
- item.use_nine_slice = false;
- item.slice_border = {};
- item.texture_size = {1.0f, 1.0f};
-
- item.texture_id = context_.getWhiteTextureId();
- if (sprite.texture.isValid()) {
- Texture* tex = resource_manager_.getTexture(sprite.texture);
- if (tex) {
- item.texture_id = tex->getId();
- item.texture_size = glm::vec2(
- static_cast<f32>(tex->getWidth()),
- static_cast<f32>(tex->getHeight())
- );
-
- const auto* metadata = resource_manager_.getTextureMetadata(sprite.texture);
- if (metadata && metadata->sliceBorder.hasSlicing()) {
- item.use_nine_slice = true;
- item.slice_border = metadata->sliceBorder;
- }
- }
- }
-
- items_.push_back(item);
- stats_.total_items++;
- }
-}
-
-void RenderPipeline::cullItems() {
- if (view_bounds_ == glm::vec4(0.0f)) {
- stats_.visible_items = static_cast<u32>(items_.size());
- return;
- }
-
- auto it = std::remove_if(items_.begin(), items_.end(),
- [this](const RenderItem& item) {
- return !isItemVisible(item);
- });
-
- stats_.culled_items = static_cast<u32>(std::distance(it, items_.end()));
- items_.erase(it, items_.end());
- stats_.visible_items = static_cast<u32>(items_.size());
-}
-
-bool RenderPipeline::isItemVisible(const RenderItem& item) const {
- f32 halfWidth = item.size.x * item.scale.x * 0.5f;
- f32 halfHeight = item.size.y * item.scale.y * 0.5f;
-
- f32 left = item.position.x - halfWidth;
- f32 right = item.position.x + halfWidth;
- f32 bottom = item.position.y - halfHeight;
- f32 top = item.position.y + halfHeight;
-
- return !(right < view_bounds_.x || left > view_bounds_.y ||
- top < view_bounds_.z || bottom > view_bounds_.w);
-}
-
-void RenderPipeline::sortItems() {
- std::sort(items_.begin(), items_.end(),
- [](const RenderItem& a, const RenderItem& b) {
- return a.sortKey() < b.sortKey();
- });
-}
-
-void RenderPipeline::buildBatches() {
- batches_.clear();
- if (items_.empty()) {
- return;
- }
-
- std::unordered_set<u32> uniqueTextures;
- u32 textureSwitch = 0;
-
- u32 currentTexture = items_[0].texture_id;
- u32 batchStart = 0;
- uniqueTextures.insert(currentTexture);
-
- for (u32 i = 1; i < items_.size(); ++i) {
- uniqueTextures.insert(items_[i].texture_id);
- if (items_[i].texture_id != currentTexture) {
- batches_.push_back({currentTexture, batchStart, i - batchStart});
- currentTexture = items_[i].texture_id;
- batchStart = i;
- textureSwitch++;
- }
- }
-
- batches_.push_back({currentTexture, batchStart,
- static_cast<u32>(items_.size()) - batchStart});
-
- stats_.batch_count = static_cast<u32>(batches_.size());
- stats_.unique_textures = static_cast<u32>(uniqueTextures.size());
- stats_.texture_switches = textureSwitch;
-
- stats_.triangles = stats_.visible_items * 2;
- stats_.vertices = stats_.visible_items * 4;
-}
-
-void RenderPipeline::executeBatches() {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisable(GL_DEPTH_TEST);
-
- batcher_->setProjection(view_projection_);
- batcher_->beginBatch();
-
- for (const auto& item : items_) {
- glm::vec2 finalSize = item.size * glm::vec2(item.scale);
-
- // Use nine-slice rendering if enabled and has valid borders
- if (item.use_nine_slice) {
- f32 angle = glm::angle(item.rotation);
- glm::vec3 axis = glm::axis(item.rotation);
- if (axis.z < 0) {
- angle = -angle;
- }
-
- batcher_->drawNineSlice(
- glm::vec2(item.position),
- finalSize,
- item.texture_id,
- item.texture_size,
- item.slice_border,
- item.color,
- angle
- );
- } else {
- f32 angle = glm::angle(item.rotation);
- glm::vec3 axis = glm::axis(item.rotation);
- if (axis.z < 0) {
- angle = -angle;
- }
-
- if (std::abs(angle) > 0.001f) {
- batcher_->drawRotatedQuad(
- glm::vec2(item.position),
- finalSize,
- angle,
- item.texture_id,
- item.color
- );
- } else {
- batcher_->drawQuad(
- glm::vec3(item.position.x, item.position.y, item.depth),
- finalSize,
- item.texture_id,
- item.color
- );
- }
- }
- }
-
- batcher_->endBatch();
- stats_.draw_calls = batcher_->getDrawCallCount();
-}
-
-void RenderPipeline::executeNonBatched() {
- Shader* shader = context_.getTextureShader();
- VertexArray* quadVAO = context_.getQuadVAO();
-
- if (!shader || !quadVAO) {
- return;
- }
-
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisable(GL_DEPTH_TEST);
-
- for (const auto& item : items_) {
- glm::mat4 model = glm::mat4(1.0f);
- model = glm::translate(model, item.position);
- model *= glm::mat4_cast(item.rotation);
- model = glm::scale(model, glm::vec3(
- item.size.x * item.scale.x,
- item.size.y * item.scale.y,
- 1.0f
- ));
-
- shader->bind();
- shader->setUniform("u_projection", view_projection_);
- shader->setUniform("u_model", model);
- shader->setUniform("u_color", item.color);
-
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, item.texture_id);
- shader->setUniform("u_texture", 0);
-
- RenderCommand::drawIndexed(*quadVAO);
- stats_.draw_calls++;
- }
-}
-
-} // namespace esengine
diff --git a/src/esengine/renderer/RenderPipeline.hpp b/src/esengine/renderer/RenderPipeline.hpp
deleted file mode 100644
index eeaf74151..000000000
--- a/src/esengine/renderer/RenderPipeline.hpp
+++ /dev/null
@@ -1,217 +0,0 @@
-/**
- * @file RenderPipeline.hpp
- * @brief Unified 2D render pipeline with batching and sorting
- * @details Provides efficient sprite rendering with layer sorting,
- * texture batching, and optional frustum culling.
- *
- * @author ESEngine Team
- * @date 2026
- *
- * @copyright Copyright (c) 2026 ESEngine Team
- * Licensed under the MIT License.
- */
-#pragma once
-
-// =============================================================================
-// Includes
-// =============================================================================
-
-#include "../core/Types.hpp"
-#include "../math/Math.hpp"
-#include "../ecs/Registry.hpp"
-#include "../ecs/components/Transform.hpp"
-#include "../ecs/components/Sprite.hpp"
-#include "RenderContext.hpp"
-#include "../resource/ResourceManager.hpp"
-#include "../resource/TextureMetadata.hpp"
-
-#include <vector>
-
-namespace esengine {
-
-// =============================================================================
-// Forward Declarations
-// =============================================================================
-
-class BatchRenderer2D;
-
-// =============================================================================
-// RenderItem
-// =============================================================================
-
-/**
- * @brief Single renderable item in the pipeline
- */
-struct RenderItem {
- Entity entity; ///< Source entity ID
- glm::vec3 position; ///< World position
- glm::quat rotation; ///< World rotation
- glm::vec3 scale; ///< World scale
- glm::vec2 size; ///< Sprite size
- glm::vec4 color; ///< Tint color
- glm::vec2 uv_offset; ///< UV offset for sprite sheets
- glm::vec2 uv_scale; ///< UV scale for sprite sheets
- u32 texture_id; ///< GPU texture handle
- i32 layer; ///< Render layer
- f32 depth; ///< Z depth for sorting
- bool flip_x; ///< Horizontal flip
- bool flip_y; ///< Vertical flip
- bool use_nine_slice; ///< Use nine-slice rendering
- resource::SliceBorder slice_border; ///< Nine-slice borders
- glm::vec2 texture_size; ///< Texture dimensions for nine-slice UV calc
-
- /** @brief Generates a 64-bit sort key for efficient sorting */
- u64 sortKey() const;
-};
-
-// =============================================================================
-// RenderBatch
-// =============================================================================
-
-/**
- * @brief Group of render items sharing the same texture
- */
-struct RenderBatch {
- u32 texture_id; ///< Batch texture
- u32 start_index; ///< Start index in items array
- u32 count; ///< Number of items in batch
-};
-
-// =============================================================================
-// RenderPipeline
-// =============================================================================
-
-/**
- * @brief Unified 2D render pipeline
- *
- * @details Provides a collect-cull-sort-batch-render pipeline for efficient
- * 2D sprite rendering. Uses BatchRenderer2D for batching multiple
- * sprites into single draw calls.
- *
- * @code
- * RenderPipeline pipeline(context, resourceManager);
- *
- * pipeline.begin(viewProjection);
- * pipeline.submit(registry);
- * pipeline.end();
- *
- * auto stats = pipeline.getStats();
- * @endcode
- */
-class RenderPipeline {
-public:
- // =========================================================================
- // Types
- // =========================================================================
-
- /**
- * @brief Pipeline statistics
- */
- struct Stats {
- // Rendering
- u32 draw_calls = 0; ///< Number of draw calls
- u32 batch_count = 0; ///< Number of batches
- u32 triangles = 0; ///< Total triangles rendered
- u32 vertices = 0; ///< Total vertices rendered
-
- // Objects
- u32 total_items = 0; ///< Total items submitted
- u32 visible_items = 0; ///< Items actually rendered
- u32 culled_items = 0; ///< Items culled by frustum
-
- // Textures
- u32 unique_textures = 0; ///< Unique textures used
- u32 texture_switches = 0; ///< Texture bind changes
- };
-
- // =========================================================================
- // Constructor / Destructor
- // =========================================================================
-
- /**
- * @brief Constructs render pipeline
- * @param context Render context for shared resources
- * @param resource_manager Resource manager for texture lookup
- */
- RenderPipeline(RenderContext& context, resource::ResourceManager& resource_manager);
- ~RenderPipeline();
-
- RenderPipeline(const RenderPipeline&) = delete;
- RenderPipeline& operator=(const RenderPipeline&) = delete;
-
- // =========================================================================
- // Configuration
- // =========================================================================
-
- /**
- * @brief Enables or disables frustum culling
- * @param enabled True to enable culling
- */
- void setCullingEnabled(bool enabled) { culling_enabled_ = enabled; }
-
- /**
- * @brief Sets the view bounds for frustum culling
- * @param bounds View bounds (left, right, bottom, top in world space)
- */
- void setViewBounds(const glm::vec4& bounds) { view_bounds_ = bounds; }
-
- // =========================================================================
- // Rendering
- // =========================================================================
-
- /**
- * @brief Begins a new render frame
- * @param view_projection Combined view-projection matrix
- */
- void begin(const glm::mat4& view_projection);
-
- /**
- * @brief Submits all sprite entities from registry
- * @param registry ECS registry to collect from
- */
- void submit(ecs::Registry& registry);
-
- /**
- * @brief Submits a single render item manually
- * @param item The item to render
- */
- void submit(const RenderItem& item);
-
- /** @brief Ends the frame (sorts, batches, and renders) */
- void end();
-
- // =========================================================================
- // Statistics
- // =========================================================================
-
- /** @brief Gets pipeline statistics for the last frame */
- const Stats& getStats() const { return stats_; }
-
- /** @brief Resets statistics counters */
- void resetStats() { stats_ = Stats{}; }
-
-private:
- void collectFromRegistry(ecs::Registry& registry);
- void cullItems();
- void sortItems();
- void buildBatches();
- void executeBatches();
- void executeNonBatched();
- bool isItemVisible(const RenderItem& item) const;
-
- RenderContext& context_;
- resource::ResourceManager& resource_manager_;
- Unique<BatchRenderer2D> batcher_;
-
- std::vector<RenderItem> items_;
- std::vector<RenderBatch> batches_;
-
- glm::mat4 view_projection_;
- glm::vec4 view_bounds_;
- bool culling_enabled_ = false;
- bool batching_enabled_ = true;
-
- Stats stats_;
-};
-
-} // namespace esengine
diff --git a/src/esengine/renderer/RenderStage.hpp b/src/esengine/renderer/RenderStage.hpp
new file mode 100644
index 000000000..7f9e8bdb5
--- /dev/null
+++ b/src/esengine/renderer/RenderStage.hpp
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "../core/Types.hpp"
+
+namespace esengine {
+
+enum class RenderStage : u8 {
+ Background = 0,
+ Opaque = 1,
+ Transparent = 2,
+ Overlay = 3,
+};
+
+} // namespace esengine
diff --git a/src/esengine/renderer/RenderTarget.cpp b/src/esengine/renderer/RenderTarget.cpp
new file mode 100644
index 000000000..fba52630d
--- /dev/null
+++ b/src/esengine/renderer/RenderTarget.cpp
@@ -0,0 +1,100 @@
+#include "RenderTarget.hpp"
+
+namespace esengine {
+
+void RenderTarget::init(u32 width, u32 height, bool depth) {
+ width_ = width;
+ height_ = height;
+ has_depth_ = depth;
+
+ FramebufferSpec spec;
+ spec.width = width;
+ spec.height = height;
+ spec.depthStencil = depth;
+
+ framebuffer_ = Framebuffer::create(spec);
+}
+
+void RenderTarget::shutdown() {
+ framebuffer_.reset();
+ width_ = 0;
+ height_ = 0;
+}
+
+void RenderTarget::bind() {
+ if (framebuffer_) {
+ framebuffer_->bind();
+ }
+}
+
+void RenderTarget::unbind() {
+ if (framebuffer_) {
+ framebuffer_->unbind();
+ }
+}
+
+void RenderTarget::resize(u32 width, u32 height) {
+ if (width == width_ && height == height_) return;
+
+ width_ = width;
+ height_ = height;
+
+ if (framebuffer_) {
+ framebuffer_->resize(width, height);
+ }
+}
+
+u32 RenderTarget::getColorTexture() const {
+ return framebuffer_ ? framebuffer_->getColorAttachment() : 0;
+}
+
+RenderTargetManager::Handle RenderTargetManager::create(u32 width, u32 height, bool depth) {
+ Handle handle;
+
+ if (!free_list_.empty()) {
+ handle = free_list_.back();
+ free_list_.pop_back();
+ } else {
+ handle = next_handle_++;
+ targets_.resize(handle);
+ }
+
+ auto target = makeUnique<RenderTarget>();
+ target->init(width, height, depth);
+
+ usize index = handle - 1;
+ if (index < targets_.size()) {
+ targets_[index] = std::move(target);
+ }
+
+ return handle;
+}
+
+RenderTarget* RenderTargetManager::get(Handle handle) {
+ if (handle == INVALID_HANDLE || handle > targets_.size()) {
+ return nullptr;
+ }
+ return targets_[handle - 1].get();
+}
+
+void RenderTargetManager::release(Handle handle) {
+ if (handle == INVALID_HANDLE || handle > targets_.size()) {
+ return;
+ }
+
+ auto& target = targets_[handle - 1];
+ if (target) {
+ target->shutdown();
+ target.reset();
+ free_list_.push_back(handle);
+ }
+}
+
+bool RenderTargetManager::isValid(Handle handle) const {
+ if (handle == INVALID_HANDLE || handle > targets_.size()) {
+ return false;
+ }
+ return targets_[handle - 1] != nullptr;
+}
+
+} // namespace esengine
diff --git a/src/esengine/renderer/RenderTarget.hpp b/src/esengine/renderer/RenderTarget.hpp
new file mode 100644
index 000000000..7217a8989
--- /dev/null
+++ b/src/esengine/renderer/RenderTarget.hpp
@@ -0,0 +1,61 @@
+#pragma once
+
+#include "../core/Types.hpp"
+#include "Framebuffer.hpp"
+
+#include <glm/glm.hpp>
+#include <vector>
+
+namespace esengine {
+
+class RenderTarget {
+public:
+ RenderTarget() = default;
+ ~RenderTarget() = default;
+
+ RenderTarget(const RenderTarget&) = delete;
+ RenderTarget& operator=(const RenderTarget&) = delete;
+ RenderTarget(RenderTarget&&) = default;
+ RenderTarget& operator=(RenderTarget&&) = default;
+
+ void init(u32 width, u32 height, bool depth = true);
+ void shutdown();
+
+ void bind();
+ void unbind();
+ void resize(u32 width, u32 height);
+
+ u32 getColorTexture() const;
+ glm::uvec2 getSize() const { return { width_, height_ }; }
+ u32 getWidth() const { return width_; }
+ u32 getHeight() const { return height_; }
+
+ bool isValid() const { return framebuffer_ != nullptr; }
+
+private:
+ Unique<Framebuffer> framebuffer_;
+ u32 width_ = 0;
+ u32 height_ = 0;
+ bool has_depth_ = true;
+};
+
+class RenderTargetManager {
+public:
+ using Handle = u32;
+ static constexpr Handle INVALID_HANDLE = 0;
+
+ RenderTargetManager() = default;
+ ~RenderTargetManager() = default;
+
+ Handle create(u32 width, u32 height, bool depth = true);
+ RenderTarget* get(Handle handle);
+ void release(Handle handle);
+ bool isValid(Handle handle) const;
+
+private:
+ std::vector<Unique<RenderTarget>> targets_;
+ std::vector<Handle> free_list_;
+ Handle next_handle_ = 1;
+};
+
+} // namespace esengine
diff --git a/src/esengine/renderer/Renderer.cpp b/src/esengine/renderer/Renderer.cpp
index a843196db..0addb575e 100644
--- a/src/esengine/renderer/Renderer.cpp
+++ b/src/esengine/renderer/Renderer.cpp
@@ -99,6 +99,26 @@ void RenderCommand::setBlendFunc() {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
+void RenderCommand::setBlendMode(BlendMode mode) {
+ switch (mode) {
+ case BlendMode::Normal:
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ break;
+ case BlendMode::Additive:
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ break;
+ case BlendMode::Multiply:
+ glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
+ break;
+ case BlendMode::Screen:
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
+ break;
+ case BlendMode::PremultipliedAlpha:
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ break;
+ }
+}
+
void RenderCommand::setCulling(bool enabled) {
if (enabled) {
glEnable(GL_CULL_FACE);
diff --git a/src/esengine/resource/Handle.hpp b/src/esengine/resource/Handle.hpp
index f21d048bf..aea6d6dc1 100644
--- a/src/esengine/resource/Handle.hpp
+++ b/src/esengine/resource/Handle.hpp
@@ -91,6 +91,10 @@ namespace esengine {
class IndexBuffer;
}
+namespace esengine::spine {
+ struct SpineSkeletonData;
+}
+
// =============================================================================
// Handle Type Aliases
// =============================================================================
@@ -109,6 +113,9 @@ using VertexBufferHandle = Handle<esengine::VertexBuffer>;
/** @brief Handle to an index buffer resource */
using IndexBufferHandle = Handle<esengine::IndexBuffer>;
+/** @brief Handle to a Spine skeleton data resource */
+using SpineDataHandle = Handle<esengine::spine::SpineSkeletonData>;
+
} // namespace esengine::resource
// =============================================================================