Make mjrfilament.h conform to C standards.

PiperOrigin-RevId: 932424719
Change-Id: I1f8d8d91041ea1c2b77010761404bf0e519bcc29
This commit is contained in:
Haroon Qureshi
2026-06-15 06:32:10 -07:00
committed by Copybara-Service
parent 4e10f20be6
commit 7472440dbd
+85 -72
View File
@@ -15,11 +15,11 @@
#ifndef MUJOCO_SRC_RENDER_FILAMENT_MJRFILAMENT_H_ #ifndef MUJOCO_SRC_RENDER_FILAMENT_MJRFILAMENT_H_
#define MUJOCO_SRC_RENDER_FILAMENT_MJRFILAMENT_H_ #define MUJOCO_SRC_RENDER_FILAMENT_MJRFILAMENT_H_
#include <cstdint> #include <stdint.h>
#include <mujoco/mjmodel.h> #include <mujoco/mjmodel.h>
#include <mujoco/mjrender.h> #include <mujoco/mjrender.h>
#include <mujoco/mujoco.h> #include <mujoco/mjtype.h>
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
@@ -52,13 +52,13 @@ extern "C" {
// values are assumed to be 0/NULL unless otherwise specified. // values are assumed to be 0/NULL unless otherwise specified.
// //
// For now, we'll just define opaque handles for each of our components. // For now, we'll just define opaque handles for each of our components.
struct mjrfContext {}; typedef struct mjrfContext_ {} mjrfContext;
struct mjrfTexture {}; typedef struct mjrfTexture_ {} mjrfTexture;
struct mjrfMesh {}; typedef struct mjrfMesh_ {} mjrfMesh;
struct mjrfScene {}; typedef struct mjrfScene_ {} mjrfScene;
struct mjrfLight {}; typedef struct mjrfLight_ {} mjrfLight;
struct mjrfRenderable {}; typedef struct mjrfRenderable_ {} mjrfRenderable;
struct mjrfRenderTarget {}; typedef struct mjrfRenderTarget_ {} mjrfRenderTarget;
// ## Rendering Context (mjrfContext) // ## Rendering Context (mjrfContext)
// //
@@ -89,11 +89,12 @@ typedef enum mjrGraphicsApi_ { // underlying graphics API to use for rendering
mjGRAPHICS_API_VULKAN, // vulkan mjGRAPHICS_API_VULKAN, // vulkan
} mjrGraphicsApi; } mjrGraphicsApi;
struct mjrFilamentConfig { // parameters for creating filament context (mjrfContext) struct mjrFilamentConfig_ { // parameters for creating filament context (mjrfContext)
int graphics_api; // mjrGraphicsApi; rendering graphics API int graphics_api; // mjrGraphicsApi; rendering graphics API
mjtBool force_software_rendering; // force backend to use software rendering mjtBool force_software_rendering; // force backend to use software rendering
void* native_window; // platform-dependent window handle (or nullptr for windowless) void* native_window; // platform-dependent window handle (or nullptr for windowless)
}; };
typedef struct mjrFilamentConfig_ mjrFilamentConfig;
// Initializes the mjrFilamentConfig to default values. // Initializes the mjrFilamentConfig to default values.
void mjrf_defaultFilamentConfig(mjrFilamentConfig* config); void mjrf_defaultFilamentConfig(mjrFilamentConfig* config);
@@ -114,7 +115,7 @@ typedef enum mjrDrawMode_ { // how to draw objects in the scene
mjDRAW_MODE_SEGMENTATION_BY_COLOR, // generate visually distinct colors using segmentation id mjDRAW_MODE_SEGMENTATION_BY_COLOR, // generate visually distinct colors using segmentation id
} mjrDrawMode; } mjrDrawMode;
struct mjrfRenderRequest { // a single rendering operation struct mjrfRenderRequest_ { // a single rendering operation
mjrfScene* scene; // scene to render mjrfScene* scene; // scene to render
mjrCamera camera; // camera (viewpoint) from which to render scene mjrCamera camera; // camera (viewpoint) from which to render scene
mjrRect viewport; // viewport (rect area) into which to render mjrRect viewport; // viewport (rect area) into which to render
@@ -124,17 +125,19 @@ struct mjrfRenderRequest { // a single rendering operation
mjtBool enable_reflections; // enable reflections, enabled by default mjtBool enable_reflections; // enable reflections, enabled by default
mjtBool enable_shadows; // enable shadows, enabled by default mjtBool enable_shadows; // enable shadows, enabled by default
}; };
typedef struct mjrfRenderRequest_ mjrfRenderRequest;
// Initializes the mjrfRenderRequest to default values. // Initializes the mjrfRenderRequest to default values.
void mjrf_defaultRenderRequest(mjrfRenderRequest* request); void mjrf_defaultRenderRequest(mjrfRenderRequest* request);
struct mjrfReadPixelsRequest { // a single read operation struct mjrfReadPixelsRequest_ { // a single read operation
mjrfRenderTarget* target; // render target from which to read the image pixels mjrfRenderTarget* target; // render target from which to read the image pixels
void* output; // buffer into which the pixels will be stored void* output; // buffer into which the pixels will be stored
mjtSize num_bytes; // size of output buffer mjtSize num_bytes; // size of output buffer
mjrfCallback read_completed; // callback when read is complete; can use to free output mjrfCallback read_completed; // callback when read is complete; can use to free output
void* user_data; // user data for read_completed_callback void* user_data; // user data for read_completed_callback
}; };
typedef struct mjrfReadPixelsRequest_ mjrfReadPixelsRequest;
// Initializes the mjrfReadPixelsRequest to default values. // Initializes the mjrfReadPixelsRequest to default values.
void mjrf_defaultReadPixelsRequest(mjrfReadPixelsRequest* request); void mjrf_defaultReadPixelsRequest(mjrfReadPixelsRequest* request);
@@ -161,9 +164,10 @@ void mjrf_waitForFrame(mjrfContext* ctx, mjrfFrameHandle frame);
// Sets the clear color for the renderer. // Sets the clear color for the renderer.
void mjrf_setClearColor(mjrfContext* ctx, const float color[3]); void mjrf_setClearColor(mjrfContext* ctx, const float color[3]);
struct mjrfFrameStats { // stats for a single frame of rendering struct mjrfFrameStats_ { // stats for a single frame of rendering
double frame_rate; // frame rate, in frames per second double frame_rate; // frame rate, in frames per second
}; };
typedef struct mjrfFrameStats_ mjrfFrameStats;
// Initializes the mjrFrameStats to default values. // Initializes the mjrFrameStats to default values.
void mjrf_defaultFrameStats(mjrfFrameStats* stats); void mjrf_defaultFrameStats(mjrfFrameStats* stats);
@@ -180,30 +184,33 @@ void mjrf_getFrameStats(mjrfContext* ctx, mjrfFrameHandle frame, mjrfFrameStats*
// filament's `cmgen` tool to generate a KTX image from your source image. This tool will calculate // filament's `cmgen` tool to generate a KTX image from your source image. This tool will calculate
// additional data (i.e. the spherical harmonics) and encode that information into the KTX file. // additional data (i.e. the spherical harmonics) and encode that information into the KTX file.
struct mjrfTextureConfig { // parameters for creating a texture (mjrfTexture) struct mjrfTextureConfig_ { // parameters for creating a texture (mjrfTexture)
int width; // texture width; or number of bytes for compressed data (e.g. KTX) int width; // texture width; or number of bytes for compressed data (e.g. KTX)
int height; // texture height; or 0 for compressed data (e.g. KTX) int height; // texture height; or 0 for compressed data (e.g. KTX)
int format; // mjrPixelFormat; (e.g. RGB8, RGBA8, KTX, etc.) int format; // mjrPixelFormat; (e.g. RGB8, RGBA8, KTX, etc.)
int color_space; // mjrColorSpace; (e.g. LINEAR, sRGB, etc.) int color_space; // mjrColorSpace; (e.g. LINEAR, sRGB, etc.)
int sampler_type; // mjrSamplerType; texture sampler (e.g. 2D, cube, etc.) int sampler_type; // mjrSamplerType; texture sampler (e.g. 2D, cube, etc.)
}; };
typedef struct mjrfTextureConfig_ mjrfTextureConfig;
// Initializes the mjrfTextureConfig to default values. // Initializes the mjrfTextureConfig to default values.
void mjrf_defaultTextureConfig(mjrfTextureConfig* config); void mjrf_defaultTextureConfig(mjrfTextureConfig* config);
// Creates a filament texture. Note that the texture will not be created on the GPU until // Creates a filament texture. Note that the texture will not be created on the
// `mjrf_setTextureData()` is called. // GPU until `mjrf_setTextureData()` is called.
mjrfTexture* mjrf_createTexture(mjrfContext* ctx, const mjrfTextureConfig* config); mjrfTexture* mjrf_createTexture(mjrfContext* ctx,
const mjrfTextureConfig* config);
// Destroys the texture. // Destroys the texture.
void mjrf_destroyTexture(mjrfTexture* texture); void mjrf_destroyTexture(mjrfTexture* texture);
struct mjrfTextureData { // binary data for a texture (mjrfTexture) struct mjrfTextureData_ { // binary data for a texture (mjrfTexture)
const void* bytes; // pointer to image data, or nullptr for empty texture const void* bytes; // pointer to image data, or nullptr for empty texture
mjtSize num_bytes; // number of bytes in the image data mjtSize num_bytes; // number of bytes in the image data
mjrfCallback release; // callback when data has finished uploading mjrfCallback release; // callback when data has finished uploading
void* user_data; // user data for release callback void* user_data; // user data for release callback
}; };
typedef struct mjrfTextureData_ mjrfTextureData;
// Initializes the mjrfTextureData to default values. // Initializes the mjrfTextureData to default values.
void mjrf_defaultTextureData(mjrfTextureData* data); void mjrf_defaultTextureData(mjrfTextureData* data);
@@ -245,21 +252,22 @@ int mjrf_getSamplerType(const mjrfTexture* texture);
// Maximum number of vertex attributes in a mesh. // Maximum number of vertex attributes in a mesh.
enum { mjMAX_VERTEX_ATTRIBUTES = 16 }; enum { mjMAX_VERTEX_ATTRIBUTES = 16 };
struct mjrfMeshData { // binary data for a mesh (mjrfMesh) struct mjrfMeshData_ { // binary data for a mesh (mjrfMesh)
mjtSize num_vertices; // number of vertices; all vertex attributes share this size mjtSize num_vertices; // number of vertices; all vertex attributes share this size
int nattributes; // number of attributes defined int nattributes; // number of attributes defined
mjrVertexAttribute attributes[mjMAX_VERTEX_ATTRIBUTES]; // per-vertex attribute information mjrVertexAttribute attributes[mjMAX_VERTEX_ATTRIBUTES]; // per-vertex attribute information
mjtBool interleaved; // true if vertex attributes are interleaved mjtBool interleaved; // true if vertex attributes are interleaved
mjtSize num_indices; // number of indices mjtSize num_indices; // number of indices
const void* indices; // indices data array const void* indices; // indices data array
int index_type; // mjrIndexType; (e.g. UINT16 or UINT32) int index_type; // mjrIndexType; (e.g. UINT16 or UINT32)
int primitive_type; // mjrMeshPrimitiveType; (e.g. TRIANGLES, etc.) int primitive_type; // mjrMeshPrimitiveType; (e.g. TRIANGLES, etc.)
mjtBool compute_bounds; // if true, compute bounds from vertex positions mjtBool compute_bounds; // if true, compute bounds from vertex positions
float bounds_min[3]; // min/max bounds; assume unset if bounds_min == bounds_max float bounds_min[3]; // min/max bounds; assume unset if bounds_min == bounds_max
float bounds_max[3]; float bounds_max[3];
mjrfCallback release; // callback when data has finished uploading mjrfCallback release; // callback when data has finished uploading
void* user_data; // user data for release callback void* user_data; // user data for release callback
}; };
typedef struct mjrfMeshData_ mjrfMeshData;
// Initializes the mjrfMeshData to default values. // Initializes the mjrfMeshData to default values.
void mjrf_defaultMeshData(mjrfMeshData* data); void mjrf_defaultMeshData(mjrfMeshData* data);
@@ -275,8 +283,9 @@ void mjrf_destroyMesh(mjrfMesh* mesh);
// A scene is a collection of entities (Lights and Renderables) that describes what is to be // A scene is a collection of entities (Lights and Renderables) that describes what is to be
// rendered. // rendered.
struct mjrfSceneParams { // parameters for creating a scene (mjrfScene) struct mjrfSceneParams_ { // parameters for creating a scene (mjrfScene)
}; };
typedef struct mjrfSceneParams_ mjrfSceneParams;
// Initializes the mjrfSceneParams to default values. // Initializes the mjrfSceneParams to default values.
void mjrf_defaultSceneParams(mjrfSceneParams* params); void mjrf_defaultSceneParams(mjrfSceneParams* params);
@@ -322,7 +331,7 @@ void mjrf_configureSceneFromModel(mjrfScene* scene, const mjModel* model);
// lights as you want. Each light source (except image based lights) may or may not cast shadows. // lights as you want. Each light source (except image based lights) may or may not cast shadows.
// Each shadow-casting light incurs a performance cost. // Each shadow-casting light incurs a performance cost.
struct mjrfLightParams { // parameters for creating a light (mjrfLight) struct mjrfLightParams_ { // parameters for creating a light (mjrfLight)
int type; // mjrLightType; type of light (e.g. spot, point, image, etc.) int type; // mjrLightType; type of light (e.g. spot, point, image, etc.)
const mjrfTexture* texture; // texture; only for image lights const mjrfTexture* texture; // texture; only for image lights
float color[3]; // RGB color float color[3]; // RGB color
@@ -334,6 +343,7 @@ struct mjrfLightParams { // parameters for creating a light (mjrfLight)
float bulb_radius; // bulb radius, used for soft shadows float bulb_radius; // bulb radius, used for soft shadows
float vsm_blur_width; // variance shadow map blur width float vsm_blur_width; // variance shadow map blur width
}; };
typedef struct mjrfLightParams_ mjrfLightParams;
// Initializes the mjrfLightParams to default values. // Initializes the mjrfLightParams to default values.
void mjrf_defaultLightParams(mjrfLightParams* params); void mjrf_defaultLightParams(mjrfLightParams* params);
@@ -375,22 +385,22 @@ int mjrf_getLightType(const mjrfLight* light);
// //
// Which lighting model is used is determined by the mjrfMaterial properties. // Which lighting model is used is determined by the mjrfMaterial properties.
struct mjrfMaterial { // material properties for a renderable (mjrfMaterial) struct mjrfMaterial_ { // material properties for a renderable (mjrfMaterial)
float color[4]; // object color; defaults to white float color[4]; // object color; defaults to white
int32_t segmentation_id; // ID for segmentation rendering; maps to RGB8 color (i.e. 24 bits) int32_t segmentation_id; // ID for segmentation rendering; maps to RGB8 color (i.e. 24 bits)
int32_t island_id; // ID to which the renderable belongs int32_t island_id; // ID to which the renderable belongs
int sleep_state; // mjtSleepState; sleep state of the renderable int sleep_state; // mjtSleepState; sleep state of the renderable
float uv_scale[3]; // scale applied to UV coordinates; defaults to (1,1,1) float uv_scale[3]; // scale applied to UV coordinates; defaults to (1,1,1)
float uv_offset[3]; // offset applied to UV coordinates; defaults to (0,0,0) float uv_offset[3]; // offset applied to UV coordinates; defaults to (0,0,0)
float scissor[4]; // if non-zero, applies scissor testing when rendering float scissor[4]; // if non-zero, applies scissor testing when rendering
float metallic; // metallic factory [0, 1]; disabled if < 0 float metallic; // metallic factory [0, 1]; disabled if < 0
float roughness; // roughness factor [0, 1]; disabled if < 0 float roughness; // roughness factor [0, 1]; disabled if < 0
float specular; // specular factor [0, 1]; disabled if < 0 float specular; // specular factor [0, 1]; disabled if < 0
float glossiness; // glossiness factor [0, 1]; disabled if < 0 float glossiness; // glossiness factor [0, 1]; disabled if < 0
float emissive; // emissive/glow factor [0, 1]; disabled if < 0 float emissive; // emissive/glow factor [0, 1]; disabled if < 0
float reflectance; // blend factor for reflective surfaces [0, 1]; applies only to planes float reflectance; // blend factor for reflective surfaces [0, 1]; applies only to planes
mjtBool decor_ux; // for ux elements, does not apply any lighting mjtBool decor_ux; // for ux elements, does not apply any lighting
mjtBool selected; // for "selected" ux elements, adds additional styling mjtBool selected; // for "selected" ux elements, adds additional styling
const mjrfTexture* color_texture; // color/albedo texture (RGB8) const mjrfTexture* color_texture; // color/albedo texture (RGB8)
const mjrfTexture* opacity_texture; // opacity texture (A8) const mjrfTexture* opacity_texture; // opacity texture (A8)
const mjrfTexture* normal_texture; // normal map texture (RGB8) const mjrfTexture* normal_texture; // normal map texture (RGB8)
@@ -401,15 +411,17 @@ struct mjrfMaterial { // material properties for a renderable (mjrfMater
const mjrfTexture* emissive_texture; // emissive texture (RGB8) const mjrfTexture* emissive_texture; // emissive texture (RGB8)
const mjrfTexture* reflection_texture; // reflection texture, for internal use only const mjrfTexture* reflection_texture; // reflection texture, for internal use only
}; };
typedef struct mjrfMaterial_ mjrfMaterial;
// Initializes the mjrfMaterial to default values. // Initializes the mjrfMaterial to default values.
void mjrf_defaultMaterial(mjrfMaterial* material); void mjrf_defaultMaterial(mjrfMaterial* material);
struct mjrfRenderableParams { // parameters for creating a renderable (mjrfRenderable) struct mjrfRenderableParams_ { // parameters for creating a renderable (mjrfRenderable)
mjtBool cast_shadows; // if true, casts shadows mjtBool cast_shadows; // if true, casts shadows
mjtBool receive_shadows; // if true, receives shadows mjtBool receive_shadows; // if true, receives shadows
uint16_t blend_order; // controls draw order for transparent objects [0, 8] uint16_t blend_order; // controls draw order for transparent objects [0, 8]
}; };
typedef struct mjrfRenderableParams_ mjrfRenderableParams;
// Initializes the mjrfRenderableParams to default values. // Initializes the mjrfRenderableParams to default values.
void mjrf_defaultRenderableParams(mjrfRenderableParams* params); void mjrf_defaultRenderableParams(mjrfRenderableParams* params);
@@ -450,12 +462,13 @@ void mjrf_setRenderableSize(mjrfRenderable* renderable, const float size[3]);
// A render target is a memory buffer that holds the results of a rendering operation. (This is an // A render target is a memory buffer that holds the results of a rendering operation. (This is an
// alternative to rendering directly to the screen.) See mjrf_render for more details. // alternative to rendering directly to the screen.) See mjrf_render for more details.
struct mjrfRenderTargetConfig { // parameters for creating a render target (mjrfRenderTarget) struct mjrfRenderTargetConfig_ { // parameters for creating a render target (mjrfRenderTarget)
int width; // texture width int width; // texture width
int height; // texture height int height; // texture height
int color_format; // mjrPixelFormat; pixel format for color buffer int color_format; // mjrPixelFormat; pixel format for color buffer
int depth_format; // mjrPixelFormat; pixel format for depth buffer int depth_format; // mjrPixelFormat; pixel format for depth buffer
}; };
typedef struct mjrfRenderTargetConfig_ mjrfRenderTargetConfig;
// Initializes the RenderTargetConfig to default values. // Initializes the RenderTargetConfig to default values.
void mjrf_defaultRenderTargetConfig(mjrfRenderTargetConfig* config); void mjrf_defaultRenderTargetConfig(mjrfRenderTargetConfig* config);