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.

fix: Enable OpenGL rendering for Native platform and setup editor layout

esengine6305f18330e1
diff --git a/src/esengine/editor/EditorApplication.cpp b/src/esengine/editor/EditorApplication.cpp
index 83a5e5c87..421201430 100644
--- a/src/esengine/editor/EditorApplication.cpp
+++ b/src/esengine/editor/EditorApplication.cpp
@@ -18,7 +18,14 @@
#include "../ui/widgets/Label.hpp"
#include "../ui/widgets/Button.hpp"
#include "../ui/layout/StackLayout.hpp"
+#include "../ui/docking/DockArea.hpp"
+#include "../ecs/components/Common.hpp"
+#include "../ecs/components/Transform.hpp"
+#include "../ecs/components/Hierarchy.hpp"
#include "core/EditorEvents.hpp"
+#include "panels/HierarchyPanel.hpp"
+#include "panels/InspectorPanel.hpp"
+#include "panels/SceneViewPanel.hpp"
namespace esengine {
namespace editor {
@@ -58,6 +65,12 @@ void EditorApplication::onInit() {
}
});
+ // Create demo scene for testing
+ createDemoScene();
+
+ // Setup editor UI layout
+ setupEditorLayout();
+
setupEventListeners();
}
@@ -230,5 +243,99 @@ void EditorApplication::setupEventListeners() {
}));
}
+void EditorApplication::setupEditorLayout() {
+ ES_LOG_INFO("setupEditorLayout: Creating dock area...");
+
+ // Create main dock area
+ auto dockArea = makeUnique<ui::DockArea>(ui::WidgetId("editor.dock_area"));
+ dockArea_ = dockArea.get();
+
+ // Configure dock area
+ dockArea_->setMinPanelSize(glm::vec2(150.0f, 100.0f));
+ dockArea_->setSplitterThickness(4.0f);
+ dockArea_->setTabBarHeight(26.0f);
+
+ ES_LOG_INFO("setupEditorLayout: Creating SceneViewPanel...");
+ // Create Scene View panel (center - add first as the main content)
+ auto sceneViewPanel = makeUnique<SceneViewPanel>(registry_, selection_);
+ ES_LOG_INFO("setupEditorLayout: SceneViewPanel created, setting min size...");
+ sceneViewPanel->setMinSize(glm::vec2(400.0f, 300.0f));
+ ES_LOG_INFO("setupEditorLayout: Adding SceneViewPanel to dock...");
+ dockArea_->addPanel(std::move(sceneViewPanel), ui::DockDropZone::Center);
+
+ ES_LOG_INFO("setupEditorLayout: Creating HierarchyPanel...");
+ // Create Hierarchy panel (left side)
+ auto hierarchyPanel = makeUnique<HierarchyPanel>(registry_, selection_);
+ hierarchyPanel->setMinSize(glm::vec2(200.0f, 200.0f));
+ ES_LOG_INFO("setupEditorLayout: Adding HierarchyPanel to dock...");
+ dockArea_->addPanel(std::move(hierarchyPanel), ui::DockDropZone::Left, nullptr, 0.2f);
+
+ ES_LOG_INFO("setupEditorLayout: Creating InspectorPanel...");
+ // Create Inspector panel (right side)
+ auto inspectorPanel = makeUnique<InspectorPanel>(registry_, selection_, commandHistory_);
+ inspectorPanel->setMinSize(glm::vec2(250.0f, 200.0f));
+ ES_LOG_INFO("setupEditorLayout: Adding InspectorPanel to dock...");
+ dockArea_->addPanel(std::move(inspectorPanel), ui::DockDropZone::Right, nullptr, 0.25f);
+
+ ES_LOG_INFO("setupEditorLayout: Setting root widget...");
+ // Set dock area as the root widget
+ uiContext_->setRoot(std::move(dockArea));
+
+ ES_LOG_INFO("Editor layout initialized with Hierarchy, SceneView, and Inspector panels");
+}
+
+void EditorApplication::createDemoScene() {
+ // Create some demo entities for testing the editor
+
+ // Root entity
+ Entity root = registry_.create();
+ registry_.emplace<ecs::Name>(root, "Scene Root");
+ registry_.emplace<ecs::LocalTransform>(root);
+
+ // Camera entity
+ Entity camera = registry_.create();
+ registry_.emplace<ecs::Name>(camera, "Main Camera");
+ registry_.emplace<ecs::LocalTransform>(camera, glm::vec3(0.0f, 5.0f, 10.0f));
+
+ // Light entity
+ Entity light = registry_.create();
+ registry_.emplace<ecs::Name>(light, "Directional Light");
+ registry_.emplace<ecs::LocalTransform>(light, glm::vec3(0.0f, 10.0f, 0.0f));
+
+ // Parent-child hierarchy: Player with children
+ Entity player = registry_.create();
+ registry_.emplace<ecs::Name>(player, "Player");
+ registry_.emplace<ecs::LocalTransform>(player, glm::vec3(0.0f, 1.0f, 0.0f));
+
+ Entity playerMesh = registry_.create();
+ registry_.emplace<ecs::Name>(playerMesh, "PlayerMesh");
+ registry_.emplace<ecs::LocalTransform>(playerMesh);
+ registry_.emplace<ecs::Parent>(playerMesh, player);
+
+ Entity playerWeapon = registry_.create();
+ registry_.emplace<ecs::Name>(playerWeapon, "Weapon");
+ registry_.emplace<ecs::LocalTransform>(playerWeapon, glm::vec3(0.5f, 0.0f, 0.0f));
+ registry_.emplace<ecs::Parent>(playerWeapon, player);
+
+ // Add children to player
+ auto& playerChildren = registry_.emplace<ecs::Children>(player);
+ playerChildren.entities = {playerMesh, playerWeapon};
+
+ // Some standalone entities
+ Entity ground = registry_.create();
+ registry_.emplace<ecs::Name>(ground, "Ground");
+ registry_.emplace<ecs::LocalTransform>(ground, glm::vec3(0.0f, 0.0f, 0.0f), glm::quat(1.0f, 0.0f, 0.0f, 0.0f), glm::vec3(100.0f, 0.1f, 100.0f));
+
+ Entity obstacle1 = registry_.create();
+ registry_.emplace<ecs::Name>(obstacle1, "Obstacle 1");
+ registry_.emplace<ecs::LocalTransform>(obstacle1, glm::vec3(5.0f, 1.0f, 0.0f));
+
+ Entity obstacle2 = registry_.create();
+ registry_.emplace<ecs::Name>(obstacle2, "Obstacle 2");
+ registry_.emplace<ecs::LocalTransform>(obstacle2, glm::vec3(-5.0f, 1.0f, 3.0f));
+
+ ES_LOG_INFO("Demo scene created with {} entities", registry_.entityCount());
+}
+
} // namespace editor
} // namespace esengine
diff --git a/src/esengine/editor/EditorApplication.hpp b/src/esengine/editor/EditorApplication.hpp
index aace759dc..464797934 100644
--- a/src/esengine/editor/EditorApplication.hpp
+++ b/src/esengine/editor/EditorApplication.hpp
@@ -21,6 +21,7 @@
#include "../math/Math.hpp"
#include "../events/Dispatcher.hpp"
#include "../ui/UIContext.hpp"
+#include "../ui/docking/DockArea.hpp"
#include "command/CommandHistory.hpp"
#include "core/Selection.hpp"
@@ -91,6 +92,12 @@ public:
*/
ui::UIContext& getUIContext() { return *uiContext_; }
+ /**
+ * @brief Get the ECS registry (from base Application class)
+ * @return Reference to the ECS registry
+ */
+ ecs::Registry& getEditorRegistry() { return Application::getRegistry(); }
+
protected:
// =========================================================================
// Application Lifecycle Overrides
@@ -160,6 +167,16 @@ private:
*/
void setupEventListeners();
+ /**
+ * @brief Setup editor UI layout with docking panels
+ */
+ void setupEditorLayout();
+
+ /**
+ * @brief Create demo entities for testing
+ */
+ void createDemoScene();
+
// =========================================================================
// Constants
// =========================================================================
@@ -175,6 +192,7 @@ private:
CommandHistory commandHistory_; ///< Undo/redo history
EntitySelection selection_; ///< Entity selection manager
Unique<ui::UIContext> uiContext_; ///< UI system context
+ ui::DockArea* dockArea_ = nullptr; ///< Main docking area (owned by UIContext)
// =========================================================================
// State
diff --git a/src/esengine/editor/main.cpp b/src/esengine/editor/main.cpp
index 793d3b8d1..36f0ab28c 100644
--- a/src/esengine/editor/main.cpp
+++ b/src/esengine/editor/main.cpp
@@ -18,6 +18,7 @@
*/
int main() {
esengine::Log::init();
+
ES_LOG_INFO("Starting ESEngine Editor...");
esengine::editor::EditorApplication editor;
diff --git a/src/esengine/renderer/Renderer.cpp b/src/esengine/renderer/Renderer.cpp
index 4330d2512..3707ee97b 100644
--- a/src/esengine/renderer/Renderer.cpp
+++ b/src/esengine/renderer/Renderer.cpp
@@ -14,7 +14,15 @@
#include "RenderCommand.hpp"
#include "../core/Log.hpp"
#include "../resource/ResourceManager.hpp"
-#include "OpenGLHeaders.hpp"
+
+#ifdef ES_PLATFORM_WEB
+ #include <GLES3/gl3.h>
+#else
+ #ifdef _WIN32
+ #include <windows.h>
+ #endif
+ #include <glad/glad.h>
+#endif
#include <array>
#include <vector>
@@ -26,8 +34,7 @@ namespace esengine {
// ========================================
void RenderCommand::init() {
-#ifdef ES_PLATFORM_WEB
- ES_LOG_INFO("RenderCommand initialized (WebGL)");
+ ES_LOG_INFO("RenderCommand initialized");
// Enable depth testing by default
glEnable(GL_DEPTH_TEST);
@@ -35,7 +42,6 @@ void RenderCommand::init() {
// Enable blending
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-#endif
}
void RenderCommand::shutdown() {
@@ -43,110 +49,73 @@ void RenderCommand::shutdown() {
}
void RenderCommand::setViewport(i32 x, i32 y, u32 width, u32 height) {
-#ifdef ES_PLATFORM_WEB
- glViewport(x, y, width, height);
-#else
- (void)x; (void)y; (void)width; (void)height;
-#endif
+ glViewport(x, y, static_cast<GLsizei>(width), static_cast<GLsizei>(height));
}
void RenderCommand::setClearColor(const glm::vec4& color) {
-#ifdef ES_PLATFORM_WEB
glClearColor(color.r, color.g, color.b, color.a);
-#else
- (void)color;
-#endif
}
void RenderCommand::clear() {
-#ifdef ES_PLATFORM_WEB
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-#endif
}
void RenderCommand::drawIndexed(const VertexArray& vao, u32 indexCount) {
-#ifdef ES_PLATFORM_WEB
vao.bind();
auto ib = vao.getIndexBuffer();
u32 count = indexCount ? indexCount : (ib ? ib->getCount() : 0);
if (count > 0 && ib) {
GLenum type = ib->is16Bit() ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
- glDrawElements(GL_TRIANGLES, count, type, nullptr);
+ glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(count), type, nullptr);
}
-#else
- (void)vao; (void)indexCount;
-#endif
}
void RenderCommand::drawArrays(u32 vertexCount) {
-#ifdef ES_PLATFORM_WEB
- glDrawArrays(GL_TRIANGLES, 0, vertexCount);
-#else
- (void)vertexCount;
-#endif
+ glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(vertexCount));
}
void RenderCommand::setDepthTest(bool enabled) {
-#ifdef ES_PLATFORM_WEB
if (enabled) {
glEnable(GL_DEPTH_TEST);
} else {
glDisable(GL_DEPTH_TEST);
}
-#else
- (void)enabled;
-#endif
}
void RenderCommand::setDepthWrite(bool enabled) {
-#ifdef ES_PLATFORM_WEB
glDepthMask(enabled ? GL_TRUE : GL_FALSE);
-#else
- (void)enabled;
-#endif
}
void RenderCommand::setBlending(bool enabled) {
-#ifdef ES_PLATFORM_WEB
if (enabled) {
glEnable(GL_BLEND);
} else {
glDisable(GL_BLEND);
}
-#else
- (void)enabled;
-#endif
}
void RenderCommand::setBlendFunc() {
-#ifdef ES_PLATFORM_WEB
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-#endif
}
void RenderCommand::setCulling(bool enabled) {
-#ifdef ES_PLATFORM_WEB
if (enabled) {
glEnable(GL_CULL_FACE);
} else {
glDisable(GL_CULL_FACE);
}
-#else
- (void)enabled;
-#endif
}
void RenderCommand::setCullFace(bool front) {
-#ifdef ES_PLATFORM_WEB
glCullFace(front ? GL_FRONT : GL_BACK);
-#else
- (void)front;
-#endif
}
void RenderCommand::setWireframe(bool enabled) {
+#ifndef ES_PLATFORM_WEB
+ glPolygonMode(GL_FRONT_AND_BACK, enabled ? GL_LINE : GL_FILL);
+#else
(void)enabled;
- // WebGL doesn't support wireframe mode directly
+#endif
}
// ========================================
diff --git a/src/esengine/renderer/Shader.cpp b/src/esengine/renderer/Shader.cpp
index 7d927033b..4d624b8b4 100644
--- a/src/esengine/renderer/Shader.cpp
+++ b/src/esengine/renderer/Shader.cpp
@@ -12,7 +12,15 @@
#include "Shader.hpp"
#include "../core/Log.hpp"
-#include "OpenGLHeaders.hpp"
+
+#ifdef ES_PLATFORM_WEB
+ #include <GLES3/gl3.h>
+#else
+ #ifdef _WIN32
+ #include <windows.h>
+ #endif
+ #include <glad/glad.h>
+#endif
#include <fstream>
@@ -20,9 +28,7 @@ namespace esengine {
Shader::~Shader() {
if (programId_ != 0) {
-#ifdef ES_PLATFORM_WEB
glDeleteProgram(programId_);
-#endif
programId_ = 0;
}
}
@@ -35,9 +41,7 @@ Shader::Shader(Shader&& other) noexcept
Shader& Shader::operator=(Shader&& other) noexcept {
if (this != &other) {
if (programId_ != 0) {
-#ifdef ES_PLATFORM_WEB
glDeleteProgram(programId_);
-#endif
}
programId_ = other.programId_;
uniformCache_ = std::move(other.uniformCache_);
@@ -94,19 +98,14 @@ Unique<Shader> Shader::createFromFile(const std::string& vertexPath, const std::
}
void Shader::bind() const {
-#ifdef ES_PLATFORM_WEB
glUseProgram(programId_);
-#endif
}
void Shader::unbind() const {
-#ifdef ES_PLATFORM_WEB
glUseProgram(0);
-#endif
}
bool Shader::compile(const std::string& vertexSrc, const std::string& fragmentSrc) {
-#ifdef ES_PLATFORM_WEB
// Create vertex shader
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
const char* vertexSrcPtr = vertexSrc.c_str();
@@ -172,12 +171,6 @@ bool Shader::compile(const std::string& vertexSrc, const std::string& fragmentSr
ES_LOG_DEBUG("Shader compiled successfully (program ID: {})", programId_);
return true;
-#else
- (void)vertexSrc;
- (void)fragmentSrc;
- ES_LOG_WARN("Shader compilation not available in native mode");
- return false;
-#endif
}
i32 Shader::getUniformLocation(const std::string& name) const {
@@ -186,79 +179,40 @@ i32 Shader::getUniformLocation(const std::string& name) const {
return it->second;
}
-#ifdef ES_PLATFORM_WEB
i32 location = glGetUniformLocation(programId_, name.c_str());
uniformCache_[name] = location;
if (location == -1) {
ES_LOG_WARN("Uniform '{}' not found in shader", name);
}
return location;
-#else
- return -1;
-#endif
}
void Shader::setUniform(const std::string& name, i32 value) const {
-#ifdef ES_PLATFORM_WEB
glUniform1i(getUniformLocation(name), value);
-#else
- (void)name;
- (void)value;
-#endif
}
void Shader::setUniform(const std::string& name, f32 value) const {
-#ifdef ES_PLATFORM_WEB
glUniform1f(getUniformLocation(name), value);
-#else
- (void)name;
- (void)value;
-#endif
}
void Shader::setUniform(const std::string& name, const glm::vec2& value) const {
-#ifdef ES_PLATFORM_WEB
glUniform2f(getUniformLocation(name), value.x, value.y);
-#else
- (void)name;
- (void)value;
-#endif
}
void Shader::setUniform(const std::string& name, const glm::vec3& value) const {
-#ifdef ES_PLATFORM_WEB
glUniform3f(getUniformLocation(name), value.x, value.y, value.z);
-#else
- (void)name;
- (void)value;
-#endif
}
void Shader::setUniform(const std::string& name, const glm::vec4& value) const {
-#ifdef ES_PLATFORM_WEB
glUniform4f(getUniformLocation(name), value.x, value.y, value.z, value.w);
-#else
- (void)name;
- (void)value;
-#endif
}
void Shader::setUniform(const std::string& name, const glm::mat3& value) const {
-#ifdef ES_PLATFORM_WEB
glUniformMatrix3fv(getUniformLocation(name), 1, GL_FALSE, glm::value_ptr(value));
-#else
- (void)name;
- (void)value;
-#endif
}
void Shader::setUniform(const std::string& name, const glm::mat4& value) const {
-#ifdef ES_PLATFORM_WEB
glUniformMatrix4fv(getUniformLocation(name), 1, GL_FALSE, glm::value_ptr(value));
-#else
- (void)name;
- (void)value;
-#endif
}
} // namespace esengine
diff --git a/src/esengine/ui/UIContext.cpp b/src/esengine/ui/UIContext.cpp
index 3e025598c..c949927a4 100644
--- a/src/esengine/ui/UIContext.cpp
+++ b/src/esengine/ui/UIContext.cpp
@@ -148,7 +148,9 @@ void UIContext::update(f32 deltaTime) {
}
void UIContext::render() {
- if (!root_ || !renderer_) return;
+ if (!root_ || !renderer_) {
+ return;
+ }
glm::mat4 projection = glm::ortho(0.0f, static_cast<f32>(viewportWidth_),
static_cast<f32>(viewportHeight_), 0.0f, -1.0f, 1.0f);
diff --git a/src/esengine/ui/docking/DockArea.cpp b/src/esengine/ui/docking/DockArea.cpp
index 4a756d1e1..1398f7b27 100644
--- a/src/esengine/ui/docking/DockArea.cpp
+++ b/src/esengine/ui/docking/DockArea.cpp
@@ -282,7 +282,9 @@ glm::vec2 DockArea::measure(f32 availableWidth, f32 availableHeight) {
}
void DockArea::render(UIBatchRenderer& renderer) {
- if (!rootNode_) return;
+ if (!rootNode_) {
+ return;
+ }
rootNode_->setBounds(getBounds());
rootNode_->layout(splitterThickness_, tabBarHeight_);
diff --git a/src/esengine/ui/rendering/UIBatchRenderer.cpp b/src/esengine/ui/rendering/UIBatchRenderer.cpp
index 3573a870d..5be4ccff2 100644
--- a/src/esengine/ui/rendering/UIBatchRenderer.cpp
+++ b/src/esengine/ui/rendering/UIBatchRenderer.cpp
@@ -400,8 +400,11 @@ void UIBatchRenderer::flushQuadBatch() {
data_->shader->setUniform("u_projection", data_->projection);
i32 samplers[MAX_TEXTURE_SLOTS] = {0, 1, 2, 3, 4, 5, 6, 7};
- glUniform1iv(glGetUniformLocation(data_->shader->getProgramId(), "u_textures"),
- MAX_TEXTURE_SLOTS, samplers);
+ if (!data_->shader) {
+ return;
+ }
+ GLint loc = glGetUniformLocation(data_->shader->getProgramId(), "u_textures");
+ glUniform1iv(loc, MAX_TEXTURE_SLOTS, samplers);
RenderCommand::drawIndexed(*data_->vao, data_->indexCount);