WIP on creating utils for creating offscreen render targets.
This commit is contained in:
@@ -144,28 +144,29 @@ bool Playground::OpenPlaygroundHere(Renderer::RenderCallback render_callback) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TextureDescriptor color0_desc;
|
||||
color0_desc.format = PixelFormat::kB8G8R8A8UNormInt;
|
||||
color0_desc.size = {
|
||||
TextureDescriptor color0_tex;
|
||||
color0_tex.format = PixelFormat::kB8G8R8A8UNormInt;
|
||||
color0_tex.size = {
|
||||
static_cast<ISize::Type>(current_drawable.texture.width),
|
||||
static_cast<ISize::Type>(current_drawable.texture.height)};
|
||||
color0_tex.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget);
|
||||
|
||||
ColorAttachment color0;
|
||||
color0.texture =
|
||||
std::make_shared<TextureMTL>(color0_desc, current_drawable.texture);
|
||||
std::make_shared<TextureMTL>(color0_tex, current_drawable.texture);
|
||||
color0.clear_color = Color::SkyBlue();
|
||||
color0.load_action = LoadAction::kClear;
|
||||
color0.store_action = StoreAction::kStore;
|
||||
|
||||
TextureDescriptor stencil_texture_descriptor;
|
||||
stencil_texture_descriptor.format = PixelFormat::kD32FloatS8UNormInt;
|
||||
stencil_texture_descriptor.size = color0_desc.size;
|
||||
stencil_texture_descriptor.usage =
|
||||
TextureDescriptor stencil0_tex;
|
||||
stencil0_tex.format = PixelFormat::kD32FloatS8UNormInt;
|
||||
stencil0_tex.size = color0_tex.size;
|
||||
stencil0_tex.usage =
|
||||
static_cast<TextureUsageMask>(TextureUsage::kShaderRead) |
|
||||
static_cast<TextureUsageMask>(TextureUsage::kShaderWrite);
|
||||
auto stencil_texture =
|
||||
renderer_.GetContext()->GetPermanentsAllocator()->CreateTexture(
|
||||
StorageMode::kDeviceTransient, stencil_texture_descriptor);
|
||||
StorageMode::kDeviceTransient, stencil0_tex);
|
||||
stencil_texture->SetLabel("PlaygroundMainStencil");
|
||||
|
||||
StencilAttachment stencil0;
|
||||
|
||||
@@ -114,6 +114,9 @@ bool RenderPassMTL::IsValid() const {
|
||||
}
|
||||
|
||||
void RenderPassMTL::SetLabel(std::string label) {
|
||||
if (label.empty()) {
|
||||
return;
|
||||
}
|
||||
label_ = std::move(label);
|
||||
transients_buffer_->SetLabel(SPrintF("%s Transients", label_.c_str()));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "impeller/renderer/render_target.h"
|
||||
|
||||
#include "impeller/renderer/allocator.h"
|
||||
#include "impeller/renderer/context.h"
|
||||
#include "impeller/renderer/texture.h"
|
||||
|
||||
namespace impeller {
|
||||
@@ -70,4 +72,52 @@ const std::optional<StencilAttachment>& RenderTarget::GetStencilAttachment()
|
||||
return stencil_;
|
||||
}
|
||||
|
||||
RenderTarget RenderTarget::CreateOffscreen(const Context& context,
|
||||
ISize size,
|
||||
std::string label) {
|
||||
TextureDescriptor color_tex0;
|
||||
color_tex0.format = PixelFormat::kB8G8R8A8UNormInt;
|
||||
color_tex0.size = size;
|
||||
color_tex0.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget);
|
||||
|
||||
TextureDescriptor stencil_tex0;
|
||||
stencil_tex0.format = PixelFormat::kD32FloatS8UNormInt;
|
||||
stencil_tex0.size = size;
|
||||
stencil_tex0.usage =
|
||||
static_cast<TextureUsageMask>(TextureUsage::kShaderRead) |
|
||||
static_cast<TextureUsageMask>(TextureUsage::kShaderWrite);
|
||||
|
||||
ColorAttachment color0;
|
||||
color0.clear_color = Color::BlackTransparent();
|
||||
color0.load_action = LoadAction::kClear;
|
||||
color0.store_action = StoreAction::kStore;
|
||||
color0.texture = context.GetPermanentsAllocator()->CreateTexture(
|
||||
StorageMode::kDevicePrivate, color_tex0);
|
||||
|
||||
if (!color0.texture) {
|
||||
return {};
|
||||
}
|
||||
|
||||
color0.texture->SetLabel(label);
|
||||
|
||||
StencilAttachment stencil0;
|
||||
stencil0.load_action = LoadAction::kClear;
|
||||
stencil0.store_action = StoreAction::kDontCare;
|
||||
stencil0.clear_stencil = 0u;
|
||||
stencil0.texture = context.GetPermanentsAllocator()->CreateTexture(
|
||||
StorageMode::kDeviceTransient, stencil_tex0);
|
||||
|
||||
if (!stencil0.texture) {
|
||||
return {};
|
||||
}
|
||||
|
||||
stencil0.texture->SetLabel(label);
|
||||
|
||||
RenderTarget target;
|
||||
target.SetColorAttachment(std::move(color0), 0u);
|
||||
target.SetStencilAttachment(std::move(stencil0));
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -13,8 +13,14 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class Context;
|
||||
|
||||
class RenderTarget {
|
||||
public:
|
||||
static RenderTarget CreateOffscreen(const Context& context,
|
||||
ISize size,
|
||||
std::string label = "Offscreen");
|
||||
|
||||
RenderTarget();
|
||||
|
||||
~RenderTarget();
|
||||
|
||||
Reference in New Issue
Block a user