Please consider making ktxStream public#438
Conversation
ktxStream publicktxStream public
|
Happy to hear you are creating a Rust wrapper. Please add a test (external to the library) that uses the stream functions. This is to ensure that linking will be successful on Windows, i.e. the all the necessary functions are properly exported. Adding the Rust wrapper to the |
include/ktx.h
Outdated
| { | ||
| void* data; | ||
| ktx_size_t size; | ||
| } custom; |
There was a problem hiding this comment.
Rename this custom_ptr to indicate it is for storing a pointer and not for data. Also change data to address.
Is this sufficient for the other uses you mentioned, e.g. a c++ stream wrapper? If someone needs to add a new field to this union for their use case, then their applications will require a new version of libktx. I'm not sure there is any solution that would let people add a new stream type that does not fit into this declaration but will let apps using it run on an older version of the library.
There was a problem hiding this comment.
Done! I also added another allocatorAddress pointer to it. Hopefully two pointers + a size_t are enough for all usecases.
I suppose that, in the worst case, one would need to allocate on the heap? Without touching the struct definition.
Adding the wrapper to I could write some C++ integration tests instead, maybe based on |
|
Hi, I added some |
Sounds great. Reviewing the tests you've added will take more time that I have at this moment. Hopefully later today. Sorry about the workflow approval thing. This is new and seems related to GitHub Actions which we've just added for the Android build. I thought the approval I gave yesterday would stick for further changes on this PR. Apparently not. |
No worries, I'm fixing unforeseen cross-platform bugs in the meantime 👍 |
And fix the streambuf wrapper's behaviour for this case.
49722a5 to
0cc6a15
Compare
See KhronosGroup/KTX-Software#438 for more details; will revert if/when it gets merged. Also removed the wrapper.h function and regenerated the FFI.
ktxStream publicktxStream public
|
Please fix the travis build. When the Rust wrapper is released, please add a pointer to it to the wiki. |
|
Hi, I am not exactly sure of why it is failing? The logs say the repo is not REUSE 3.0 compliant, but all files have a license and the same build does pass on Mac Os. EDIT: EDIT²: deleted LICENSES/GPL-2.0-or-later.txt and renamed a entry in .reuse/dep5, lint works now |
|
I needed to fix the |
And fix the streambuf wrapper's behaviour for this case.
|
Thank you for bringing the need for this to my attention and for your incredibly thorough PR. It is impressive work. |
I just wrapped it with some Rust glue, but thank you :) |
... to enable wrappers for languages with their own i/o models. * Move ktxStream definitions to ktx.h * Expose or implement ktxStream functions * Add eStreamTypeCustom * Add basic ktxStream <-> C++ integration tests * Add a test for ktxTexture1_WriteKTX2ToStream * Add a KTX2->KTX2 writing test
... to enable wrappers for languages with their own i/o models. * Move ktxStream definitions to ktx.h * Expose or implement ktxStream functions * Add eStreamTypeCustom * Add basic ktxStream <-> C++ integration tests * Add a test for ktxTexture1_WriteKTX2ToStream * Add a KTX2->KTX2 writing test
... to enable wrappers for languages with their own i/o models. * Move ktxStream definitions to ktx.h * Expose or implement ktxStream functions * Add eStreamTypeCustom * Add basic ktxStream <-> C++ integration tests * Add a test for ktxTexture1_WriteKTX2ToStream * Add a KTX2->KTX2 writing test
... to enable wrappers for languages with their own i/o models. * Move ktxStream definitions to ktx.h * Expose or implement ktxStream functions * Add eStreamTypeCustom * Add basic ktxStream <-> C++ integration tests * Add a test for ktxTexture1_WriteKTX2ToStream * Add a KTX2->KTX2 writing test
... to enable wrappers for languages with their own i/o models. * Move ktxStream definitions to ktx.h * Expose or implement ktxStream functions * Add eStreamTypeCustom * Add basic ktxStream <-> C++ integration tests * Add a test for ktxTexture1_WriteKTX2ToStream * Add a KTX2->KTX2 writing test
... to enable wrappers for languages with their own i/o models. * Move ktxStream definitions to ktx.h * Expose or implement ktxStream functions * Add eStreamTypeCustom * Add basic ktxStream <-> C++ integration tests * Add a test for ktxTexture1_WriteKTX2ToStream * Add a KTX2->KTX2 writing test
Hi,
This pull request moves
lib/stream.h's contents toktx.h, and it makes all the previously-private types and functions therein public.It also adds a
customstream type, with a user pointer and asize_tin itsdata.Motivation
I am currently creating a Rust wrapper for this library, and I wanted to read/write KTXs from Rust streams - anything dyn (Read + Write + Seek), like std::fs::File. So I had to:
ktxStreampublic.ktxStream(read, write, getpos, setpos...).Custom
ktxStreams would be useful in many other scenarios, though. Off the top of my head:std::iostreamsFILE *streamsNotes
customstruct contains both avoid *andsize_t. This would allow for direct storage of Rust's "fat pointers" (a pointer to a vtable + a size).My current workaround is to add another layer of indirection (
ktxMem *reinterpret-casted as a pointer to a Rust struct -> heap-allocated fat pointer -> heap-allocated trait object). Having thesize_tin thedataunion would remove the need for heap-allocating the pointer.Thanks!