Renderer2D Deep Dive
Renderer2D is the current rendering layer inside Cocoa Engine. It is focused on building a clean 2D rendering pipeline around draw commands, materials, shaders, textures, and GPU resource ownership.
The goal is not only to draw sprites, but to understand and design the engine systems that sit between scene data and the graphics API.
Purpose
Renderer2D exists to turn high-level render requests into GPU draw calls.
The current direction is:
Scene / ECS
↓
Render System
↓
Renderer2D
↓
MaterialHandle
↓
MaterialManager
↓
ShaderManager + TextureManager
↓
GraphicsDevice
↓
OpenGLThis keeps scene objects from directly owning shaders, textures, buffers, or OpenGL resources.
Instead, objects reference engine-managed resources through handles, and the renderer resolves those handles at draw time.
Why This Matters
A simple renderer can hardcode a shader, bind one texture, and draw one quad.
That works for a demo, but it does not scale into an engine.
Renderer2D is being designed around the ideas needed for a real rendering system:
- Draw command submission
- Resource handles
- Material-based rendering
- Shader and texture managers
- GPU resource abstraction
- Future batching
- Future camera support
- Future ECS-driven rendering
The goal is to keep rendering flexible without over-engineering the first version.
Current Design
Renderer2D is responsible for accepting draw requests and converting them into renderable commands.
A draw request should not need to know how OpenGL works. It should only need to describe what should be drawn.
Current renderer responsibilities include:
- Managing quad geometry
- Resolving material handles
- Resolving shader and texture resources
- Binding render state
- Submitting indexed draw calls through
GraphicsDevice
The renderer sits above the low-level graphics API and below the scene/ECS layer.
Resource Ownership
One of the main design goals is to avoid passing raw graphics objects throughout the engine.
Instead of scene components owning a Texture2D or Shader, they can eventually reference a MaterialHandle.
Sprite / Render Component
↓
MaterialHandle
↓
Material
↓
ShaderHandle + TextureHandle + TintThis keeps ownership centralized inside the engine managers.
That design makes it easier to cache resources, reuse materials, batch draw calls, and eventually support editor workflows or packed assets.
Material-Based Rendering
The renderer is moving toward material-based draw calls.
A material represents the CPU-side render data needed to draw an object:
- Shader handle
- Texture handle
- Tint/color data
- Future material properties
This is more scalable than having every draw call manually bind a shader and texture.
The long-term goal is for Renderer2D to submit draw commands by material, allowing the renderer to group, sort, and batch work more intelligently.
GraphicsDevice Boundary
Renderer2D does not need to directly expose raw OpenGL behavior to higher-level systems.
The GraphicsDevice abstraction provides a boundary between engine rendering code and the graphics backend.
That boundary matters because it keeps renderer code cleaner and makes the engine architecture easier to evolve.
Current backend direction:
Renderer2D
↓
GraphicsDevice
↓
OpenGL implementationThis gives the engine room to grow without spreading raw graphics API calls across scene or application code.
Near-Term Goals
The next steps for Renderer2D are:
- Add transform support
- Add camera/view-projection support
- Draw multiple sprites
- Improve material binding
- Add sprite/render components through ECS
- Introduce batching
- Sort or group draw commands by material
- Reduce hardcoded shader and texture assumptions
These features will move the renderer from a first working implementation toward a more complete 2D rendering system.
Long-Term Direction
The long-term goal is for Renderer2D to support a scene-driven workflow:
World
↓
Render System gathers visible render components
↓
Renderer2D receives draw commands
↓
Renderer2D batches and submits work
↓
GraphicsDevice executes GPU commandsThat structure creates a cleaner separation between game logic, scene data, rendering decisions, and GPU execution.
What This Demonstrates
Renderer2D demonstrates my interest in graphics programming and engine architecture beyond simply using a game engine.
This work shows:
- Understanding of the rendering pipeline
- GPU resource management
- Shader and texture binding
- Engine-level resource handles
- Renderer layering
- OpenGL-backed graphics programming
- C++ ownership and lifetime design
- Incremental architecture growth
- Testable design around graphics-adjacent systems