Add functions to create context and render.
Rename mjrf_render to mjrf_renderScene to avoid naming collision. This function is will be removed in a future CL. PiperOrigin-RevId: 910764245 Change-Id: If4d05e806a9699570ca4bbc882f28bfdd05dbd8d
This commit is contained in:
committed by
Copybara-Service
parent
9f972aa42e
commit
a692283db3
@@ -36,7 +36,7 @@ void mjr_freeContext(mjrContext* con) {
|
||||
mjrf_freeContext(con);
|
||||
}
|
||||
void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
|
||||
mjrf_render(viewport, scn, con);
|
||||
mjrf_renderScene(viewport, scn, con);
|
||||
}
|
||||
void mjr_uploadMesh(const mjModel* m, const mjrContext* con, int meshid) {
|
||||
mjrf_uploadMesh(m, con, meshid);
|
||||
|
||||
@@ -145,6 +145,14 @@ void mjr_defaultReadPixelsRequest(mjrReadPixelsRequest* request) {
|
||||
memset(request, 0, sizeof(mjrReadPixelsRequest));
|
||||
}
|
||||
|
||||
mjrfContext* mjrf_createContext(const mjrFilamentConfig* config) {
|
||||
return new mujoco::FilamentContext(config);
|
||||
}
|
||||
|
||||
void mjrf_destroyContext(mjrfContext* ctx) {
|
||||
delete mujoco::FilamentContext::downcast(ctx);
|
||||
}
|
||||
|
||||
mjrTexture* mjrf_createTexture(mjrfContext* ctx, const mjrTextureConfig* cfg) {
|
||||
return new mujoco::Texture(mujoco::FilamentContext::downcast(ctx), *cfg);
|
||||
}
|
||||
@@ -328,6 +336,20 @@ void mjrf_configureSceneFromModel(mjrScene* scene, const mjModel* model) {
|
||||
mujoco::SceneView::downcast(scene)->Configure(model);
|
||||
}
|
||||
|
||||
mjrFrameHandle mjrf_render(mjrfContext* ctx, const mjrRenderRequest* req,
|
||||
int nreq, const mjrReadPixelsRequest* read_req,
|
||||
int nread_req) {
|
||||
return mujoco::FilamentContext::downcast(ctx)->Render(
|
||||
{req, static_cast<size_t>(nreq)},
|
||||
{read_req, static_cast<size_t>(nread_req)});
|
||||
}
|
||||
|
||||
void mjrf_waitForFrame(mjrfContext* ctx, mjrFrameHandle frame) {
|
||||
mujoco::FilamentContext::downcast(ctx)->WaitForFrame(frame);
|
||||
}
|
||||
|
||||
// Legacy API, to be deprecated.
|
||||
|
||||
void mjrf_makeFilamentContext(const mjModel* m, mjrContext* con,
|
||||
const mjrFilamentConfig* config) {
|
||||
// TODO: Support multiple contexts and multiple threads. For now, we'll just
|
||||
@@ -361,7 +383,7 @@ void mjrf_freeContext(mjrContext* con) {
|
||||
mjrf_defaultContext(con);
|
||||
}
|
||||
|
||||
void mjrf_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
|
||||
void mjrf_renderScene(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
|
||||
CheckFilamentContext();
|
||||
g_filament_context->Render(viewport, scn);
|
||||
}
|
||||
|
||||
@@ -421,6 +421,15 @@ struct mjrFilamentConfig {
|
||||
bool force_software_rendering;
|
||||
};
|
||||
|
||||
// Initializes the mjrFilamentConfig to default values.
|
||||
void mjrf_defaultFilamentConfig(mjrFilamentConfig* config);
|
||||
|
||||
// Creates a filament rendering context.
|
||||
mjrfContext* mjrf_createContext(const mjrFilamentConfig* config);
|
||||
|
||||
// Destroys the filament rendering context.
|
||||
void mjrf_destroyContext(mjrfContext* ctx);
|
||||
|
||||
// Creates a texture for the filament renderer.
|
||||
mjrTexture* mjrf_createTexture(mjrfContext* ctx, const mjrTextureConfig* cfg);
|
||||
|
||||
@@ -538,6 +547,14 @@ void mjrf_setSceneReflectionsEnabled(mjrScene* scene, bool enabled);
|
||||
// Configures the scene based on the parameters in the model.
|
||||
void mjrf_configureSceneFromModel(mjrScene* scene, const mjModel* model);
|
||||
|
||||
// Submits the given requests for rendering.
|
||||
mjrFrameHandle mjrf_render(mjrfContext* ctx, const mjrRenderRequest* req,
|
||||
int nreq, const mjrReadPixelsRequest* read_req,
|
||||
int nread_req);
|
||||
|
||||
// Waits for the rendering to complete for the given frame handle.
|
||||
void mjrf_waitForFrame(mjrfContext* ctx, mjrFrameHandle frame);
|
||||
|
||||
// Legacy API, to be deprecated.
|
||||
|
||||
void mjrf_defaultFilamentConfig(mjrFilamentConfig* config);
|
||||
@@ -551,7 +568,7 @@ void mjrf_makeContext(const mjModel* m, mjrContext* con, int fontscale);
|
||||
|
||||
void mjrf_freeContext(mjrContext* con);
|
||||
|
||||
void mjrf_render(mjrRect viewport, mjvScene* scn, const mjrContext* con);
|
||||
void mjrf_renderScene(mjrRect viewport, mjvScene* scn, const mjrContext* con);
|
||||
|
||||
void mjrf_uploadMesh(const mjModel* m, const mjrContext* con, int meshid);
|
||||
|
||||
|
||||
@@ -25,6 +25,11 @@ namespace mujoco {
|
||||
template <typename T>
|
||||
using UniquePtr = std::unique_ptr<T, void (*)(T*)>;
|
||||
|
||||
inline UniquePtr<mjrfContext> CreateContext(const mjrFilamentConfig& config) {
|
||||
mjrfContext* context = mjrf_createContext(&config);
|
||||
return UniquePtr<mjrfContext>(context, mjrf_destroyContext);
|
||||
}
|
||||
|
||||
inline UniquePtr<mjrTexture> CreateTexture(mjrfContext* ctx,
|
||||
const mjrTextureConfig& config) {
|
||||
mjrTexture* texture = mjrf_createTexture(ctx, &config);
|
||||
|
||||
@@ -95,7 +95,7 @@ void Renderer::Init(const mjModel* model) {
|
||||
: mjGRAPHICS_API_VULKAN;
|
||||
mjrf_makeFilamentContext(model, &render_context_, &render_config);
|
||||
render_ = [&](mjrRect rect, mjvScene* scene) {
|
||||
mjrf_render(rect, scene, &render_context_);
|
||||
mjrf_renderScene(rect, scene, &render_context_);
|
||||
};
|
||||
set_buffer_ = [&](int framebuffer) {
|
||||
mjrf_setBuffer(framebuffer, &render_context_);
|
||||
|
||||
Reference in New Issue
Block a user