Pass filament::Engine instead of FilamentContext
for textures, meshes, and render targets. PiperOrigin-RevId: 911770834 Change-Id: I081458e118f0e91091d6d4df7b760e9dbb321672
This commit is contained in:
committed by
Copybara-Service
parent
0f53f55853
commit
b6aac76cc4
@@ -32,7 +32,6 @@
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
#include <mujoco/mujoco.h>
|
||||
#include "experimental/filament/filament/filament_context.h"
|
||||
#include "experimental/filament/filament/math_util.h"
|
||||
#include "experimental/filament/render_context_filament.h"
|
||||
|
||||
@@ -103,8 +102,8 @@ int FillSequence(std::byte* buffer, std::size_t num_bytes) {
|
||||
return num;
|
||||
}
|
||||
|
||||
Mesh::Mesh(FilamentContext* ctx, const mjrMeshData& data)
|
||||
: engine_(ctx->GetEngine()), shared_state_(std::make_shared<SharedState>()) {
|
||||
Mesh::Mesh(filament::Engine* engine, const mjrMeshData& data)
|
||||
: engine_(engine), shared_state_(std::make_shared<SharedState>()) {
|
||||
type_ = data.primitive_type == mjMESH_PRIMITIVE_TYPE_TRIANGLES
|
||||
? filament::RenderableManager::PrimitiveType::TRIANGLES
|
||||
: filament::RenderableManager::PrimitiveType::LINES;
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <filament/RenderableManager.h>
|
||||
#include <filament/VertexBuffer.h>
|
||||
#include <math/vec4.h>
|
||||
#include "experimental/filament/filament/filament_context.h"
|
||||
#include "experimental/filament/render_context_filament.h"
|
||||
|
||||
// Functions for creating filament vertex and index buffers.
|
||||
@@ -39,8 +38,7 @@ namespace mujoco {
|
||||
class Mesh : public mjrMesh {
|
||||
public:
|
||||
// Creates a Mesh from the given MeshData.
|
||||
Mesh(FilamentContext* ctx, const mjrMeshData& data);
|
||||
|
||||
Mesh(filament::Engine* engine, const mjrMeshData& data);
|
||||
~Mesh();
|
||||
|
||||
Mesh(const Mesh&) = delete;
|
||||
|
||||
@@ -26,15 +26,14 @@
|
||||
#include <filament/RenderTarget.h>
|
||||
#include <filament/Texture.h>
|
||||
#include <mujoco/mujoco.h>
|
||||
#include "experimental/filament/filament/filament_context.h"
|
||||
#include "experimental/filament/filament/texture.h"
|
||||
#include "experimental/filament/render_context_filament.h"
|
||||
|
||||
namespace mujoco {
|
||||
|
||||
RenderTarget::RenderTarget(FilamentContext* ctx,
|
||||
RenderTarget::RenderTarget(filament::Engine* engine,
|
||||
const mjrRenderTargetConfig& config)
|
||||
: ctx_(ctx), config_(config) {
|
||||
: engine_(engine), config_(config) {
|
||||
if (config_.width > 0 && config_.height > 0) {
|
||||
Prepare(config_.width, config_.height);
|
||||
}
|
||||
@@ -67,7 +66,7 @@ void RenderTarget::Prepare(int width, int height) {
|
||||
color_config.color_space = mjCOLORSPACE_LINEAR;
|
||||
color_config.format = mjPIXEL_FORMAT_RGB8;
|
||||
color_flags.color_attachment = true;
|
||||
color_texture_ = std::make_unique<Texture>(ctx_, color_config, color_flags);
|
||||
color_texture_ = std::make_unique<Texture>(engine_, color_config, color_flags);
|
||||
|
||||
mjrTextureConfig depth_config;
|
||||
mjr_defaultTextureConfig(&depth_config);
|
||||
@@ -79,14 +78,14 @@ void RenderTarget::Prepare(int width, int height) {
|
||||
depth_config.color_space = mjCOLORSPACE_LINEAR;
|
||||
depth_config.format = mjPIXEL_FORMAT_DEPTH32F;
|
||||
depth_flags.depth_attachment = true;
|
||||
depth_texture_ = std::make_unique<Texture>(ctx_, depth_config, depth_flags);
|
||||
depth_texture_ = std::make_unique<Texture>(engine_, depth_config, depth_flags);
|
||||
|
||||
filament::RenderTarget::Builder builder;
|
||||
builder.texture(filament::RenderTarget::AttachmentPoint::COLOR,
|
||||
color_texture_->GetFilamentTexture());
|
||||
builder.texture(filament::RenderTarget::AttachmentPoint::DEPTH,
|
||||
depth_texture_->GetFilamentTexture());
|
||||
render_target_ = builder.build(*ctx_->GetEngine());
|
||||
render_target_ = builder.build(*engine_);
|
||||
}
|
||||
|
||||
void RenderTarget::ReadColorPixels(filament::Renderer* renderer, uint8_t* bytes,
|
||||
@@ -120,7 +119,7 @@ void RenderTarget::ReadColorPixels(filament::Renderer* renderer, uint8_t* bytes,
|
||||
|
||||
void RenderTarget::Destroy() {
|
||||
if (render_target_) {
|
||||
ctx_->GetEngine()->destroy(render_target_);
|
||||
engine_->destroy(render_target_);
|
||||
render_target_ = nullptr;
|
||||
}
|
||||
color_texture_.reset();
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#include <filament/Engine.h>
|
||||
#include <filament/Texture.h>
|
||||
#include "experimental/filament/filament/filament_context.h"
|
||||
#include "experimental/filament/filament/texture.h"
|
||||
#include "experimental/filament/render_context_filament.h"
|
||||
|
||||
@@ -32,7 +31,7 @@ class RenderTarget : public mjrRenderTarget {
|
||||
public:
|
||||
// Defines the types of textures to create for the color and depth
|
||||
// attachments.
|
||||
RenderTarget(FilamentContext* ctx, const mjrRenderTargetConfig& config);
|
||||
RenderTarget(filament::Engine* engine, const mjrRenderTargetConfig& config);
|
||||
~RenderTarget() noexcept;
|
||||
|
||||
RenderTarget(const RenderTarget&) = delete;
|
||||
@@ -65,7 +64,7 @@ class RenderTarget : public mjrRenderTarget {
|
||||
private:
|
||||
void Destroy();
|
||||
|
||||
FilamentContext* ctx_ = nullptr;
|
||||
filament::Engine* engine_ = nullptr;
|
||||
mjrRenderTargetConfig config_;
|
||||
filament::RenderTarget* render_target_ = nullptr;
|
||||
std::unique_ptr<Texture> color_texture_ = nullptr;
|
||||
|
||||
@@ -308,7 +308,8 @@ void SceneView::AddReflectiveRenderable(Renderable* renderable) {
|
||||
|
||||
config.color_format = mjPIXEL_FORMAT_RGBA8;
|
||||
config.depth_format = mjPIXEL_FORMAT_DEPTH32F;
|
||||
reflect_targets_.push_back(std::make_unique<RenderTarget>(ctx_, config));
|
||||
reflect_targets_.push_back(
|
||||
std::make_unique<RenderTarget>(ctx_->GetEngine(), config));
|
||||
}
|
||||
|
||||
// Prepare a render target for the reflective renderable.
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include <image/Ktx1Bundle.h>
|
||||
#include <ktxreader/Ktx1Reader.h>
|
||||
#include <mujoco/mujoco.h>
|
||||
#include "experimental/filament/filament/filament_context.h"
|
||||
#include "experimental/filament/render_context_filament.h"
|
||||
|
||||
namespace mujoco {
|
||||
@@ -112,9 +111,9 @@ static filament::Texture::InternalFormat GetTextureInternalFormat(
|
||||
}
|
||||
}
|
||||
|
||||
Texture::Texture(FilamentContext* ctx, const mjrTextureConfig& config,
|
||||
Texture::Texture(filament::Engine* engine, const mjrTextureConfig& config,
|
||||
InternalFlags flags)
|
||||
: engine_(ctx->GetEngine()), config_(config) {
|
||||
: engine_(engine), config_(config) {
|
||||
if (IsCompressed(config_)) {
|
||||
// We defer creation of compressed textures until Upload() is called. In
|
||||
// the meantime, we don't really know anything about the texture (e.g.
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <filament/Engine.h>
|
||||
#include <filament/Texture.h>
|
||||
#include <math/vec3.h>
|
||||
#include "experimental/filament/filament/filament_context.h"
|
||||
#include "experimental/filament/render_context_filament.h"
|
||||
|
||||
// Functions for creating filament textures.
|
||||
@@ -35,7 +34,7 @@ class Texture : public mjrTexture {
|
||||
};
|
||||
|
||||
// Creates a texture with the given data.
|
||||
Texture(FilamentContext* ctx, const mjrTextureConfig& config,
|
||||
Texture(filament::Engine* engine, const mjrTextureConfig& config,
|
||||
InternalFlags flags = InternalFlags());
|
||||
|
||||
~Texture();
|
||||
|
||||
@@ -154,7 +154,8 @@ void mjrf_destroyContext(mjrfContext* ctx) {
|
||||
}
|
||||
|
||||
mjrTexture* mjrf_createTexture(mjrfContext* ctx, const mjrTextureConfig* cfg) {
|
||||
return new mujoco::Texture(mujoco::FilamentContext::downcast(ctx), *cfg);
|
||||
return new mujoco::Texture(
|
||||
mujoco::FilamentContext::downcast(ctx)->GetEngine(), *cfg);
|
||||
}
|
||||
|
||||
void mjrf_destroyTexture(mjrTexture* texture) {
|
||||
@@ -162,7 +163,8 @@ void mjrf_destroyTexture(mjrTexture* texture) {
|
||||
}
|
||||
|
||||
mjrMesh* mjrf_createMesh(mjrfContext* ctx, const mjrMeshData* data) {
|
||||
return new mujoco::Mesh(mujoco::FilamentContext::downcast(ctx), *data);
|
||||
return new mujoco::Mesh(mujoco::FilamentContext::downcast(ctx)->GetEngine(),
|
||||
*data);
|
||||
}
|
||||
|
||||
void mjrf_destroyMesh(mjrMesh* mesh) { delete mujoco::Mesh::downcast(mesh); }
|
||||
@@ -195,15 +197,14 @@ void mjrf_destroyRenderable(mjrRenderable* renderable) {
|
||||
|
||||
mjrRenderTarget* mjrf_createRenderTarget(mjrfContext* ctx,
|
||||
const mjrRenderTargetConfig* config) {
|
||||
return new mujoco::RenderTarget(mujoco::FilamentContext::downcast(ctx),
|
||||
*config);
|
||||
return new mujoco::RenderTarget(
|
||||
mujoco::FilamentContext::downcast(ctx)->GetEngine(), *config);
|
||||
}
|
||||
|
||||
void mjrf_destroyRenderTarget(mjrRenderTarget* render_target) {
|
||||
delete mujoco::RenderTarget::downcast(render_target);
|
||||
}
|
||||
|
||||
|
||||
void mjrf_setTextureData(mjrTexture* texture, const mjrTextureData* data) {
|
||||
mujoco::Texture::downcast(texture)->Upload(*data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user