separate IBL from skybox and add setBackgroundImage method

This commit is contained in:
Nick Fisher
2022-08-09 09:52:07 +08:00
parent 12edd1f0b2
commit 2cb0d57eed
16 changed files with 1066 additions and 85 deletions

View File

@@ -0,0 +1,170 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef IMAGE_BASISENCODER_H_
#define IMAGE_BASISENCODER_H_
#include <stddef.h>
#include <stdint.h>
#include <utils/compiler.h>
#include <image/LinearImage.h>
namespace image {
struct BasisEncoderBuilderImpl;
struct BasisEncoderImpl;
class UTILS_PUBLIC BasisEncoder {
public:
enum class IntermediateFormat {
UASTC,
ETC1S,
};
class Builder {
public:
/**
* Constructs a Ktx2 builder with a fixed number of miplevels and layers.
*
* The number of mips and layers is required up front to allow pre-allocation of the
* appropriate BasisU input vectors.
*
* @param mipCount number of mipmap levels, including the base; must be at least 1.
* @param layerCount either 1 or the number of layers in an array texture.
*
* For cubemaps and cubemap arrays, multiply the layer count by 6 and pack the faces in
* standard GL order.
*/
Builder(size_t mipCount, size_t layerCount) noexcept;
~Builder() noexcept;
Builder(Builder&& that) noexcept;
Builder& operator=(Builder&& that) noexcept;
/**
* Enables the linear flag. (default value: FALSE)
*
* This does two things:
* (1) Specifies that the image should be encoded without a transfer function.
* (2) Adds a tag to the ktx file that tells the loader that no transfer function was used.
*
* Note that the tag does not actually affect the compression process, it's basically just a
* hint to the reader. At the time of this writing, BasisU does not make a distinction
* between sRGB targets and linear targets.
*/
Builder& linear(bool enabled) noexcept;
/**
* Enables cubemap or cubemap array mode. (default value: FALSE)
*
* When this is enabled the number of layers should be divisible by 6.
*/
Builder& cubemap(bool enabled) noexcept;
/**
* Chooses the intermediate format as described in the BasisU docs. (default value: UASTC)
*
* For highest quality, use UASTC.
*/
Builder& intermediateFormat(IntermediateFormat format) noexcept;
/**
* Specifies that only the first component of the incoming LinearImage should be honored.
*
* default value: FALSE
*/
Builder& grayscale(bool enabled) noexcept;
/**
* Specifies that the incoming image should be transfored from [-1, +1] to [0, 1] before it
* passed to the Basis encoder.
*
* default value: FALSE
*/
Builder& normals(bool enabled) noexcept;
/**
* Initializes the basis encoder with the given number of jobs.
*
* default value: 4
*/
Builder& jobs(size_t count) noexcept;
/**
* Supresses status messages.
*
* default value: FALSE
*/
Builder& quiet(bool enabled) noexcept;
/**
* Submits image data in linear floating-point format.
*
* This must be called for every miplevel.
*/
Builder& miplevel(size_t mipIndex, size_t layerIndex, const LinearImage& image) noexcept;
/**
* Creates a BasisU encoder and returns null if an error occurred.
*/
BasisEncoder* build();
private:
BasisEncoderBuilderImpl* mImpl;
Builder(const Builder&) = delete;
Builder& operator=(const Builder&) = delete;
};
~BasisEncoder() noexcept;
BasisEncoder(BasisEncoder&& that) noexcept;
BasisEncoder& operator=(BasisEncoder&& that) noexcept;
/**
* Triggers compression of all miplevels and waits until all jobs are done.
*
* The resulting KTX2 contents can be retrieved using the getters below.
*
* @returns false if an error occurred.
*/
bool encode();
/**
* Gets the number of bytes in the generated KTX2 file.
*
* This can only be called if encode() is successfully called first.
*/
size_t getKtx2ByteCount() const noexcept;
/**
* Gets the content of the generated KTX2 file.
*
* This memory is owned by BasisEncoder and is freed when the encoder is freed.
* This can only be called if encode() is successfully called first.
*/
uint8_t const* getKtx2Data() const noexcept;
private:
BasisEncoder(BasisEncoderImpl*) noexcept;
BasisEncoder(const BasisEncoder&) = delete;
BasisEncoder& operator=(const BasisEncoder&) = delete;
BasisEncoderImpl* mImpl;
friend struct BasisEncoderBuilderImpl;
};
} // namespace image
#endif // IMAGE_BASISENCODER_H_

View File

@@ -0,0 +1,47 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef IMAGE_HDRDECODER_H_
#define IMAGE_HDRDECODER_H_
#include <imageio/ImageDecoder.h>
namespace image {
class HDRDecoder : public ImageDecoder::Decoder {
public:
static HDRDecoder* create(std::istream& stream);
static bool checkSignature(char const* buf);
HDRDecoder(const HDRDecoder&) = delete;
HDRDecoder& operator=(const HDRDecoder&) = delete;
private:
explicit HDRDecoder(std::istream& stream);
~HDRDecoder() override;
// ImageDecoder::Decoder interface
LinearImage decode() override;
static const char sigRadiance[];
static const char sigRGBE[];
std::istream& mStream;
std::streampos mStreamStartPos;
};
} // namespace image
#endif /* IMAGE_IMAGEDECODER_H_ */

View File

@@ -0,0 +1,69 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef IMAGE_IMAGEDECODER_H_
#define IMAGE_IMAGEDECODER_H_
#include <iosfwd>
#include <string>
#include <image/LinearImage.h>
#include <utils/compiler.h>
namespace image {
class UTILS_PUBLIC ImageDecoder {
public:
enum class ColorSpace {
LINEAR,
SRGB
};
// Returns linear floating-point data, or a non-valid image if an error occured.
static LinearImage decode(std::istream& stream, const std::string& sourceName,
ColorSpace sourceSpace = ColorSpace::SRGB);
class Decoder {
public:
virtual LinearImage decode() = 0;
virtual ~Decoder() = default;
ColorSpace getColorSpace() const noexcept {
return mColorSpace;
}
void setColorSpace(ColorSpace colorSpace) noexcept {
mColorSpace = colorSpace;
}
private:
ColorSpace mColorSpace = ColorSpace::SRGB;
};
private:
enum class Format {
NONE,
PNG,
HDR,
PSD,
EXR
};
};
} // namespace image
#endif /* IMAGE_IMAGEDECODER_H_ */

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <image/LinearImage.h>
#include <utils/Path.h>
namespace image {
enum class ComparisonMode {
SKIP,
COMPARE,
UPDATE,
};
// Saves an image to disk or does a load-and-compare, depending on comparison mode.
// This makes it easy for unit tests to have compare / update commands.
// The passed-in image is the "result image" and the expected image is the "golden image".
void updateOrCompare(LinearImage result, const utils::Path& golden, ComparisonMode, float epsilon);
} // namespace image

View File

@@ -0,0 +1,64 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef IMAGE_IMAGEENCODER_H_
#define IMAGE_IMAGEENCODER_H_
#include <iosfwd>
#include <string>
#include <image/LinearImage.h>
#include <utils/compiler.h>
namespace image {
class UTILS_PUBLIC ImageEncoder {
public:
enum class Format {
PNG, // 8-bit sRGB, 1 or 3 channels
PNG_LINEAR, // 8-bit linear RGB, 1 or 3 channels
HDR, // 8-bit linear RGBE, 3 channels only
RGBM, // 8-bit RGBM, as PNG, 3 channels only
PSD, // 16-bit sRGB or 32-bit linear RGB, 3 channels only
// Default: 16 bit
EXR, // 16-bit linear RGB (half-float), 3 channels only
// Default: PIZ compression
DDS, // 8-bit sRGB, 1, 2 or 3 channels;
// 16-bit or 32-bit linear RGB, 1, 2 or 3 channels
// Default: 16 bit
DDS_LINEAR, // 8-bit, 16-bit or 32-bit linear RGB, 1, 2 or 3 channels
// Default: 16 bit
RGB_10_11_11_REV, // RGBA PNG file, but containing 11_11_10 data
};
// Consumes linear floating-point data, returns false if unable to encode.
static bool encode(std::ostream& stream, Format format, const LinearImage& image,
const std::string& compression, const std::string& destName);
static Format chooseFormat(const std::string& name, bool forceLinear = false);
static std::string chooseExtension(Format format);
class Encoder {
public:
virtual bool encode(const LinearImage& image) = 0;
virtual ~Encoder() = default;
};
};
} // namespace image
#endif /* IMAGE_IMAGEENCODER_H_ */