Refactoring basic text rendering

This commit is contained in:
Dynamitos
2025-01-08 19:15:12 +01:00
parent eef78e8aa5
commit e487867f96
70 changed files with 608 additions and 1133 deletions
+1 -1
View File
@@ -9,4 +9,4 @@ target_sources(Editor
MeshLoader.h
MeshLoader.cpp
TextureLoader.h
TextureLoader.cpp)
TextureLoader.cpp "../../../tests/Engine/UI/Element.cpp")
+5 -18
View File
@@ -30,7 +30,6 @@ void FontLoader::importAsset(FontImportArgs args) {
// in case of the space character there is no bitmap
// so we create a single pixel empty texture
uint8 transparentPixel = 0;
void FontLoader::import(FontImportArgs args, PFontAsset asset) {
FT_Library ft;
FT_Error error = FT_Init_FreeType(&ft);
@@ -39,7 +38,6 @@ void FontLoader::import(FontImportArgs args, PFontAsset asset) {
error = FT_New_Face(ft, args.filePath.string().c_str(), 0, &face);
assert(!error);
FT_Set_Pixel_Sizes(face, 0, 48);
Array<Gfx::OTexture2D> usedTextures;
for (uint32 c = 0; c < 256; ++c) {
if (FT_Load_Char(face, c, FT_LOAD_RENDER)) {
std::cout << "error loading " << (char)c << std::endl;
@@ -49,28 +47,17 @@ void FontLoader::import(FontImportArgs args, PFontAsset asset) {
glyph.size = IVector2(face->glyph->bitmap.width, face->glyph->bitmap.rows);
glyph.bearing = IVector2(face->glyph->bitmap_left, face->glyph->bitmap_top);
glyph.advance = face->glyph->advance.x;
TextureCreateInfo imageData;
imageData.format = Gfx::SE_FORMAT_R8_UINT;
imageData.width = face->glyph->bitmap.width;
imageData.height = face->glyph->bitmap.rows;
imageData.sourceData.data = face->glyph->bitmap.buffer;
imageData.sourceData.size = imageData.width * imageData.height;
if (imageData.width == 0 || imageData.height == 0) {
glyph.textureData.resize(glyph.size.x * glyph.size.y);
if (glyph.textureData.size() == 0) {
glyph.size.x = 1;
glyph.size.y = 1;
glyph.bearing.x = 0;
glyph.bearing.y = 0;
imageData.width = 1;
imageData.height = 1;
imageData.sourceData.size = sizeof(uint8);
imageData.sourceData.data = &transparentPixel;
glyph.textureData.add(0); // load a single transparent pixel, so that we dont have to handle empty textures later
} else {
std::memcpy(glyph.textureData.data(), face->glyph->bitmap.buffer, glyph.textureData.size());
}
glyph.textureIndex = usedTextures.size();
usedTextures.add(graphics->createTexture2D(imageData));
}
FT_Done_Face(face);
FT_Done_FreeType(ft);
asset->setUsedTextures(std::move(usedTextures));
AssetRegistry::saveAsset(asset, FontAsset::IDENTIFIER, asset->getFolderPath(), asset->getName());
+10 -19
View File
@@ -3,40 +3,31 @@
#include "Asset/AssetRegistry.h"
#include "Asset/FontLoader.h"
#include "Graphics/Graphics.h"
#include "UI/System.h"
#include "Window/Window.h"
#include "UI/Element/Text.h"
using namespace Seele;
using namespace Seele::Editor;
InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo)
: View(graphics, std::move(window), std::move(createInfo), "InspectorView")
//, renderGraph(RenderGraphBuilder::build(
// UIPass(graphics),
// TextPass(graphics)
//))
,
uiSystem(new UI::System()) {
// renderGraph.updateViewport(viewport);
uiSystem->updateViewport(viewport);
: View(graphics, window, createInfo, "InspectorView"), uiSystem(new UI::System(new UI::Text("Test"))) {
renderGraph.addPass(new UIPass(graphics, uiSystem));
renderGraph.setViewport(viewport);
renderGraph.createRenderPass();
}
InspectorView::~InspectorView() {}
void InspectorView::beginUpdate() {
// co_return;
}
void InspectorView::beginUpdate() {}
void InspectorView::update() {
// co_return;
}
void InspectorView::update() {}
void InspectorView::commitUpdate() {}
void InspectorView::prepareRender() {}
void InspectorView::render() {}
void InspectorView::render() { renderGraph.render(Component::Camera()); }
void InspectorView::applyArea(URect area) {}
void InspectorView::keyCallback(KeyCode, InputAction, KeyModifier) {}
+5 -5
View File
@@ -1,10 +1,8 @@
#pragma once
#include "Graphics/RenderPass/RenderGraph.h"
#include "Graphics/RenderPass/TextPass.h"
#include "Graphics/RenderPass/UIPass.h"
#include "UI/Elements/Panel.h"
#include "Window/View.h"
#include "UI/System.h"
namespace Seele {
DECLARE_REF(Actor)
@@ -20,11 +18,13 @@ class InspectorView : public View {
virtual void prepareRender() override;
virtual void render() override;
void selectActor();
protected:
virtual void applyArea(URect area) override;
UI::PSystem uiSystem;
PActor selectedActor;
RenderGraph renderGraph;
Component::Camera cam;
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override;
virtual void mouseMoveCallback(double xPos, double yPos) override;
+48 -37
View File
@@ -11,6 +11,7 @@
#include "Graphics/Vulkan/Graphics.h"
#endif
#include "Graphics/StaticMeshVertexData.h"
#include "Window/InspectorView.h"
#include "Window/PlayView.h"
#include "Window/WindowManager.h"
#include <fmt/core.h>
@@ -36,9 +37,9 @@ Array<Halfedge> generateEdges() {
Array<Halfedge> edges;
for (auto ind : indices) {
uint32 baseIndex = edges.size();
edges.add(Halfedge{ind.x, baseIndex+1, baseIndex+2, UINT32_MAX});
edges.add(Halfedge{ind.y, baseIndex+2, baseIndex, UINT32_MAX});
edges.add(Halfedge{ind.z, baseIndex, baseIndex+1, UINT32_MAX});
edges.add(Halfedge{ind.x, baseIndex + 1, baseIndex + 2, UINT32_MAX});
edges.add(Halfedge{ind.y, baseIndex + 2, baseIndex, UINT32_MAX});
edges.add(Halfedge{ind.z, baseIndex, baseIndex + 1, UINT32_MAX});
}
for (uint32 i = 0; i < edges.size(); ++i) {
if (edges[i].twinID == UINT32_MAX) {
@@ -83,9 +84,9 @@ int main() {
OWindowManager windowManager = new WindowManager();
AssetRegistry::init(sourcePath / "Assets", graphics);
AssetImporter::init(graphics);
// AssetImporter::importFont(FontImportArgs{
// .filePath = "./fonts/Calibri.ttf",
// });
AssetImporter::importFont(FontImportArgs{
.filePath = "./fonts/arial.ttf",
});
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/cube.fbx",
});
@@ -100,35 +101,35 @@ int main() {
// .filePath = sourcePath / "import/models/ship.fbx",
// .importPath = "ship",
// });
//AssetImporter::importTexture(TextureImportArgs{
// AssetImporter::importTexture(TextureImportArgs{
// .filePath = sourcePath / "import/textures/azeroth.png",
//});
//AssetImporter::importTexture(TextureImportArgs{
// AssetImporter::importTexture(TextureImportArgs{
// .filePath = sourcePath / "import/textures/azeroth_height.png",
//});
//AssetImporter::importTexture(TextureImportArgs{
// AssetImporter::importTexture(TextureImportArgs{
// .filePath = sourcePath / "import/textures/wgen.png",
//});
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
.importPath = "Whitechapel",
});
//AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/plane.obj",
// .importPath = "",
//});
// AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj",
// .importPath = "suburbs",
// });
// AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/minecraft-medieval-city.fbx",
// .importPath = "minecraft",
// });
// AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/Volvo/Volvo.fbx",
// .importPath = "Volvo",
// .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
// .importPath = "Whitechapel",
//});
// AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/plane.obj",
// .importPath = "",
// });
// AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj",
// .importPath = "suburbs",
// });
// AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/minecraft-medieval-city.fbx",
// .importPath = "minecraft",
// });
// AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/Volvo/Volvo.fbx",
// .importPath = "Volvo",
// });
getThreadPool().waitIdle();
vd->commitMeshes();
WindowCreateInfo mainWindowInfo = {
@@ -138,16 +139,26 @@ int main() {
.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB,
};
auto window = windowManager->addWindow(graphics, mainWindowInfo);
ViewportCreateInfo sceneViewInfo = {
.dimensions =
{
.size = {1920, 1080},
.offset = {0, 0},
},
.numSamples = Gfx::SE_SAMPLE_COUNT_4_BIT,
};
OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string());
sceneView->setFocused();
// ViewportCreateInfo sceneViewInfo = {
// .dimensions =
// {
// .size = {1920, 1080},
// .offset = {0, 0},
// },
// .numSamples = Gfx::SE_SAMPLE_COUNT_4_BIT,
// };
// OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string());
// sceneView->setFocused();
OInspectorView inspectorView = new Editor::InspectorView(graphics, window,
ViewportCreateInfo{
.dimensions =
{
.size = {1920, 1080},
.offset = {0, 0},
},
.fieldOfView = 0,
.numSamples = Gfx::SE_SAMPLE_COUNT_1_BIT,
});
while (windowManager->isActive() && getGlobals().running) {
windowManager->render();