Rename types to conform to mjr naming conventions.
PiperOrigin-RevId: 904438811 Change-Id: I77fe14592a4460234e0aff473ee3f530e652bca9
This commit is contained in:
committed by
Copybara-Service
parent
fa33310750
commit
c1c7643fad
@@ -72,8 +72,8 @@ uintptr_t ImguiBridge::UploadImage(uintptr_t tex_id, const uint8_t* pixels,
|
||||
// new texture.
|
||||
if (texture == nullptr || texture->GetWidth() != width ||
|
||||
texture->GetHeight() != height) {
|
||||
TextureConfig config;
|
||||
DefaultTextureConfig(&config);
|
||||
mjrTextureConfig config;
|
||||
mjr_defaultTextureConfig(&config);
|
||||
config.width = width;
|
||||
config.height = height;
|
||||
config.target = mjTEXTURE_2D;
|
||||
@@ -89,8 +89,8 @@ uintptr_t ImguiBridge::UploadImage(uintptr_t tex_id, const uint8_t* pixels,
|
||||
const auto callback =
|
||||
+[](void* user) { delete[] reinterpret_cast<std::byte*>(user); };
|
||||
|
||||
TextureData texture_data;
|
||||
DefaultTextureData(&texture_data);
|
||||
mjrTextureData texture_data;
|
||||
mjr_defaultTextureData(&texture_data);
|
||||
texture_data.bytes = bytes;
|
||||
texture_data.nbytes = num_bytes;
|
||||
texture_data.user_data = bytes;
|
||||
@@ -106,8 +106,8 @@ void ImguiBridge::CreateTexture(ImTextureData* data) {
|
||||
mju_error("Unsupported texture format.");
|
||||
}
|
||||
|
||||
TextureConfig config;
|
||||
DefaultTextureConfig(&config);
|
||||
mjrTextureConfig config;
|
||||
mjr_defaultTextureConfig(&config);
|
||||
config.width = data->Width;
|
||||
config.height = data->Height;
|
||||
config.target = mjTEXTURE_2D;
|
||||
@@ -127,8 +127,8 @@ void ImguiBridge::UpdateTexture(ImTextureData* data) {
|
||||
mju_error("Texture not found: %llu", data->TexID);
|
||||
}
|
||||
|
||||
TextureData texture_data;
|
||||
DefaultTextureData(&texture_data);
|
||||
mjrTextureData texture_data;
|
||||
mjr_defaultTextureData(&texture_data);
|
||||
texture_data.bytes = data->GetPixels();
|
||||
texture_data.nbytes = data->Width * data->Height * 4;
|
||||
texture_data.user_data = nullptr;
|
||||
|
||||
@@ -575,8 +575,8 @@ void ModelObjects::UploadTexture(const mjModel* model, int id) {
|
||||
mju_error("Invalid texture index: %d", id);
|
||||
}
|
||||
|
||||
TextureConfig config;
|
||||
DefaultTextureConfig(&config);
|
||||
mjrTextureConfig config;
|
||||
mjr_defaultTextureConfig(&config);
|
||||
config.width = model->tex_width[id];
|
||||
config.height = model->tex_height[id];
|
||||
config.target = (mjtTexture)model->tex_type[id];
|
||||
@@ -600,8 +600,8 @@ void ModelObjects::UploadTexture(const mjModel* model, int id) {
|
||||
}
|
||||
|
||||
|
||||
TextureData payload;
|
||||
DefaultTextureData(&payload);
|
||||
mjrTextureData payload;
|
||||
mjr_defaultTextureData(&payload);
|
||||
payload.bytes = model->tex_data + model->tex_adr[id];
|
||||
payload.nbytes =
|
||||
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;
|
||||
height_ = height;
|
||||
|
||||
TextureConfig color_config;
|
||||
DefaultTextureConfig(&color_config);
|
||||
mjrTextureConfig color_config;
|
||||
mjr_defaultTextureConfig(&color_config);
|
||||
Texture::InternalFlags color_flags;
|
||||
color_config.width = width;
|
||||
color_config.height = height;
|
||||
@@ -63,8 +63,8 @@ void RenderTarget::Prepare(int width, int height) {
|
||||
color_flags.color_attachment = true;
|
||||
color_texture_ = std::make_unique<Texture>(engine_, color_config, color_flags);
|
||||
|
||||
TextureConfig depth_config;
|
||||
DefaultTextureConfig(&depth_config);
|
||||
mjrTextureConfig depth_config;
|
||||
mjr_defaultTextureConfig(&depth_config);
|
||||
Texture::InternalFlags depth_flags;
|
||||
depth_config.width = width;
|
||||
depth_config.height = height;
|
||||
|
||||
@@ -27,8 +27,8 @@ namespace mujoco {
|
||||
|
||||
// Defines the basic properties of a render target.
|
||||
struct RenderTargetConfig {
|
||||
mjtPixelFormat color_format;
|
||||
mjtPixelFormat depth_format;
|
||||
mjrPixelFormat color_format;
|
||||
mjrPixelFormat depth_format;
|
||||
};
|
||||
|
||||
// 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);
|
||||
|
||||
TextureConfig config;
|
||||
DefaultTextureConfig(&config);
|
||||
mjrTextureConfig config;
|
||||
mjr_defaultTextureConfig(&config);
|
||||
config.width = 1;
|
||||
config.height = 1;
|
||||
config.target = mjTEXTURE_CUBE;
|
||||
@@ -74,9 +74,9 @@ static std::unique_ptr<Texture> CreateFallbackIndirectLightTexture(
|
||||
|
||||
auto texture = std::make_unique<Texture>(object_mgr->GetEngine(), config);
|
||||
|
||||
TextureData payload;
|
||||
DefaultTextureData(&payload);
|
||||
payload.bytes = (void*)asset->GetBytes().data();
|
||||
mjrTextureData payload;
|
||||
mjr_defaultTextureData(&payload);
|
||||
payload.bytes = asset->GetBytes().data();
|
||||
payload.nbytes = asset->GetBytes().size();
|
||||
payload.release_callback = +[](void* user_data) {
|
||||
delete static_cast<ObjectManager::Asset*>(user_data);
|
||||
|
||||
@@ -29,15 +29,15 @@ namespace mujoco {
|
||||
|
||||
static constexpr int kNumFacesPerCube = 6;
|
||||
|
||||
static bool IsCompressed(const TextureConfig& config) {
|
||||
static bool IsCompressed(const mjrTextureConfig& config) {
|
||||
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;
|
||||
}
|
||||
|
||||
static int GetFaceHeight(const TextureConfig& config) {
|
||||
static int GetFaceHeight(const mjrTextureConfig& config) {
|
||||
int face_height = config.height;
|
||||
if (config.width != config.height) {
|
||||
if (config.width * kNumFacesPerCube != config.height) {
|
||||
@@ -51,7 +51,7 @@ static int GetFaceHeight(const TextureConfig& config) {
|
||||
return face_height;
|
||||
}
|
||||
|
||||
static int GetNumChannels(const TextureConfig& config) {
|
||||
static int GetNumChannels(const mjrTextureConfig& config) {
|
||||
switch (config.format) {
|
||||
case mjPIXEL_FORMAT_R8:
|
||||
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) {
|
||||
case mjPIXEL_FORMAT_R8:
|
||||
return filament::Texture::Format::R;
|
||||
@@ -80,7 +80,7 @@ static filament::Texture::Format GetTextureFormat(const TextureConfig& config) {
|
||||
}
|
||||
|
||||
static filament::Texture::InternalFormat GetTextureInternalFormat(
|
||||
const TextureConfig& config) {
|
||||
const mjrTextureConfig& config) {
|
||||
if (config.color_space == mjCOLORSPACE_SRGB) {
|
||||
switch (config.format) {
|
||||
case mjPIXEL_FORMAT_RGB8:
|
||||
@@ -110,15 +110,15 @@ static filament::Texture::InternalFormat GetTextureInternalFormat(
|
||||
}
|
||||
}
|
||||
|
||||
void DefaultTextureData(TextureData* data) {
|
||||
std::memset(data, 0, sizeof(TextureData));
|
||||
void mjr_defaultTextureData(mjrTextureData* data) {
|
||||
std::memset(data, 0, sizeof(mjrTextureData));
|
||||
}
|
||||
|
||||
void DefaultTextureConfig(TextureConfig* config) {
|
||||
std::memset(config, 0, sizeof(TextureConfig));
|
||||
void mjr_defaultTextureConfig(mjrTextureConfig* config) {
|
||||
std::memset(config, 0, sizeof(mjrTextureConfig));
|
||||
}
|
||||
|
||||
Texture::Texture(filament::Engine* engine, const TextureConfig& config,
|
||||
Texture::Texture(filament::Engine* engine, const mjrTextureConfig& config,
|
||||
InternalFlags flags)
|
||||
: engine_(engine), config_(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;
|
||||
release_callback_ = data.release_callback;
|
||||
|
||||
|
||||
@@ -21,12 +21,13 @@
|
||||
#include <filament/Texture.h>
|
||||
#include <math/vec3.h>
|
||||
#include <mujoco/mjmodel.h>
|
||||
#include <mujoco/mujoco.h>
|
||||
|
||||
// Functions for creating filament textures.
|
||||
namespace mujoco {
|
||||
|
||||
// Pixel formats for textures.
|
||||
typedef enum mjtPixelFormat_ {
|
||||
typedef enum mjrPixelFormat_ {
|
||||
mjPIXEL_FORMAT_UNKNOWN = 0,
|
||||
mjPIXEL_FORMAT_R8,
|
||||
mjPIXEL_FORMAT_RGB8,
|
||||
@@ -34,15 +35,18 @@ typedef enum mjtPixelFormat_ {
|
||||
mjPIXEL_FORMAT_R32F,
|
||||
mjPIXEL_FORMAT_DEPTH32F,
|
||||
mjPIXEL_FORMAT_KTX,
|
||||
} mjtPixelFormat;
|
||||
} mjrPixelFormat;
|
||||
|
||||
typedef mjtTexture mjrTextureTarget;
|
||||
typedef mjtColorSpace mjrColorSpace;
|
||||
|
||||
// The binary contents of a texture.
|
||||
struct TextureData {
|
||||
struct mjrTextureData {
|
||||
// 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.
|
||||
size_t nbytes;
|
||||
mjtSize nbytes;
|
||||
|
||||
// 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
|
||||
@@ -54,10 +58,10 @@ struct TextureData {
|
||||
};
|
||||
|
||||
// Initializes the TextureData to default values.
|
||||
void DefaultTextureData(TextureData* data);
|
||||
void mjr_defaultTextureData(mjrTextureData* data);
|
||||
|
||||
// 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
|
||||
// number of bytes in the compressed data.
|
||||
int width;
|
||||
@@ -67,17 +71,17 @@ struct TextureConfig {
|
||||
int height;
|
||||
|
||||
// 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.)
|
||||
mjtPixelFormat format;
|
||||
mjrPixelFormat format;
|
||||
|
||||
// The color space of the texture (e.g. LINEAR, sRGB, etc.)
|
||||
mjtColorSpace color_space;
|
||||
mjrColorSpace color_space;
|
||||
};
|
||||
|
||||
// Initializes the TextureConfig to default values.
|
||||
void DefaultTextureConfig(TextureConfig* config);
|
||||
void mjr_defaultTextureConfig(mjrTextureConfig* config);
|
||||
|
||||
// Wrapper around a filament::Texture.
|
||||
class Texture {
|
||||
@@ -90,13 +94,13 @@ class Texture {
|
||||
};
|
||||
|
||||
// Creates a texture with the given data.
|
||||
Texture(filament::Engine* engine, const TextureConfig& config,
|
||||
Texture(filament::Engine* engine, const mjrTextureConfig& config,
|
||||
InternalFlags flags = InternalFlags());
|
||||
|
||||
~Texture();
|
||||
|
||||
// Uploads the given data to the texture.
|
||||
void Upload(const TextureData& data);
|
||||
void Upload(const mjrTextureData& data);
|
||||
|
||||
// Returns the width of the texture.
|
||||
int GetWidth() const { return config_.width; }
|
||||
@@ -121,7 +125,7 @@ class Texture {
|
||||
|
||||
filament::Engine* engine_ = nullptr;
|
||||
filament::Texture* texture_ = nullptr;
|
||||
TextureConfig config_;
|
||||
mjrTextureConfig config_;
|
||||
SphericalHarmonics spherical_harmonics_;
|
||||
bool has_spherical_harmonics_ = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user