diff options
author | Treeki <treeki@gmail.com> | 2010-10-08 23:46:51 +0200 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2010-10-08 23:46:51 +0200 |
commit | c2cd2300ab03a41999b8e4e38cf0d29abb786918 (patch) | |
tree | 8b03994c84a9e7b2be0a6c39d9c85bec7315575a | |
parent | b92673def2816cf8010997c87368d7045944ce63 (diff) | |
download | LayoutStudio-c2cd2300ab03a41999b8e4e38cf0d29abb786918.tar.gz LayoutStudio-c2cd2300ab03a41999b8e4e38cf0d29abb786918.zip |
material structs finished... finally :( testing time now!
-rw-r--r-- | LayoutStudio.pro | 8 | ||||
-rw-r--r-- | README.markdown | 3 | ||||
-rw-r--r-- | lyt/common.h | 14 | ||||
-rw-r--r-- | lyt/materials/alphacompare.cpp | 52 | ||||
-rw-r--r-- | lyt/materials/alphacompare.h | 40 | ||||
-rw-r--r-- | lyt/materials/blendmode.cpp | 47 | ||||
-rw-r--r-- | lyt/materials/blendmode.h | 39 | ||||
-rw-r--r-- | lyt/materials/material.cpp | 21 | ||||
-rw-r--r-- | lyt/materials/material.h | 21 | ||||
-rw-r--r-- | lyt/materials/tevstage.cpp | 72 |
10 files changed, 293 insertions, 24 deletions
diff --git a/LayoutStudio.pro b/LayoutStudio.pro index b087b3e..8665bcd 100644 --- a/LayoutStudio.pro +++ b/LayoutStudio.pro @@ -26,7 +26,9 @@ SOURCES += main.cpp \ lyt/materials/chanctrl.cpp \ lyt/materials/tevswaptable.cpp \ lyt/materials/indirectstage.cpp \ - lyt/materials/tevstage.cpp + lyt/materials/tevstage.cpp \ + lyt/materials/alphacompare.cpp \ + lyt/materials/blendmode.cpp HEADERS += lsmainwindow.h \ lsglobals.h \ lyt/packagebase.h \ @@ -48,7 +50,9 @@ HEADERS += lsmainwindow.h \ lyt/materials/chanctrl.h \ lyt/materials/tevswaptable.h \ lyt/materials/indirectstage.h \ - lyt/materials/tevstage.h + lyt/materials/tevstage.h \ + lyt/materials/alphacompare.h \ + lyt/materials/blendmode.h FORMS += lsmainwindow.ui RESOURCES += resources.qrc diff --git a/README.markdown b/README.markdown index 635bd2a..0aa3ff0 100644 --- a/README.markdown +++ b/README.markdown @@ -28,7 +28,8 @@ GX GPU emulation in the [Dolphin][dol] GameCube/Wii emulator. ### Current (Short-Term) TODO ### - Disassemble code that sets up indirect textures for materials -- Finish other material structs (plus writing) +- Test code for material structs +- Add usd1 handling - Add LYTLayout packing - Add U8 archive support - Add TPL file support diff --git a/lyt/common.h b/lyt/common.h index 2cddffd..c75813b 100644 --- a/lyt/common.h +++ b/lyt/common.h @@ -49,6 +49,20 @@ inline quint32 BitExtract(quint32 value, int count, int start) { return (value & mask) >> (32 - (start + count)); } +inline quint32 BitInsert(quint32 value, int newValue, int count, int start) { + quint32 mask = 0; + for (int i = start; i < start+count; i++) { + mask |= (0x80000000 >> i); + } + + value &= ~mask; + value |= (newValue << (32 - (start + count))) & mask; + return value; +} + + + + QByteArray PadByteArray(QByteArray original, int newLength, char padWith='\0'); diff --git a/lyt/materials/alphacompare.cpp b/lyt/materials/alphacompare.cpp new file mode 100644 index 0000000..a0e2f0f --- /dev/null +++ b/lyt/materials/alphacompare.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + 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/>. +*******************************************************************************/ + +#include "alphacompare.h" +#include "../layout.h" + +LYTAlphaCompare::LYTAlphaCompare() { +} + +void LYTAlphaCompare::dumpToDebug() { + qDebug() << "LYTAlphaCompare @" << (void*)this; + qDebug() << "Comp0:" << comp0 << "- Ref0:" << ref0; + qDebug() << "Comp1:" << comp1 << "- Ref1:" << ref1; + qDebug() << "Op:" << op; +} + + +void LYTAlphaCompare::writeToDataStream(QDataStream &out) { + out << (quint8)(comp0 | (comp1 << 4)); + out << (quint8)op; + out << (quint8)ref0; + out << (quint8)ref1; +} + + +void LYTAlphaCompare::readFromDataStream(QDataStream &in) { + quint8 value; + + in >> (quint8&)value; + comp0 = BitExtract(value, 4, 32 - 4); + comp1 = BitExtract(value, 4, 32 - 8); + + in >> (quint8&)op; + in >> (quint8&)ref0; + in >> (quint8&)ref1; +} + + diff --git a/lyt/materials/alphacompare.h b/lyt/materials/alphacompare.h new file mode 100644 index 0000000..0287252 --- /dev/null +++ b/lyt/materials/alphacompare.h @@ -0,0 +1,40 @@ +/******************************************************************************* + 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 LYTALPHACOMPARE_H +#define LYTALPHACOMPARE_H + +#include "../common.h" +#include "QtCore/QDataStream" + +class LYTAlphaCompare { +public: + LYTAlphaCompare(); + + void writeToDataStream(QDataStream &out); + void readFromDataStream(QDataStream &in); + + void dumpToDebug(); + + quint8 comp0; + quint8 ref0; + quint8 op; + quint8 comp1; + quint8 ref1; +}; + +#endif // LYTALPHACOMPARE_H diff --git a/lyt/materials/blendmode.cpp b/lyt/materials/blendmode.cpp new file mode 100644 index 0000000..d02cd9b --- /dev/null +++ b/lyt/materials/blendmode.cpp @@ -0,0 +1,47 @@ +/******************************************************************************* + 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/>. +*******************************************************************************/ + +#include "blendmode.h" +#include "../layout.h" + +LYTBlendMode::LYTBlendMode() { +} + +void LYTBlendMode::dumpToDebug() { + qDebug() << "LYTBlendMode @" << (void*)this; + qDebug() << "srcFactor:" << srcFactor << "- destFactor:" << destFactor; + qDebug() << "op:" << op << "- type:" << type; +} + + +void LYTBlendMode::writeToDataStream(QDataStream &out) { + out << (quint8)type; + out << (quint8)srcFactor; + out << (quint8)destFactor; + out << (quint8)op; +} + + +void LYTBlendMode::readFromDataStream(QDataStream &in) { + in >> (quint8&)type; + in >> (quint8&)srcFactor; + in >> (quint8&)destFactor; + in >> (quint8&)op; +} + + + diff --git a/lyt/materials/blendmode.h b/lyt/materials/blendmode.h new file mode 100644 index 0000000..5f5847f --- /dev/null +++ b/lyt/materials/blendmode.h @@ -0,0 +1,39 @@ +/******************************************************************************* + 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 LYTBLENDMODE_H +#define LYTBLENDMODE_H + +#include "../common.h" +#include "QtCore/QDataStream" + +class LYTBlendMode { +public: + LYTBlendMode(); + + void writeToDataStream(QDataStream &out); + void readFromDataStream(QDataStream &in); + + void dumpToDebug(); + + quint8 type; + quint8 srcFactor; + quint8 destFactor; + quint8 op; +}; + +#endif // LYTBLENDMODE_H diff --git a/lyt/materials/material.cpp b/lyt/materials/material.cpp index 1c89ae8..f79fd08 100644 --- a/lyt/materials/material.cpp +++ b/lyt/materials/material.cpp @@ -114,7 +114,7 @@ void LYTMaterial::readFromDataStream(QDataStream &in) { this->readIndirectStage(in); } - /*// TevStage + // TevStage tevStages.clear(); for (int i = 0; i < resourceNum.getTevStageNum(); i++) { @@ -135,7 +135,7 @@ void LYTMaterial::readFromDataStream(QDataStream &in) { this->readBlendMode(in); } else { this->hasBlendMode = false; - }*/ + } } @@ -183,3 +183,20 @@ void LYTMaterial::readIndirectStage(QDataStream &in) { this->indTexStages.last().readFromDataStream(in); this->indTexStages.last().dumpToDebug(); } + +void LYTMaterial::readTevStage(QDataStream &in) { + this->tevStages.append(LYTTevStage()); + this->tevStages.last().readFromDataStream(in); + this->tevStages.last().dumpToDebug(); +} + +void LYTMaterial::readAlphaCompare(QDataStream &in) { + this->alphaCompare.readFromDataStream(in); + this->alphaCompare.dumpToDebug(); +} + +void LYTMaterial::readBlendMode(QDataStream &in) { + this->blendMode.readFromDataStream(in); + this->blendMode.dumpToDebug(); +} + diff --git a/lyt/materials/material.h b/lyt/materials/material.h index 43eb62f..bfdf80b 100644 --- a/lyt/materials/material.h +++ b/lyt/materials/material.h @@ -31,6 +31,8 @@ #include "tevswaptable.h" #include "indirectstage.h" #include "tevstage.h" +#include "alphacompare.h" +#include "blendmode.h" class LYTLayout; @@ -55,25 +57,6 @@ public: -class LYTAlphaCompare { -public: - void writeToDataStream(QDataStream &out); - void readFromDataStream(QDataStream &in); - - void dumpToDebug(); - -}; - -class LYTBlendMode { -public: - void writeToDataStream(QDataStream &out); - void readFromDataStream(QDataStream &in); - - void dumpToDebug(); - -}; - - class LYTMaterial { diff --git a/lyt/materials/tevstage.cpp b/lyt/materials/tevstage.cpp index 31e55b1..7244e4e 100644 --- a/lyt/materials/tevstage.cpp +++ b/lyt/materials/tevstage.cpp @@ -23,10 +23,82 @@ LYTTevStage::LYTTevStage() { void LYTTevStage::dumpToDebug() { qDebug() << "LYTTevStage @" << (void*)this; + qDebug() << "TEV order: texCoord" << texCoord << ", colour" << colour << ", texMap" << texMap; + qDebug() << "SwapMode: ras" << rasSwapMode << ", tex" << texSwapMode; + + qDebug() << "Colour In:" << colourInA << colourInB << colourInC << colourInD; + qDebug() << "Op:" << colourOp << ", Bias:" << colourBias << ", Scale:" << colourScale; + qDebug() << "Clamp:" << colourClamp << ", OutReg:" << colourOutReg; + + qDebug() << "Alpha In:" << alphaInA << alphaInB << alphaInC << alphaInD; + qDebug() << "Op:" << alphaOp << ", Bias:" << alphaBias << ", Scale:" << alphaScale; + qDebug() << "Clamp:" << alphaClamp << ", OutReg:" << alphaOutReg; + + qDebug() << "Colour Const:" << colourConst << ", Alpha Const:" << alphaConst; + + qDebug() << "Indirect Stage:" << indStage << ", Format:" << indFormat; + qDebug() << "Bias:" << indBias << ", Matrix:" << indMatrix; + qDebug() << "WrapS:" << indWrapS << ", WrapT:" << indWrapT << ", AddPrev:" << indAddPrev; + qDebug() << "UtcLod:" << indUtcLod << ", AlphaSel:" << indAlphaSel; } void LYTTevStage::writeToDataStream(QDataStream &out) { + char data[0x10]; + qMemSet(data, 0, 0x10); + + // TEV order: + data[0] = texCoord; + colour = data[1]; + data[2] = texMap & 0xFF; + data[3] = BitInsert(data[3], texMap >> 8, 1, 32 - 1); + + // SwapMode: + data[3] = BitInsert(data[3], rasSwapMode, 2, 32 - 3); + data[3] = BitInsert(data[3], texSwapMode, 2, 32 - 5); + + // Colour In: + data[4] = BitInsert(data[4], colourInA, 4, 32 - 4); + data[4] = BitInsert(data[4], colourInB, 4, 32 - 8); + data[5] = BitInsert(data[5], colourInC, 4, 32 - 4); + data[5] = BitInsert(data[5], colourInD, 4, 32 - 8); + + // Colour Op: + data[6] = BitInsert(data[6], colourOp, 4, 32 - 4); + data[6] = BitInsert(data[6], colourBias, 2, 32 - 6); + data[6] = BitInsert(data[6], colourScale, 2, 32 - 8); + data[7] = BitInsert(data[7], colourClamp, 1, 32 - 1); + data[7] = BitInsert(data[7], colourOutReg, 2, 32 - 3); + + // Alpha In: + data[8] = BitInsert(data[8], alphaInA, 4, 32 - 4); + data[8] = BitInsert(data[8], alphaInB, 4, 32 - 8); + data[9] = BitInsert(data[9], alphaInC, 4, 32 - 4); + data[9] = BitInsert(data[9], alphaInD, 4, 32 - 8); + + // Alpha Op: + data[10] = BitInsert(data[10], alphaOp, 4, 32 - 4); + data[10] = BitInsert(data[10], alphaBias, 2, 32 - 6); + data[10] = BitInsert(data[10], alphaScale, 2, 32 - 8); + data[11] = BitInsert(data[11], alphaClamp, 1, 32 - 1); + data[11] = BitInsert(data[11], alphaOutReg, 2, 32 - 3); + + // Constants: + data[7] = BitInsert(data[7], colourConst, 5, 32 - 8); + data[11] = BitInsert(data[11], alphaConst, 5, 32 - 8); + + // Indirect: + data[12] = indStage; + data[15] = BitInsert(data[15], indFormat, 2, 32 - 2); + data[13] = BitInsert(data[13], indBias, 3, 32 - 3); + data[13] = BitInsert(data[13], indMatrix, 4, 32 - 7); + data[14] = BitInsert(data[14], indWrapS, 3, 32 - 3); + data[14] = BitInsert(data[14], indWrapT, 3, 32 - 6); + data[15] = BitInsert(data[15], indAddPrev, 1, 32 - 3); + data[15] = BitInsert(data[15], indUtcLod, 1, 32 - 4); + data[15] = BitInsert(data[15], indAlphaSel, 2, 32 - 6); + + out.writeRawData(data, 0x10); } |