Fixed gcc warnings and errors

pull/699/head
Otger 2015-11-29 20:17:06 +01:00
parent 4f757cdf5a
commit d72443d6b0
5 changed files with 80 additions and 71 deletions

View File

@ -353,6 +353,8 @@ namespace glTF
//! Objects marked as special are not exported (used to emulate the binary body buffer)
virtual bool IsSpecial() const
{ return false; }
virtual ~Object() {}
};
@ -391,8 +393,8 @@ namespace glTF
{
friend struct Accessor;
uint8_t* data;
Accessor& accessor;
uint8_t* data;
size_t elemSize, stride;
Indexer(Accessor& acc);
@ -535,6 +537,8 @@ namespace glTF
std::string mimeType;
int width, height;
private:
uint8_t* mData;
size_t mDataLength;
@ -770,7 +774,10 @@ namespace glTF
void AttachToDocument(Document& doc);
void DetachFromDocument();
void WriteObjects(AssetWriter& writer);
void WriteObjectsImpl(AssetWriter& writer);
void WriteObjects(AssetWriter& writer)
{ WriteObjectsImpl(writer); }
Ref<T> Add(T* obj);

View File

@ -61,7 +61,7 @@ namespace {
template<size_t N> struct ReadHelper<float[N]> { static bool Read(Value& val, float (&out)[N]) {
if (!val.IsArray() || val.Size() != N) return false;
for (int i = 0; i < N; ++i) {
for (size_t i = 0; i < N; ++i) {
if (val[i].IsNumber())
out[i] = static_cast<float>(val[i].GetDouble());
}
@ -446,7 +446,9 @@ T Accessor::Indexer::GetValue(int i)
}
inline Image::Image()
: mData(0)
: width(0)
, height(0)
, mData(0)
, mDataLength(0)
{
@ -459,8 +461,8 @@ inline void Image::Read(Value& obj, Asset& r)
if (r.extensionsUsed.KHR_binary_glTF) {
if (Value* ext = FindObject(*extensions, "KHR_binary_glTF")) {
int width = MemberOrDefault(*ext, "width", 0);
int height = MemberOrDefault(*ext, "height", 0);
width = MemberOrDefault(*ext, "width", 0);
height = MemberOrDefault(*ext, "height", 0);
ReadMember(*ext, "mimeType", mimeType);
@ -607,25 +609,25 @@ namespace {
inline bool GetAttribVector(Mesh::Primitive& p, const char* attr, Mesh::AccessorList*& v, int& pos)
{
if (pos = Compare(attr, "POSITION")) {
if ((pos = Compare(attr, "POSITION"))) {
v = &(p.attributes.position);
}
else if (pos = Compare(attr, "NORMAL")) {
else if ((pos = Compare(attr, "NORMAL"))) {
v = &(p.attributes.normal);
}
else if (pos = Compare(attr, "TEXCOORD")) {
else if ((pos = Compare(attr, "TEXCOORD"))) {
v = &(p.attributes.texcoord);
}
else if (pos = Compare(attr, "COLOR")) {
else if ((pos = Compare(attr, "COLOR"))) {
v = &(p.attributes.color);
}
else if (pos = Compare(attr, "JOINT")) {
else if ((pos = Compare(attr, "JOINT"))) {
v = &(p.attributes.joint);
}
else if (pos = Compare(attr, "JOINTMATRIX")) {
else if ((pos = Compare(attr, "JOINTMATRIX"))) {
v = &(p.attributes.jointmatrix);
}
else if (pos = Compare(attr, "WEIGHT")) {
else if ((pos = Compare(attr, "WEIGHT"))) {
v = &(p.attributes.weight);
}
else return false;
@ -647,7 +649,8 @@ inline void Mesh::Read(Value& obj, Asset& r)
for (Value::MemberIterator it = attrs->MemberBegin(); it != attrs->MemberEnd(); ++it) {
if (!it->value.IsString()) continue;
const char* attr = it->name.GetString();
// Valid attribute semantics include POSITION, NORMAL, TEXCOORD, COLOR, JOINT, JOINTMATRIX, and WEIGHT.Attribute semantics can be of the form[semantic]_[set_index], e.g., TEXCOORD_0, TEXCOORD_1, etc.
// Valid attribute semantics include POSITION, NORMAL, TEXCOORD, COLOR, JOINT, JOINTMATRIX,
// and WEIGHT.Attribute semantics can be of the form[semantic]_[set_index], e.g., TEXCOORD_0, TEXCOORD_1, etc.
int undPos = 0;
Mesh::AccessorList* vec = 0;
@ -920,7 +923,7 @@ inline void Asset::Load(const std::string& pFile, bool isBinary)
if (doc.HasParseError()) {
char buffer[32];
sprintf(buffer, "%u", doc.GetErrorOffset());
sprintf(buffer, "%d", static_cast<int>(doc.GetErrorOffset()));
throw DeadlyImportError(std::string("JSON parse error, offset ") + buffer + ": "
+ GetParseError_En(doc.GetParseError()));
}
@ -1107,12 +1110,12 @@ namespace Util
inline char EncodeCharBase64(uint8_t b)
{
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="[b];
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="[size_t(b)];
}
inline uint8_t DecodeCharBase64(char c)
{
return DATA<true>::tableDecodeBase64[c]; // TODO faster with lookup table or ifs?
return DATA<true>::tableDecodeBase64[size_t(c)]; // TODO faster with lookup table or ifs?
/*if (c >= 'A' && c <= 'Z') return c - 'A';
if (c >= 'a' && c <= 'z') return c - 'a' + 26;
if (c >= '0' && c <= '9') return c - '0' + 52;

View File

@ -190,7 +190,7 @@ namespace glTF {
else {
for (size_t i = 0; i < lst.size(); ++i) {
char buffer[32];
sprintf(buffer, "%s_%d", semantic, i);
sprintf(buffer, "%s_%d", semantic, int(i));
attrs.AddMember(Value(buffer, w.mAl).Move(), Value(lst[i]->id, w.mAl).Move(), w.mAl);
}
}
@ -304,52 +304,10 @@ namespace glTF {
}
template<class T>
void LazyDict<T>::WriteObjects(AssetWriter& w)
{
if (mObjs.empty()) return;
Value* container = &w.mDoc;
if (mExtId) {
Value* exts = FindObject(w.mDoc, "extensions");
if (!exts) {
w.mDoc.AddMember("extensions", Value().SetObject().Move(), w.mDoc.GetAllocator());
exts = FindObject(w.mDoc, "extensions");
}
if (!(container = FindObject(*exts, mExtId))) {
exts->AddMember(StringRef(mExtId), Value().SetObject().Move(), w.mDoc.GetAllocator());
container = FindObject(*exts, mExtId);
}
}
Value* dict;
if (!(dict = FindObject(*container, mDictId))) {
container->AddMember(StringRef(mDictId), Value().SetObject().Move(), w.mDoc.GetAllocator());
dict = FindObject(*container, mDictId);
}
for (size_t i = 0; i < mObjs.size(); ++i) {
if (mObjs[i]->IsSpecial()) continue;
Value obj;
obj.SetObject();
if (!mObjs[i]->name.empty()) {
obj.AddMember("name", StringRef(mObjs[i]->name.c_str()), w.mAl);
}
Write(obj, *mObjs[i], w);
dict->AddMember(StringRef(mObjs[i]->id), obj, w.mAl);
}
}
AssetWriter::AssetWriter(Asset& a)
: mAsset(a)
, mDoc()
: mDoc()
, mAsset(a)
, mAl(mDoc.GetAllocator())
{
mDoc.SetObject();
@ -368,7 +326,6 @@ namespace glTF {
}
}
void AssetWriter::WriteFile(const char* path)
{
bool isBinary = mAsset.extensionsUsed.KHR_binary_glTF;
@ -485,6 +442,48 @@ namespace glTF {
}
template<class T>
void LazyDict<T>::WriteObjectsImpl(AssetWriter& w)
{
if (mObjs.empty()) return;
Value* container = &w.mDoc;
if (mExtId) {
Value* exts = FindObject(w.mDoc, "extensions");
if (!exts) {
w.mDoc.AddMember("extensions", Value().SetObject().Move(), w.mDoc.GetAllocator());
exts = FindObject(w.mDoc, "extensions");
}
if (!(container = FindObject(*exts, mExtId))) {
exts->AddMember(StringRef(mExtId), Value().SetObject().Move(), w.mDoc.GetAllocator());
container = FindObject(*exts, mExtId);
}
}
Value* dict;
if (!(dict = FindObject(*container, mDictId))) {
container->AddMember(StringRef(mDictId), Value().SetObject().Move(), w.mDoc.GetAllocator());
dict = FindObject(*container, mDictId);
}
for (size_t i = 0; i < mObjs.size(); ++i) {
if (mObjs[i]->IsSpecial()) continue;
Value obj;
obj.SetObject();
if (!mObjs[i]->name.empty()) {
obj.AddMember("name", StringRef(mObjs[i]->name.c_str()), w.mAl);
}
Write(obj, *mObjs[i], w);
dict->AddMember(StringRef(mObjs[i]->id), obj, w.mAl);
}
}
}

View File

@ -338,7 +338,7 @@ void glTFExporter::ExportScene()
// root node will be the first one exported (idx 0)
if (mAsset->nodes.Size() > 0) {
scene->nodes.push_back(mAsset->nodes.Get(0u));
scene->nodes.push_back(mAsset->nodes.Get(size_t(0)));
}
// set as the default scene

View File

@ -120,10 +120,10 @@ bool glTFImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool
static void CopyValue(const glTF::vec3& v, aiColor3D& out)
{
out.r = v[0]; out.g = v[1]; out.b = v[2];
}
//static void CopyValue(const glTF::vec3& v, aiColor3D& out)
//{
// out.r = v[0]; out.g = v[1]; out.b = v[2];
//}
static void CopyValue(const glTF::vec4& v, aiColor4D& out)
{
@ -421,14 +421,14 @@ void glTFImporter::ImportLights(glTF::Asset& r)
case Light::Type_directional:
ail->mType = aiLightSource_DIRECTIONAL; break;
case Light::Type_point:
ail->mType = aiLightSource_POINT; break;
case Light::Type_spot:
ail->mType = aiLightSource_SPOT; break;
case Light::Type_ambient:
ail->mType = aiLightSource_AMBIENT; break;
default: // Light::Type_point
ail->mType = aiLightSource_POINT; break;
}
CopyValue(l.color, ail->mColorAmbient);