The Inner Workings of GPU Rendering for 2D and 3D Graphics

Authors
Kacper Fałat
Software Engineer
@
Callstack

The canvas is no longer just a piece of fabric stretched over a wooden frame. It has transformed into the glowing screens of our computers, where artists and engineers alike create visual masterpieces. But how do these electronic canvases come to life with vibrant graphics? The answer lies in the intricate dance between software and hardware, orchestrated by the graphics engine.

GPU is powering our graphics experience already from the decades so it should not be a mystery how it works. It doesn’t matter if we are using 2D or 3D graphics, our GPU is a performance monster. Let’s dive deep first into what the GPU is to get rid of the buzzwords and mysteries.

What is the GPU why is it important?

A GPU stands for graphics processing unit. It’s a specialized piece of hardware responsible for rendering images, videos, and 2D or 3D animations on your computer screen.

Unlike the CPU (central processing unit), which focuses on sequential serial processing, a GPU excels at parallel processing.

Here are the key points:

  1. Rendering Images and Videos: Every PC uses a GPU to display visual content, whether you’re browsing the web, watching videos, or playing games.
  2. Math Calculations: GPUs perform quick mathematical calculations related to graphics, freeing up the CPU to handle other tasks.
  3. Thousands of Cores: A GPU has thousands of smaller cores designed for multitasking. These cores work together to process graphics data efficiently.
  4. Graphics Cards: GPUs are commonly found in graphics cards (also known as video cards). These cards contain the actual graphics processor chip and RAM to handle demanding graphics loads, such as gaming.
  5. Integrated vs. Discrete GPUs:
  • Integrated Graphics: Some processors (like Intel’s) have integrated graphics built right into the chip. These are cost-effective but less powerful.
  • Discrete Graphics: Desktop PCs can use separate graphics cards (discrete GPUs) for better performance. Laptops may also have discrete GPUs, although they’re not as easy to upgrade.

In summary, the GPU is supplemental hardware to the brain of our devices that helps its creative end to please our eyes.

They are designed to perform complicated mathematical calculations and algorithms that are backing moving bits into pixels on our screens so we can enjoy all of beauty of the art on our desktop or even better - in our pockets.

Types of computer graphics

raster and vector lines

Let’s start easy. At the heart of computer graphics are two fundamental types: raster and vector.

Raster graphics

Also known as bitmap images, they are composed of tiny dots called pixels. Each pixel is a small square that can be assigned a color. When combined, these pixels form the images we see on our screens. This method is akin to pointillism, where numerous small dots of color create a detailed painting.

Vector graphics

Those graphics use mathematical formulas to represent images. These formulas define shapes, lines, and curves that are filled with color. Unlike raster graphics, vector images can be scaled to any size without losing quality, making them ideal for logos, fonts, and illustrations that require precision and scalability.

Our monitor is 2D canvas and 2D graphics is 2D so there should be no revelations that it’s pretty straightforward to paint it on the screen. But it’s not when it comes to rendering graphics; current system designs and graphics cards prefer using 3D space even for rendering 2D graphics which we will cover later.

Designing 3D images

illustration of how 3D graphics is designed

The 3D graphics is a bit more complex piece of cake, basically, our display is still a 2D canvas and we can’t directly draw on this surface 3 dimension objects because that’s how physics works. So we are taking the chunk of reality from 3D space; basically, it’s called viewport and camera.

The primary compound of the virtual 3D space is a vertex - a point in 3D space having 3 coordinates, X, Y, Z. When we combine 3 vertices we have face. When we combine multiple faces we are getting the mesh - for example a game character or a cube.

When we apply the 2D image which is called texture or, more professionally, material we are getting the final 3D object.

After that, we can apply shading and other filters to make the user delighted by the visual experience. To tackle the issue that our screen is 2D and graphics is 3D, we need some tools and some tricks to convert the 3D space into flat 2D picture.

And then update it, many times, usually 60 per second so the user is tricked into believing that they are looking at something with depth and they have control over it. But basically, the user is looking at very rapidly changing 2D pictures moving the viewport inside a real 3D space.

The camera is looking at a specific viewport and, just like with human eyes, we are casting rays of light that are touching the 3D virtual space. We convert these reflections into a 2D picture.

The graphics engine: A symphony of code

The graphics engine is the maestro conducting the creation of these images. It’s a complex piece of software that takes digital information from the computer’s central processing unit (CPU) and translates it into visual content that can be displayed on the screen.

This process involves several steps, each meticulously carried out to ensure the final image is rendered correctly.

a graph showing how a graphics engine works

Step 1: The vertex processor

The journey begins with the vertex processor, a stage where the basic building blocks of 3D graphics, known as vertices, are processed. Vertices are points in 3D space that define the corners of shapes.

The vertex processor takes these points and performs transformations on them, changing their positions based on various factors like the viewer’s perspective and the object’s location in the virtual world.

This is a really important stage because it is moving local coordinates into world coordinates so we can displace 3D elements to their proper place. For example, a tree in a game needs to stay at a correct place, not in the center, when it’s representing its default state.

Step 2: The tessellation and geometry shaders

Next, the tessellation and geometry shaders add complexity to the shapes. Tessellation breaks down the shapes into smaller parts, allowing for more detailed and smoother surfaces. The geometry shader can then manipulate these parts, adding effects like shadows and reflections.

Step 3: The rasterizer

The rasterizer converts the 3D shapes into 2D images by determining which pixels on the screen correspond to the vertices. This step is crucial as it bridges the gap between the 3D models and the 2D screen.

Step 4: The pixel processor

Once the shapes are rasterized, the pixel processor comes into play. It calculates the color of each pixel based on lighting, texture, and other visual effects. This stage is where the image truly comes to life with rich colors and realistic details.

Step 5: The output merger

Finally, the output merger combines all the processed pixels to form the complete image.It also handles depth, ensuring that objects closer to the viewer appear in front of those further away.

Step 6: Frame buffer

After our graphics is processed, rasterized (converted to pixels) we are ready to display it on the screen. The frame buffer is an object responsible for holding pixels that we are seeing on our display.

Currently, the graphics is double buffered which means our graphics card is holding two frames. One is displayed to us, the other one is being painted. Once painting is done, we are swapping them and begin the process from the scratch again, and again, until we turn off our device.

These frequent updates are tricking our brains that we see smooth animations even if we are only looking at rapidly changing static 2D images.

Conclusion: The masterpiece revealed

As the graphics engine and GPU work together, they bring the digital world to our screens. From the simplest shapes to the most complex 3D models, the process remains the same: a meticulous method of transforming data into visual art.

It’s a process that continues to evolve, pushing the boundaries of what’s possible in the realm of computer graphics.

Insights

Learn more about Performance

cover

Jul 3Podcast

Why Nitro Is More Than a Faster Bridge

Marc Rousavy (Margelo) talks Nitro modules, native state, zero-copy data, Vision Camera, and why speed is only part of the story.

cover

May 25Article

Profile React Components in React Native Release Builds

Learn how to profile React components in React Native release builds with @callstack/inspector, using an Expo app setup that requires zero native code changes.

cover

Nov 21Article

Memory Ownership Models: When JavaScript Meets Native Code

A deep dive into how React Native handles memory when JavaScript and native code share ArrayBuffer data. Learn why async processing can break, how GC affects raw pointers, and the safe patterns for building high-performance native integrations.

cover

Oct 14Article

From Files to Buffers: Building Real-Time Audio Pipelines in React Native

Learn how to move beyond file-based audio APIs and work directly with in-memory PCM data in React Native. This guide shows how to construct WAV buffers, use JSI for zero-copy transfers, and enable real-time audio processing.

cover

Sep 8Article

How to Add Custom JSI Bindings in Your TurboModule (and Why You Might Need Them)

TurboModules provide a type-safe way to write native code in React Native. JSI sits underneath as a lower-level API, enabling direct interaction with the JavaScript runtime. Beyond what TurboModules expose, JSI gives you access to powerful features, such as working directly with ArrayBuffers. This article shows how to inject a custom binding step by step.

cover

Jul 24Article

Exploring Fibers: Cooperative Multitasking and Lock-Free Task Execution

Explore how fibers enable lightweight, cooperative multitasking. This guide walks through building a simple scheduler, managing task dependencies without locks, and using Tracy to visualize performance.

cover

May 21Article

Multithreading Isn’t Free: Performance Pitfalls Visualized

Learn how to profile and optimize multithreaded apps. Discover why more threads don’t always mean faster results and how bad thread contention really is.

Event Cover

Apr 28Webinar

Master JavaScript Performance in React Native (Part 2)

Learn to fix JS performance issues in React Native-from debounce bugs to Redux selectors, in this hands-on webinar with real code examples.

Events Cover

Apr 24Talk

Tips & Tricks From The Ultimate Guide to React Native Optimization 2025

View flattening, React 19 hooks, real DevTools tips-learn what actually helps your React Native app run faster.

Events Cover

Apr 24Talk

User-Focused Performance Tracking

Discover how Expensify defines and tracks performance metrics that actually impact user experience.

cover

Dec 18Podcast

React Native FastIO: Nitro-Powered Performance Boost

Listen to Mike Grabowski talk about React Native FastIO, a collection of primitives for working with data in React Native and its performance benefits.

cover

Oct 15Podcast

Superfast Nitro Modules With Marc Rousavy

Even faster React Native apps? That's possible with Nitro Modules! Tune in to the conversation with their creator, Marc Rousavy.

cover

Mar 19Tutorial

The Hard Way vs. The React Native AI SDK Way: Stop Writing Custom Modules for Every Model

Learn how React Native AI uses a unified provider model to switch between cloud and on-device LLMs without rewriting application logic, enabling reliable AI experiences online and offline.

cover

Mar 12Tutorial

Build Smarter Apps: Tool Calling & AI Orchestration Explained

Learn how on-device models in React Native can call tools, interact with external APIs, and return structured outputs you can use directly in application logic.

cover

Mar 5Tutorial

MLC LLM + React Native: On-Device AI Without the Pain

Learn how to run third-party on-device LLMs in React Native using MLC LLM. Choose your models, run them efficiently across platforms, and keep a unified JavaScript API with React Native AI.

cover

Feb 24Tutorial

Intelligent Fallbacks with Apple Intelligence in React Native

Learn how to use Apple’s built-in Foundation Models in React Native apps, reduce memory usage, and enable fast, fully on-device AI with React Native AI Apple.

cover

Feb 10Tutorial

What Is the React Native AI SDK? A Complete Intro & Quickstart

Learn why on-device AI matters for React Native apps, how local LLMs behave offline, and what problems React Native AI is designed to solve from day one.

cover

Jan 29Tutorial

Implementing an Android TurboModule with Kotlin

Learn how to implement a React Native TurboModule on Android, from the TypeScript spec and Codegen to the Kotlin implementation and package registration.

cover

Jan 19Tutorial

Working with Different Threads in Swift TurboModules

Learn how JavaScript, native module, background, and main threads interact in React Native TurboModules, and how to use GCD queues to run async work safely in Swift.

cover

Jan 9Tutorial

How to Add Type-Safe Constants to Swift TurboModules

Learn how to expose typed, immutable constants from a Swift TurboModule using Codegen, and get full end-to-end type safety between native and JavaScript.

cover

Dec 30Tutorial

Adding Event Emitters to Your TurboModule in Swift

Learn how to emit native events from a Swift TurboModule and subscribe to them in JavaScript, including proper memory management and Codegen integration.

cover

Dec 22Tutorial

Writing Your First TurboModule in Swift

Learn how to build a fully working TurboModule in Swift, integrate it with Codegen, and bridge it through Objective‑C inside an Expo app.