What Graphics Backends Does JSAR Support? Complete Technical Reference

JSAR currently supports only the OpenGL family of graphics backends—specifically OpenGL Core, OpenGL ES 2.0, and OpenGL ES 3.0+—while Vulkan, Metal, Direct3D 11, and Direct3D 12 are defined in the API but not yet implemented.

The m-creativelab/jsar-runtime repository implements a cross-platform rendering layer that abstracts native graphics APIs through a Render-Hardware Interface (RHI). Understanding what graphics backends JSAR supports is essential for deploying applications across desktop, mobile, and web platforms, as the backend selection determines WebGL compatibility and rendering capabilities.

JSAR Render-Hardware Interface Architecture

JSAR's graphics abstraction layer centers on the Render-Hardware Interface (RHI), which decouples the runtime from platform-specific graphics implementations. The RHIBackendType enum in src/renderer/render_api.hpp (lines 68-81) declares all available graphics APIs, though only OpenGL variants are currently functional.

This abstraction allows JSAR to target multiple platforms while maintaining a consistent API surface. The runtime automatically selects the appropriate backend during initialization based on the host platform's capabilities and Unity's active graphics device.

Currently Supported Graphics Backends

As of the latest implementation, JSAR activates only OpenGL-based renderers. The supported configurations are explicitly documented in src/renderer/render_api.hpp (lines 91-100):

  • OpenGLCore: Desktop OpenGL core profile for Linux, macOS, and Windows desktop deployments.
  • OpenGLESv2: OpenGL ES 2.0, providing WebGL 1.0 compatibility for older mobile devices and legacy web contexts.
  • OpenGLESv3: OpenGL ES 3.0/3.1/3.2, enabling WebGL 2.0 features including multiple render targets, 3D textures, and instanced rendering.

The runtime exposes WebGL 2.0 capability through the SupportsWebGL2() method, which returns true only when the active backend is OpenGLESv3.

Planned but Unimplemented Graphics Backends

The RHIBackendType enum includes several modern graphics APIs reserved for future implementation. These backends are defined in the source code but lack concrete implementations in the rendering layer:

  • VULKAN: Cross-platform explicit API for high-performance rendering on modern GPUs.
  • Metal: Apple's low-overhead graphics API for iOS and macOS platforms.
  • D3D11: Microsoft Direct3D 11 for Windows platform compatibility.
  • D3D12: Microsoft Direct3D 12 for modern Windows gaming and application performance.

These values exist in src/renderer/render_api.hpp to maintain API stability, but selecting them at runtime will result in fallback behavior or initialization failures until implementations are added.

How JSAR Selects the Graphics Backend

Backend selection occurs automatically during Unity initialization in src/runtime/unity_entry.cpp (lines 75-80). The runtime queries Unity's active graphics device type and maps it to the corresponding RHIBackendType:

// Backend selection logic from src/runtime/unity_entry.cpp
if (unityGraphicsDevice == kUnityGfxRendererOpenGLES20) {
    backend = RHIBackendType::OpenGLESv2;
} else if (unityGraphicsDevice == kUnityGfxRendererOpenGLES30) {
    backend = RHIBackendType::OpenGLESv3;
} else {
    backend = RHIBackendType::OpenGLCore; // Desktop fallback
}

This automatic selection ensures the runtime uses the most compatible OpenGL variant for the host platform without requiring manual configuration. Desktop platforms default to OpenGL Core, while mobile and WebGL contexts select the appropriate OpenGL ES variant.

Detecting the Active Backend in TypeScript

Applications running on JSAR can query the active graphics backend at runtime using the TypeScript bindings exposed in lib/bindings/renderer.ts. The following example demonstrates how to identify the current renderer and check for WebGL 2.0 support:

import { RHIFactory } from "jsar-runtime/lib/bindings/renderer";

// Retrieve the concrete RHI instance
const rhi = RHIFactory.GetChecked();

// Identify the backend
switch (rhi.GetBackendType()) {
  case "OpenGLCore":
    console.log("Running on Desktop OpenGL");
    break;
  case "OpenGLESv2":
    console.log("Running on OpenGL ES 2.0 (WebGL 1)");
    break;
  case "OpenGLESv3":
    console.log("Running on OpenGL ES 3.x (WebGL 2)");
    break;
  default:
    console.warn("Unsupported backend");
}

// Query WebGL 2 capability
if (rhi.SupportsWebGL2()) {
  console.log("WebGL 2 features are available");
}

The GetBackendType() method returns the string representation of the RHIBackendType enum, while SupportsWebGL2() provides a convenience check that returns true only when the active backend is OpenGLESv3.

Key Source Files for Graphics Backend Support

Understanding the graphics backend implementation requires examining these specific files in the m-creativelab/jsar-runtime repository:

File Role
src/renderer/render_api.hpp Declares the RHIBackendType enum (lines 68-81), documents the supported backend matrix (lines 91-100), and defines the virtual RHI interface including SupportsWebGL2() and GetBackendType().
src/renderer/render_api_opengles.cpp Implements the concrete OpenGL ES backend (RHI_OpenGL class) handling all OpenGL-ES specific rendering commands and buffer management.
src/runtime/unity_entry.cpp Unity plugin entry point that selects the graphics backend during initialization (lines 75-80) based on Unity's active graphics device type.
lib/bindings/renderer.ts TypeScript type definitions and factory methods exposing the RHI to JSAR client scripts, including RHIFactory and backend detection methods.

Summary

  • JSAR currently supports only OpenGL-based graphics backends: OpenGL Core (desktop), OpenGL ES 2.0 (WebGL 1), and OpenGL ES 3.0+ (WebGL 2).
  • The Render-Hardware Interface (RHI) abstracts these backends through the RHIBackendType enum defined in src/renderer/render_api.hpp.
  • Vulkan, Metal, Direct3D 11, and Direct3D 12 are reserved in the API but not yet implemented.
  • Backend selection occurs automatically during Unity initialization in src/runtime/unity_entry.cpp based on the host platform's graphics capabilities.
  • JavaScript applications can detect the active backend at runtime using GetBackendType() and check for WebGL 2.0 support via SupportsWebGL2().

Frequently Asked Questions

Does JSAR support Vulkan or Metal graphics backends?

No. While the RHIBackendType enum in src/renderer/render_api.hpp includes VULKAN and Metal as reserved values, these backends are not yet implemented in the current JSAR runtime. Only OpenGL Core and OpenGL ES variants are functional.

How does JSAR determine which graphics backend to use?

JSAR automatically selects the graphics backend during Unity initialization. In src/runtime/unity_entry.cpp (lines 75-80), the runtime queries Unity's active graphics device type and maps it to the corresponding RHIBackendType, choosing OpenGL ES 2.0 or 3.0 for mobile and WebGL contexts, or OpenGL Core for desktop platforms.

Can JavaScript code detect the active graphics backend at runtime?

Yes. JSAR exposes the active backend through TypeScript bindings in lib/bindings/renderer.ts. You can call RHIFactory.GetChecked().GetBackendType() to retrieve the current backend as a string, and use SupportsWebGL2() to verify whether WebGL 2.0 features are available.

Is Direct3D 11 or Direct3D 12 supported on Windows?

No. Although D3D11 and D3D12 are defined in the RHIBackendType enum in src/renderer/render_api.hpp, these Direct3D backends lack concrete implementations. Windows builds currently use the OpenGL Core backend for all rendering operations.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →