Allow dimensions to be specified when creating a render target.

PiperOrigin-RevId: 907622395
Change-Id: I0f806f4d77afa6a178a20d36dae3e96b81359494
This commit is contained in:
Haroon Qureshi
2026-04-29 09:12:58 -07:00
committed by Copybara-Service
parent 7e848e9406
commit 4e7b2f2124
4 changed files with 19 additions and 2 deletions
@@ -134,11 +134,12 @@ void MjrFilamentRenderer::ReadPixels(mjrRect viewport, unsigned char* rgb,
if (rgb) {
mjrRenderTargetConfig config;
mjr_defaultRenderTargetConfig(&config);
config.width = viewport.width;
config.height = viewport.height;
config.color_format = mjPIXEL_FORMAT_RGB8;
config.depth_format = mjPIXEL_FORMAT_DEPTH32F;
auto target =
std::make_unique<RenderTarget>(filament_context_.get(), config);
target->Prepare(viewport.width, viewport.height);
render_requests_[0].target = target.get();
render_requests_[1].target = target.get();
@@ -34,7 +34,11 @@ namespace mujoco {
RenderTarget::RenderTarget(FilamentContext* ctx,
const mjrRenderTargetConfig& config)
: ctx_(ctx), config_(config) {}
: ctx_(ctx), config_(config) {
if (config_.width > 0 && config_.height > 0) {
Prepare(config_.width, config_.height);
}
}
RenderTarget::~RenderTarget() noexcept {
Destroy();
@@ -47,6 +51,11 @@ void RenderTarget::Prepare(int width, int height) {
Destroy();
width_ = width;
height_ = height;
if (width_ <= 0 || height_ <= 0) {
width_ = 0;
height_ = 0;
return;
}
mjrTextureConfig color_config;
mjr_defaultTextureConfig(&color_config);
@@ -116,6 +116,7 @@ void mjr_defaultRenderableParams(mjrRenderableParams* params) {
}
void mjr_defaultRenderTargetConfig(mjrRenderTargetConfig* config) {
memset(config, 0, sizeof(mjrRenderTargetConfig));
config->color_format = mjPIXEL_FORMAT_RGBA8;
config->depth_format = mjPIXEL_FORMAT_DEPTH32F;
}
@@ -326,7 +326,13 @@ void mjr_defaultLightParams(mjrLightParams* params);
// Defines the basic properties of a render target.
struct mjrRenderTargetConfig {
// The width of the render target.
int width;
// The height of the render target.
int height;
// The format of the color buffer in the render target.
mjrPixelFormat color_format;
// The format of the depth buffer in the render target.
mjrPixelFormat depth_format;
};