-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IGL: Add load helpers to texture_loader
Summary: This diff adds new load and loadToExternalMemory helper methods to texture_loader. These are intended to support use cases where the texture data is not directly in a form usable by the GPU (e.g., png, jpeg). A new memorySizeInBytes is also added to help allocate memory to load the data to. A new supporting class, IData, is also introduced to hold data when the class itself must allocate the data. Reviewed By: MichaelTay Differential Revision: D49135958 fbshipit-source-id: 59d050e2a125b6f9c6b138ca765bebeb4abed3cd
- Loading branch information
1 parent
ae1ed3e
commit f060edf
Showing
6 changed files
with
276 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include <IGLU/texture_loader/IData.h> | ||
|
||
namespace iglu::textureloader { | ||
namespace { | ||
class ByteData final : public IData { | ||
public: | ||
ByteData(std::unique_ptr<uint8_t[]> data, size_t length) noexcept; | ||
|
||
~ByteData() final = default; | ||
|
||
[[nodiscard]] const uint8_t* IGL_NONNULL data() const noexcept final; | ||
[[nodiscard]] uint32_t length() const noexcept final; | ||
|
||
private: | ||
std::unique_ptr<uint8_t[]> data_; | ||
uint32_t length_ = 0; | ||
}; | ||
|
||
ByteData::ByteData(std::unique_ptr<uint8_t[]> data, size_t length) noexcept : | ||
data_(std::move(data)), length_(length) {} | ||
|
||
const uint8_t* IGL_NONNULL ByteData::data() const noexcept { | ||
IGL_ASSERT(data_ != nullptr); | ||
return data_.get(); | ||
} | ||
|
||
uint32_t ByteData::length() const noexcept { | ||
return length_; | ||
} | ||
|
||
} // namespace | ||
|
||
std::unique_ptr<IData> IData::tryCreate(std::unique_ptr<uint8_t[]> data, | ||
uint32_t length, | ||
igl::Result* IGL_NULLABLE outResult) { | ||
if (data == nullptr) { | ||
igl::Result::setResult(outResult, igl::Result::Code::ArgumentNull, "data is nullptr"); | ||
return nullptr; | ||
} | ||
|
||
if (length == 0u) { | ||
igl::Result::setResult(outResult, igl::Result::Code::ArgumentInvalid, "length is 0"); | ||
return nullptr; | ||
} | ||
|
||
return std::make_unique<ByteData>(std::move(data), length); | ||
} | ||
|
||
} // namespace iglu::textureloader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <igl/Common.h> | ||
#include <memory> | ||
|
||
namespace iglu::textureloader { | ||
|
||
/// Interface for accessing data. | ||
class IData { | ||
protected: | ||
IData() noexcept = default; | ||
|
||
public: | ||
virtual ~IData() = default; | ||
|
||
static std::unique_ptr<IData> tryCreate(std::unique_ptr<uint8_t[]> data, | ||
uint32_t length, | ||
igl::Result* IGL_NULLABLE outResult); | ||
|
||
[[nodiscard]] virtual const uint8_t* IGL_NONNULL data() const noexcept = 0; | ||
[[nodiscard]] virtual uint32_t length() const noexcept = 0; | ||
}; | ||
|
||
} // namespace iglu::textureloader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.