mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-12 04:59:05 +08:00
Revert "Support simultaneous gltf load/saves"
This reverts commit d2a2703ec59fcd86f546c350f68502199eded8e6.
This commit is contained in:
parent
d2a2703ec5
commit
906f98fa74
@ -736,11 +736,11 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f
|
|||||||
char header[] = "#?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n";
|
char header[] = "#?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n";
|
||||||
s->func(s->context, header, sizeof(header)-1);
|
s->func(s->context, header, sizeof(header)-1);
|
||||||
|
|
||||||
//#ifdef STBI_MSC_SECURE_CRT
|
#ifdef STBI_MSC_SECURE_CRT
|
||||||
len = sprintf_s(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
|
len = sprintf_s(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
|
||||||
//#else
|
#else
|
||||||
//len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
|
len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
|
||||||
//#endif
|
#endif
|
||||||
s->func(s->context, buffer, len);
|
s->func(s->context, buffer, len);
|
||||||
|
|
||||||
for(i=0; i < y; i++)
|
for(i=0; i < y; i++)
|
||||||
|
61
tiny_gltf.h
61
tiny_gltf.h
@ -1650,52 +1650,33 @@ class TinyGLTF {
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
#ifdef TINYGLTF_USE_RAPIDJSON
|
#ifdef TINYGLTF_USE_RAPIDJSON
|
||||||
|
|
||||||
#ifdef TINYGLTF_USE_RAPIDJSON_CRTALLOCATOR
|
|
||||||
// This uses the RapidJSON CRTAllocator. It is thread safe and multiple
|
|
||||||
// documents may be active at once.
|
|
||||||
using json = rapidjson::GenericValue<rapidjson::UTF8<>, rapidjson::CrtAllocator>;
|
|
||||||
using json_const_iterator = json::ConstMemberIterator;
|
|
||||||
using json_const_array_iterator = json const *;
|
|
||||||
using JsonDocument =
|
|
||||||
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator>;
|
|
||||||
rapidjson::CrtAllocator s_CrtAllocator; //stateless and thread safe
|
|
||||||
rapidjson::CrtAllocator &GetAllocator() { return s_CrtAllocator; }
|
|
||||||
#else
|
|
||||||
// This uses the default RapidJSON MemoryPoolAllocator. It is very fast, but
|
|
||||||
// not thread safe. Only a single JsonDocument may be active at any one time,
|
|
||||||
// meaning only a single gltf load/save can be active any one time.
|
|
||||||
using json = rapidjson::Value;
|
using json = rapidjson::Value;
|
||||||
using json_const_iterator = json::ConstMemberIterator;
|
using json_const_iterator = json::ConstMemberIterator;
|
||||||
using json_const_array_iterator = json const *;
|
using json_const_array_iterator = json const*;
|
||||||
rapidjson::Document *s_pActiveDocument = nullptr;
|
|
||||||
rapidjson::Document::AllocatorType &GetAllocator() {
|
rapidjson::Document* s_pActiveDocument = nullptr;
|
||||||
assert(s_pActiveDocument); //Root json node must be JsonDocument type
|
|
||||||
return s_pActiveDocument->GetAllocator();
|
struct JsonDocument : public rapidjson::Document
|
||||||
}
|
{
|
||||||
struct JsonDocument : public rapidjson::Document {
|
|
||||||
JsonDocument() {
|
JsonDocument() {
|
||||||
assert(s_pActiveDocument ==
|
assert(s_pActiveDocument == nullptr); //Code assumes only one document is active at a time
|
||||||
nullptr); // When using default allocator, only one document can be active at a time, if you need
|
|
||||||
// multiple active at once, define TINYGLTF_USE_RAPIDJSON_CRTALLOCATOR
|
|
||||||
s_pActiveDocument = this;
|
s_pActiveDocument = this;
|
||||||
}
|
}
|
||||||
JsonDocument(const JsonDocument &) = delete;
|
JsonDocument(const JsonDocument&) = delete;
|
||||||
JsonDocument(JsonDocument &&rhs) noexcept
|
JsonDocument(JsonDocument&& rhs) noexcept : rapidjson::Document(std::move(rhs))
|
||||||
: rapidjson::Document(std::move(rhs)) {
|
{
|
||||||
s_pActiveDocument = this;
|
s_pActiveDocument = this;
|
||||||
rhs.isNil = true;
|
rhs.isNil = true;
|
||||||
}
|
}
|
||||||
~JsonDocument() {
|
~JsonDocument() {
|
||||||
if (!isNil) {
|
if (!isNil)
|
||||||
|
{
|
||||||
s_pActiveDocument = nullptr;
|
s_pActiveDocument = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isNil = false;
|
bool isNil = false;
|
||||||
};
|
};
|
||||||
#endif // TINYGLTF_USE_RAPIDJSON_CRTALLOCATOR
|
|
||||||
#else
|
#else
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
using json_const_iterator = json::const_iterator;
|
using json_const_iterator = json::const_iterator;
|
||||||
@ -5693,7 +5674,7 @@ namespace
|
|||||||
json JsonFromString(const char* s)
|
json JsonFromString(const char* s)
|
||||||
{
|
{
|
||||||
#ifdef TINYGLTF_USE_RAPIDJSON
|
#ifdef TINYGLTF_USE_RAPIDJSON
|
||||||
return json(s, GetAllocator());
|
return json(s, s_pActiveDocument->GetAllocator());
|
||||||
#else
|
#else
|
||||||
return json(s);
|
return json(s);
|
||||||
#endif
|
#endif
|
||||||
@ -5724,7 +5705,7 @@ namespace
|
|||||||
void JsonAssign(json& dest, const json& src)
|
void JsonAssign(json& dest, const json& src)
|
||||||
{
|
{
|
||||||
#ifdef TINYGLTF_USE_RAPIDJSON
|
#ifdef TINYGLTF_USE_RAPIDJSON
|
||||||
dest.CopyFrom(src, GetAllocator());
|
dest.CopyFrom(src, s_pActiveDocument->GetAllocator());
|
||||||
#else
|
#else
|
||||||
dest = src;
|
dest = src;
|
||||||
#endif
|
#endif
|
||||||
@ -5737,7 +5718,7 @@ namespace
|
|||||||
{
|
{
|
||||||
o.SetObject();
|
o.SetObject();
|
||||||
}
|
}
|
||||||
o.AddMember(json(key, GetAllocator()), std::move(value), GetAllocator());
|
o.AddMember(json(key, s_pActiveDocument->GetAllocator()), std::move(value), s_pActiveDocument->GetAllocator());
|
||||||
#else
|
#else
|
||||||
o[key] = std::move(value);
|
o[key] = std::move(value);
|
||||||
#endif
|
#endif
|
||||||
@ -5746,7 +5727,7 @@ namespace
|
|||||||
void JsonPushBack(json& o, json&& value)
|
void JsonPushBack(json& o, json&& value)
|
||||||
{
|
{
|
||||||
#ifdef TINYGLTF_USE_RAPIDJSON
|
#ifdef TINYGLTF_USE_RAPIDJSON
|
||||||
o.PushBack(std::move(value), GetAllocator());
|
o.PushBack(std::move(value), s_pActiveDocument->GetAllocator());
|
||||||
#else
|
#else
|
||||||
o.push_back(std::move(value));
|
o.push_back(std::move(value));
|
||||||
#endif
|
#endif
|
||||||
@ -5774,7 +5755,7 @@ namespace
|
|||||||
{
|
{
|
||||||
#ifdef TINYGLTF_USE_RAPIDJSON
|
#ifdef TINYGLTF_USE_RAPIDJSON
|
||||||
o.SetArray();
|
o.SetArray();
|
||||||
o.Reserve(static_cast<rapidjson::SizeType>(s), GetAllocator());
|
o.Reserve(static_cast<rapidjson::SizeType>(s), s_pActiveDocument->GetAllocator());
|
||||||
#endif
|
#endif
|
||||||
(void)(o);
|
(void)(o);
|
||||||
(void)(s);
|
(void)(s);
|
||||||
@ -5839,16 +5820,16 @@ static bool ValueToJson(const Value &value, json *ret) {
|
|||||||
obj.SetBool(value.Get<bool>());
|
obj.SetBool(value.Get<bool>());
|
||||||
break;
|
break;
|
||||||
case STRING_TYPE:
|
case STRING_TYPE:
|
||||||
obj.SetString(value.Get<std::string>().c_str(), GetAllocator());
|
obj.SetString(value.Get<std::string>().c_str(), s_pActiveDocument->GetAllocator());
|
||||||
break;
|
break;
|
||||||
case ARRAY_TYPE: {
|
case ARRAY_TYPE: {
|
||||||
obj.SetArray();
|
obj.SetArray();
|
||||||
obj.Reserve(static_cast<rapidjson::SizeType>(value.ArrayLen()), GetAllocator());
|
obj.Reserve(static_cast<rapidjson::SizeType>(value.ArrayLen()), s_pActiveDocument->GetAllocator());
|
||||||
for (unsigned int i = 0; i < value.ArrayLen(); ++i) {
|
for (unsigned int i = 0; i < value.ArrayLen(); ++i) {
|
||||||
Value elementValue = value.Get(int(i));
|
Value elementValue = value.Get(int(i));
|
||||||
json elementJson;
|
json elementJson;
|
||||||
if (ValueToJson(value.Get(int(i)), &elementJson))
|
if (ValueToJson(value.Get(int(i)), &elementJson))
|
||||||
obj.PushBack(std::move(elementJson), GetAllocator());
|
obj.PushBack(std::move(elementJson), s_pActiveDocument->GetAllocator());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -5863,7 +5844,7 @@ static bool ValueToJson(const Value &value, json *ret) {
|
|||||||
for (auto &it : objMap) {
|
for (auto &it : objMap) {
|
||||||
json elementJson;
|
json elementJson;
|
||||||
if (ValueToJson(it.second, &elementJson)) {
|
if (ValueToJson(it.second, &elementJson)) {
|
||||||
obj.AddMember(json(it.first.c_str(), GetAllocator()), std::move(elementJson), GetAllocator());
|
obj.AddMember(json(it.first.c_str(), s_pActiveDocument->GetAllocator()), std::move(elementJson), s_pActiveDocument->GetAllocator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user