Rename types to conform to mjr naming conventions.

PiperOrigin-RevId: 904438811
Change-Id: I77fe14592a4460234e0aff473ee3f530e652bca9
This commit is contained in:
Haroon Qureshi
2026-04-23 07:09:44 -07:00
committed by Copybara-Service
parent fa33310750
commit c1c7643fad
7 changed files with 53 additions and 49 deletions
@@ -72,8 +72,8 @@ uintptr_t ImguiBridge::UploadImage(uintptr_t tex_id, const uint8_t* pixels,
// new texture. // new texture.
if (texture == nullptr || texture->GetWidth() != width || if (texture == nullptr || texture->GetWidth() != width ||
texture->GetHeight() != height) { texture->GetHeight() != height) {
TextureConfig config; mjrTextureConfig config;
DefaultTextureConfig(&config); mjr_defaultTextureConfig(&config);
config.width = width; config.width = width;
config.height = height; config.height = height;
config.target = mjTEXTURE_2D; config.target = mjTEXTURE_2D;
@@ -89,8 +89,8 @@ uintptr_t ImguiBridge::UploadImage(uintptr_t tex_id, const uint8_t* pixels,
const auto callback = const auto callback =
+[](void* user) { delete[] reinterpret_cast<std::byte*>(user); }; +[](void* user) { delete[] reinterpret_cast<std::byte*>(user); };
TextureData texture_data; mjrTextureData texture_data;
DefaultTextureData(&texture_data); mjr_defaultTextureData(&texture_data);
texture_data.bytes = bytes; texture_data.bytes = bytes;
texture_data.nbytes = num_bytes; texture_data.nbytes = num_bytes;
texture_data.user_data = bytes; texture_data.user_data = bytes;
@@ -106,8 +106,8 @@ void ImguiBridge::CreateTexture(ImTextureData* data) {
mju_error("Unsupported texture format."); mju_error("Unsupported texture format.");
} }
TextureConfig config; mjrTextureConfig config;
DefaultTextureConfig(&config); mjr_defaultTextureConfig(&config);
config.width = data->Width; config.width = data->Width;
config.height = data->Height; config.height = data->Height;
config.target = mjTEXTURE_2D; config.target = mjTEXTURE_2D;
@@ -127,8 +127,8 @@ void ImguiBridge::UpdateTexture(ImTextureData* data) {
mju_error("Texture not found: %llu", data->TexID); mju_error("Texture not found: %llu", data->TexID);
} }
TextureData texture_data; mjrTextureData texture_data;
DefaultTextureData(&texture_data); mjr_defaultTextureData(&texture_data);
texture_data.bytes = data->GetPixels(); texture_data.bytes = data->GetPixels();
texture_data.nbytes = data->Width * data->Height * 4; texture_data.nbytes = data->Width * data->Height * 4;
texture_data.user_data = nullptr; texture_data.user_data = nullptr;
@@ -575,8 +575,8 @@ void ModelObjects::UploadTexture(const mjModel* model, int id) {
mju_error("Invalid texture index: %d", id); mju_error("Invalid texture index: %d", id);
} }
TextureConfig config; mjrTextureConfig config;
DefaultTextureConfig(&config); mjr_defaultTextureConfig(&config);
config.width = model->tex_width[id]; config.width = model->tex_width[id];
config.height = model->tex_height[id]; config.height = model->tex_height[id];
config.target = (mjtTexture)model->tex_type[id]; config.target = (mjtTexture)model->tex_type[id];
@@ -600,8 +600,8 @@ void ModelObjects::UploadTexture(const mjModel* model, int id) {
} }
TextureData payload; mjrTextureData payload;
DefaultTextureData(&payload); mjr_defaultTextureData(&payload);
payload.bytes = model->tex_data + model->tex_adr[id]; payload.bytes = model->tex_data + model->tex_adr[id];
payload.nbytes = payload.nbytes =
model->tex_width[id] * model->tex_height[id] * model->tex_nchannel[id]; model->tex_width[id] * model->tex_height[id] * model->tex_nchannel[id];
@@ -51,8 +51,8 @@ void RenderTarget::Prepare(int width, int height) {
width_ = width; width_ = width;
height_ = height; height_ = height;
TextureConfig color_config; mjrTextureConfig color_config;
DefaultTextureConfig(&color_config); mjr_defaultTextureConfig(&color_config);
Texture::InternalFlags color_flags; Texture::InternalFlags color_flags;
color_config.width = width; color_config.width = width;
color_config.height = height; color_config.height = height;
@@ -63,8 +63,8 @@ void RenderTarget::Prepare(int width, int height) {
color_flags.color_attachment = true; color_flags.color_attachment = true;
color_texture_ = std::make_unique<Texture>(engine_, color_config, color_flags); color_texture_ = std::make_unique<Texture>(engine_, color_config, color_flags);
TextureConfig depth_config; mjrTextureConfig depth_config;
DefaultTextureConfig(&depth_config); mjr_defaultTextureConfig(&depth_config);
Texture::InternalFlags depth_flags; Texture::InternalFlags depth_flags;
depth_config.width = width; depth_config.width = width;
depth_config.height = height; depth_config.height = height;
@@ -27,8 +27,8 @@ namespace mujoco {
// Defines the basic properties of a render target. // Defines the basic properties of a render target.
struct RenderTargetConfig { struct RenderTargetConfig {
mjtPixelFormat color_format; mjrPixelFormat color_format;
mjtPixelFormat depth_format; mjrPixelFormat depth_format;
}; };
// Initializes the RenderTargetConfig to default values. // Initializes the RenderTargetConfig to default values.
@@ -64,8 +64,8 @@ static std::unique_ptr<Texture> CreateFallbackIndirectLightTexture(
std::unique_ptr<ObjectManager::Asset> asset = object_mgr->LoadAsset(filename); std::unique_ptr<ObjectManager::Asset> asset = object_mgr->LoadAsset(filename);
TextureConfig config; mjrTextureConfig config;
DefaultTextureConfig(&config); mjr_defaultTextureConfig(&config);
config.width = 1; config.width = 1;
config.height = 1; config.height = 1;
config.target = mjTEXTURE_CUBE; config.target = mjTEXTURE_CUBE;
@@ -74,9 +74,9 @@ static std::unique_ptr<Texture> CreateFallbackIndirectLightTexture(
auto texture = std::make_unique<Texture>(object_mgr->GetEngine(), config); auto texture = std::make_unique<Texture>(object_mgr->GetEngine(), config);
TextureData payload; mjrTextureData payload;
DefaultTextureData(&payload); mjr_defaultTextureData(&payload);
payload.bytes = (void*)asset->GetBytes().data(); payload.bytes = asset->GetBytes().data();
payload.nbytes = asset->GetBytes().size(); payload.nbytes = asset->GetBytes().size();
payload.release_callback = +[](void* user_data) { payload.release_callback = +[](void* user_data) {
delete static_cast<ObjectManager::Asset*>(user_data); delete static_cast<ObjectManager::Asset*>(user_data);
+12 -12
View File
@@ -29,15 +29,15 @@ namespace mujoco {
static constexpr int kNumFacesPerCube = 6; static constexpr int kNumFacesPerCube = 6;
static bool IsCompressed(const TextureConfig& config) { static bool IsCompressed(const mjrTextureConfig& config) {
return config.format == mjPIXEL_FORMAT_KTX; return config.format == mjPIXEL_FORMAT_KTX;
} }
static bool IsCubeMap(const TextureConfig& config) { static bool IsCubeMap(const mjrTextureConfig& config) {
return config.target == mjTEXTURE_CUBE || config.target == mjTEXTURE_SKYBOX; return config.target == mjTEXTURE_CUBE || config.target == mjTEXTURE_SKYBOX;
} }
static int GetFaceHeight(const TextureConfig& config) { static int GetFaceHeight(const mjrTextureConfig& config) {
int face_height = config.height; int face_height = config.height;
if (config.width != config.height) { if (config.width != config.height) {
if (config.width * kNumFacesPerCube != config.height) { if (config.width * kNumFacesPerCube != config.height) {
@@ -51,7 +51,7 @@ static int GetFaceHeight(const TextureConfig& config) {
return face_height; return face_height;
} }
static int GetNumChannels(const TextureConfig& config) { static int GetNumChannels(const mjrTextureConfig& config) {
switch (config.format) { switch (config.format) {
case mjPIXEL_FORMAT_R8: case mjPIXEL_FORMAT_R8:
return 1; return 1;
@@ -65,7 +65,7 @@ static int GetNumChannels(const TextureConfig& config) {
} }
} }
static filament::Texture::Format GetTextureFormat(const TextureConfig& config) { static filament::Texture::Format GetTextureFormat(const mjrTextureConfig& config) {
switch (config.format) { switch (config.format) {
case mjPIXEL_FORMAT_R8: case mjPIXEL_FORMAT_R8:
return filament::Texture::Format::R; return filament::Texture::Format::R;
@@ -80,7 +80,7 @@ static filament::Texture::Format GetTextureFormat(const TextureConfig& config) {
} }
static filament::Texture::InternalFormat GetTextureInternalFormat( static filament::Texture::InternalFormat GetTextureInternalFormat(
const TextureConfig& config) { const mjrTextureConfig& config) {
if (config.color_space == mjCOLORSPACE_SRGB) { if (config.color_space == mjCOLORSPACE_SRGB) {
switch (config.format) { switch (config.format) {
case mjPIXEL_FORMAT_RGB8: case mjPIXEL_FORMAT_RGB8:
@@ -110,15 +110,15 @@ static filament::Texture::InternalFormat GetTextureInternalFormat(
} }
} }
void DefaultTextureData(TextureData* data) { void mjr_defaultTextureData(mjrTextureData* data) {
std::memset(data, 0, sizeof(TextureData)); std::memset(data, 0, sizeof(mjrTextureData));
} }
void DefaultTextureConfig(TextureConfig* config) { void mjr_defaultTextureConfig(mjrTextureConfig* config) {
std::memset(config, 0, sizeof(TextureConfig)); std::memset(config, 0, sizeof(mjrTextureConfig));
} }
Texture::Texture(filament::Engine* engine, const TextureConfig& config, Texture::Texture(filament::Engine* engine, const mjrTextureConfig& config,
InternalFlags flags) InternalFlags flags)
: engine_(engine), config_(config) { : engine_(engine), config_(config) {
if (IsCompressed(config_)) { if (IsCompressed(config_)) {
@@ -166,7 +166,7 @@ Texture::~Texture() {
} }
} }
void Texture::Upload(const TextureData& data) { void Texture::Upload(const mjrTextureData& data) {
user_data_ = data.user_data; user_data_ = data.user_data;
release_callback_ = data.release_callback; release_callback_ = data.release_callback;
+18 -14
View File
@@ -21,12 +21,13 @@
#include <filament/Texture.h> #include <filament/Texture.h>
#include <math/vec3.h> #include <math/vec3.h>
#include <mujoco/mjmodel.h> #include <mujoco/mjmodel.h>
#include <mujoco/mujoco.h>
// Functions for creating filament textures. // Functions for creating filament textures.
namespace mujoco { namespace mujoco {
// Pixel formats for textures. // Pixel formats for textures.
typedef enum mjtPixelFormat_ { typedef enum mjrPixelFormat_ {
mjPIXEL_FORMAT_UNKNOWN = 0, mjPIXEL_FORMAT_UNKNOWN = 0,
mjPIXEL_FORMAT_R8, mjPIXEL_FORMAT_R8,
mjPIXEL_FORMAT_RGB8, mjPIXEL_FORMAT_RGB8,
@@ -34,15 +35,18 @@ typedef enum mjtPixelFormat_ {
mjPIXEL_FORMAT_R32F, mjPIXEL_FORMAT_R32F,
mjPIXEL_FORMAT_DEPTH32F, mjPIXEL_FORMAT_DEPTH32F,
mjPIXEL_FORMAT_KTX, mjPIXEL_FORMAT_KTX,
} mjtPixelFormat; } mjrPixelFormat;
typedef mjtTexture mjrTextureTarget;
typedef mjtColorSpace mjrColorSpace;
// The binary contents of a texture. // The binary contents of a texture.
struct TextureData { struct mjrTextureData {
// Pointer to the image data. If null, an empty texture will be created. // Pointer to the image data. If null, an empty texture will be created.
void* bytes; const void* bytes;
// The number of bytes in the image data. // The number of bytes in the image data.
size_t nbytes; mjtSize nbytes;
// Because rendering may be multithreaded, we cannot make assumptions about // Because rendering may be multithreaded, we cannot make assumptions about
// when the image data will finish uploading to the GPU. As such, we will use // when the image data will finish uploading to the GPU. As such, we will use
@@ -54,10 +58,10 @@ struct TextureData {
}; };
// Initializes the TextureData to default values. // Initializes the TextureData to default values.
void DefaultTextureData(TextureData* data); void mjr_defaultTextureData(mjrTextureData* data);
// Defines the basic properties of a texture. // Defines the basic properties of a texture.
struct TextureConfig { struct mjrTextureConfig {
// The width of the texture. For compressed textures (e.g. KTX), this is the // The width of the texture. For compressed textures (e.g. KTX), this is the
// number of bytes in the compressed data. // number of bytes in the compressed data.
int width; int width;
@@ -67,17 +71,17 @@ struct TextureConfig {
int height; int height;
// The target of the texture (e.g. 2D, cube, etc.) // The target of the texture (e.g. 2D, cube, etc.)
mjtTexture target; mjrTextureTarget target;
// The format of the pixels in the texture (e.g. RGB8, RGBA8, KTX, etc.) // The format of the pixels in the texture (e.g. RGB8, RGBA8, KTX, etc.)
mjtPixelFormat format; mjrPixelFormat format;
// The color space of the texture (e.g. LINEAR, sRGB, etc.) // The color space of the texture (e.g. LINEAR, sRGB, etc.)
mjtColorSpace color_space; mjrColorSpace color_space;
}; };
// Initializes the TextureConfig to default values. // Initializes the TextureConfig to default values.
void DefaultTextureConfig(TextureConfig* config); void mjr_defaultTextureConfig(mjrTextureConfig* config);
// Wrapper around a filament::Texture. // Wrapper around a filament::Texture.
class Texture { class Texture {
@@ -90,13 +94,13 @@ class Texture {
}; };
// Creates a texture with the given data. // Creates a texture with the given data.
Texture(filament::Engine* engine, const TextureConfig& config, Texture(filament::Engine* engine, const mjrTextureConfig& config,
InternalFlags flags = InternalFlags()); InternalFlags flags = InternalFlags());
~Texture(); ~Texture();
// Uploads the given data to the texture. // Uploads the given data to the texture.
void Upload(const TextureData& data); void Upload(const mjrTextureData& data);
// Returns the width of the texture. // Returns the width of the texture.
int GetWidth() const { return config_.width; } int GetWidth() const { return config_.width; }
@@ -121,7 +125,7 @@ class Texture {
filament::Engine* engine_ = nullptr; filament::Engine* engine_ = nullptr;
filament::Texture* texture_ = nullptr; filament::Texture* texture_ = nullptr;
TextureConfig config_; mjrTextureConfig config_;
SphericalHarmonics spherical_harmonics_; SphericalHarmonics spherical_harmonics_;
bool has_spherical_harmonics_ = false; bool has_spherical_harmonics_ = false;