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