Skip to content

Repository files navigation

ForgeEngine

ForgeEngine is a personal, experimental rendering and layout engine designed to explore the architecture behind modern browser engines and graphical user interfaces. The project combines a lightweight HTML/CSS processing pipeline, a layout engine, a rendering backend, and a basic UI/widget system into a single cohesive framework built around SDL3.

What began as a learning-oriented project has grown into a capable platform for understanding how content is parsed, styled, laid out, and painted on screen. ForgeEngine is not a production browser engine, but it provides a strong foundation for experimenting with core concepts such as DOM construction, style resolution, box layout, painting commands, text rendering, and immediate rendering workflows.

screen shot


Overview

ForgeEngine aims to demonstrate how a web-like document can be transformed from raw source into visible pixels through a structured pipeline:

  1. Parse HTML into a document tree.
  2. Parse and collect CSS rules.
  3. Resolve styles for each node.
  4. Build a render tree and layout tree.
  5. Generate painting commands.
  6. Execute those commands through a rendering backend.

This architecture mirrors the high-level flow used by large browser engines, although the implementation here is intentionally compact and educational.


Project Goals

The primary goals of ForgeEngine are:

  • Build a clear understanding of browser engine internals.
  • Create a modular codebase for experimenting with layout and rendering.
  • Support simple HTML and CSS documents with a basic visual output.
  • Provide a foundation for future expansion into richer UI components and more advanced layout behavior.
  • Demonstrate how a renderer can be driven from structured commands rather than ad-hoc drawing logic.

Key Features

1. HTML Parsing and DOM Construction

The engine includes an HTML tokenizer and parser capable of transforming markup into a hierarchical DOM-like structure. The parser models the document tree using nodes that preserve parent-child relationships and basic content semantics.

This is the first major step in turning static markup into a structured representation suitable for styling and layout.

2. CSS Parsing and Style Handling

ForgeEngine contains a CSS parser and stylesheet representation that allow CSS to be collected from style blocks and attached to the document tree. Although the system is still evolving, it provides a solid base for selector interpretation, declaration parsing, and style application.

This layer is central to making the engine behave more like a browser than a simple renderer.

3. Style Resolution

Once the DOM and stylesheet data are available, the style resolution stage evaluates which declarations should apply to each node. This step is critical for turning raw markup and CSS rules into meaningful visual properties.

4. Layout Engine

The layout subsystem builds a tree of layout boxes and computes the geometry required to place content in a viewport. The engine supports the idea of block-style structure and box-based positioning, which is essential for displaying text and container-based content.

5. Rendering Pipeline

The project includes an operation-based rendering pipeline that generates rendering commands from the computed layout tree. These commands are then executed by the virtual machine-like runtime layer, which interacts with the SDL3 rendering context.

This separation between command generation and command execution is a strong architectural choice because it makes the system easier to extend and reason about.

6. Text Rendering

ForgeEngine includes a text rendering subsystem that integrates font handling and glyph rendering. This is important because text is one of the most fundamental parts of UI and document rendering.

7. Widget and UI Layer

The project also contains a widget-oriented layer for building UI elements and interactive components. Although still relatively lightweight, this portion provides a foundation for extending the engine beyond pure document rendering into richer interface development.


Architecture

The engine is organized around a pipeline that is easy to follow conceptually:

HTML input
  -> Tokenization
  -> Parsing into DOM nodes
  -> CSS collection and style resolution
  -> Layout tree construction
  -> Command generation
  -> Rendering via SDL3

Each subsystem is isolated into its own module so the project can be understood and extended incrementally.

Core Runtime Flow

  • The application entry point initializes SDL3 and creates a window and renderer.
  • The initialization layer builds a document from embedded sample HTML.
  • The parser builds a DOM tree.
  • Style resolution attaches computed styling.
  • Layout produces box geometry.
  • Rendering commands are generated and executed.
  • The frame loop updates the screen continuously.

Project Structure

The repository is organized into a set of specialized modules:

  • core/ — drawing and basic rendering primitives.
  • init/ — main initialization and orchestration logic.
  • layout/ — layout tree creation and box layout computation.
  • paint/ — painting abstractions and drawing operations.
  • renderer/ — rendering backend integration.
  • op_generator/ — generation of rendering commands.
  • forgehtml/ — HTML tokenizer, parser, and related models.
  • forgecss/ — CSS parsing and stylesheet handling.
  • text/ — font, glyph, and text rendering support.
  • widget/ — UI/widget infrastructure.
  • vm/ — runtime execution of generated rendering commands.
  • types/ — shared type definitions.

This modular structure makes the engine easier to maintain and extend as different capabilities are added.


Build and Run

Requirements

The project is structured for macOS development and uses Xcode as its primary build environment.

Required dependencies are already bundled with the repository:

  • SDL3.xcframework
  • SDL3_image.xcframework
  • Font files such as Inter-Regular.ttf and Roboto-Regular.ttf

Build Steps

  1. Open the Xcode project file at ForgeEngine.xcodeproj.
  2. Select the ForgeEngine target.
  3. Build the project.
  4. Run the application.

The main sample application creates a window and renders a small HTML document using the engine pipeline.

Notes

Because this project is still evolving, you should expect incremental changes in behavior, feature completeness, and rendering fidelity as the engine grows.


Development Notes

Implementation Style

The codebase favors a hands-on, highly educational approach. It is designed to make the internals of rendering and layout understandable rather than abstracted away behind heavy frameworks or external dependencies.

Extensibility

The architecture is intentionally modular so future work can include:

  • richer CSS support,
  • better selector matching,
  • more layout modes,
  • improved text measurement,
  • animation and interaction handling,
  • additional widget components,
  • a stronger rendering abstraction layer.

Current Status

ForgeEngine is an active experimental project. It already demonstrates a meaningful end-to-end path from HTML/CSS input to visual output, but it should be considered a research and learning platform rather than a full-featured browser engine.

Current work focuses on establishing a coherent architecture and proving that the core pipeline can operate successfully from parsing through rendering.


Example Usage

The application entry point in the project initializes the engine, parses a sample HTML document, builds layout and render commands, and displays the result in a window using SDL3.

The overall experience is intentionally simple and approachable, which makes the project especially useful for understanding the flow of a rendering engine without the complexity of a fully production-grade browser stack.


Why This Project Matters

ForgeEngine is valuable not only as a software project, but also as a study in systems design. It brings together multiple disciplines that are central to modern graphics and UI programming:

  • parsing,
  • data modeling,
  • layout mathematics,
  • rendering pipelines,
  • text handling,
  • and windowed application development.

For anyone interested in browser internals, UI architecture, or graphics programming, this repository offers a practical and approachable path into those concepts.


Future Direction

Potential directions for the project include:

  • improved CSS support and selector matching,
  • better layout accuracy,
  • richer text shaping and font support,
  • more complete widget functionality,
  • a more robust scene graph or display tree,
  • and higher-quality rendering output.

The long-term goal is to evolve ForgeEngine from an experimental engine into a capable foundation for custom UI and document rendering experiences.


Contributing

Contributions are welcome if you are interested in expanding the engine, improving its architecture, or adding new capabilities. The project is especially suited for developers who want to explore rendering systems, browser internals, or UI engine design in a practical and hands-on way.


License

This project is maintained as an independent personal engineering effort. Please review the repository contents for any existing licensing or attribution requirements before redistribution or reuse.

About

A browser engine written in C++20

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages