1# OpenHarmony Documentation 2 3**Status: DRAFT** (Pending validation on target devices) 4 5## Architecture Overview 6 7Mesa 3D is designed to handle a broad range of graphics APIs and drivers efficiently. It achieves this by sharing components such as interfaces, compiler optimization passes, and more. This modular approach enhances flexibility and maintainability. 8 9Below, we explore the key layers of Mesa 3D’s architecture and their roles. 10 11### 1. GL Dispatch 12 13```c 14glGenBuffers(..); 15glDrawArrays(..); 16``` 17 18Every OpenGL application operates with at least one **GL context**, which stores all GL-related states, including textures, buffer objects, and enables. Each OpenGL API call (e.g., `glGenBuffers(..)`) must act according to the current context. 19 20For applications with multiple GL contexts, Mesa ensures the correct context is associated with every function call. This dispatch mechanism is optimized for minimal overhead, as every OpenGL API call relies on it. 21 22For further details, refer to the official documentation: [Mesa Dispatch](https://docs.mesa3d.org/dispatch.html) 23 24### 2. Mesa Core 25 26```c 27void GLAPIENTRY 28_mesa_GenBuffers(GLsizei n, GLuint *buffers) 29{ 30 GET_CURRENT_CONTEXT(ctx); 31 create_buffers_err(ctx, n, buffers, false); 32} 33``` 34 35Mesa Core is the primary implementation layer for rendering APIs like OpenGL and OpenGLES. It handles: 36 37- **API Implementation**: Supports OpenGL and OpenGLES functionalities. 38- **API Validation**: Ensures that API calls adhere to specifications. 39- **Context Management**: Tracks and manages GL states. 40- **Version & Extension Exposure**: Determines and exposes supported API versions and extensions. 41 42### 3. State Tracker 43 44The **State Tracker** acts as an intermediary between Mesa Core and the **Gallium3D** interface. It transforms high-level Mesa Core functionality into a more flexible format, enabling driver optimizations. The state tracker reduces immediate-mode functionality, allowing better performance tuning. 45 46### 4. Gallium3D 47 48Gallium3D is a hardware abstraction layer that simplifies graphics driver development. It provides a structured API for managing: 49 50- **Graphics State Management**: Converts Mesa state (e.g., blend modes, texture states) into hardware-ready operations. 51- **Drawing Operations**: Maps OpenGL commands (`glDrawArrays`, `glDrawPixels`, etc.) into hardware commands. 52- **Device Agnostic API**: Enables easier cross-platform driver development for OpenGL, OpenGLES, and OpenCL. 53 54Gallium3D serves as the primary API for writing OpenGL/OpenGLES/OpenCL drivers, making it a crucial component for graphics driver development. 55 56### 5. Zink: Gallium-to-Vulkan Translation 57 58Zink is a Gallium driver that translates Gallium API calls into **Vulkan** calls. It effectively treats the Vulkan API as hardware, allowing applications to leverage Vulkan’s capabilities through the Gallium3D interface. 59 60## Conclusion 61 62Mesa 3D provides a modular, flexible approach to handling multiple graphics APIs and drivers. Its layered architecture ensures efficient dispatching, optimized state management, and cross-platform compatibility. The integration of Gallium3D and drivers like Zink further enhances its adaptability, making Mesa 3D a robust solution for modern graphics rendering. 63 64--- 65 66For further reading, refer to the official Mesa documentation: [Mesa 3D](https://docs.mesa3d.org) 67 68## Compile Guide 69 70### Install all needed build deps 71 72``` 73cd ~ 74wget https://github.com/mesonbuild/meson/releases/download/1.7.0/meson-1.7.0.tar.gz ; tar -xvzf meson-1.7.0.tar.gz ; cd meson-1.7.0/ ; ln -s meson.py meson 75 76pip install mako pyyaml 77PATH=~/meson-1.7.0/:$PATH 78``` 79 80``` 81cd /home/openharmony/workdir/third_party/mesa3d 82 83python3 ohos/build_ohos64.py /home/openharmony/workdir rpi4 /home/openharmony/workdir/third_party/mesa3d 84 85``` 86 87 - rpi4 .. can be any arm64 traget. 88 - `/home/openharmony/workdir`is the base folder, where OHOS is located. 89 90 91## Deploy into demo application 92 93 ``` 94cp /home/openharmony/workdir/third_party/mesa3d/build-ohos/install/lib/libEGL.so.1 entry/libs/arm64-v8a/ 95cp /home/openharmony/workdir/third_party/mesa3d/build-ohos/install/lib/libGLESv2.so.2 entry/libs/arm64-v8a/ 96cp /home/openharmony/workdir/third_party/mesa3d/build-ohos/install/lib/libgallium-25.1.0-devel.so entry/libs/arm64-v8a/ 97 ``` 98