From d25d8c3c565eba192958e2364ebe0b4cc5de2a44 Mon Sep 17 00:00:00 2001 From: drewcassidy Date: Fri, 2 Apr 2021 19:24:54 -0700 Subject: [PATCH] Finish block/texture bindings --- quicktex/s3tc/bc1/BC1Decoder.h | 4 ++-- quicktex/s3tc/bc3/BC3Block.h | 15 +++++++++++++-- quicktex/s3tc/bc3/_bindings.cpp | 22 ++++++++++++++++++---- quicktex/s3tc/bc4/_bindings.cpp | 5 ++++- quicktex/s3tc/bc5/BC5Block.h | 15 +++++++++++++-- quicktex/s3tc/bc5/_bindings.cpp | 32 ++++++++++++++++++++++++++++++-- 6 files changed, 80 insertions(+), 13 deletions(-) diff --git a/quicktex/s3tc/bc1/BC1Decoder.h b/quicktex/s3tc/bc1/BC1Decoder.h index 7e72e1d..95195c4 100644 --- a/quicktex/s3tc/bc1/BC1Decoder.h +++ b/quicktex/s3tc/bc1/BC1Decoder.h @@ -32,9 +32,9 @@ class BC1Decoder final : public BlockDecoder> { public: using InterpolatorPtr = std::shared_ptr; - 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()) {} + BC1Decoder(bool vwrite_alpha = false) : BC1Decoder(vwrite_alpha, std::make_shared()) {} BC1Decoder(InterpolatorPtr interpolator) : BC1Decoder(false, interpolator) {} diff --git a/quicktex/s3tc/bc3/BC3Block.h b/quicktex/s3tc/bc3/BC3Block.h index 0dc8d98..b7b1a07 100644 --- a/quicktex/s3tc/bc3/BC3Block.h +++ b/quicktex/s3tc/bc3/BC3Block.h @@ -19,6 +19,8 @@ #pragma once +#include + #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 alpha_block; + BC1Block color_block; + constexpr BC3Block() { static_assert(sizeof(BC3Block) == 16); static_assert(sizeof(std::array) == 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 \ No newline at end of file diff --git a/quicktex/s3tc/bc3/_bindings.cpp b/quicktex/s3tc/bc3/_bindings.cpp index dff8a4d..a781e48 100644 --- a/quicktex/s3tc/bc3/_bindings.cpp +++ b/quicktex/s3tc/bc3/_bindings.cpp @@ -49,12 +49,26 @@ void InitBC3(py::module_ &s3tc) { // region BC3Block auto bc3_block = BindBlock(bc3, "BC3Block"); + bc3_block.doc() = "A single BC3 block."; + bc3_block.def(py::init<>()); - bc3_block.def(py::init(), "alpha_block"_a, "color_block"_a); + bc3_block.def(py::init(), "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(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 \ No newline at end of file diff --git a/quicktex/s3tc/bc4/_bindings.cpp b/quicktex/s3tc/bc4/_bindings.cpp index b9e5c5f..4bf28a7 100644 --- a/quicktex/s3tc/bc4/_bindings.cpp +++ b/quicktex/s3tc/bc4/_bindings.cpp @@ -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"); diff --git a/quicktex/s3tc/bc5/BC5Block.h b/quicktex/s3tc/bc5/BC5Block.h index 6d0105c..6b2b58e 100644 --- a/quicktex/s3tc/bc5/BC5Block.h +++ b/quicktex/s3tc/bc5/BC5Block.h @@ -19,6 +19,8 @@ #pragma once +#include + #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 chan0_block; + BC4Block chan1_block; + constexpr BC5Block() { static_assert(sizeof(BC5Block) == 16); static_assert(sizeof(std::array) == 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 \ No newline at end of file diff --git a/quicktex/s3tc/bc5/_bindings.cpp b/quicktex/s3tc/bc5/_bindings.cpp index 6ac2b90..421425b 100644 --- a/quicktex/s3tc/bc5/_bindings.cpp +++ b/quicktex/s3tc/bc5/_bindings.cpp @@ -17,6 +17,8 @@ along with this program. If not, see . */ +#include "../../_bindings.h" + #include #include @@ -38,7 +40,31 @@ void InitBC5(py::module_ &s3tc) { py::options options; options.disable_function_signatures(); - // BC5Encoder + // region BC5Block + auto bc5_block = BindBlock(bc5, "BC5Block"); + bc5_block.doc() = "A single BC5 block."; + + bc5_block.def(py::init<>()); + bc5_block.def(py::init(), "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(bc5, "BC5Texture"); + bc5_texture.doc() = "A texture comprised of BC5 blocks."; + // endregion + + // region BC5Encoder py::class_ 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_ 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 \ No newline at end of file