Add API functions for creating and destroying objects.
Also provide a header-only C++ library that wraps created objects into unique_ptrs. PiperOrigin-RevId: 910607824 Change-Id: I0427f6dedab6aa299b3128031b055bd4d0c8e497
This commit is contained in:
committed by
Copybara-Service
parent
de030f4664
commit
88bff84cbb
@@ -23,6 +23,7 @@ target_sources(${MUJOCO_FILAMENT_TARGET_NAME}
|
||||
PUBLIC
|
||||
render_context_filament.h
|
||||
render_context_filament.cc
|
||||
render_context_filament_cpp.h
|
||||
filament/builtins.cc
|
||||
filament/builtins.h
|
||||
filament/color_grading_options.cc
|
||||
|
||||
@@ -23,6 +23,13 @@
|
||||
#include <mujoco/mjvisualize.h>
|
||||
#include <mujoco/mujoco.h>
|
||||
#include "experimental/filament/compat/mjr_filament_renderer.h"
|
||||
#include "experimental/filament/filament/filament_context.h"
|
||||
#include "experimental/filament/filament/light.h"
|
||||
#include "experimental/filament/filament/mesh.h"
|
||||
#include "experimental/filament/filament/render_target.h"
|
||||
#include "experimental/filament/filament/renderable.h"
|
||||
#include "experimental/filament/filament/scene_view.h"
|
||||
#include "experimental/filament/filament/texture.h"
|
||||
|
||||
|
||||
#if defined(TLS_FILAMENT_CONTEXT)
|
||||
@@ -136,6 +143,56 @@ void mjr_defaultReadPixelsRequest(mjrReadPixelsRequest* request) {
|
||||
memset(request, 0, sizeof(mjrReadPixelsRequest));
|
||||
}
|
||||
|
||||
mjrTexture* mjrf_createTexture(mjrfContext* ctx, const mjrTextureConfig* cfg) {
|
||||
return new mujoco::Texture(mujoco::FilamentContext::downcast(ctx), *cfg);
|
||||
}
|
||||
|
||||
void mjrf_destroyTexture(mjrTexture* texture) {
|
||||
delete mujoco::Texture::downcast(texture);
|
||||
}
|
||||
|
||||
mjrMesh* mjrf_createMesh(mjrfContext* ctx, const mjrMeshData* data) {
|
||||
return new mujoco::Mesh(mujoco::FilamentContext::downcast(ctx), *data);
|
||||
}
|
||||
|
||||
void mjrf_destroyMesh(mjrMesh* mesh) { delete mujoco::Mesh::downcast(mesh); }
|
||||
|
||||
mjrScene* mjrf_createScene(mjrfContext* ctx, const mjrSceneParams* params) {
|
||||
return new mujoco::SceneView(mujoco::FilamentContext::downcast(ctx), *params);
|
||||
}
|
||||
|
||||
void mjrf_destroyScene(mjrScene* scene) {
|
||||
delete mujoco::SceneView::downcast(scene);
|
||||
}
|
||||
|
||||
mjrLight* mjrf_createLight(mjrfContext* ctx, const mjrLightParams* params) {
|
||||
return new mujoco::Light(mujoco::FilamentContext::downcast(ctx), *params);
|
||||
}
|
||||
|
||||
void mjrf_destroyLight(mjrLight* light) {
|
||||
delete mujoco::Light::downcast(light);
|
||||
}
|
||||
|
||||
mjrRenderable* mjrf_createRenderable(mjrfContext* ctx,
|
||||
const mjrRenderableParams* params) {
|
||||
return new mujoco::Renderable(mujoco::FilamentContext::downcast(ctx),
|
||||
*params);
|
||||
}
|
||||
|
||||
void mjrf_destroyRenderable(mjrRenderable* renderable) {
|
||||
delete mujoco::Renderable::downcast(renderable);
|
||||
}
|
||||
|
||||
mjrRenderTarget* mjrf_createRenderTarget(mjrfContext* ctx,
|
||||
const mjrRenderTargetConfig* config) {
|
||||
return new mujoco::RenderTarget(mujoco::FilamentContext::downcast(ctx),
|
||||
*config);
|
||||
}
|
||||
|
||||
void mjrf_destroyRenderTarget(mjrRenderTarget* render_target) {
|
||||
delete mujoco::RenderTarget::downcast(render_target);
|
||||
}
|
||||
|
||||
void mjrf_makeFilamentContext(const mjModel* m, mjrContext* con,
|
||||
const mjrFilamentConfig* config) {
|
||||
// TODO: Support multiple contexts and multiple threads. For now, we'll just
|
||||
|
||||
@@ -421,6 +421,45 @@ struct mjrFilamentConfig {
|
||||
bool force_software_rendering;
|
||||
};
|
||||
|
||||
// Creates a texture for the filament renderer.
|
||||
mjrTexture* mjrf_createTexture(mjrfContext* ctx, const mjrTextureConfig* cfg);
|
||||
|
||||
// Destroys the texture.
|
||||
void mjrf_destroyTexture(mjrTexture* texture);
|
||||
|
||||
// Creates a mesh for the filament renderer.
|
||||
mjrMesh* mjrf_createMesh(mjrfContext* ctx, const mjrMeshData* data);
|
||||
|
||||
// Destroys the mesh.
|
||||
void mjrf_destroyMesh(mjrMesh* mesh);
|
||||
|
||||
// Creates a scene for the filament renderer.
|
||||
mjrScene* mjrf_createScene(mjrfContext* ctx, const mjrSceneParams* params);
|
||||
|
||||
// Destroys the scene.
|
||||
void mjrf_destroyScene(mjrScene* scene);
|
||||
|
||||
// Creates a light for the filament renderer.
|
||||
mjrLight* mjrf_createLight(mjrfContext* ctx, const mjrLightParams* params);
|
||||
|
||||
// Destroys the light.
|
||||
void mjrf_destroyLight(mjrLight* light);
|
||||
|
||||
// Creates a renderable for the filament renderer.
|
||||
mjrRenderable* mjrf_createRenderable(mjrfContext* ctx, const mjrRenderableParams* params);
|
||||
|
||||
// Destroys the renderable.
|
||||
void mjrf_destroyRenderable(mjrRenderable* renderable);
|
||||
|
||||
// Creates a render target for the filament renderer.
|
||||
mjrRenderTarget* mjrf_createRenderTarget(mjrfContext* ctx,
|
||||
const mjrRenderTargetConfig* config);
|
||||
|
||||
// Destroys the render target.
|
||||
void mjrf_destroyRenderTarget(mjrRenderTarget* render_target);
|
||||
|
||||
// Legacy API, to be deprecated.
|
||||
|
||||
void mjrf_defaultFilamentConfig(mjrFilamentConfig* config);
|
||||
|
||||
void mjrf_makeFilamentContext(const mjModel* m, mjrContext* con,
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
// Copyright 2026 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_RENDER_CONTEXT_FILAMENT_CPP_H_
|
||||
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_RENDER_CONTEXT_FILAMENT_CPP_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "experimental/filament/render_context_filament.h"
|
||||
|
||||
namespace mujoco {
|
||||
|
||||
// A unique pointer to a mujoco object.
|
||||
template <typename T>
|
||||
using UniquePtr = std::unique_ptr<T, void (*)(T*)>;
|
||||
|
||||
inline UniquePtr<mjrTexture> CreateTexture(mjrfContext* ctx,
|
||||
const mjrTextureConfig& config) {
|
||||
mjrTexture* texture = mjrf_createTexture(ctx, &config);
|
||||
return UniquePtr<mjrTexture>(texture, mjrf_destroyTexture);
|
||||
}
|
||||
|
||||
inline UniquePtr<mjrMesh> CreateMesh(mjrfContext* ctx,
|
||||
const mjrMeshData& data) {
|
||||
mjrMesh* mesh = mjrf_createMesh(ctx, &data);
|
||||
return UniquePtr<mjrMesh>(mesh, mjrf_destroyMesh);
|
||||
}
|
||||
|
||||
inline UniquePtr<mjrScene> CreateScene(mjrfContext* ctx,
|
||||
const mjrSceneParams& params) {
|
||||
mjrScene* scene = mjrf_createScene(ctx, ¶ms);
|
||||
return UniquePtr<mjrScene>(scene, mjrf_destroyScene);
|
||||
}
|
||||
|
||||
inline UniquePtr<mjrLight> CreateLight(mjrfContext* ctx,
|
||||
const mjrLightParams& params) {
|
||||
mjrLight* light = mjrf_createLight(ctx, ¶ms);
|
||||
return UniquePtr<mjrLight>(light, mjrf_destroyLight);
|
||||
}
|
||||
|
||||
inline UniquePtr<mjrRenderable> CreateRenderable(
|
||||
mjrfContext* ctx, const mjrRenderableParams& params) {
|
||||
mjrRenderable* renderable = mjrf_createRenderable(ctx, ¶ms);
|
||||
return UniquePtr<mjrRenderable>(renderable, mjrf_destroyRenderable);
|
||||
}
|
||||
|
||||
inline UniquePtr<mjrRenderTarget> CreateRenderTarget(
|
||||
mjrfContext* ctx, const mjrRenderTargetConfig& config) {
|
||||
mjrRenderTarget* render_target = mjrf_createRenderTarget(ctx, &config);
|
||||
return UniquePtr<mjrRenderTarget>(render_target, mjrf_destroyRenderTarget);
|
||||
}
|
||||
|
||||
} // namespace mujoco
|
||||
|
||||
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_RENDER_CONTEXT_FILAMENT_CPP_H_
|
||||
Reference in New Issue
Block a user