Finish block/texture bindings

This commit is contained in:
Andrew Cassidy 2021-04-02 19:24:54 -07:00
parent 6831c3f6c9
commit d25d8c3c56
6 changed files with 80 additions and 13 deletions

View File

@ -32,9 +32,9 @@ class BC1Decoder final : public BlockDecoder<BlockTexture<BC1Block>> {
public:
using InterpolatorPtr = std::shared_ptr<Interpolator>;
BC1Decoder(bool write_alpha, InterpolatorPtr interpolator) : write_alpha(write_alpha), _interpolator(interpolator) {}
BC1Decoder(bool vwrite_alpha, InterpolatorPtr interpolator) : write_alpha(vwrite_alpha), _interpolator(interpolator) {}
BC1Decoder(bool write_alpha = false) : BC1Decoder(write_alpha, std::make_shared<Interpolator>()) {}
BC1Decoder(bool vwrite_alpha = false) : BC1Decoder(vwrite_alpha, std::make_shared<Interpolator>()) {}
BC1Decoder(InterpolatorPtr interpolator) : BC1Decoder(false, interpolator) {}

View File

@ -19,6 +19,8 @@
#pragma once
#include <utility>
#include "../bc1/BC1Block.h"
#include "../bc4/BC4Block.h"
@ -29,6 +31,11 @@ class alignas(8) BC3Block {
static constexpr int Width = 4;
static constexpr int Height = 4;
using BlockPair = std::pair<BC4Block, BC1Block>;
BC4Block alpha_block;
BC1Block color_block;
constexpr BC3Block() {
static_assert(sizeof(BC3Block) == 16);
static_assert(sizeof(std::array<BC3Block, 10>) == 16 * 10);
@ -42,7 +49,11 @@ class alignas(8) BC3Block {
color_block = color;
}
BC4Block alpha_block;
BC1Block color_block;
BlockPair GetBlocks() const { return BlockPair(alpha_block, color_block); }
void SetBlocks(const BlockPair &blocks) {
alpha_block = blocks.first;
color_block = blocks.second;
}
};
} // namespace quicktex::s3tc

View File

@ -49,12 +49,26 @@ void InitBC3(py::module_ &s3tc) {
// region BC3Block
auto bc3_block = BindBlock<BC3Block>(bc3, "BC3Block");
bc3_block.doc() = "A single BC3 block.";
bc3_block.def(py::init<>());
bc3_block.def(py::init<BC4Block, BC1Block>(), "alpha_block"_a, "color_block"_a);
bc3_block.def(py::init<BC4Block, BC1Block>(), "alpha_block"_a, "color_block"_a, R"doc(
__init__(self, alpha_block: BC4Block, color_block: BC1Block) -> None
bc3_block.def_readwrite("alpha_block", &BC3Block::alpha_block);
bc3_block.def_readwrite("color_block", &BC3Block::color_block);
Create a new BC3Block out of a BC4 block and a BC1 block.
:param BC4Block alpha_block: The BC4 block used for alpha data.
:param BC1Block color_block: The BC1 block used for RGB data.
)doc");
bc3_block.def_readwrite("alpha_block", &BC3Block::alpha_block, "The BC4 block used for alpha data.");
bc3_block.def_readwrite("color_block", &BC3Block::color_block, "The BC1 block used for rgb data.");
bc3_block.def_property("blocks", &BC3Block::GetBlocks, &BC3Block::SetBlocks, "The BC4 and BC1 blocks that make up this block as a 2-tuple.");
// endregion
// region BC3Texture
auto bc3_texture = BindBlockTexture<BC3Block>(bc3, "BC3Texture");
bc3_texture.doc() = "A texture comprised of BC3 blocks.";
// endregion
// region BC3Encoder
@ -102,5 +116,5 @@ void InitBC3(py::module_ &s3tc) {
bc3_decoder.def_property_readonly("bc4_decoder", &BC3Decoder::GetBC4Decoder,
"Internal :py:class:`~quicktex.s3tc.bc4.BC4Decoder` used for alpha data. Readonly.");
// endregion
};
}
} // namespace quicktex::bindings

View File

@ -68,7 +68,10 @@ void InitBC4(py::module_ &s3tc) {
selectors = block.selectors
selectors[0,0] = 0
block.selectors = selectors
)doc");
)doc");
bc4_block.def_property_readonly("values", &BC4Block::GetValues, R"doc(
The interpolated values used to decode the block, coresponding with the indices in :py:attr:`selectors`.
)doc");
bc4_block.def_property_readonly("is_6value", &BC4Block::Is6Value, R"doc(
"True if the block uses 6-value interpolation, i.e. endpoint0 <= endpoint1. Readonly.
)doc");

View File

@ -19,6 +19,8 @@
#pragma once
#include <utility>
#include "../bc4/BC4Block.h"
namespace quicktex::s3tc {
@ -28,6 +30,11 @@ class alignas(8) BC5Block {
static constexpr int Width = 4;
static constexpr int Height = 4;
using BlockPair = std::pair<BC4Block, BC4Block>;
BC4Block chan0_block;
BC4Block chan1_block;
constexpr BC5Block() {
static_assert(sizeof(BC5Block) == 16);
static_assert(sizeof(std::array<BC5Block, 10>) == 16 * 10);
@ -40,7 +47,11 @@ class alignas(8) BC5Block {
chan1_block = chan1;
}
BC4Block chan0_block;
BC4Block chan1_block;
BlockPair GetBlocks() const { return BlockPair(chan0_block, chan1_block); }
void SetBlocks(const BlockPair &pair) {
chan0_block = pair.first;
chan1_block = pair.second;
}
};
} // namespace quicktex::s3tc

View File

@ -17,6 +17,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../../_bindings.h"
#include <pybind11/pybind11.h>
#include <array>
@ -38,7 +40,31 @@ void InitBC5(py::module_ &s3tc) {
py::options options;
options.disable_function_signatures();
// BC5Encoder
// region BC5Block
auto bc5_block = BindBlock<BC5Block>(bc5, "BC5Block");
bc5_block.doc() = "A single BC5 block.";
bc5_block.def(py::init<>());
bc5_block.def(py::init<BC4Block, BC4Block>(), "chan0_block"_a, "chan1_block"_a, R"doc(
__init__(self, chan0_block: BC4Block, chan1_block: BC4Block) -> None
Create a new BC5Block out of two BC4 blocks.
:param BC4Block chan0_block: The BC4 block used for the first channel.
:param BC4Block chan1_block: The BC1 block used for the second channel.
)doc");
bc5_block.def_readwrite("chan0_block", &BC5Block::chan0_block, "The BC4 block used for the first channel.");
bc5_block.def_readwrite("chan1_block", &BC5Block::chan1_block, "The BC4 block used for the second channel.");
bc5_block.def_property("blocks", &BC5Block::GetBlocks, &BC5Block::SetBlocks, "The BC4 and BC1 blocks that make up this block as a 2-tuple.");
// endregion
// region BC5Texture
auto bc5_texture = BindBlockTexture<BC5Block>(bc5, "BC5Texture");
bc5_texture.doc() = "A texture comprised of BC5 blocks.";
// endregion
// region BC5Encoder
py::class_<BC5Encoder> bc5_encoder(bc5, "BC5Encoder", R"doc(
Base: :py:class:`~quicktex.BlockEncoder`
@ -57,8 +83,9 @@ void InitBC5(py::module_ &s3tc) {
bc5_encoder.def_property_readonly("channels", &BC5Encoder::GetChannels, "A 2-tuple of channels that will be read from. 0 to 3 inclusive. Readonly.");
bc5_encoder.def_property_readonly("bc4_encoders", &BC5Encoder::GetBC4Encoders,
"2-tuple of internal :py:class:`~quicktex.s3tc.bc4.BC4Encoder` s used for each channel. Readonly.");
// endregion
// BC5Decoder
// region BC5Decoder
py::class_<BC5Decoder> bc5_decoder(bc5, "BC5Decoder", R"doc(
Base: :py:class:`~quicktex.BlockDecoder`
@ -77,5 +104,6 @@ void InitBC5(py::module_ &s3tc) {
bc5_decoder.def_property_readonly("channels", &BC5Decoder::GetChannels, "A 2-tuple of channels that will be written to. 0 to 3 inclusive. Readonly.");
bc5_decoder.def_property_readonly("bc4_decoders", &BC5Decoder::GetBC4Decoders,
"2-tuple of internal :py:class:`~quicktex.s3tc.bc4.BC4Decoder` s used for each channel. Readonly.");
// endregion
}
} // namespace quicktex::bindings