Code Read the original on Dev 2 min read 0

Codename One introduces portable 3D API for cross-platform apps

The open-source framework Codename One has launched a new portable 3D API designed to simplify cross-platform graphics development. By allowing developers to describe materials and lighting models rather than writing manual shader source code, the framework enables unified deployment across iOS, Android, Web, and Windows. This initiative removes the need for multiple shader languages while maintaining high performance through per-platform generators that target Metal, OpenGL ES, WebGL, and Direct3D.

Смартфон і планшет на яскраво-синьому тлі відображають тривимірні об'єкти: куб у червоно-зелену клітинку та металеву миску.
Смартфон і планшет на яскраво-синьому тлі відображають тривимірні об'єкти: куб у червоно-зелену клітинку та металеву миску. · Image source: Dev

According to Dev, Codename One is introducing a significant shift in how developers handle 3D graphics across diverse operating systems. The new com.codename1.gpu package provides a portable API where applications never require the developer to write shader source code manually. Instead, the framework handles the complexity of translating high-level material descriptions into platform-specific instructions.

Abstracting complex shader languages

Traditionally, cross-platform 3D development requires managing multiple distinct graphics APIs and shading languages. Developers often have to write specific code for Metal Shading Language on Apple devices, GLSL for Android and WebGL, and HLSL for Windows. Codename One addresses this fragmentation by allowing developers to define a Material object that specifies lighting models, colors, textures, and shininess.

The framework then employs per-platform generators to emit the correct shader code automatically. This approach supports five distinct GPU backends from a single Java or Kotlin codebase:

  • iOS and Mac native targets utilize Metal with runtime MSL compilation and pipeline caching.
  • Android devices run on OpenGL ES 2 via a GLSurfaceView peer.
  • Web ports use WebGL on a canvas peer, reusing the core GLSL generator.
  • Windows native ports target Direct3D 11 with HLSL generated at runtime.
  • Simulators utilize OpenGL via JOGL or a pure-Java software rasterizer as a fallback.
  • Integration with standard 3D assets

    The API is designed to work with industry-standard tools rather than just basic primitives. It includes a GltfLoader capable of reading binary glTF (.glb) files, which is the primary interchange format for software like Blender. This allows developers to ship complex models as regular project resources that load consistently across all platforms.

    By integrating 3D components into a standard layout system, the framework ensures that 3D views can sit alongside traditional UI elements like buttons and labels. The inclusion of a deterministic software rasterizer for headless environments also ensures that automated screenshot tests can verify 3D output consistently across all deployment targets.

    This architectural shift significantly lowers the barrier to entry for high-performance graphics in mobile and desktop applications. By removing the need for manual shader management, Codename One enables developers to focus on content and logic while the framework handles the underlying hardware abstraction.

    FAQ

    Which platforms does the new Codename One 3D API support?
    The framework enables unified deployment across iOS, Android, Web, and Windows. It supports native targets for Mac and iOS using Metal, Android via OpenGL ES 2, Web ports through WebGL, and Windows native ports targeting Direct3D 11.
    How does the API handle different graphics languages?
    The framework abstracts complex shader languages by allowing developers to define Material objects specifying lighting models, colors, textures, and shininess. Per-platform generators then automatically emit the correct shader code for each specific hardware backend from a single Java or Kotlin codebase.
    Can I use 3D models from external software in this framework?
    Yes, the API includes a GltfLoader capable of reading binary .glb files. This allows developers to ship complex models from tools like Blender as regular project resources that load consistently across all supported platforms.
    Telegram

    Fresh news on our Telegram

    Get instant alerts for new posts in «Code»

    @procodeandevenmore