Add XCUI new editor sandbox phase 1
This commit is contained in:
119
new_editor/src/XCUIBackend/XCUIRHICommandCompiler.h
Normal file
119
new_editor/src/XCUIBackend/XCUIRHICommandCompiler.h
Normal file
@@ -0,0 +1,119 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
namespace XCUIBackend {
|
||||
|
||||
class XCUIRHICommandCompiler {
|
||||
public:
|
||||
struct ColorVertex {
|
||||
float position[2] = { 0.0f, 0.0f };
|
||||
float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
};
|
||||
|
||||
struct TexturedVertex {
|
||||
float position[2] = { 0.0f, 0.0f };
|
||||
float uv[2] = { 0.0f, 0.0f };
|
||||
float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
};
|
||||
|
||||
enum class BatchKind : std::uint8_t {
|
||||
Color = 0,
|
||||
Textured
|
||||
};
|
||||
|
||||
struct Batch {
|
||||
BatchKind kind = BatchKind::Color;
|
||||
std::uint32_t drawListIndex = 0;
|
||||
std::uint32_t firstCommandIndex = 0;
|
||||
std::uint32_t commandCount = 0;
|
||||
std::uint32_t firstVertex = 0;
|
||||
std::uint32_t vertexCount = 0;
|
||||
UI::UIRect clipRect = {};
|
||||
UI::UITextureHandle texture = {};
|
||||
};
|
||||
|
||||
struct Stats {
|
||||
std::size_t drawListCount = 0;
|
||||
std::size_t commandCount = 0;
|
||||
std::size_t compiledCommandCount = 0;
|
||||
std::size_t skippedCommandCount = 0;
|
||||
std::size_t culledCommandCount = 0;
|
||||
std::size_t unsupportedCommandCount = 0;
|
||||
std::size_t filledRectCommandCount = 0;
|
||||
std::size_t rectOutlineCommandCount = 0;
|
||||
std::size_t textCommandCount = 0;
|
||||
std::size_t imageCommandCount = 0;
|
||||
std::size_t clipPushCommandCount = 0;
|
||||
std::size_t clipPopCommandCount = 0;
|
||||
std::size_t colorVertexCount = 0;
|
||||
std::size_t texturedVertexCount = 0;
|
||||
std::size_t triangleCount = 0;
|
||||
std::size_t batchCount = 0;
|
||||
std::size_t maxClipDepth = 0;
|
||||
std::size_t clipStackUnderflowCount = 0;
|
||||
std::size_t danglingClipDepth = 0;
|
||||
};
|
||||
|
||||
struct CompiledDrawData {
|
||||
std::vector<ColorVertex> colorVertices = {};
|
||||
std::vector<TexturedVertex> texturedVertices = {};
|
||||
std::vector<Batch> batches = {};
|
||||
Stats stats = {};
|
||||
|
||||
void Clear();
|
||||
bool Empty() const;
|
||||
};
|
||||
|
||||
struct TextRunContext {
|
||||
float requestedFontSize = 0.0f;
|
||||
float resolvedFontSize = 0.0f;
|
||||
float lineHeight = 0.0f;
|
||||
UI::UITextureHandle texture = {};
|
||||
};
|
||||
|
||||
struct TextGlyph {
|
||||
float x0 = 0.0f;
|
||||
float y0 = 0.0f;
|
||||
float x1 = 0.0f;
|
||||
float y1 = 0.0f;
|
||||
float u0 = 0.0f;
|
||||
float v0 = 0.0f;
|
||||
float u1 = 0.0f;
|
||||
float v1 = 0.0f;
|
||||
float advanceX = 0.0f;
|
||||
bool visible = true;
|
||||
};
|
||||
|
||||
class TextGlyphProvider {
|
||||
public:
|
||||
virtual ~TextGlyphProvider() = default;
|
||||
|
||||
virtual bool BeginText(float requestedFontSize, TextRunContext& outContext) const = 0;
|
||||
virtual bool ResolveGlyph(
|
||||
const TextRunContext& context,
|
||||
std::uint32_t codepoint,
|
||||
TextGlyph& outGlyph) const = 0;
|
||||
};
|
||||
|
||||
struct CompileConfig {
|
||||
UI::UIRect surfaceClipRect = {};
|
||||
const TextGlyphProvider* textGlyphProvider = nullptr;
|
||||
bool mergeBatchesWithinDrawList = true;
|
||||
};
|
||||
|
||||
void Compile(
|
||||
const UI::UIDrawData& drawData,
|
||||
const CompileConfig& config,
|
||||
CompiledDrawData& outCompiledDrawData) const;
|
||||
};
|
||||
|
||||
} // namespace XCUIBackend
|
||||
} // namespace Editor
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user