diff options
author | Treeki <treeki@gmail.com> | 2010-10-14 20:17:20 +0200 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2010-10-14 20:17:20 +0200 |
commit | ebcc95da4c26369511caa90d89c5ed06e1e4853a (patch) | |
tree | 6ed445f0204a6e6615088d135c4b29c4309077a4 /lyt/materials | |
parent | fdf8cfec2b795393d7ee901abaf747575067068b (diff) | |
download | LayoutStudio-ebcc95da4c26369511caa90d89c5ed06e1e4853a.tar.gz LayoutStudio-ebcc95da4c26369511caa90d89c5ed06e1e4853a.zip |
brlyt packing added, plus some changes in the existing API (mostly for const correctness). brlyt writing may still need some testing (especially for the material structs)
Diffstat (limited to 'lyt/materials')
-rw-r--r-- | lyt/materials/alphacompare.cpp | 4 | ||||
-rw-r--r-- | lyt/materials/alphacompare.h | 4 | ||||
-rw-r--r-- | lyt/materials/blendmode.cpp | 4 | ||||
-rw-r--r-- | lyt/materials/blendmode.h | 4 | ||||
-rw-r--r-- | lyt/materials/chanctrl.cpp | 6 | ||||
-rw-r--r-- | lyt/materials/chanctrl.h | 4 | ||||
-rw-r--r-- | lyt/materials/indirectstage.cpp | 4 | ||||
-rw-r--r-- | lyt/materials/indirectstage.h | 4 | ||||
-rw-r--r-- | lyt/materials/material.cpp | 82 | ||||
-rw-r--r-- | lyt/materials/material.h | 30 | ||||
-rw-r--r-- | lyt/materials/materialcontainer.h | 76 | ||||
-rw-r--r-- | lyt/materials/tevstage.cpp | 6 | ||||
-rw-r--r-- | lyt/materials/tevstage.h | 4 | ||||
-rw-r--r-- | lyt/materials/tevswaptable.cpp | 6 | ||||
-rw-r--r-- | lyt/materials/tevswaptable.h | 4 | ||||
-rw-r--r-- | lyt/materials/texcoordgen.cpp | 6 | ||||
-rw-r--r-- | lyt/materials/texcoordgen.h | 4 | ||||
-rw-r--r-- | lyt/materials/texmap.cpp | 4 | ||||
-rw-r--r-- | lyt/materials/texmap.h | 4 | ||||
-rw-r--r-- | lyt/materials/texsrt.cpp | 4 | ||||
-rw-r--r-- | lyt/materials/texsrt.h | 4 |
21 files changed, 211 insertions, 57 deletions
diff --git a/lyt/materials/alphacompare.cpp b/lyt/materials/alphacompare.cpp index a0e2f0f..85a9952 100644 --- a/lyt/materials/alphacompare.cpp +++ b/lyt/materials/alphacompare.cpp @@ -21,7 +21,7 @@ LYTAlphaCompare::LYTAlphaCompare() { } -void LYTAlphaCompare::dumpToDebug() { +void LYTAlphaCompare::dumpToDebug() const { qDebug() << "LYTAlphaCompare @" << (void*)this; qDebug() << "Comp0:" << comp0 << "- Ref0:" << ref0; qDebug() << "Comp1:" << comp1 << "- Ref1:" << ref1; @@ -29,7 +29,7 @@ void LYTAlphaCompare::dumpToDebug() { } -void LYTAlphaCompare::writeToDataStream(QDataStream &out) { +void LYTAlphaCompare::writeToDataStream(QDataStream &out) const { out << (quint8)(comp0 | (comp1 << 4)); out << (quint8)op; out << (quint8)ref0; diff --git a/lyt/materials/alphacompare.h b/lyt/materials/alphacompare.h index 0287252..4cc0861 100644 --- a/lyt/materials/alphacompare.h +++ b/lyt/materials/alphacompare.h @@ -25,10 +25,10 @@ class LYTAlphaCompare { public: LYTAlphaCompare(); - void writeToDataStream(QDataStream &out); + void writeToDataStream(QDataStream &out) const; void readFromDataStream(QDataStream &in); - void dumpToDebug(); + void dumpToDebug() const; quint8 comp0; quint8 ref0; diff --git a/lyt/materials/blendmode.cpp b/lyt/materials/blendmode.cpp index d02cd9b..bcbc234 100644 --- a/lyt/materials/blendmode.cpp +++ b/lyt/materials/blendmode.cpp @@ -21,14 +21,14 @@ LYTBlendMode::LYTBlendMode() { } -void LYTBlendMode::dumpToDebug() { +void LYTBlendMode::dumpToDebug() const { qDebug() << "LYTBlendMode @" << (void*)this; qDebug() << "srcFactor:" << srcFactor << "- destFactor:" << destFactor; qDebug() << "op:" << op << "- type:" << type; } -void LYTBlendMode::writeToDataStream(QDataStream &out) { +void LYTBlendMode::writeToDataStream(QDataStream &out) const { out << (quint8)type; out << (quint8)srcFactor; out << (quint8)destFactor; diff --git a/lyt/materials/blendmode.h b/lyt/materials/blendmode.h index 5f5847f..71d8cc0 100644 --- a/lyt/materials/blendmode.h +++ b/lyt/materials/blendmode.h @@ -25,10 +25,10 @@ class LYTBlendMode { public: LYTBlendMode(); - void writeToDataStream(QDataStream &out); + void writeToDataStream(QDataStream &out) const; void readFromDataStream(QDataStream &in); - void dumpToDebug(); + void dumpToDebug() const; quint8 type; quint8 srcFactor; diff --git a/lyt/materials/chanctrl.cpp b/lyt/materials/chanctrl.cpp index 5f32e65..1e3f4f8 100644 --- a/lyt/materials/chanctrl.cpp +++ b/lyt/materials/chanctrl.cpp @@ -21,16 +21,16 @@ LYTChanCtrl::LYTChanCtrl() { } -void LYTChanCtrl::dumpToDebug() { +void LYTChanCtrl::dumpToDebug() const { qDebug() << "LYTChanCtrl @" << (void*)this; qDebug() << "ColourMatSrc:" << colourMatSrc << "- AlphaMatSrc:" << alphaMatSrc; } -void LYTChanCtrl::writeToDataStream(QDataStream &out) { +void LYTChanCtrl::writeToDataStream(QDataStream &out) const { out << (quint8)colourMatSrc; out << (quint8)alphaMatSrc; - out.skipRawData(2); // padding + WritePadding(2, out); } diff --git a/lyt/materials/chanctrl.h b/lyt/materials/chanctrl.h index f0183e1..2224837 100644 --- a/lyt/materials/chanctrl.h +++ b/lyt/materials/chanctrl.h @@ -25,10 +25,10 @@ class LYTChanCtrl { public: LYTChanCtrl(); - void writeToDataStream(QDataStream &out); + void writeToDataStream(QDataStream &out) const; void readFromDataStream(QDataStream &in); - void dumpToDebug(); + void dumpToDebug() const; quint8 colourMatSrc; quint8 alphaMatSrc; diff --git a/lyt/materials/indirectstage.cpp b/lyt/materials/indirectstage.cpp index c1e6d87..362fcaf 100644 --- a/lyt/materials/indirectstage.cpp +++ b/lyt/materials/indirectstage.cpp @@ -21,14 +21,14 @@ LYTIndirectStage::LYTIndirectStage() { } -void LYTIndirectStage::dumpToDebug() { +void LYTIndirectStage::dumpToDebug() const { qDebug() << "LYTIndirectStage @" << (void*)this; qDebug() << "texCoord:" << this->texCoord << "- texMap:" << this->texMap; qDebug() << "wrap_s:" << this->wrap_s << "- wrap_t:" << this->wrap_t; } -void LYTIndirectStage::writeToDataStream(QDataStream &out) { +void LYTIndirectStage::writeToDataStream(QDataStream &out) const { out << (quint8)texCoord; out << (quint8)texMap; out << (quint8)wrap_s; diff --git a/lyt/materials/indirectstage.h b/lyt/materials/indirectstage.h index 8f381bf..c00b091 100644 --- a/lyt/materials/indirectstage.h +++ b/lyt/materials/indirectstage.h @@ -25,10 +25,10 @@ class LYTIndirectStage { public: LYTIndirectStage(); - void writeToDataStream(QDataStream &out); + void writeToDataStream(QDataStream &out) const; void readFromDataStream(QDataStream &in); - void dumpToDebug(); + void dumpToDebug() const; quint8 texCoord; quint8 texMap; diff --git a/lyt/materials/material.cpp b/lyt/materials/material.cpp index a4498c5..a775553 100644 --- a/lyt/materials/material.cpp +++ b/lyt/materials/material.cpp @@ -29,7 +29,7 @@ LYTLayout &LYTMaterial::layout() const { } -void LYTMaterial::dumpToDebug() { +void LYTMaterial::dumpToDebug() const { qDebug() << "LYTMaterial" << name << "@" << (void*)this; for (int i = 0; i < 3; i++) @@ -90,8 +90,86 @@ void LYTMaterial::dumpToDebug() { -void LYTMaterial::writeToDataStream(QDataStream &out) { +void LYTMaterial::writeToDataStream(QDataStream &out) const { WriteFixedLengthASCII(out, name, 0x14); + + for (int i = 0; i < 3; i++) + WriteS10Color(this->colours[i], out); + + for (int i = 0; i < 4; i++) + WriteRGBA8Color(this->tevKColour[i], out); + + + LYTMaterialResourceNum resourceNum; + resourceNum.setTexMapNum(texMaps.count()); + resourceNum.setTexSRTNum(texSRTs.count()); + resourceNum.setTexCoordGenNum(texCoordGens.count()); + resourceNum.setHasChanCtrl(hasChanCtrl); + resourceNum.setHasMatCol(hasMatCol); + resourceNum.setHasTevSwapTable(hasTevSwapTable); + resourceNum.setIndTexSRTNum(indTexSRTs.count()); + resourceNum.setIndTexStageNum(indTexStages.count()); + resourceNum.setTevStageNum(tevStages.count()); + resourceNum.setHasAlphaCompare(hasAlphaCompare); + resourceNum.setHasBlendMode(hasBlendMode); + out << (quint32)resourceNum.value(); + + + // TexMap + for (int i = 0; i < texMaps.count(); i++) { + texMaps.at(i).writeToDataStream(out, this->m_layout); + } + + // TexSRT + for (int i = 0; i < texSRTs.count(); i++) { + texSRTs.at(i).writeToDataStream(out); + } + + // TexCoordGen + for (int i = 0; i < texCoordGens.count(); i++) { + texCoordGens.at(i).writeToDataStream(out); + } + + // ChanCtrl + if (hasChanCtrl) { + chanCtrl.writeToDataStream(out); + } + + // MatCol + if (hasMatCol) { + WriteRGBA8Color(this->matCol, out); + } + + // TevSwapTable + if (hasTevSwapTable) { + tevSwapTable.writeToDataStream(out); + } + + // IndTexSRT + for (int i = 0; i < indTexSRTs.count(); i++) { + indTexSRTs.at(i).writeToDataStream(out); + } + + // IndTexStage + for (int i = 0; i < indTexStages.count(); i++) { + indTexStages.at(i).writeToDataStream(out); + } + + // TevStage + for (int i = 0; i < tevStages.count(); i++) { + tevStages.at(i).writeToDataStream(out); + } + + // AlphaCompare + if (hasAlphaCompare) { + alphaCompare.writeToDataStream(out); + } + + // BlendMode + if (hasBlendMode) { + blendMode.writeToDataStream(out); + } + } void LYTMaterial::readFromDataStream(QDataStream &in) { diff --git a/lyt/materials/material.h b/lyt/materials/material.h index d605244..a42a9d8 100644 --- a/lyt/materials/material.h +++ b/lyt/materials/material.h @@ -43,19 +43,19 @@ public: LYTMaterialResourceNum() : m_value(0) { } LYTMaterialResourceNum(int initValue) : m_value(initValue) { } - quint32 value() { return m_value; } - - int getTexMapNum() { return BitExtract(m_value, 4, 28); } - int getTexSRTNum() { return BitExtract(m_value, 4, 24); } - int getTexCoordGenNum() { return BitExtract(m_value, 4, 20); } - bool hasChanCtrl() { return BitExtract(m_value, 1, 6); } - bool hasMatCol() { return BitExtract(m_value, 1, 4); } - bool hasTevSwapTable() { return BitExtract(m_value, 1, 19); } - bool hasAlphaCompare() { return BitExtract(m_value, 1, 8); } - bool hasBlendMode() { return BitExtract(m_value, 1, 7); } - int getIndTexSRTNum() { return BitExtract(m_value, 2, 17); } - int getIndTexStageNum() { return BitExtract(m_value, 3, 14); } - int getTevStageNum() { return BitExtract(m_value, 5, 9); } + quint32 value() const { return m_value; } + + int getTexMapNum() const { return BitExtract(m_value, 4, 28); } + int getTexSRTNum() const { return BitExtract(m_value, 4, 24); } + int getTexCoordGenNum() const { return BitExtract(m_value, 4, 20); } + bool hasChanCtrl() const { return BitExtract(m_value, 1, 6); } + bool hasMatCol() const { return BitExtract(m_value, 1, 4); } + bool hasTevSwapTable() const { return BitExtract(m_value, 1, 19); } + bool hasAlphaCompare() const { return BitExtract(m_value, 1, 8); } + bool hasBlendMode() const { return BitExtract(m_value, 1, 7); } + int getIndTexSRTNum() const { return BitExtract(m_value, 2, 17); } + int getIndTexStageNum() const { return BitExtract(m_value, 3, 14); } + int getTevStageNum() const { return BitExtract(m_value, 5, 9); } void setTexMapNum(int v) { m_value = BitInsert(m_value, v, 4, 28); } void setTexSRTNum(int v) { m_value = BitInsert(m_value, v, 4, 24); } @@ -83,10 +83,10 @@ public: ~LYTMaterial(); - void writeToDataStream(QDataStream &out); + void writeToDataStream(QDataStream &out) const; void readFromDataStream(QDataStream &in); - void dumpToDebug(); + void dumpToDebug() const; LYTLayout &layout() const; diff --git a/lyt/materials/materialcontainer.h b/lyt/materials/materialcontainer.h new file mode 100644 index 0000000..4787bfc --- /dev/null +++ b/lyt/materials/materialcontainer.h @@ -0,0 +1,76 @@ +/******************************************************************************* + This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) + Copyright (c) 2010 Treeki (treeki@gmail.com) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 2.0. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License 2.0 for more details. + + You should have received a copy of the GNU General Public License 2.0 + along with this program. If not, see <http://www.gnu.org/licenses/>. +*******************************************************************************/ + +#ifndef LYTMATERIALCONTAINER_H +#define LYTMATERIALCONTAINER_H + +#include <QtCore/QList> +#include <QtCore/QPair> +#include "material.h" + +typedef QPair<QString, LYTMaterial *> LYTMaterialContainerEntry; + +class LYTMaterialContainer { +public: + LYTMaterialContainer() { }; + + QList<LYTMaterialContainerEntry> list; + + + void addMaterial(QString name, LYTMaterial *material) { + LYTMaterialContainerEntry entry; + entry.first = name; + entry.second = material; + this->list.append(entry); + } + + void clear() { this->list.clear(); } + int count() const { return this->list.count(); } + + + LYTMaterial *getMaterialByName(QString name) const { + foreach (LYTMaterialContainerEntry entry, this->list) { + if (entry.first == name) + return entry.second; + } + + return 0; + } + + LYTMaterial *getMaterialByIndex(int index) const { + return this->list.at(index).second; + } + + int getIndexOfName(QString name) const { + int i = 0; + + foreach (LYTMaterialContainerEntry entry, this->list) { + if (entry.first == name) + return i; + i += 1; + } + + return -1; + } + + + QString getNameOfIndex(int index) const { + return this->list.at(index).first; + } +}; + +#endif // LYTMATERIALCONTAINER_H diff --git a/lyt/materials/tevstage.cpp b/lyt/materials/tevstage.cpp index 7244e4e..768e252 100644 --- a/lyt/materials/tevstage.cpp +++ b/lyt/materials/tevstage.cpp @@ -21,7 +21,7 @@ LYTTevStage::LYTTevStage() { } -void LYTTevStage::dumpToDebug() { +void LYTTevStage::dumpToDebug() const { qDebug() << "LYTTevStage @" << (void*)this; qDebug() << "TEV order: texCoord" << texCoord << ", colour" << colour << ", texMap" << texMap; qDebug() << "SwapMode: ras" << rasSwapMode << ", tex" << texSwapMode; @@ -43,13 +43,13 @@ void LYTTevStage::dumpToDebug() { } -void LYTTevStage::writeToDataStream(QDataStream &out) { +void LYTTevStage::writeToDataStream(QDataStream &out) const { char data[0x10]; qMemSet(data, 0, 0x10); // TEV order: data[0] = texCoord; - colour = data[1]; + data[1] = colour; data[2] = texMap & 0xFF; data[3] = BitInsert(data[3], texMap >> 8, 1, 32 - 1); diff --git a/lyt/materials/tevstage.h b/lyt/materials/tevstage.h index 6132800..d052d9a 100644 --- a/lyt/materials/tevstage.h +++ b/lyt/materials/tevstage.h @@ -25,10 +25,10 @@ class LYTTevStage { public: LYTTevStage(); - void writeToDataStream(QDataStream &out); + void writeToDataStream(QDataStream &out) const; void readFromDataStream(QDataStream &in); - void dumpToDebug(); + void dumpToDebug() const; // TEV order: int texCoord; diff --git a/lyt/materials/tevswaptable.cpp b/lyt/materials/tevswaptable.cpp index 05ed497..a13a491 100644 --- a/lyt/materials/tevswaptable.cpp +++ b/lyt/materials/tevswaptable.cpp @@ -21,18 +21,18 @@ LYTTevSwapTable::LYTTevSwapTable() { } -void LYTTevSwapTable::dumpToDebug() { +void LYTTevSwapTable::dumpToDebug() const { qDebug() << "LYTTevSwapTable @" << (void*)this; for (int i = 0; i < 4; i++) { - LYTTevSwapMode *m = &mode[i]; + const LYTTevSwapMode *m = &mode[i]; qDebug() << i << ":" << m->red << "," << m->green << "," << m->blue << "," << m->alpha; } } -void LYTTevSwapTable::writeToDataStream(QDataStream &out) { +void LYTTevSwapTable::writeToDataStream(QDataStream &out) const { for (int i = 0; i < 4; i++) { quint8 val = 0; val |= mode[i].red; diff --git a/lyt/materials/tevswaptable.h b/lyt/materials/tevswaptable.h index a73facf..608df45 100644 --- a/lyt/materials/tevswaptable.h +++ b/lyt/materials/tevswaptable.h @@ -32,10 +32,10 @@ class LYTTevSwapTable { public: LYTTevSwapTable(); - void writeToDataStream(QDataStream &out); + void writeToDataStream(QDataStream &out) const; void readFromDataStream(QDataStream &in); - void dumpToDebug(); + void dumpToDebug() const; LYTTevSwapMode mode[4]; }; diff --git a/lyt/materials/texcoordgen.cpp b/lyt/materials/texcoordgen.cpp index 3d2ac75..91bdad9 100644 --- a/lyt/materials/texcoordgen.cpp +++ b/lyt/materials/texcoordgen.cpp @@ -21,17 +21,17 @@ LYTTexCoordGen::LYTTexCoordGen() { } -void LYTTexCoordGen::dumpToDebug() { +void LYTTexCoordGen::dumpToDebug() const { qDebug() << "LYTTexCoordGen @" << (void*)this; qDebug() << "GenType:" << genType << "- Mtx:" << mtx << "- Src:" << src; } -void LYTTexCoordGen::writeToDataStream(QDataStream &out) { +void LYTTexCoordGen::writeToDataStream(QDataStream &out) const { out << (quint8)genType; out << (quint8)src; out << (quint8)mtx; - out.skipRawData(1); // padding + WritePadding(1, out); } diff --git a/lyt/materials/texcoordgen.h b/lyt/materials/texcoordgen.h index f65750c..5756b70 100644 --- a/lyt/materials/texcoordgen.h +++ b/lyt/materials/texcoordgen.h @@ -25,10 +25,10 @@ class LYTTexCoordGen { public: LYTTexCoordGen(); - void writeToDataStream(QDataStream &out); + void writeToDataStream(QDataStream &out) const; void readFromDataStream(QDataStream &in); - void dumpToDebug(); + void dumpToDebug() const; quint8 genType; quint8 src; diff --git a/lyt/materials/texmap.cpp b/lyt/materials/texmap.cpp index 74fb7a9..4991139 100644 --- a/lyt/materials/texmap.cpp +++ b/lyt/materials/texmap.cpp @@ -21,14 +21,14 @@ LYTTexMap::LYTTexMap() { } -void LYTTexMap::dumpToDebug() { +void LYTTexMap::dumpToDebug() const { qDebug() << "LYTTexMap @" << (void*)this << ":" << textureName; qDebug() << "- wrap_s:" << wrap_s << "- wrap_t:" << wrap_t; qDebug() << "- mag_filter:" << mag_filter << "- min_filter:" << min_filter; } -void LYTTexMap::writeToDataStream(QDataStream &out, LYTLayout &layout) { +void LYTTexMap::writeToDataStream(QDataStream &out, LYTLayout &layout) const { quint16 texNum = layout.m_textureRefs.indexOf(textureName); out << (quint16)texNum; diff --git a/lyt/materials/texmap.h b/lyt/materials/texmap.h index e630a39..1200080 100644 --- a/lyt/materials/texmap.h +++ b/lyt/materials/texmap.h @@ -27,10 +27,10 @@ class LYTTexMap { public: LYTTexMap(); - void writeToDataStream(QDataStream &out, LYTLayout &layout); + void writeToDataStream(QDataStream &out, LYTLayout &layout) const; void readFromDataStream(QDataStream &in, LYTLayout &layout); - void dumpToDebug(); + void dumpToDebug() const; QString textureName; int wrap_s; diff --git a/lyt/materials/texsrt.cpp b/lyt/materials/texsrt.cpp index 7ffc83e..55ddb9c 100644 --- a/lyt/materials/texsrt.cpp +++ b/lyt/materials/texsrt.cpp @@ -21,7 +21,7 @@ LYTTexSRT::LYTTexSRT() { } -void LYTTexSRT::dumpToDebug() { +void LYTTexSRT::dumpToDebug() const { qDebug() << "LYTTexSRT @" << (void*)this; qDebug() << "Scale:" << xScale << "," << yScale; qDebug() << "Rotation:" << rotate; @@ -29,7 +29,7 @@ void LYTTexSRT::dumpToDebug() { } -void LYTTexSRT::writeToDataStream(QDataStream &out) { +void LYTTexSRT::writeToDataStream(QDataStream &out) const { out << (float)xTrans; out << (float)yTrans; out << (float)rotate; diff --git a/lyt/materials/texsrt.h b/lyt/materials/texsrt.h index 6bcee02..8841c18 100644 --- a/lyt/materials/texsrt.h +++ b/lyt/materials/texsrt.h @@ -25,10 +25,10 @@ class LYTTexSRT { public: LYTTexSRT(); - void writeToDataStream(QDataStream &out); + void writeToDataStream(QDataStream &out) const; void readFromDataStream(QDataStream &in); - void dumpToDebug(); + void dumpToDebug() const; float xTrans; float yTrans; |