Skip to content

Commit

Permalink
Ability to flush a GLB manifest to a stream (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yejneshwar authored Sep 3, 2024
1 parent 142f92c commit d01d109
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions GLTFSDK/Inc/GLTFSDK/GLBResourceWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ namespace Microsoft
GLBResourceWriter(std::unique_ptr<IStreamWriterCache> streamCache);
GLBResourceWriter(std::unique_ptr<IStreamWriterCache> streamCache, std::unique_ptr<std::iostream> tempBufferStream);

// Write to a stream instead of a file (can be useful for draco compression)
template <typename T>
void FlushStream(const std::string& manifest, T* stream);
void Flush(const std::string& manifest, const std::string& uri);
std::string GenerateBufferUri(const std::string& bufferId) const override;
std::ostream* GetBufferStream(const std::string& bufferId) override;
Expand Down
1 change: 1 addition & 0 deletions GLTFSDK/Inc/GLTFSDK/GLTFResourceWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <GLTFSDK/ResourceWriter.h>
#include <limits>

#include <memory>

Expand Down
1 change: 1 addition & 0 deletions GLTFSDK/Inc/GLTFSDK/PBRUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <GLTFSDK/Color.h>
#include <GLTFSDK/ExtensionsKHR.h>
#include <limits>

namespace Microsoft
{
Expand Down
1 change: 1 addition & 0 deletions GLTFSDK/Inc/GLTFSDK/ResourceReaderUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>
#include <vector>
#include <cmath>
#include <limits>

namespace Microsoft
{
Expand Down
14 changes: 12 additions & 2 deletions GLTFSDK/Source/GLBResourceWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <GLTFSDK/GLBResourceWriter.h>

#include <sstream>
#include <fstream>

using namespace Microsoft::glTF;

Expand Down Expand Up @@ -42,7 +43,8 @@ GLBResourceWriter::GLBResourceWriter(std::unique_ptr<IStreamWriterCache> streamC
{
}

void GLBResourceWriter::Flush(const std::string& manifest, const std::string& uri)
template <typename T>
void GLBResourceWriter::FlushStream(const std::string& manifest, T* stream)
{
uint32_t jsonChunkLength = static_cast<uint32_t>(manifest.length());
const uint32_t jsonPaddingLength = ::CalculatePadding(jsonChunkLength);
Expand All @@ -59,7 +61,6 @@ void GLBResourceWriter::Flush(const std::string& manifest, const std::string& ur
+ sizeof(binaryChunkLength) + GLB_CHUNK_TYPE_SIZE // 8 bytes (BIN header)
+ binaryChunkLength;

auto stream = m_streamWriterCache->Get(uri);

// Write GLB header (12 bytes)
StreamUtils::WriteBinary(*stream, GLB_HEADER_MAGIC_STRING, GLB_HEADER_MAGIC_STRING_SIZE);
Expand Down Expand Up @@ -96,6 +97,15 @@ void GLBResourceWriter::Flush(const std::string& manifest, const std::string& ur
}
}

template void GLBResourceWriter::FlushStream<std::fstream>(const std::string& manifest, std::fstream* stream);
template void GLBResourceWriter::FlushStream<std::stringstream>(const std::string& manifest, std::stringstream* stream);

void GLBResourceWriter::Flush(const std::string& manifest, const std::string& uri)
{
auto stream = m_streamWriterCache->Get(uri);
this->FlushStream<std::ostream>(manifest, stream.get());
}

std::string GLBResourceWriter::GenerateBufferUri(const std::string& bufferId) const
{
std::string bufferUri;
Expand Down
2 changes: 2 additions & 0 deletions GLTFSDK/Source/Validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <sstream>

#include <limits>

using namespace Microsoft::glTF;

namespace
Expand Down
1 change: 1 addition & 0 deletions GLTFSDK/Source/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <set>
#include <regex>
#include <sstream>
#include <limits>

using namespace Microsoft::glTF;

Expand Down

0 comments on commit d01d109

Please sign in to comment.