Add support for more pixel formats.

This commit is contained in:
Chinmay Garde 2021-07-06 17:18:20 -07:00 committed by Dan Field
parent 0f6b0b86d8
commit 6684140013
5 changed files with 14 additions and 2 deletions

View File

@ -15,6 +15,8 @@ namespace impeller {
enum class PixelFormat {
kUnknown,
kPixelFormat_R8G8B8A8_UNormInt,
kPixelFormat_R8G8B8A8_UNormInt_SRGB,
kPixelFormat_B8G8R8A8_UNormInt,
kPixelFormat_B8G8R8A8_UNormInt_SRGB,
kPixelFormat_D32_Float_S8_UNormInt,
@ -97,8 +99,9 @@ constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format) {
switch (format) {
case PixelFormat::kUnknown:
return 0u;
case PixelFormat::kPixelFormat_R8G8B8A8_UNormInt:
case PixelFormat::kPixelFormat_R8G8B8A8_UNormInt_SRGB:
case PixelFormat::kPixelFormat_B8G8R8A8_UNormInt:
return 4u;
case PixelFormat::kPixelFormat_B8G8R8A8_UNormInt_SRGB:
return 4u;
case PixelFormat::kPixelFormat_D32_Float_S8_UNormInt:

View File

@ -27,6 +27,10 @@ constexpr MTLPixelFormat ToMTLPixelFormat(PixelFormat format) {
return MTLPixelFormatBGRA8Unorm_sRGB;
case PixelFormat::kPixelFormat_D32_Float_S8_UNormInt:
return MTLPixelFormatDepth32Float_Stencil8;
case PixelFormat::kPixelFormat_R8G8B8A8_UNormInt:
return MTLPixelFormatRGBA8Unorm;
case PixelFormat::kPixelFormat_R8G8B8A8_UNormInt_SRGB:
return MTLPixelFormatRGBA8Unorm_sRGB;
}
return MTLPixelFormatInvalid;
};

View File

@ -23,6 +23,10 @@ Texture::Texture(TextureDescriptor desc, id<MTLTexture> texture)
Texture::~Texture() = default;
void Texture::SetLabel(const std::string_view& label) {
[texture_ setLabel:@(label.data())];
}
bool Texture::SetContents(const uint8_t* contents, size_t length) {
if (!IsValid() || !contents) {
return false;

View File

@ -18,7 +18,7 @@ std::optional<PixelFormat> FormatForImageResultComponents(
case ImageResult::Components::RGB:
return std::nullopt;
case ImageResult::Components::RGBA:
return PixelFormat::kPixelFormat_B8G8R8A8_UNormInt;
return PixelFormat::kPixelFormat_R8G8B8A8_UNormInt;
}
return std::nullopt;
}

View File

@ -55,6 +55,7 @@ TEST_F(PrimitivesTest, CanCreateBoxPrimitive) {
auto texture = context->GetPermanentsAllocator()->CreateTexture(
StorageMode::kHostVisible, texture_descriptor.value());
ASSERT_TRUE(texture);
texture->SetLabel("Bay Bridge");
auto uploaded = texture->SetContents(result.GetAllocation()->GetMapping(),
result.GetAllocation()->GetSize());
ASSERT_TRUE(uploaded);