Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 0 additions & 53 deletions Editor/Include/Editor/Widget/GraphicsSampleWidget.h

This file was deleted.

16 changes: 14 additions & 2 deletions Editor/Include/Editor/Widget/ProjectHub.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,32 @@ namespace Editor {
EProperty() std::string path;
};

struct EClass() CreateProjectResult {
EClassBody(CreateProjectResult)

EProperty() bool success;
EProperty() std::string error;
EProperty() std::string projectPath;
};

class ProjectHubBackend final : public QObject {
Q_OBJECT
Q_PROPERTY(QString engineVersion READ GetEngineVersion CONSTANT)
Q_PROPERTY(QJsonValue projectTemplates READ GetProjectTemplates CONSTANT)
Q_PROPERTY(QJsonValue recentProjects READ GetRecentProjects)
Q_PROPERTY(QJsonValue recentProjects READ GetRecentProjects NOTIFY RecentProjectsChanged)

public:
explicit ProjectHubBackend(ProjectHub* parent = nullptr);
~ProjectHubBackend() override;

public Q_SLOTS:
void CreateProject() const;
QJsonValue CreateProject(const QString& inName, const QString& inDirectory, const QString& inTemplatePath);
void OpenProject(const QString& inProjectPath);
QString BrowseDirectory() const;

Q_SIGNALS:
void RecentProjectsChanged();

private:
QString GetEngineVersion() const;
QJsonValue GetProjectTemplates() const;
Expand Down
103 changes: 103 additions & 0 deletions Editor/Include/Editor/Widget/Prototype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//
// Created by johnk on 2026/6/21.
//

#pragma once

#include <array>
#include <atomic>

#include <QWidget>

#include <Render/ShaderCompiler.h>
#include <Editor/Widget/GraphicsWidget.h>
#include <Editor/Widget/WebWidget.h>

namespace Editor {
class PrototypeTriangleWidget final : public GraphicsWidget {
Q_OBJECT

public:
explicit PrototypeTriangleWidget(QWidget* inParent = nullptr);
~PrototypeTriangleWidget() override;

void SetRotationSpeed(float inRadiansPerSecond);
float GetRotationSpeed() const;

protected:
void resizeEvent(QResizeEvent* event) override;

private:
static constexpr uint8_t swapChainTextureNum = 2;

void RecreateSwapChain(uint32_t inWidth, uint32_t inHeight);
void DispatchFrame();
void DrawFrame();

std::atomic<float> rotationSpeed;
float rotation;
double lastFrameSeconds;

Common::UniquePtr<RHI::Semaphore> imageReadySemaphore;
Common::UniquePtr<RHI::Semaphore> renderFinishedSemaphore;
Common::UniquePtr<RHI::Fence> frameFence;
Common::UniquePtr<RHI::SwapChain> swapChain;
std::array<RHI::Texture*, swapChainTextureNum> swapChainTextures;
std::array<Common::UniquePtr<RHI::TextureView>, swapChainTextureNum> swapChainTextureViews;
Render::ShaderCompileOutput vsCompileOutput;
Render::ShaderCompileOutput psCompileOutput;
Common::UniquePtr<RHI::ShaderModule> vsModule;
Common::UniquePtr<RHI::ShaderModule> psModule;
Common::UniquePtr<RHI::BindGroupLayout> bindGroupLayout;
Common::UniquePtr<RHI::PipelineLayout> pipelineLayout;
Common::UniquePtr<RHI::RasterPipeline> pipeline;
Common::UniquePtr<RHI::Buffer> vertexBuffer;
Common::UniquePtr<RHI::BufferView> vertexBufferView;
Common::UniquePtr<RHI::Buffer> uniformBuffer;
Common::UniquePtr<RHI::BufferView> uniformBufferView;
Common::UniquePtr<RHI::BindGroup> bindGroup;
Common::UniquePtr<RHI::CommandBuffer> commandBuffer;
Common::UniquePtr<Common::WorkerThread> drawThread;
std::atomic_bool running;
};

class PrototypeBackend final : public QObject {
Q_OBJECT
Q_PROPERTY(double rotationSpeed READ GetRotationSpeed CONSTANT)

public:
explicit PrototypeBackend(PrototypeTriangleWidget* inTriangle, QObject* inParent = nullptr);
~PrototypeBackend() override;

public Q_SLOTS:
void SetRotationSpeed(double inDegreesPerSecond);

private:
double GetRotationSpeed() const;

PrototypeTriangleWidget* triangle;
};

class PrototypeWebWidget final : public WebWidget {
Q_OBJECT

public:
explicit PrototypeWebWidget(PrototypeTriangleWidget* inTriangle, QWidget* inParent = nullptr);
~PrototypeWebWidget() override;

private:
PrototypeBackend* backend;
};

class PrototypePlayground final : public QWidget {
Q_OBJECT

public:
explicit PrototypePlayground(QWidget* inParent = nullptr);
~PrototypePlayground() override;

private:
PrototypeTriangleWidget* triangle;
PrototypeWebWidget* web;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,27 @@ struct FragmentInput {

#if VERTEX_SHADER
cbuffer vsUniform {
float3 vertexColor;
float rotation;
};

FragmentInput VSMain(
uint vertexId : SV_VertexID,
VkLocation(0) float3 position : POSITION)
{
const float sinR = sin(rotation);
const float cosR = cos(rotation);
const float2 rotated = float2(
position.x * cosR - position.y * sinR,
position.x * sinR + position.y * cosR);

FragmentInput fragmentInput;
fragmentInput.position = float4(position.xyz, 1.0f);
fragmentInput.position = float4(rotated, position.z, 1.0f);
#if VULKAN
fragmentInput.position.y = - fragmentInput.position.y;
#endif

fragmentInput.color = float4(0.0f, 0.0f, 0.0f, 1.0f);
fragmentInput.color[vertexId % 3] = vertexColor[vertexId % 3];
fragmentInput.color[vertexId % 3] = 1.0f;
return fragmentInput;
}
#endif
Expand Down
34 changes: 11 additions & 23 deletions Editor/Src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
#include <Runtime/Engine.h>
#include <Editor/Widget/Editor.h>
#include <Editor/Widget/ProjectHub.h>
#include <Editor/Widget/Prototype.h>
#include <Editor/WebUIServer.h>

#if BUILD_CONFIG_DEBUG
#include <Editor/Widget/GraphicsSampleWidget.h>

static Core::CmdlineArgValue<bool> caGraphicsSample(
"graphicsSample", "-graphicsSample", false,
"Whether to run graphics sample instead of editor");
#endif
static Core::CmdlineArgValue<bool> caPrototype(
"prototype", "-prototype", false,
"Whether to run the prototype playground (native graphics widget mixed with web widget) instead of editor");

static Core::CmdlineArgValue<std::string> caRhiType(
"rhiType", "-rhi", RHI::GetPlatformDefaultRHIAbbrString(),
Expand All @@ -28,21 +25,17 @@ static Core::CmdlineArgValue<std::string> caProjectRoot(
"project root path");

enum class EditorApplicationModel : uint8_t {
#if BUILD_CONFIG_DEBUG
graphicsSample,
#endif
prototype,
projectHub,
editor,
max
};

static EditorApplicationModel GetAppModel()
{
#if BUILD_CONFIG_DEBUG
if (caGraphicsSample.GetValue()) {
return EditorApplicationModel::graphicsSample;
if (caPrototype.GetValue()) {
return EditorApplicationModel::prototype;
}
#endif
if (caProjectRoot.GetValue().empty()) {
return EditorApplicationModel::projectHub;
}
Expand All @@ -51,11 +44,8 @@ static EditorApplicationModel GetAppModel()

static bool NeedInitCore(EditorApplicationModel inModel)
{
bool result = inModel == EditorApplicationModel::editor;
#if BUILD_CONFIG_DEBUG
result = result || inModel == EditorApplicationModel::graphicsSample;
#endif
return result;
return inModel == EditorApplicationModel::editor
|| inModel == EditorApplicationModel::prototype;
}

static void InitializePreQtApp(EditorApplicationModel inModel)
Expand Down Expand Up @@ -91,11 +81,9 @@ static void Cleanup(EditorApplicationModel inModel)

static Common::UniquePtr<QWidget> CreateMainWidget(EditorApplicationModel inModel)
{
#if BUILD_CONFIG_DEBUG
if (inModel == EditorApplicationModel::graphicsSample) {
return new Editor::GraphicsSampleWidget();
if (inModel == EditorApplicationModel::prototype) {
return new Editor::PrototypePlayground();
}
#endif
if (inModel == EditorApplicationModel::projectHub) { // NOLINT
return new Editor::ProjectHub();
}
Expand Down
Loading
Loading