How jeasoon-osp/soft-renderer works
Main Components
• Android UI/App Layer: Represented by the Java/Kotlin code (e.g., MainActivity.kt and related graphic classes in com.jeasoon.gl.softrenderer) and Android layout files. This layer manages the app lifecycle, user input, and resource handling.
• JNI Bridge: The “glue” between the Java/Kotlin UI and the native C++ code. This includes interactions defined in the Android project (under app/src/main/java) that delegate calls to native functions.
• Native Rendering Engine (C++ Layer): The heart of the renderer located in app/src/main/cpp. Break this layer into submodules reflecting the internal architecture:
• GPU Simulation Module (under src/gpu): Contains classes such as BufferObject, Program, Texture, Raster, and their variants (e.g., PhongProgram, TextureProgram). These modules simulate aspects of the graphics pipeline.
• Graphics Module (under src/graphic): Handles camera, model, view, and pose management. Under “model” are further divisions, including integration of assimp (and its Android specific IO systems) to load 3D models.
• Mathematical Utilities (under src/math): Implements vectors, matrices, and assorted math functions supporting rendering transformations.
• Utility Module (under src/util): Provides error handling, logging (ALog, Error.cpp), and timing, which are critical for debugging and performance management.
• Asset Management: Located in app/src/main/assets, which holds the 3D model files (monkey.obj, monster.fbx) and possibly texture or other resource files used by the renderer.
Relationships and Data Flow
• From the JNI Bridge, illustrate the invocation of C++ native functions, which then branch into the rendering engine.
• How assets (models and textures) are fetched and loaded using assimp and stbi.
Important Architectural Patterns and Design Principles
• Layered Architecture: Emphasize the clear separation between the presentation (Android Java/Kotlin), business logic (native C++ rendering engine), and utility (math, gpu, and util modules).
• Modularity: Note that the native code is organized into self-contained modules that communicate through well-defined interfaces.
• JNI as a Communication Bridge: Illustrate how the JNI layer facilitates interaction between the high-level Android components and the performance-critical native modules.
Relevant Technologies and Frameworks
• Android Framework: For lifecycle management and UI.
• Kotlin/Java: Used in app/src/main/java.
• C++ with CMake: For native rendering code (note the CMakeLists.txt for building the C++ code).
• Assimp and STB Image Libraries: Mark these as external dependencies integrated into the model and texture loading subsystems.
• gradle and other build scripts: Indicate that the project is built as an Android app using Gradle and Kotlin DSL (build.gradle.kts).
• Clear labels on each component like “Android UI”, “JNI Bridge”, “Rendering Engine Core”, “GPU Simulation”, “Graphics (Camera/Model/View)”, “Math Utilities”, and “Asset Management”.
• Additionally, include notes or call-outs on important design details such as performance optimizations in the native code, the modular design for maintainability, and the specific role each third-party dependency plays.